title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Four Boxplots on One Figure MathPlotLib | 37,863,657 | <p>So I have multiple data files, all of which I am using dataframes in order to easily process the information. All of the files are NetCDF files. I am trying to plot 4 boxplot graphs on the same figure, so that they all are easily able to be compared (I am looking at how averages across the same time selections peak ... | 1 | 2016-06-16T15:38:16Z | 37,865,923 | <p>You are only getting three graphs because you are giving <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplot" rel="nofollow">subplot</a> the wrong arguments and overwriting axes you previously created.
From the documentation:</p>
<pre><code>subplot(nrows, ncols, plot_number)
</code></pre>
... | 1 | 2016-06-16T17:37:34Z | [
"python",
"matplotlib",
"python-xarray"
] |
Pandas.dataframe.query() - fetch not null rows (Pandas equivalent to SQL: "IS NOT NULL") | 37,863,660 | <p>I am fetching the rows with some values from pandas dataframe with the following code. I need to convert this code to pandas.query(). </p>
<pre><code>results= rs_gp[rs_gp['Col1'].notnull()]
</code></pre>
<p>When I convert to: <code>results= rs_gp.query('Col1!=None')</code></p>
<p>It gives me the error 'None is no... | 1 | 2016-06-16T15:38:33Z | 37,864,482 | <p>try this:</p>
<pre><code>rs_gp.query('Col1 == Col1')
</code></pre>
<p>Demo:</p>
<pre><code>In [42]: df = pd.DataFrame({'Col1':['aaa', np.nan, 'bbb', None, '', 'ccc']})
In [43]: df
Out[43]:
Col1
0 aaa
1 NaN
2 bbb
3 None
4
5 ccc
In [44]: df.query('Col1 == Col1')
Out[44]:
Col1
0 aaa
2 bbb
4
5 ccc
... | 0 | 2016-06-16T16:18:34Z | [
"python",
"pandas",
"dataframe"
] |
SparkStreaming, RabbitMQ and MQTT in python using pika | 37,863,801 | <p>Just to make things tricky, I'd like to consume messages from the rabbitMQ queue. Now I know there is a plugin for MQTT on rabbit (<a href="https://www.rabbitmq.com/mqtt.html">https://www.rabbitmq.com/mqtt.html</a>). </p>
<p>However I cannot seem to make an example work where Spark consumes a message that has been ... | 13 | 2016-06-16T15:46:18Z | 38,027,189 | <p>From the <code>MqttAsyncClient</code> Javadoc, the server URI must have one of the following schemes: <code>tcp://</code>, <code>ssl://</code>, or <code>local://</code>. You need to change your <code>brokerUrl</code> above to have one of these schemes.</p>
<p>For more information, here's a link to the source for <... | 2 | 2016-06-25T09:55:42Z | [
"python",
"apache-spark",
"rabbitmq",
"mqtt",
"pika"
] |
SparkStreaming, RabbitMQ and MQTT in python using pika | 37,863,801 | <p>Just to make things tricky, I'd like to consume messages from the rabbitMQ queue. Now I know there is a plugin for MQTT on rabbit (<a href="https://www.rabbitmq.com/mqtt.html">https://www.rabbitmq.com/mqtt.html</a>). </p>
<p>However I cannot seem to make an example work where Spark consumes a message that has been ... | 13 | 2016-06-16T15:46:18Z | 38,172,737 | <p>It looks like you are using wrong port number. Assuming that:</p>
<ul>
<li>you have a local instance of RabbitMQ running with default settings and you've enabled MQTT plugin (<code>rabbitmq-plugins enable rabbitmq_mqtt</code>) and restarted RabbitMQ server</li>
<li>included <code>spark-streaming-mqtt</code> when ex... | 2 | 2016-07-03T17:51:21Z | [
"python",
"apache-spark",
"rabbitmq",
"mqtt",
"pika"
] |
Use glob to find arbirary length numbers | 37,863,953 | <p>I'm looking for the glob-pattern that find all files containing the pattern <code>myfile_[SomeNumber].txt</code></p>
<p>My naive attempt was </p>
<pre><code>glob.glob("myfile_[0-9]*.txt")
</code></pre>
<p>but this also find all files on the form <code>myfile_[SomeNumber][AnyStuff].txt</code></p>
<p>This answer s... | 2 | 2016-06-16T15:53:42Z | 37,864,354 | <p>You are probably confusing regular expression syntax with glob constructs. <code>[0-9]*</code> in globbing means "a single digit followed by zero or more of <em>any</em> character". So drop the <code>*</code>.</p>
<p>In <em>extended globbing</em> there is a qualifier of "one or more", but that is not supported b... | 3 | 2016-06-16T16:11:23Z | [
"python",
"glob"
] |
PIL - apply the same operation to every pixel | 37,863,967 | <p>I create an image and fill the pixels:</p>
<pre><code>img = Image.new( 'RGB', (2000,2000), "black") # create a new black image
pixels = img.load() # create the pixel map
for i in range(img.size[0]): # for every pixel:
for j in range(img.size[1]):
#do some stuff that requires i and j as parameter
</cod... | 4 | 2016-06-16T15:54:15Z | 37,868,135 | <p><em>Note: I will first answer the question, then propose an, in my opinion, better alternative</em></p>
<h2>Answering the question</h2>
<p>It is hard to give advice without knowing what changes you intend to apply and whether the loading of the image as a PIL image is part of the question or a given.</p>
<ul>
<li... | 1 | 2016-06-16T19:45:11Z | [
"python",
"python-imaging-library"
] |
pandas dataframe list partial string matching python | 37,864,085 | <p>I have a dataframe df:</p>
<p>df: </p>
<pre><code> chr gene_name
0 1 ARF3
1 1 ABC
2 1 ARF3, ENSG123
3 1 ENSG,ARF3
4 1 ANG
5 2 XVY
6 2 PQR
7 3 RST
8 4 ... | 2 | 2016-06-16T15:59:04Z | 37,864,171 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.contains.html" rel="nofollow"><code>contains</code></a> with <code>join</code> all values with <code>|</code> (<code>or</code>):</p>
<pre><code>gene_list = ['ARF3','ABC' ]
print ('|'.join(gene_list))
ARF3|ABC
print (df.ge... | 0 | 2016-06-16T16:03:21Z | [
"python",
"list",
"pandas",
"dataframe"
] |
how to get equation for nonlinear mutivariate regression in which one variable is dependent on other two independent variables in python | 37,864,097 | <p>I have set of 5000 data points of like_so_ (x,y,z) for eg (0,1,50)
where x=1,y=2,z=120.with help of these 5000 enteries,i have to get an equation in<br>
which given x and y ,equation should be able to get value of z</p>
| 1 | 2016-06-16T15:59:43Z | 37,887,488 | <p>You can use <a href="http://statsmodels.sourceforge.net/devel/generated/statsmodels.regression.linear_model.OLS.html" rel="nofollow"><code>statsmodels.ols</code></a>. Some sample data - assuming you can create a <code>pd.DataFrame</code> from your <code>(x, y, z)</code> data:</p>
<pre><code>import pandas as pd
df =... | 0 | 2016-06-17T17:50:53Z | [
"python",
"numpy",
"pandas",
"dataframe",
"machine-learning"
] |
Apply color to specific cells with openpyxl | 37,864,152 | <p>I'm trying to apply the color blue to a row of cells, but when I do it doesn't return an error or make any changes.</p>
<pre><code>wb = load_workbook(filename='concentrated.xlsx')
ws2 = wb.get_sheet_by_name('Data in')
HeaderFill = PatternFill(start_color='002b43', end_color='002b43', fill_type='solid')
for cell i... | 0 | 2016-06-16T16:02:11Z | 37,864,536 | <p>Well, you're not actually assigning HeaderFill to anything in your loop. The correct thing to assign it to is the <strong>fill</strong> property of the cell.</p>
<p>So:</p>
<pre><code>for row in ws2['A3':'O3']:
for cell in row:
cell.fill = HeaderFill
</code></pre>
<p>EDIT:
Thanks to Charlie Clark for ... | 1 | 2016-06-16T16:21:16Z | [
"python",
"xlsx",
"openpyxl"
] |
How do I add a colorbar to an image while saving it? | 37,864,160 | <p>I have a 2 dimensional matrix, say <code>img</code> which I want to save as in image, using the <code>'hot'</code> colormap. The following code</p>
<pre><code>import matplotlib.pyplot as plt
plt.imsave("out.jpg", img, cmap = 'hot')
</code></pre>
<p>allows me to do this. However, I want to save the colorbar along ... | 1 | 2016-06-16T16:02:34Z | 37,864,551 | <p>I'm not sure how to add a colorbar to your image before you save it like you want to, and I'm not even sure if that's possible. But I can provide you with a way to plot your image, add the colorbar, and save it, but format it the way you want. Try something like the following</p>
<pre><code>import matplotlib.pyplot... | 2 | 2016-06-16T16:22:00Z | [
"python",
"matplotlib",
"data-visualization"
] |
Transpose column to row with Spark | 37,864,222 | <p>I'm trying to transpose some columns of my table to row.
I'm using Python and Spark 1.5.0. Here is my initial table:</p>
<pre><code>+-----+-----+-----+-------+
| A |col_1|col_2|col_...|
+-----+-------------------+
| 1 | 0.0| 0.6| ... |
| 2 | 0.6| 0.7| ... |
| 3 | 0.5| 0.9| ... |
| ...| ...| ... | 3 | 2016-06-16T16:06:13Z | 37,864,698 | <p>Use flatmap. Something like below should work</p>
<pre><code>from pyspark.sql import Row
def rowExpander(row):
rowDict = row.asDict()
valA = rowDict.pop('A')
for k in rowDict:
yield Row(**{'A': valA , 'colID' = k, 'colValue' : row[k]})
newDf = sqlContext.createDataFrame(df.rdd.flatMap(rowExpan... | 1 | 2016-06-16T16:29:18Z | [
"python",
"apache-spark",
"pivot",
"transpose"
] |
Transpose column to row with Spark | 37,864,222 | <p>I'm trying to transpose some columns of my table to row.
I'm using Python and Spark 1.5.0. Here is my initial table:</p>
<pre><code>+-----+-----+-----+-------+
| A |col_1|col_2|col_...|
+-----+-------------------+
| 1 | 0.0| 0.6| ... |
| 2 | 0.6| 0.7| ... |
| 3 | 0.5| 0.9| ... |
| ...| ...| ... | 3 | 2016-06-16T16:06:13Z | 37,865,027 | <p>The Spark local linear algebra libraries are presently very weak: and they do not include basic operations as the above.</p>
<p>There is a JIRA for fixing this for Spark 2.1 - but that will not help you <em>today</em>.</p>
<p>Something to consider: performing a transpose will likely require completely shuffling th... | 2 | 2016-06-16T16:47:49Z | [
"python",
"apache-spark",
"pivot",
"transpose"
] |
Transpose column to row with Spark | 37,864,222 | <p>I'm trying to transpose some columns of my table to row.
I'm using Python and Spark 1.5.0. Here is my initial table:</p>
<pre><code>+-----+-----+-----+-------+
| A |col_1|col_2|col_...|
+-----+-------------------+
| 1 | 0.0| 0.6| ... |
| 2 | 0.6| 0.7| ... |
| 3 | 0.5| 0.9| ... |
| ...| ...| ... | 3 | 2016-06-16T16:06:13Z | 37,865,645 | <p>It is relatively simple to do with basic Spark SQL functions.</p>
<p><strong>Python</strong></p>
<pre><code>from pyspark.sql.functions import array, col, explode, struct, lit
df = sc.parallelize([(1, 0.0, 0.6), (1, 0.6, 0.7)]).toDF(["A", "col_1", "col_2"])
def to_long(df, by):
# Filter dtypes and split into... | 4 | 2016-06-16T17:20:53Z | [
"python",
"apache-spark",
"pivot",
"transpose"
] |
Redirection from index to a post fails while solving prevention duplicate vote | 37,864,419 | <p>I want to save the votes of an user of each post in order to prevent duplicate vote. The idea is to save the upvotes in 'liked_eintraege'. The user should only be able to vote on the result page, not index page. Hence I added it to the result view.</p>
<p>Currently if you upvote a post, the points go up but the pro... | 1 | 2016-06-16T16:15:23Z | 37,927,816 | <p>This fixed my problem!</p>
<pre><code>liked_eintraege = request.user.liked_eintraege.all()
</code></pre>
<p>instead of filtering it (filter(id__in=[eintrag.id for eintrag in eintraege])), because the template already does this! Thanks anyway.</p>
| 1 | 2016-06-20T16:48:43Z | [
"python",
"django",
"django-templates",
"django-views"
] |
Data Loss reading from one file, processing and writing to another? Python | 37,864,425 | <p>I wrote a script to transform a large 4MB textfile with 40k+ lines of unordered data to a specifically formatted and easier to deal with CSV file.</p>
<p><strong>Problem</strong>:</p>
<p>Analyzing my file sizes, it appears i've lost over 1MB of data (20K Lines | <em>edit:</em> original file was 7MB so lost ~4MB of... | 2 | 2016-06-16T16:15:45Z | 37,864,799 | <p>I've rewritten the main loop that seems fishy to me, using csv package.</p>
<p>Your reformo_sort routine is incomplet and syntaxically incorrect, with empty elif blocks and missing processing, so I got incomplete lines, but that should work much better than your code. Note the usage of csv, the "binary" flag, the s... | 1 | 2016-06-16T16:35:07Z | [
"python",
"file",
"csv",
"io"
] |
How to selectively toggle OpenCV's VideoWriter based on user actions | 37,864,445 | <p>Suppose I have a number of video clips which are supposed to show a particular sequence of steps but when the clips were created they may have included unwanted action before or after the event.</p>
<p>Would it be possible to use OpenCV to automatically play the video frame by frame so an operator can then hit a k... | 1 | 2016-06-16T16:17:03Z | 37,900,819 | <p>After thinking about it, writing the video frame by frame wouldn't be a great use of resources and might not scale.</p>
<p>I'll expand this code to write the event data to a CSV file and use that in conjunction with MoviePy to extract the subclips based on the timestamps recorded when the left mouse button was down... | 1 | 2016-06-18T19:23:33Z | [
"python",
"opencv"
] |
Numpy or pandas: test whether upper or lower bound is reached in array / series, and which is reached first | 37,864,466 | <p>I have a pandas Series.</p>
<p>I need to check whether a lower or upper bound is reached within the series.</p>
<p>In the event of both lower and upper bound being reached, I need to know <strong>which is reached first</strong>.</p>
<p>I can use the <code>.max()</code> and <code>.min()</code> functions to determi... | 2 | 2016-06-16T16:17:50Z | 37,864,688 | <pre><code>s = pd.Series(np.sin(np.arange(0, 7, .1)))
upper_bound = 0.5
lower_bound = -0.5
filtered = s[(s >= upper_bound) | (s <= lower_bound)]
first_crossing = None
if not filtered.empty:
first_crossing = 'UPPER' if filtered.index[0] >= upper_bound else 'LOWER'
>>> first_crossing
'UPPER'
</co... | 2 | 2016-06-16T16:28:27Z | [
"python",
"numpy",
"pandas"
] |
Append spark Dstream to a single file in python | 37,864,526 | <p>I have a program reading Kafka and printing output in spark. I need this output to be appended to a single file..
my code writes to a folder. which spark writes to multiple files and then I have another utility which will aggregate the results from files.</p>
<p>Is there any simple way to append data from multiple ... | -1 | 2016-06-16T16:20:46Z | 37,875,786 | <p>I could do it using foreachRDD</p>
<pre><code>def tpprint(val, num=10):
"""
Print the first num elements of each RDD generated in this DStream.
@param num: the number of elements from the first will be printed.
"""
def takeAndPrint(time, rdd):
taken = rdd.take(num + 1)
print("###... | 0 | 2016-06-17T07:38:58Z | [
"python",
"apache-spark",
"pyspark"
] |
Matplotlib and Ipython-notebook: Displaying exactly the figure that will be saved | 37,864,735 | <p>I am using ipython-notebook a lot at the moment for numerical analysis and plotting of data. In the process of preparing publication quality plots there is a lot of tweaking to get the layout just right, however I can't get ipython/matplotlib to show me what I will be saving in the browser. Making the process more... | 2 | 2016-06-16T16:31:23Z | 37,866,560 | <p>The behavior is due to the fact that the magic <code>%matplotlib inline</code> defaults to using the
<code>bbox_inches='tight'</code> when rendering inline.</p>
<p>I know you asked about changing the behavior of <code>plt.show()</code>, but alternatively, you could change the behavior of <code>savefig()</code> to ... | 1 | 2016-06-16T18:16:39Z | [
"python",
"matplotlib",
"ipython",
"ipython-notebook",
"jupyter-notebook"
] |
Matplotlib and Ipython-notebook: Displaying exactly the figure that will be saved | 37,864,735 | <p>I am using ipython-notebook a lot at the moment for numerical analysis and plotting of data. In the process of preparing publication quality plots there is a lot of tweaking to get the layout just right, however I can't get ipython/matplotlib to show me what I will be saving in the browser. Making the process more... | 2 | 2016-06-16T16:31:23Z | 37,879,281 | <p>As noted by @andrew, the ipython magics are enforcing <code>bbox_inches='tight'</code> by default. This can be overridden using other magics as explained in the <a href="http://ipython.readthedocs.io/en/stable/interactive/magics.html" rel="nofollow" title="ipython documentation">ipython documentation</a>:</p>
<pre... | 2 | 2016-06-17T10:29:48Z | [
"python",
"matplotlib",
"ipython",
"ipython-notebook",
"jupyter-notebook"
] |
python xlwt tries to overwrite existing sheet rather than create new sheet | 37,864,767 | <p>I have a simple app with a GUI that takes in a number of presets, runs some tests on them, and saves the results to an excel sheet. My problem is, each time I change the presets and hit the button, the program attempts to overwrite the data that was created in the last test, rather than create a new sheet like I wan... | 0 | 2016-06-16T16:33:05Z | 37,868,126 | <p>I solved this issue. For whoever is interested, look at the nested for-loop around the sheet.write() functions. Notice that the way the index is set up, the function is commanded to write to the same cells for every value in the array A2. This causes an exception as the program attempts to overwrite cells.</p>
| 0 | 2016-06-16T19:44:58Z | [
"python",
"debugging",
"exception",
"xls",
"xlwt"
] |
Validating a field in Create Profile Form | 37,864,849 | <p>I am trying to build a Create Profile Form after registration and my codes are below.Its already working only for a slight problem,that is,if the <code>name</code> field of <code>Profile</code> model matches one in database,django brings an error message <code>column slug is not unique</code> .I see that slug field ... | 0 | 2016-06-16T16:38:02Z | 37,872,448 | <p><code>ModelForm</code>s actually <a href="https://docs.djangoproject.com/en/1.9/ref/models/instances/#validating-objects" rel="nofollow">validate uniqueness</a> as part of the <code>is_valid()</code> checks. </p>
<p>The problem in your case is that you are manually setting the <code>slug</code> after running <code>... | 0 | 2016-06-17T03:04:22Z | [
"python",
"django"
] |
Python OS symlink and .json.gz files | 37,864,850 | <p>I am creating a symlink with Python. First, I check if the file exists and then create the symlink.</p>
<pre><code>import os
project = 'test'
if os.path.isfile("../../project/json/nodes1.json.gz"):
os.symlink("../../project/json/nodes1.json.gz","../simulations/"+project+"/nodes1.json.gz")
</code></pre>
<p>How... | 2 | 2016-06-16T16:38:03Z | 37,864,989 | <p>Unless you specify the <code>dir_fd</code> argument to the <a href="https://docs.python.org/3/library/os.html#os.symlink" rel="nofollow"><code>os.symlink()</code></a> function, you need to specify the absolute path for both <code>src</code> and <code>dst</code> argument. </p>
| 1 | 2016-06-16T16:46:27Z | [
"python",
"json",
"gzip"
] |
Python OS symlink and .json.gz files | 37,864,850 | <p>I am creating a symlink with Python. First, I check if the file exists and then create the symlink.</p>
<pre><code>import os
project = 'test'
if os.path.isfile("../../project/json/nodes1.json.gz"):
os.symlink("../../project/json/nodes1.json.gz","../simulations/"+project+"/nodes1.json.gz")
</code></pre>
<p>How... | 2 | 2016-06-16T16:38:03Z | 37,866,300 | <p>symlink paths are relative to the directory where the symlink lives. Your real file is two levels up from the current directory but your symlink is only one level up and then an extra level deep. If I make up names for your parent directories, it would be something like</p>
<pre><code>current directory aaa/bbb/... | 1 | 2016-06-16T18:00:50Z | [
"python",
"json",
"gzip"
] |
Altering form fields in django | 37,864,906 | <p>I'm a beginner in Django. I'm just lost why this wouldn't work.</p>
<p>I'm trying to initialize fields with optgroup and its options</p>
<p>in views.py</p>
<pre><code>class SystemDetailView(DetailView):
"""Detail view for Systems"""
form_class = system_form()
model = System
template_name = 'systems/system_detail... | 2 | 2016-06-16T16:41:22Z | 37,864,957 | <pre><code>form_class = system_form()
</code></pre>
<p>The thing is, <em>system_form</em> is an <em>instance method</em>. It means to call it you need an instance of <em>SystemDetailView</em> while you clearly don't have one while creating <em>SystemDetailView</em>.</p>
<p>It seems you just need a function that retur... | 1 | 2016-06-16T16:44:42Z | [
"python",
"django"
] |
pandas to loop through DataFrames and keep only specified column headings. Error results if specified heading is not in DataFrame | 37,865,007 | <p>I want to use pandas in python to loop through multiple DataFrames and keep only headings from a specified keep_col list. The code results in an error if a DataFrame does not contain a specified heading (KeyError: "['str2'] not in index").</p>
<p>The following pandas code creates 2 example DataFrames with differing... | 1 | 2016-06-16T16:47:06Z | 37,865,091 | <p>you can use <a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.DataFrame.filter.html" rel="nofollow">filter()</a> function in conjunction with RegEx:</p>
<pre><code>In [79]: mask = r'^(?:A|str2)$'
In [80]: df1.filter(regex=mask)
Out[80]:
A str2
0 -1.190226 -0.123637
1 -1.7... | 1 | 2016-06-16T16:51:31Z | [
"python",
"pandas",
"multiple-columns",
"heading"
] |
pandas to loop through DataFrames and keep only specified column headings. Error results if specified heading is not in DataFrame | 37,865,007 | <p>I want to use pandas in python to loop through multiple DataFrames and keep only headings from a specified keep_col list. The code results in an error if a DataFrame does not contain a specified heading (KeyError: "['str2'] not in index").</p>
<p>The following pandas code creates 2 example DataFrames with differing... | 1 | 2016-06-16T16:47:06Z | 37,865,410 | <p>You can use a list comprehension to generate a list of all column headers that are in <code>keep_col</code>. </p>
<pre><code>new_df1 = df1[[c for c in df1.columns if c in keep_col]]
new_df2 = df1[[c for c in df2.columns if c in keep_col]]
print new_df1
>>>
A str2
0 1.480978 0.369485
1 -0.... | 0 | 2016-06-16T17:08:35Z | [
"python",
"pandas",
"multiple-columns",
"heading"
] |
Canvas instruction invisible in Kivy | 37,865,041 | <p>I want to create a <code>TextInput</code> and modify its canvas to have a white <code>RoundedRectangle</code> in the background. I made the <code>background_color</code> transparent, but I don't see that rectangle behind the <code>TextInput</code>.<br>
I've tried to instead draw on <code>canvas.before</code> and <co... | 0 | 2016-06-16T16:48:34Z | 37,886,471 | <p>Simple! You set <code>Color</code> in canvas which is set to (some?) other components too (probably via OpenGL directly). Therefore you have to "unset" it - or better said set it to the default <code>Color</code>, which you have already access to:</p>
<pre><code>from kivy.lang import Builder
from kivy.base import r... | 0 | 2016-06-17T16:40:54Z | [
"python",
"python-3.x",
"kivy"
] |
Are "dummy URLs" required to make function calls to Flask from the front-end? | 37,865,055 | <p>I am making my first web app with Flask wherein a database of drinks is displayed on the front-end based on selected ingredients. Then the user selects a drink and an in-page pop-up appears with some drink info and a button "make", when the user hits "make" it calls some python code on the back end (Flask) to contro... | 0 | 2016-06-16T16:49:33Z | 37,865,699 | <p>As others mentioned, you can secure the endpoint so that a user has to provide credentials to issue a successful request to that endpoint.</p>
<p>In addition, your endpoint should be using proper HTTP semantics if its creating / updating data. i.e. <code>POST</code> to create a drink, <code>PUT</code> to update a ... | 0 | 2016-06-16T17:23:47Z | [
"python",
"flask"
] |
How to get elements of one pandas dataframe based on the index from another in Python? | 37,865,173 | <p>I have some data that looks largely like the following:</p>
<pre><code>y=numpy.random.uniform(0,1,10)
yx_index=[2,5,6,8]
yx=numpy.random.normal(0,1,4)
sety=pandas.DataFrame(y,columns=['set_y'])
subset_yx=pandas.DataFrame(yx,columns=['subset'],index=yx_index)
</code></pre>
<p>output:</p>
<pre><code>set_y=
... | 1 | 2016-06-16T16:55:36Z | 37,865,215 | <p>you can use one of many available <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#different-choices-for-indexing" rel="nofollow">indexers</a>. I would recommend <code>.ix[]</code> which is usually faster compared to <code>loc</code> / <code>iloc</code>:</p>
<pre><code>In [86]: set_y.ix[set_x.inde... | 2 | 2016-06-16T16:57:30Z | [
"python",
"pandas"
] |
Trouble creating dataframe using pandas: ValueError/data type not understood | 37,865,177 | <p>I'm a bit new to pandas/numpy and have had trouble with this issue.</p>
<p>I have a group of 10 lists, each of which have 58 elements in them (strings). When I try to join them into a dataframe</p>
<pre><code>df = pd.Dataframe(a, b, c, d, e, f, g, h, i, j)
</code></pre>
<p>I get the error <code>"ValueError: Shape... | 0 | 2016-06-16T16:55:47Z | 37,865,243 | <p>Use this:</p>
<pre><code>df = pd.Dataframe([a, b, c, d, e, f, g, h, i, j])
</code></pre>
<p>The difference</p>
<pre><code># You had
df = pd.Dataframe( a, b, c, d, e, f, g, h, i, j )
# ^ \________________________/
# | |
# data argument |
# ... | 0 | 2016-06-16T16:59:10Z | [
"python",
"pandas",
"dataframe"
] |
Insert widget (Label) into Listbox in Tkinter | 37,865,323 | <p>Hi people is it possible to insert Label widget into Listbox in tkinter instead of some str value and attach to it a scrollbar? </p>
| -2 | 2016-06-16T17:03:29Z | 37,865,722 | <p>Based on the documentation online, No</p>
<blockquote>
<p>The listbox can only contain text items...</p>
</blockquote>
<p>for further details on the ListBox: <a href="http://effbot.org/tkinterbook/listbox.htm" rel="nofollow">http://effbot.org/tkinterbook/listbox.htm</a></p>
| 1 | 2016-06-16T17:25:38Z | [
"python",
"tkinter"
] |
Is there a better way than this to make bar plot of UNIQUE counts between categorical pandas columns | 37,865,361 | <p>I have pairs of categorical data but I don't want to double count instances where "toy" and "B" for instance are together multiple times.
I can do a pivot table with counts, but what I want is the equivalent of that with 1 or 0 depending if ANY matched that combo of 2 values or not, not the number of matches, 2, 3, ... | 3 | 2016-06-16T17:06:08Z | 37,869,258 | <p>IIUC you can do it this way:</p>
<pre><code>(df.groupby(['attrib2','group'])
.size()
.reset_index()
.groupby('attrib2')
.size()
.plot.bar(rot=0)
)
</code></pre>
<p><a href="http://i.stack.imgur.com/rj5mW.png" rel="nofollow"><img src="http://i.stack.imgur.com/rj5mW.png" alt="enter image description h... | 0 | 2016-06-16T21:00:31Z | [
"python",
"pandas"
] |
python requests - can not get body at 2nd request | 37,865,395 | <p>I want to scrape data, but I can only request successfully the 1st time, when I re-run, I cannot get the body again.</p>
<p>my code:</p>
<pre><code>url="http://www.carparts.com/results/?N=0&Nr=AND%28universal%3A0%29&Ntk=Main&Ntx=mode+matchallany&Nty=1&PN=0+5727&VN=4294953018+4294962799+4294... | 0 | 2016-06-16T17:07:48Z | 37,876,469 | <p>It happened to me also, once I made an initial request the source changed slightly for all subsequent requests, to get the data you could forget about the results and use the <em>product</em> divs:</p>
<pre><code>pageSkimData = requests.get(url, headers=request_headers)
treeSkimData = html.fromstring(pageSkimData.c... | 0 | 2016-06-17T08:16:40Z | [
"python",
"python-requests"
] |
python IO: Splitting words from textfile into python array, avoiding escaping chars, newlines, hexvalues | 37,865,418 | <p>I'm having a hard time importing and splitting words properly from a simple txt-file into a python array.</p>
<p>Txtfile:</p>
<pre><code>test1 file test1 test1Â
test2 test2Â
test 3 test3, test3.
test 4, test 4.
test 5
^Ltest 6.
</code></pre>
<p>When doing a simple <code>for lines in file: array.append(line... | 0 | 2016-06-16T17:09:04Z | 37,868,165 | <p>Single line solution:</p>
<pre><code>[w for w in file.read().split() if re.match(r'[\w\n\.]+$',w)]
</code></pre>
<p>For parsing large file, it's better to pre-compile the regex.</p>
<pre><code>import re
word_ptn = re.compile(r'[\w\n\.]+$')
[w for w in file.read().split() if word_ptn.match(w)]
</code></pre>
<p>Th... | 0 | 2016-06-16T19:46:42Z | [
"python",
"arrays",
"string",
"io",
"split"
] |
Scrapping english version of a website | 37,865,433 | <p>I am trying to scrape the English version of a Japanese website, the problem is that the link for the Japanese and English version are the same, is there a way to tell beautifulsoup to scrape the English version instead of the Japanese?</p>
<p>Link I want to scrape:</p>
<p><a href="https://data.j-league.or.jp/SFMS... | 0 | 2016-06-16T17:09:54Z | 37,865,557 | <p>To demonstrate that adding <code>lang=en</code> url query parameter actually works:</p>
<pre><code>>>> import requests
>>> from bs4 import BeautifulSoup
>>>
>>> url = "https://data.j-league.or.jp/SFMS02/?match_card_id=17975"
>>> english_url = "https://data.j-league.or.jp... | 2 | 2016-06-16T17:16:17Z | [
"python",
"web-scraping",
"beautifulsoup"
] |
Python How to fill an array arr[i, j] within a for loop that calculates the values that will be put into i and j | 37,865,593 | <p>This is a program that must compute the flow rate of salt water needed to achieve a certain density profile. The important variables I need to store are Q and t as they will then be used to tell my pump how fast to run in real time.</p>
<pre><code>import numpy as np
for z in np.arange(0, 0.5, 0.01):
Q = a + z... | -5 | 2016-06-16T17:18:08Z | 37,866,054 | <p>If I understand your question correctly, this should do the trick.</p>
<pre><code>arr = []
for z in np.arange(0, 0.5, 0.01):
Q = a + z
t = b + z
# here I would like to store Q and t in an array
arr.append([t,Q])
for item in arr:
i = item[0]
j = item[1]
</code></pre>
<p>It creates a list ... | 0 | 2016-06-16T17:45:02Z | [
"python",
"arrays"
] |
Python How to fill an array arr[i, j] within a for loop that calculates the values that will be put into i and j | 37,865,593 | <p>This is a program that must compute the flow rate of salt water needed to achieve a certain density profile. The important variables I need to store are Q and t as they will then be used to tell my pump how fast to run in real time.</p>
<pre><code>import numpy as np
for z in np.arange(0, 0.5, 0.01):
Q = a + z... | -5 | 2016-06-16T17:18:08Z | 37,866,073 | <p>Multidimensional arrays are just arrays of arrays.</p>
<p>If <code>arr</code> is defined as the 2D array that looks like:</p>
<pre><code>[ [1, 2],
[3, 4],
[5, 6] ]
</code></pre>
<p><code>arr[0]</code> would return <code>[1,2]</code></p>
<p>If you have an empty array, as in <code>arr = []</code> and you want ... | 0 | 2016-06-16T17:46:24Z | [
"python",
"arrays"
] |
Python How to fill an array arr[i, j] within a for loop that calculates the values that will be put into i and j | 37,865,593 | <p>This is a program that must compute the flow rate of salt water needed to achieve a certain density profile. The important variables I need to store are Q and t as they will then be used to tell my pump how fast to run in real time.</p>
<pre><code>import numpy as np
for z in np.arange(0, 0.5, 0.01):
Q = a + z... | -5 | 2016-06-16T17:18:08Z | 37,867,384 | <p>You can create a 2-d array without a Python loop using <a href="http://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html" rel="nofollow">broadcasting</a>:</p>
<pre><code>#Constants
a = 3
b = 2
</code></pre>
<p>Make <code>z</code> a 2-d array</p>
<pre><code>z = np.array((np.arange(0, 0.1, 0.01),np.aran... | 0 | 2016-06-16T19:00:11Z | [
"python",
"arrays"
] |
running bash command from python3 | 37,865,608 | <p>I am trying to remove some file (from my linux machine), except few:</p>
<pre><code>touch INCAR KPOINTS foo bar
$ls
bar foo INCAR KPOINTS
$python3 mini.py
Job Done
$ls
bar foo INCAR KPOINTS
</code></pre>
<p>The <code>mini.py</code> is:</p>
<pre><code>#!/usr/bin/python3
import subprocess
subprocess.run(['r... | 1 | 2016-06-16T17:19:00Z | 37,866,115 | <p>It doesn't work because <a href="http://wiki.bash-hackers.org/syntax/pattern#extended_pattern_language" rel="nofollow"><code>!()</code></a> is an extended matching pattern, and needs to be enabled explicitly:</p>
<pre><code>subprocess.run(['/bin/bash', '-O', 'extglob', '-c', 'rm -f !(INCAR|KPOINTS|PO*|*.sh)'])
</co... | 4 | 2016-06-16T17:49:33Z | [
"python",
"bash"
] |
running bash command from python3 | 37,865,608 | <p>I am trying to remove some file (from my linux machine), except few:</p>
<pre><code>touch INCAR KPOINTS foo bar
$ls
bar foo INCAR KPOINTS
$python3 mini.py
Job Done
$ls
bar foo INCAR KPOINTS
</code></pre>
<p>The <code>mini.py</code> is:</p>
<pre><code>#!/usr/bin/python3
import subprocess
subprocess.run(['r... | 1 | 2016-06-16T17:19:00Z | 37,866,155 | <p>you can also use</p>
<pre><code>import os
os.system('rm -f !(INCAR|KPOINTS|PO*|*.sh)')
</code></pre>
| -1 | 2016-06-16T17:51:56Z | [
"python",
"bash"
] |
Pandas: logical and of two dataframes | 37,865,686 | <p>I have 2 dataframes which have boolean entries</p>
<p><a href="http://i.stack.imgur.com/CIV7S.png" rel="nofollow"><img src="http://i.stack.imgur.com/CIV7S.png" alt="df1"></a></p>
<p><a href="http://i.stack.imgur.com/Ow3JL.png" rel="nofollow"><img src="http://i.stack.imgur.com/Ow3JL.png" alt="df2"></a></p>
<p>How ... | 0 | 2016-06-16T17:23:01Z | 37,865,800 | <pre><code>np.random.seed([3,1415])
df1 = pd.DataFrame(np.random.choice((True, False), (5, 3)),
pd.date_range('2016-06-06', '2016-06-10'), list('ABC'))
df2 = pd.DataFrame(np.random.choice((True, False), (5, 3)),
pd.date_range('2016-06-06', '2016-06-10'), list('ABC'))
df1
</code></... | 2 | 2016-06-16T17:30:36Z | [
"python",
"pandas"
] |
How to discontinue a line graph in the plot pandas or matplotlib python | 37,865,694 | <p>My challenge is to plot many sequences of data organized in the column (where each column is the data for many simualtions for the same identificator (ID)) and index of pandas dataframe is the months of simulation. The problem is in the line created by pandas linking the different simulations in the same column. </p... | 5 | 2016-06-16T17:23:29Z | 38,036,456 | <p>Here a solution that directly uses matplotlib:</p>
<pre><code># code until "plotting" same as question
# plotting
simlen = 5
for c in columns:
for i in range(0, len(index), simlen):
plt.plot(index[i:i+simlen], dataset[i:i+simlen][c],
color=dict(A='b', B='g')[c],
label=c if i == 0 else None)
plt.l... | 1 | 2016-06-26T08:07:21Z | [
"python",
"python-3.x",
"pandas",
"matplotlib"
] |
Python Pandas put each column to a new row | 37,865,763 | <p>I am trying to make new rows out of existing rows with splitting data. I currently have(Notice random spaces exist between quotes and numbers sometimes)</p>
<pre><code>FIT-1401,"0327.0001, 0327.0002"
FIT-1056," 0361.0001, 0361.0004, 3000.0010"
FIT-831,1120.0009
FIT-491,1207
</code></pre>
<p>I would like exactly a... | 0 | 2016-06-16T17:28:07Z | 37,866,180 | <h3>Setup</h3>
<pre><code>from StringIO import StringIO
import pandas as pd
text = """FIT-1401,"0327.0001, 0327.0002"
FIT-1056," 0361.0001, 0361.0004, 3000.0010"
FIT-831,1120.0009
FIT-491,1207"""
df = pd.read_csv(StringIO(text), index_col=0, header=None)
</code></pre>
<h3>Solution</h3>
<pre><code>df1 = df.iloc[:, ... | 1 | 2016-06-16T17:53:50Z | [
"python",
"csv",
"pandas"
] |
Why the number of PCA's changed? | 37,865,844 | <p>I was doing PCA on a dataset. In order to find the optimal number of PCA's, I used the number of features as the number of PCA. However, when I looked at the explained variance ratio, I noticed that the number of PCA's has changed. Originally, the dataset was 200 * 300, so after doing PCA with # of components = 300,... | 0 | 2016-06-16T17:33:16Z | 37,865,845 | <p>This is actually <a href="http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html" rel="nofollow">due to the built-in setting of PCA in sklearn</a>:</p>
<blockquote>
<p>n_components : int, None or string Number of components to keep. </p>
<p>if n_components is not set all components a... | 3 | 2016-06-16T17:33:16Z | [
"python",
"machine-learning",
"scikit-learn",
"pca"
] |
Get index of the minimum of multi-index Pandas DataFrame using level | 37,865,865 | <p>I have a <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html" rel="nofollow">Pandas DataFrame</a> that is <a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html" rel="nofollow">multiindexed</a> and want to find the minimum value of a certain column in a subset of rows on ... | 2 | 2016-06-16T17:34:46Z | 37,866,330 | <p>This should work:</p>
<pre><code>df.loc[df.loc[df.col1 == 5.].groupby(level=0).col2.idxmin()]
col1 col2
v1 record5 5.0 114
v2 record5 5.0 114
</code></pre>
<h3>Note</h3>
<p>I'm using <code>idxmin</code> as you thought you ought to. But the context matters. I'm using it following a <code>gr... | 2 | 2016-06-16T18:02:08Z | [
"python",
"pandas",
"dataframe",
"multi-index"
] |
Get index of the minimum of multi-index Pandas DataFrame using level | 37,865,865 | <p>I have a <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html" rel="nofollow">Pandas DataFrame</a> that is <a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html" rel="nofollow">multiindexed</a> and want to find the minimum value of a certain column in a subset of rows on ... | 2 | 2016-06-16T17:34:46Z | 37,866,797 | <pre><code>>>> (df[df.col1 == 5]
.groupby(level=0, as_index=False).col2
.apply(lambda group: group.nsmallest(1))
0 v1 record5 114
1 v2 record5 114
dtype: int64
</code></pre>
<p>Or...</p>
<pre><code>>>> df[df.col1 == 5].groupby(level=0).col2.nsmallest(1)
v1 v1 record5 114
v2 ... | 1 | 2016-06-16T18:29:02Z | [
"python",
"pandas",
"dataframe",
"multi-index"
] |
Extracting Data from JSON | 37,865,975 | <p>I have a large JSON item returned through a REST API, I wont junk up this with the full text but here is the code I am currently using:</p>
<pre><code>import urllib2
import json
req = urllib2.Request
('http://elections.huffingtonpost.com/
pollster/api/polls.json?state=IA')
response = urllib2.urlopen(req)
the_pa... | -1 | 2016-06-16T17:40:39Z | 37,866,007 | <p>The problem is, that you overwrite <code>print</code> with your data, instead of printing the data. Just remove the <code>=</code> in the last line and it should work fine:
</p>
<pre><code>print decode
</code></pre>
<p>If you want to use Python 3, you need parenthesis for <code>print</code>. This would look like t... | 2 | 2016-06-16T17:42:29Z | [
"python",
"json"
] |
Extracting Data from JSON | 37,865,975 | <p>I have a large JSON item returned through a REST API, I wont junk up this with the full text but here is the code I am currently using:</p>
<pre><code>import urllib2
import json
req = urllib2.Request
('http://elections.huffingtonpost.com/
pollster/api/polls.json?state=IA')
response = urllib2.urlopen(req)
the_pa... | -1 | 2016-06-16T17:40:39Z | 37,866,069 | <p>it is because you do</p>
<pre><code>print = decode
</code></pre>
<p>instead, if you are using python 2 do</p>
<pre><code>print decode
</code></pre>
<p>or in python 3 do</p>
<pre><code>print(decode)
</code></pre>
| 0 | 2016-06-16T17:45:51Z | [
"python",
"json"
] |
Yum install return bad interpreter: No such file or directory | 37,866,060 | <p>I tried to do <code>yum install zlib-devel</code> I got </p>
<p><a href="http://i.stack.imgur.com/AuXcw.png" rel="nofollow"><img src="http://i.stack.imgur.com/AuXcw.png" alt="enter image description here"></a></p>
<p>How can I fix this so I can use my <code>yum install</code>again ?</p>
| 1 | 2016-06-16T17:45:14Z | 37,894,757 | <p>Yum is broken because a python problem. You can use the rpm utility to reinstall python, or to manually install zlib-devel.</p>
<p>Yum ins't a requirement for installing packages. It just makes it more convenient. You can manually download any rpm package for CentOS. I prefer to find what I need using <a href="... | 2 | 2016-06-18T08:06:14Z | [
"python",
"centos",
"yum"
] |
initialization with python list | 37,866,104 | <p>I have a problem with correct initialization within a list</p>
<pre><code>import random
a = [random.randint(0,1) for x in range(10)] # getting random 0 and 1
b = a[:] # copying 'a' list for purpose of analysis
for x,y in enumerate(b): # adding + 1 where value is 1
if y != 0:
b[x] += b[x-1]
print(... | 1 | 2016-06-16T17:48:42Z | 37,866,216 | <p>You can skip the first value rather easily:
</p>
<pre><code>for x,y in enumerate(b[1:]): # adding + 1 where value is 1
if y != 0:
b[x + 1] += b[x]
</code></pre>
<p><code>b[1:]</code> just skips the first value from the list for the enumeration. This way the first number is untouched. But because the in... | 2 | 2016-06-16T17:56:08Z | [
"python",
"python-3.x",
"initialization"
] |
Groupby with TimeGrouper 'backwards' | 37,866,145 | <p>I have a <code>DataFrame</code> containing a time series:</p>
<pre><code>rng = pd.date_range('2016-06-01', periods=24*7, freq='H')
ones = pd.Series([1]*24*7, rng)
rdf = pd.DataFrame({'a': ones})
</code></pre>
<p>Last entry is <code>2016-06-07 23:00:00</code>. I now want to group this by, say two days, basically li... | 5 | 2016-06-16T17:51:14Z | 37,887,371 | <p>Since the question now focuses on grouping by week, you can simply:</p>
<pre><code>rdf.resample('W-{}'.format(rdf.index[-1].strftime('%a')), closed='right', label='right').sum()
</code></pre>
<p>You can use <code>loffset</code> to get it to work - at least for most periods (using <code>.resample()</code>):</p>
<p... | 0 | 2016-06-17T17:42:59Z | [
"python",
"numpy",
"pandas",
"time-series"
] |
Groupby with TimeGrouper 'backwards' | 37,866,145 | <p>I have a <code>DataFrame</code> containing a time series:</p>
<pre><code>rng = pd.date_range('2016-06-01', periods=24*7, freq='H')
ones = pd.Series([1]*24*7, rng)
rdf = pd.DataFrame({'a': ones})
</code></pre>
<p>Last entry is <code>2016-06-07 23:00:00</code>. I now want to group this by, say two days, basically li... | 5 | 2016-06-16T17:51:14Z | 37,987,159 | <p>Since I primarily want to group by 7 days, aka one week, I am using this method now to come to the desired bins:</p>
<pre><code>from pandas.tseries.offsets import Week
# Let's not make full weeks
hours = 24*6*4
rng = pd.date_range('2016-06-01', periods=hours, freq='H')
# Set week start to whatever the last weekda... | 0 | 2016-06-23T09:11:28Z | [
"python",
"numpy",
"pandas",
"time-series"
] |
Python parsing out nested | 37,866,201 | <p>I am using the simple_salesforce library for importing data from Salesforce. 2 rows come back as what looks like a triple nested dict..</p>
<pre><code>OrderedDict([(u'totalSize', 2), (u'done', True), (u'records',
[OrderedDict([(u'attributes',
OrderedDict([(u'type', u'Account'), (u'url',
u'/services/data/v29.0/so... | 2 | 2016-06-16T17:54:56Z | 37,866,439 | <pre><code>queryResults.items()[2][1]
</code></pre>
<p>That gives you a list of <code>OrderedDict</code>'s with the attributes. Thus:</p>
<pre><code>data = []
for i in queryResults.items()[2][1]:
name = i['Name']
clientID = i['Client_ID']
data.append([name,clientID])
for i in data:
print(i[0] + " " +... | 1 | 2016-06-16T18:08:47Z | [
"python",
"python-2.7"
] |
Python parsing out nested | 37,866,201 | <p>I am using the simple_salesforce library for importing data from Salesforce. 2 rows come back as what looks like a triple nested dict..</p>
<pre><code>OrderedDict([(u'totalSize', 2), (u'done', True), (u'records',
[OrderedDict([(u'attributes',
OrderedDict([(u'type', u'Account'), (u'url',
u'/services/data/v29.0/so... | 2 | 2016-06-16T17:54:56Z | 37,866,551 | <p>If I got your answer right this should do the trick:</p>
<pre><code>from collections import OrderedDict
d = OrderedDict([(u'totalSize', 2), (u'done', True), (u'records', [
OrderedDict([(u'attributes',
OrderedDict([(u'type', u'Account'), (u'url',
u'/services/data/v29.0/sobjects/Account/98234fd'... | 4 | 2016-06-16T18:16:11Z | [
"python",
"python-2.7"
] |
Pygame Platformer Scrolling Bug | 37,866,257 | <p>So while working on my engine, I wanted to add an enemy in there, sounded simple enough. Even though my enemy is in the game, not violating the laws of physics (for the most part), the weird part is that I gave him 0 control over movement, but the enemy keeps following the player sprite as I move along.</p>
<p>Now ... | 1 | 2016-06-16T17:58:21Z | 37,877,327 | <p>The problem is in your <code>scroll</code>, or rather your <code>shift_world</code> function. You shift every object in <code>self.object_list</code>. For Level01, this list only contains the block objects. In <code>scroll</code>, you then shift every block and the player, <em>but not the enemy</em>. This means the ... | 0 | 2016-06-17T09:01:04Z | [
"python",
"pygame"
] |
Python requests.exceptions.ChunkedEncodingError | 37,866,291 | <p>I am writing a python script that does these steps below.</p>
<ul>
<li>Query a MongoDB database</li>
<li>Parse and aggregate results</li>
<li>Upload data to a ServiceNow table via a REST API</li>
</ul>
<p>This works most of the time but occasionally I see this error:</p>
<pre><code>requests.exceptions.ChunkedEnco... | 0 | 2016-06-16T18:00:19Z | 37,884,997 | <p><a href="http://wiki.servicenow.com/index.php?title=Transaction_Quotas#Default_Quota_Rules&gsc.tab=0/" rel="nofollow">ServiceNow prevents REST transactions</a> from running for longer than 60 seconds. </p>
<p>I'm not too sure how large your dataset is, but you will want to chunk the data into smaller pieces to ... | 1 | 2016-06-17T15:13:30Z | [
"python",
"mongodb",
"rest",
"import",
"servicenow"
] |
How can I fix red symbolic link in Linux ? | 37,866,313 | <p>I did <code>ls -l /usr/bin/python</code></p>
<p>I got</p>
<p><a href="http://i.stack.imgur.com/wvA2p.png" rel="nofollow"><img src="http://i.stack.imgur.com/wvA2p.png" alt="enter image description here"></a></p>
<p>How can I fix that red symbolic link ? </p>
| 0 | 2016-06-16T18:01:23Z | 37,866,511 | <p>You can enter
$which python
to see where your python path is.</p>
<p>you can then use
$ln -s /thepathfromabove/python2.7 python</p>
<p>Please accept the answer if it works for you. Thx.</p>
| -2 | 2016-06-16T18:13:26Z | [
"python",
"linux",
"centos",
"symlink"
] |
How can I fix red symbolic link in Linux ? | 37,866,313 | <p>I did <code>ls -l /usr/bin/python</code></p>
<p>I got</p>
<p><a href="http://i.stack.imgur.com/wvA2p.png" rel="nofollow"><img src="http://i.stack.imgur.com/wvA2p.png" alt="enter image description here"></a></p>
<p>How can I fix that red symbolic link ? </p>
| 0 | 2016-06-16T18:01:23Z | 37,866,512 | <p><code>ls -l /usr/bin/python</code> will only show the symbolic link.</p>
<p>Use <code>ls -l /usr/bin/ | grep python2.7</code> to see if <code>python2.7</code> is in the directory.</p>
<p>The output should be something like this:</p>
<pre><code>lrwxrwxrwx 1 root root 9 Jun 3 16:39 python -> python2.7... | 1 | 2016-06-16T18:13:37Z | [
"python",
"linux",
"centos",
"symlink"
] |
Python - is `threading.Event` "set" during garbage collection? | 37,866,346 | <p>The title of this post pretty much sums up my question - will threads waiting on an <code>Event</code> be notified if that event has been garbage collected? In my particular case I have a class whose instances have an <code>Event</code> as an attribute, and I'm wondering whether I should implement a <code>__del__</c... | 0 | 2016-06-16T18:02:55Z | 37,866,866 | <p>Since other objects hold a reference to the event, the event itself won't be deleted or garbage collected. It has no idea that your object is being deleted. Whether you want your class to have a <code>__del__</code> that sets the event when the object is deleted (either naturally through having its ref count go to z... | 2 | 2016-06-16T18:32:28Z | [
"python",
"multithreading",
"events",
"garbage-collection"
] |
Python - is `threading.Event` "set" during garbage collection? | 37,866,346 | <p>The title of this post pretty much sums up my question - will threads waiting on an <code>Event</code> be notified if that event has been garbage collected? In my particular case I have a class whose instances have an <code>Event</code> as an attribute, and I'm wondering whether I should implement a <code>__del__</c... | 0 | 2016-06-16T18:02:55Z | 37,867,577 | <p>Note that it's not necessarily the case that waiting for an <code>Event</code> implies the <code>Event</code> isn't in trash. <em>Cyclic</em> trash is one possibility, and here's another:</p>
<pre><code>import threading
class C(object):
def __init__(self):
self.e = threading.Event()
def __del__(s... | 1 | 2016-06-16T19:12:01Z | [
"python",
"multithreading",
"events",
"garbage-collection"
] |
Get Cron to run based on User Input | 37,866,398 | <p>I have a flask app that schedules tasks (python scripts) to run. I've done some searching and I believe using cron is the best solution to schedule these tasks. However, the time these tasks runs depends on user input. A user can input the date they want the script to start running along with the cadence (daily, wee... | 1 | 2016-06-16T18:06:25Z | 37,866,463 | <p>A standard pattern for this functionality is to create a bootstrap cron job that runs every minute; its purpose is to check your database for tasks to run at a certain time.</p>
<p>In many cases, the every-minute cron job executes almost immediately. When it finds a job to run (based on a preset-schedule or user in... | 1 | 2016-06-16T18:09:44Z | [
"python",
"cron"
] |
Getting ParserError (a custom exception), even though the conditions for the exception are not met. I've shown my code below | 37,866,399 | <p>When I assign value to word_list at the by default, the program works fine. But when I assign value to word_list by getting it from use through raw_input(), I get ParserError, even though the input is correct.</p>
<p>I am unable to understand as to why this is happening. Any help would be greatly appreciated.</p>
... | 1 | 2016-06-16T18:06:26Z | 37,866,802 | <p>there is no error while taking input through raw_input,check this way</p>
<pre><code>def parse_subject(word_list):
skip(word_list,'stop')
word_type = peek(word_list)
if word_type == 'noun':
return match(word_list)
elif word_type == 'verb':
return 'player'
else:
raise Parse... | 0 | 2016-06-16T18:29:09Z | [
"python"
] |
Python cmd module - Resume prompt after async event | 37,866,403 | <p>I am maintaining an operator terminal based on cmd. The customer asked for an alerting behavior. e.g. a message shown onscreen when some asynchronous event occurs. I made a thread that periodically checks for alerts, and when it finds some, it just prints them to stdout.</p>
<p>This seems to work OK, but it doesn't... | 2 | 2016-06-16T18:06:37Z | 37,869,106 | <p>I ended up overriding Cmd.cmdloop with my own version, replacing the readlines() with my own readlines that use non-blocking terminal IO.</p>
<p>Non-Blocking terminal IO info here:
<a href="http://stackoverflow.com/questions/2408560/python-nonblocking-console-input" title="python-nonblocking-console-input">Non-Bloc... | 0 | 2016-06-16T20:49:28Z | [
"python",
"asynchronous",
"cmd",
"alert"
] |
How to extract word frequency from document-term matrix? | 37,866,450 | <p>I am doing LDA analysis with Python. And I used the following code to create a document-term matrix</p>
<pre><code>corpus = [dictionary.doc2bow(text) for text in texts].
</code></pre>
<p>Is there any easy ways to count the word frequency over the whole corpus. Since I do have the dictionary which is a term-id list... | 0 | 2016-06-16T18:09:14Z | 37,867,872 | <p>You can use <code>nltk</code> in order to count word frequency in string <code>texts</code></p>
<pre><code>from nltk import FreqDist
import nltk
texts = 'hi there hello there'
words = nltk.tokenize.word_tokenize(texts)
fdist = FreqDist(words)
</code></pre>
<p><code>fdist</code> will give you word frequency of give... | 1 | 2016-06-16T19:30:00Z | [
"python",
"dictionary",
"text-mining"
] |
Scrapy crawled pages, but scraped 0 items | 37,866,455 | <p>I am fairly new to Python, Scrapy and this board, so please bear with me, as I try to illustrate my problem.</p>
<p>My goal is to collect the names (and possibly prices) of all available hotels in Berlin on booking.com for a specific date (see for example the predefined start_url) with the help of Scrapy.</p>
<p>I... | 2 | 2016-06-16T18:09:33Z | 37,866,659 | <p>I think the problem may be with your <code>XPath</code> on this line: </p>
<p><code>hotels = s.xpath('//div[@class="sr_item_content sr_item_content_slider_wrapper"]')</code></p>
<p>From <a href="http://stackoverflow.com/questions/3881044/how-to-get-html-elements-with-multiple-css-classes">this SO question</a> it l... | -1 | 2016-06-16T18:22:04Z | [
"python",
"web-scraping",
"scrapy",
"web-crawler"
] |
"Save result buffer" and "Visualize tree" via python-weka-wrapper-0.3.8? | 37,866,465 | <p>Is there a way to achieve "Save result buffer" and "Visualize tree" options that are available in the weka tool, <em>through weka-python-wrapper also</em>? (As the weka tool does not provide scripting options). Not able to find it in the python-weka-wrapper-0.3.8 documentation. Please help or direct me where to find... | -1 | 2016-06-16T18:09:56Z | 37,871,966 | <p>The <a href="https://github.com/fracpete/python-weka-wrapper" rel="nofollow">python-weka-wrapper</a> library does not come with a GUI, hence the question is a bit misplaced. However, this is covered in the examples section of the python-weka-wrapper documentation (<a href="http://pythonhosted.org/python-weka-wrapper... | 0 | 2016-06-17T01:58:33Z | [
"python",
"weka"
] |
regex re.findall to to find the substrings with space on both sides | 37,866,480 | <p>I am trying to use re.findall on my text column to find either of the following with spaces at both the sides, since thats the only important. I am using following script</p>
<pre><code>url = '#MnA deals for 2015 across all #oilandgas sectors were lower than WAR WARduring the CFO Great CIO Recession'
regex=re.fin... | 0 | 2016-06-16T18:11:14Z | 37,866,520 | <p>You can use a lookahead:</p>
<pre><code>>>> re.findall(r'\b(?:WAR|CIO|CISO|CTO|C-Suite|CMO|CFO|Founder+)(?=\s|$)', url)
['WAR', 'CFO', 'CIO']
</code></pre>
<p><code>(?=\s|$)</code> will assert presence of a whitespace or line end after your keywords.</p>
<p>For 2nd task use this regex:</p>
<pre><code>&g... | 2 | 2016-06-16T18:14:04Z | [
"python",
"regex",
"findall"
] |
regex re.findall to to find the substrings with space on both sides | 37,866,480 | <p>I am trying to use re.findall on my text column to find either of the following with spaces at both the sides, since thats the only important. I am using following script</p>
<pre><code>url = '#MnA deals for 2015 across all #oilandgas sectors were lower than WAR WARduring the CFO Great CIO Recession'
regex=re.fin... | 0 | 2016-06-16T18:11:14Z | 37,866,528 | <p>Using word boundary<a href="http://www.regular-expressions.info/wordboundaries.html" rel="nofollow"> [Know more</a> ] in your regex will solve your problem</p>
<p>Regex</p>
<pre><code>\b(?:WAR|CIO|CISO|CTO|C-Suite|CMO|CFO|Founder+)\b
</code></pre>
<p>Code</p>
<pre><code>url = '#MnA deals for 2015 across all #oil... | 2 | 2016-06-16T18:14:37Z | [
"python",
"regex",
"findall"
] |
regex re.findall to to find the substrings with space on both sides | 37,866,480 | <p>I am trying to use re.findall on my text column to find either of the following with spaces at both the sides, since thats the only important. I am using following script</p>
<pre><code>url = '#MnA deals for 2015 across all #oilandgas sectors were lower than WAR WARduring the CFO Great CIO Recession'
regex=re.fin... | 0 | 2016-06-16T18:11:14Z | 37,866,645 | <p>method 1: wrongly detects theWAR as WAR</p>
<p>Another way of doing it: use \b to delimit word only</p>
<pre><code>regex=re.findall(r'\b(WAR|CIO|CISO|CTO|C-Suite|CMO|CFO|Founder)\b',url)
url = '#MnA deals for 2015 across all #oilandgas theWAR sectors were lower than WAR WARduring the CFO Great CIO'
regex=re.fin... | 2 | 2016-06-16T18:21:11Z | [
"python",
"regex",
"findall"
] |
Run PyCharm's spell checking against the whole project | 37,866,490 | <p>I want to check the spelling in all files in my PyCharm project. Right now, I have to open each file and look for highlighted errors. Is there a way to run PyCharm's spell check on the whole project?</p>
| 2 | 2016-06-16T18:12:01Z | 37,866,721 | <p>You can run inspections against scopes besides the current file. If the inspection profile has spell checking enabled (it does by default), you will get a view of all errors that it finds.</p>
<ol>
<li><p>Go to "Code -> Inspect Code..."</p>
<p><a href="http://i.stack.imgur.com/tLzjq.png" rel="nofollow"><img src="... | 2 | 2016-06-16T18:25:28Z | [
"python",
"pycharm",
"spell-checking"
] |
Load multiple files into dataframe | 37,866,575 | <p>Is it possible to load multiple files as one dataframe? Normally, if I have one file to load, I will call for example:</p>
<pre><code>file1 = "/a/b/c/folder/file1.csv"
dc = sqlContext.read.format('com.databricks.spark.csv').options(header='false', inferschema='true').load(file1)
</code></pre>
<p>But I want to load... | 0 | 2016-06-16T18:17:33Z | 37,928,967 | <p>I think <code>sqlContext.read.format('com.databricks.spark.csv').options(header='false', inferschema='true').load(folder)</code> works. Previously I got error is because I am ready compressed files, and they are oversized compared with the memory</p>
| 0 | 2016-06-20T18:01:19Z | [
"python",
"dataframe",
"io",
"pyspark",
"pyspark-sql"
] |
How to test Alert/Popup in Selenium using Python | 37,866,584 | <p>I'm stuck with my automation where when I enter wrong username and password it will pop up saying "Unable to login. Try different username"</p>
<pre><code>def test_logonWrongUserName(self):
self.setUpClass() # Initialize the driver
self.sh.navigateToUrl("http://test.com")
self.sh.member_Login("Foo", "a... | 2 | 2016-06-16T18:18:05Z | 37,866,782 | <p>You need to <a href="http://selenium-python.readthedocs.io/waits.html#explicit-waits" rel="nofollow">wait for the alert to be present</a>, assert you have the expected <a href="http://selenium-python.readthedocs.io/api.html#selenium.webdriver.common.alert.Alert.text" rel="nofollow">text</a> inside and then close/<a ... | 2 | 2016-06-16T18:28:14Z | [
"python",
"python-3.x",
"selenium"
] |
Trying to get title of table using python docx | 37,866,648 | <p>I have a Word DOCX in the following format:</p>
<pre><code>Title
- text
Title1
- Description
Title2
- Definition
- Table2
- text
Title3
- Definition
- Table3
- text
...
</code></pre>
<p>I am using python docx, and would like to get the "title" that matches with every "table" (ie the title that is clo... | 1 | 2016-06-16T18:21:22Z | 37,871,823 | <p>This thread in the GitHub issues list might be helpful:
<a href="https://github.com/python-openxml/python-docx/issues/40" rel="nofollow">https://github.com/python-openxml/python-docx/issues/40</a></p>
<p>If you add an iter_block_items() function, make sure you use the one at toward the end of the thread, it's had t... | 0 | 2016-06-17T01:37:37Z | [
"python",
"python-docx"
] |
python script working when run in cmd but not when run from file | 37,866,674 | <p>I have a module installed in to my python. I try to run it from CMD and it works but when I run a file with the exact same commands it doesn't work. any ideas?
<a href="http://i.stack.imgur.com/CrKAY.png" rel="nofollow"><img src="http://i.stack.imgur.com/CrKAY.png" alt="python outcome"></a>
The top row is when I run... | 0 | 2016-06-16T18:22:51Z | 37,866,746 | <p>in the upper window, you are in the "Desktop" directory. In the lower window, you are in your home directory.</p>
| -1 | 2016-06-16T18:26:28Z | [
"python",
"python-2.7"
] |
python script working when run in cmd but not when run from file | 37,866,674 | <p>I have a module installed in to my python. I try to run it from CMD and it works but when I run a file with the exact same commands it doesn't work. any ideas?
<a href="http://i.stack.imgur.com/CrKAY.png" rel="nofollow"><img src="http://i.stack.imgur.com/CrKAY.png" alt="python outcome"></a>
The top row is when I run... | 0 | 2016-06-16T18:22:51Z | 37,866,834 | <p>Try to put the lib in the same folder of the script and it should work</p>
| -1 | 2016-06-16T18:31:05Z | [
"python",
"python-2.7"
] |
python script working when run in cmd but not when run from file | 37,866,674 | <p>I have a module installed in to my python. I try to run it from CMD and it works but when I run a file with the exact same commands it doesn't work. any ideas?
<a href="http://i.stack.imgur.com/CrKAY.png" rel="nofollow"><img src="http://i.stack.imgur.com/CrKAY.png" alt="python outcome"></a>
The top row is when I run... | 0 | 2016-06-16T18:22:51Z | 37,867,324 | <p>The problem is that your script has the same name as the module that you want to import. In the working case, you run python in <code>C:\Users\Isaac\Desktop</code> and then import. Python finds the <code>Envyronment</code> module and everyone is happy.</p>
<p>In the non-working case, you change directories to <code... | 0 | 2016-06-16T18:57:15Z | [
"python",
"python-2.7"
] |
Efficient way to convert dictionary of list to pair list of key and value | 37,866,736 | <p>I have dictionary of list as follows (it can be more than 1M elements, also assume dictionary is sorted by key)</p>
<pre><code>import scipy.sparse as sp
d = {0: [0,1], 1: [1,2,3],
2: [3,4,5], 3: [4,5,6],
4: [5,6,7], 5: [7],
6: [7,8,9]}
</code></pre>
<p>I want to know what is the most efficient wa... | 4 | 2016-06-16T18:26:06Z | 37,867,315 | <p>You can change the input size for the benchmark:</p>
<pre><code>import time
l = xrange(10000)
x = dict([(k, list(l)) for k in xrange(1000)])
def f(d):
row_ind = [k for k, v in d.iteritems() for _ in range(len(v))]
col_ind = [i for ids in d.values() for i in ids]
def ff(d):
import pandas as pd
df... | 0 | 2016-06-16T18:56:39Z | [
"python",
"dictionary",
"itertools"
] |
Efficient way to convert dictionary of list to pair list of key and value | 37,866,736 | <p>I have dictionary of list as follows (it can be more than 1M elements, also assume dictionary is sorted by key)</p>
<pre><code>import scipy.sparse as sp
d = {0: [0,1], 1: [1,2,3],
2: [3,4,5], 3: [4,5,6],
4: [5,6,7], 5: [7],
6: [7,8,9]}
</code></pre>
<p>I want to know what is the most efficient wa... | 4 | 2016-06-16T18:26:06Z | 37,868,074 | <p>The first rule of thumb of optimization in python is, to make sure that your innermost loop is outsourced to some library function. This only applies for cpython - pypy is a completely different story.
In your case using extend is giving some significant speedup.</p>
<pre><code>import time
l = range(10000)
x = dict... | 2 | 2016-06-16T19:41:27Z | [
"python",
"dictionary",
"itertools"
] |
Efficient way to convert dictionary of list to pair list of key and value | 37,866,736 | <p>I have dictionary of list as follows (it can be more than 1M elements, also assume dictionary is sorted by key)</p>
<pre><code>import scipy.sparse as sp
d = {0: [0,1], 1: [1,2,3],
2: [3,4,5], 3: [4,5,6],
4: [5,6,7], 5: [7],
6: [7,8,9]}
</code></pre>
<p>I want to know what is the most efficient wa... | 4 | 2016-06-16T18:26:06Z | 38,880,207 | <p>There is a function called a <em>decorator</em>. The decorator is always above a def or class function. Use <code>import timer @timer.Timer()</code> or something like that over your code. You can Google more. Or go to this link: <a href="https://wiki.python.org/moin/PythonDecorators" rel="nofollow">https://wiki.pyt... | -2 | 2016-08-10T17:44:45Z | [
"python",
"dictionary",
"itertools"
] |
Set border using Python xlwings | 37,866,812 | <p>Is there a way to set border lines for an Excel file from Python using xlwings? I was looking at the documentation but cannot figure out. </p>
<p>I want to create a file like this using xlwings
<a href="http://i.stack.imgur.com/uNfo6.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/uNfo6.jpg" alt="enter image... | 0 | 2016-06-16T18:30:08Z | 37,884,569 | <p>As far as I know, this isn't a feature that's built into xlwings at this point. However, you can use the lower level pywin32 functions (with caveats) as described in the xlwings docs <a href="http://docs.xlwings.org/en/stable/missing_features.html" rel="nofollow">here</a>.</p>
<p>Here's a brief example of how to se... | 2 | 2016-06-17T14:49:41Z | [
"python",
"excel",
"xlwings"
] |
python access dict key by key | 37,866,845 | <p>I use instances of a custom class (similar to a 2D vector with a bunch of extra stuff among other things) as a dict key.<br />
It uses custom hash and equals magic-methods that basically makes it equal to a tuple with the initialization data.</p>
<p>The data set I'm dealing with is so big that memory (RAM) is a mai... | 2 | 2016-06-16T18:31:32Z | 37,868,335 | <p>What you want to do, essentially, is to control the creation of <code>MyVect</code> instances so that, for a given set of initialization data, only one instance of <code>MyVect</code> is created.</p>
<p>I would suggest using a <a href="https://en.wikipedia.org/wiki/Factory_method_pattern" rel="nofollow">Factory met... | 1 | 2016-06-16T19:57:06Z | [
"python",
"dictionary"
] |
Counting Unique Names in a Pandas Data Frame | 37,866,875 | <p>I have simplified the large data frame to this simple data frame:</p>
<pre><code>IDX POS REF ALT
13 633 C A
15 643 C T
42 2015 G A
43 2016 G A
151 9538 T C
154 9542 TC TCC,T
169 10041 T A
170 10041 T TAA,TA
</code></pre>
<p>The data is from a genomic region with nucle... | 1 | 2016-06-16T18:32:56Z | 37,867,128 | <p>I'd <code>count</code> the commas and add 1</p>
<pre><code>df['COUNT'] = df.ALT.str.count(',') + 1
</code></pre>
| 2 | 2016-06-16T18:46:59Z | [
"python",
"pandas",
"dataframe",
"iteration"
] |
Annotating scatter plot in groupby plot | 37,866,876 | <p>I have a df like so:</p>
<pre><code>ID Prcp NDVI Year
1 1.4 0.1 2000
1 2.3 0.4 2001
1 4.4 0.8 2002
1 0.4 0.1 2003
2 2.1 0.6 2000
2 1.2 0.4 2001
2 3.4 0.7 2002
2 2.8 0.5 2003
</code></pre>
<p>and I want to do a scatter plot of <c... | 1 | 2016-06-16T18:32:56Z | 37,950,725 | <p>I achieved it like this:</p>
<pre><code>df=pd.read_csv(r'E:\path.csv')
with PdfPages(r'E:\pth.pdf') as pdf:
for i, group in first.groupby('ID'):
fig, ax = plt.subplots()
plot = group.plot(x=['Prcp'], y=['NDVI'], title='NDVI_' + str(i), kind='scatter', ax=ax).get_figure()
... | 0 | 2016-06-21T17:18:27Z | [
"python",
"pandas",
"matplotlib"
] |
Pycharm anaconda import tensor flow library issue | 37,866,877 | <p>The following program works well under anaconda from command line interface (I am using Mac OS), but it has errors about cannot import/find tensorflow module from PyCharm (using Python 2.7). I already set Python interpreter to be anaconda in PyCharm, still got this error. If anyone have any ideas, it will be great.<... | 4 | 2016-06-16T18:32:57Z | 37,964,635 | <p><strong>You need to do these following steps:</strong></p>
<ol>
<li>Go to settings (ctrl+alt+s or File menu->Settings or alt+f+t)</li>
<li>Under Prject: go to Project Interpreter</li>
<li>Choose the interpreter you'd like to use</li>
<li>Click on the gear button (Right top - next to the interpreter selection)</li>... | 1 | 2016-06-22T09:58:08Z | [
"python",
"python-2.7",
"pycharm",
"tensorflow",
"anaconda"
] |
Pycharm anaconda import tensor flow library issue | 37,866,877 | <p>The following program works well under anaconda from command line interface (I am using Mac OS), but it has errors about cannot import/find tensorflow module from PyCharm (using Python 2.7). I already set Python interpreter to be anaconda in PyCharm, still got this error. If anyone have any ideas, it will be great.<... | 4 | 2016-06-16T18:32:57Z | 37,976,634 | <p>Under <code>Preferences => Project Interpreter</code> setting, is tensorflow listed among the packages?</p>
<p>Apparently No (from your screenshots).</p>
<p>Are there any other python conda installations when you use the drop down on project interpreter? If there are, try those and see what happens. The <code>t... | 5 | 2016-06-22T19:24:41Z | [
"python",
"python-2.7",
"pycharm",
"tensorflow",
"anaconda"
] |
Permission denied trying to uninstall nose | 37,866,939 | <p>I have been having a really hard time getting nose to installed properly on my mac. Many people on the site have had this problem in the past and I was following the instructions of past posts. In the terminal is shows that nose is installed and upgraded.</p>
<pre><code>pip install nose
</code></pre>
<p>When I tri... | 1 | 2016-06-16T18:36:13Z | 37,867,588 | <p>If permission is denied, then you should try uninstalling it with super-user privileges. That is, run <code>sudo pip uninstall nose</code>.</p>
| 1 | 2016-06-16T19:12:25Z | [
"python"
] |
Tensorflow, select operation giving error | 37,866,950 | <p>I need my model to behave differently during training vs testing. I am trying to build I sequence to sequence model and I want to feed the expected output into the decoder when training and the actual output when I am testing. I defined the following placeholder which should contain a scaler value. </p>
<pre><co... | 1 | 2016-06-16T18:37:00Z | 37,868,116 | <p>You are right, <code>tf.select</code> wants the condition to be of the same shape as the two other inputs.</p>
<p>You should instead use <code>tf.cond</code>. See <a href="http://stackoverflow.com/questions/37299345/using-if-conditions-inside-a-tensorflow-graph/37302813#37302813">this detailed answer</a> about usin... | 1 | 2016-06-16T19:44:19Z | [
"python",
"tensorflow"
] |
Pattern search in pandas.dataframe.query() | 37,866,998 | <p>I have the following dataframe:</p>
<pre><code>----------------------------
Index| col1 | col2 |
----------------------------
0 | 1 | a-b-c
1 | 2 | d-e-f
2 | 3 | g
----------------------------
</code></pre>
<p>I want to be able to make queries like:</p>
<pre><code>myvar= 'a'
df.query('@myvar ... | 2 | 2016-06-16T18:39:46Z | 37,867,184 | <p>This should work:</p>
<pre><code>df = pd.DataFrame([[1, 'a-b-c'], [2, 'd-e-f'], [3, 'g']], columns=['col1', 'col2'])
myvar = 'a'
df.loc[df.col2.str.contains(myvar)]
col1 col2
0 1 a-b-c
</code></pre>
| 0 | 2016-06-16T18:50:09Z | [
"python",
"pandas",
"pattern-matching"
] |
Pattern search in pandas.dataframe.query() | 37,866,998 | <p>I have the following dataframe:</p>
<pre><code>----------------------------
Index| col1 | col2 |
----------------------------
0 | 1 | a-b-c
1 | 2 | d-e-f
2 | 3 | g
----------------------------
</code></pre>
<p>I want to be able to make queries like:</p>
<pre><code>myvar= 'a'
df.query('@myvar ... | 2 | 2016-06-16T18:39:46Z | 37,931,559 | <p>i'm afraid you can't do it using .query(). It will compare your @myvar to the whole string - try to set myvar = "g" and re-execute your query - it'll return you a row with index == 2.</p>
<p>AFAIK, regular expressions <a href="https://github.com/pydata/pandas/issues/9240" rel="nofollow">aren't supported</a> in Data... | 0 | 2016-06-20T20:48:31Z | [
"python",
"pandas",
"pattern-matching"
] |
Syntax error in len(sys.argv) | 37,867,056 | <p>Python interpreter gives Syntax error while running below code: </p>
<pre><code>import sys
if len(sys.argv) == 3:
a=sys.argv[1]
b=sys.argv[2]
sum=int(a) + int(b)
print "The sum is: ", sum
elif len(sys.argv) != 3:
print "Only two arguments allowed !"
else:
print "Please enter two numbers as argument wit... | 1 | 2016-06-16T18:43:03Z | 37,867,111 | <p>Your file is interpreted by your shell, not Python interpreter. Try specifying binary when running it:</p>
<pre><code>luckee@zarvis:~/python$ python sumtwo.py 5 10
</code></pre>
<p>Alternatively, you may add <a href="https://en.wikipedia.org/wiki/Shebang_(Unix)" rel="nofollow">shebang</a> as a first line of your s... | 2 | 2016-06-16T18:46:21Z | [
"python"
] |
Retrieve rows from data frame for partial matching in column of the data frame with elements in list | 37,867,060 | <p>I have a dataframe df:</p>
<pre><code>df:
chr gene_name
1 ARF3
1 ABC
1 ARF3,ENSG123
1 ENSG1245,ARF3, ENSG89
1 ENSG,ARF3
1 ANG
2 XVY
2 PQR
3 RST
4 TAC
</code></... | 3 | 2016-06-16T18:43:10Z | 37,867,345 | <p>Try:</p>
<pre><code>df2 = pd.concat([df1[df1['gene_name'].str.contains(gene)] for gene in gene_list])
</code></pre>
<p>Let me know if you have more problems.</p>
| 0 | 2016-06-16T18:58:13Z | [
"python",
"pandas",
"filter",
"dataframe"
] |
Retrieve rows from data frame for partial matching in column of the data frame with elements in list | 37,867,060 | <p>I have a dataframe df:</p>
<pre><code>df:
chr gene_name
1 ARF3
1 ABC
1 ARF3,ENSG123
1 ENSG1245,ARF3, ENSG89
1 ENSG,ARF3
1 ANG
2 XVY
2 PQR
3 RST
4 TAC
</code></... | 3 | 2016-06-16T18:43:10Z | 37,867,400 | <h3>Solution</h3>
<pre><code>df = pd.DataFrame([[1, 'ARF3'],
[1, 'ABC'],
[1, 'ARF3,ENSG123'],
[1, 'ENSG1245,ARF3,ENSG89'],
[1, 'ENSG,ARF3'],
[1, 'ANG'],
[2, 'XVY'],
[2, 'PQR'],
... | 1 | 2016-06-16T19:01:03Z | [
"python",
"pandas",
"filter",
"dataframe"
] |
Retrieve rows from data frame for partial matching in column of the data frame with elements in list | 37,867,060 | <p>I have a dataframe df:</p>
<pre><code>df:
chr gene_name
1 ARF3
1 ABC
1 ARF3,ENSG123
1 ENSG1245,ARF3, ENSG89
1 ENSG,ARF3
1 ANG
2 XVY
2 PQR
3 RST
4 TAC
</code></... | 3 | 2016-06-16T18:43:10Z | 37,868,921 | <p>Another simplier solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.split.html" rel="nofollow"><code>str.split</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.isin.html" rel="nofollow"><code>DataFrame.isin</code></a> with <a h... | 2 | 2016-06-16T20:37:37Z | [
"python",
"pandas",
"filter",
"dataframe"
] |
I want to read in strings to the new line character in Python 2.7 | 37,867,070 | <p>I have a long text file that I am trying to pull certain strings out of. The length of these strings are variable with the text file but are always located after certain identifiers. So for example say my text file looks like this:</p>
<p>junk text...</p>
<p>Name:<br>
Age: </p>
<p>Robert</p>
<p>twenty<br>
four.... | 0 | 2016-06-16T18:43:35Z | 37,867,509 | <p>You could do this by finding age, then moving forward your cursor two lines if you would like to do that, if you want the entire section of text after the "junk", and you know how long that text is, this would also work:</p>
<pre><code>lookup = 'age'
lines=[]
with open('C:/Users/Luke/Desktop/Summer 2016/Programs/un... | 0 | 2016-06-16T19:08:31Z | [
"python",
"python-2.7"
] |
I want to read in strings to the new line character in Python 2.7 | 37,867,070 | <p>I have a long text file that I am trying to pull certain strings out of. The length of these strings are variable with the text file but are always located after certain identifiers. So for example say my text file looks like this:</p>
<p>junk text...</p>
<p>Name:<br>
Age: </p>
<p>Robert</p>
<p>twenty<br>
four.... | 0 | 2016-06-16T18:43:35Z | 37,867,608 | <p>After you found the location in string, you can split the String by \n\n and get the first item.</p>
<pre><code>s = file_str[namepos2 :]
name = s.split('\n\n')[0]
</code></pre>
| 0 | 2016-06-16T19:13:47Z | [
"python",
"python-2.7"
] |
Distributing tests using selenium grid using subprocess approach(plain grid or using jenkins) | 37,867,085 | <p>I would like to distribute my tests between my local machine and the remote machine. I have 2 tests and would like to run them side by side for faster execution.
One on the local machine and the other one is on the remote machine. I have setup my hub and one node on the local and also I have registered the other no... | 0 | 2016-06-16T18:44:26Z | 37,875,034 | <p>Any time your code requests a browser from the grid hub, the grid hub will search among it's registered grid nodes for a free browser instance that match with your requested capabilities. You don't need to do anything for this except request the browser as you are doing here <code>self.driver = webdriver.Remote(comm... | 1 | 2016-06-17T06:56:57Z | [
"python",
"selenium",
"selenium-grid2",
"parallel-testing"
] |
Sort and Filter data from a Panda Dataframe according to date range | 37,867,092 | <p>My dataframe has two columns: (i) a date column in a string format and (ii) an int value. I would like to convert the date string into a date object and then filter and sort the data according to a date range. Converting one string to a date worked fine with: </p>
<pre><code>date = dateutil.parser.parse(date_string... | 1 | 2016-06-16T18:44:51Z | 37,867,174 | <p>You want to use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>pd.to_datetime</code></a>:</p>
<pre><code>df['etime'] = pd.to_datetime(df['etime'], format="%H:%M:%S")
</code></pre>
| 2 | 2016-06-16T18:49:42Z | [
"python",
"pandas",
"filter",
"dataframe"
] |
Sort and Filter data from a Panda Dataframe according to date range | 37,867,092 | <p>My dataframe has two columns: (i) a date column in a string format and (ii) an int value. I would like to convert the date string into a date object and then filter and sort the data according to a date range. Converting one string to a date worked fine with: </p>
<pre><code>date = dateutil.parser.parse(date_string... | 1 | 2016-06-16T18:44:51Z | 37,868,063 | <p>Try this: </p>
<pre><code>df['etime'] = pd.to_datetime(df['etime'], format="%Y%m%d %H:%M:%S")
df[df['etime'].between([begin_date, end_date])]
</code></pre>
<p>Caution: Since your code says <code>date</code> and you use <code>time</code> and then sort on <code>time</code>. The results may not be what you are afte... | 0 | 2016-06-16T19:40:34Z | [
"python",
"pandas",
"filter",
"dataframe"
] |
How to remove an item from a list if its in one or two (or N) other lists | 37,867,126 | <p>I have a parent list called <code>parent_list</code>, and two subsets via which I'm to filter the <code>parent_list</code>. These subsets are also python lists, and they're called <code>filter1</code> and <code>filter2</code>.</p>
<p>Can I do:</p>
<pre><code>final_list = [object for object in parent_list if object... | 3 | 2016-06-16T18:46:48Z | 37,867,187 | <p>I think you can do it as below:</p>
<pre><code>final_list = [object for object in parent_list if (object.pk not in filter1) and (object.pk not in filter2)]
</code></pre>
<p>I recomend make two sets <code>filter1</code> and <code>filter2</code> with the <code>object.pk</code> to be filtered just bc getting an eleme... | 1 | 2016-06-16T18:50:28Z | [
"python",
"list-comprehension"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.