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
Python selenium webdriver. Find elements with specified class name
38,698,948
<p>I am using Selenium to parse a page containing markup that looks a bit like this:</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;title&gt;Example&lt;/title&gt;&lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;span class="Fw(500) D(ib) Fz(42px)"&gt;1&lt;/span&gt; &lt;span class="Fw(500)...
0
2016-08-01T12:29:55Z
38,699,056
<p>Try to find elements by XPath:</p> <pre><code>//span[@class='foobar'] </code></pre> <p>This should work. </p>
-1
2016-08-01T12:34:32Z
[ "python", "selenium" ]
Python QtGui Create drop down list with buttons
38,699,013
<p>I have to create a drop down list in QtGui, and I need the option to click on the items.</p> <p>I tried to use- QtGui.QComboBox(), but the items opened like comboBox- the selected item appear in the middle of the list and when the windows is small- I can't see all the items.</p> <p>I tried also to create a class: ...
1
2016-08-01T12:32:29Z
38,700,346
<p>Your question is very interesting!! I have been thinking a lot for giving you an appropriate answer, but I really don't have one... The only thing I have in mind is waiting for an answer from the stack-overflow experts...</p> <p>Good luck and keep asking such questions!!</p>
0
2016-08-01T13:37:12Z
[ "python", "combobox", "dropdown", "qtgui" ]
Python QtGui Create drop down list with buttons
38,699,013
<p>I have to create a drop down list in QtGui, and I need the option to click on the items.</p> <p>I tried to use- QtGui.QComboBox(), but the items opened like comboBox- the selected item appear in the middle of the list and when the windows is small- I can't see all the items.</p> <p>I tried also to create a class: ...
1
2016-08-01T12:32:29Z
38,722,900
<p>You can override the combobox stylesheet:</p> <pre><code>combo.setStyleSheet("QComboBox { combobox-popup: 0; }") </code></pre> <p>and it will show the items like drop-down list.</p>
0
2016-08-02T14:13:42Z
[ "python", "combobox", "dropdown", "qtgui" ]
Web2PY caching password
38,699,035
<p>I'm just starting to use Web2PY. My basic one page app authenticates users to a AD based LDAP service. I need to collect other data via rest api calls on behave of the user from the server side of the app. I'd like to cache the username and password of the user for a session so the user doesn't have to be prompte...
0
2016-08-01T12:33:35Z
38,837,806
<p>Just wanted to close out on this in case someone in the future is looking at this as well.</p> <p>I was able to capture the password used to login by adding the following to my db.py</p> <p>def on_ldap_connect(form):<br> &emsp;&emsp;username = request.vars.username<br> &emsp;&emsp;password = request.vars.password<...
0
2016-08-08T20:17:22Z
[ "python" ]
Create XML file in Python using minidom (more than one parented element)
38,699,080
<p>I'm currently attempting to create a double-parented XML file within Python using minidom, however I'm struggling to get it to work (and by struggling I mean it's not)</p> <p>I'm trying to create something like this:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;twitter&gt; &lt;account&gt; &lt;name&gt...
0
2016-08-01T12:35:54Z
38,699,304
<p>Instead of e.g. <code>nameContent.appendChild(nameElement)</code> you need e.g <code>nameElement.appendChild(nameContent)</code> as you need to append the text node create to the element node created earlier.</p>
0
2016-08-01T12:46:04Z
[ "python", "xml", "minidom" ]
Strip everything after list of possible delimiters without regex
38,699,114
<p>I have a list of possible delimiters. I am processing a few thousand strings and need to strip everything after one of the delimiters is found. Note: There will never be a case when more than 1 delimiter is in the string.</p> <p>Example:</p> <pre><code>patterns = ['abc', 'def'] example_string = 'hello world abc 12...
1
2016-08-01T12:37:23Z
38,699,248
<p>You could use the <a href="https://docs.python.org/2/library/string.html#string.find" rel="nofollow">find</a> function. Here each pattern is checked and if found the string is sliced at the start location of the pattern (or the end location of the pattern by adding the length of the pattern, as in the example):</p> ...
3
2016-08-01T12:43:11Z
[ "python", "regex" ]
Strip everything after list of possible delimiters without regex
38,699,114
<p>I have a list of possible delimiters. I am processing a few thousand strings and need to strip everything after one of the delimiters is found. Note: There will never be a case when more than 1 delimiter is in the string.</p> <p>Example:</p> <pre><code>patterns = ['abc', 'def'] example_string = 'hello world abc 12...
1
2016-08-01T12:37:23Z
38,699,257
<p>using the find methode </p> <blockquote> <p>string.find(s, sub[, start[, end]])</p> </blockquote> <p>Return the lowest index in s where the substring sub is found such that sub is wholly contained in s[start:end]. Return -1 on failure. Defaults for start and end and interpretation of negative values is the same ...
2
2016-08-01T12:43:33Z
[ "python", "regex" ]
Strip everything after list of possible delimiters without regex
38,699,114
<p>I have a list of possible delimiters. I am processing a few thousand strings and need to strip everything after one of the delimiters is found. Note: There will never be a case when more than 1 delimiter is in the string.</p> <p>Example:</p> <pre><code>patterns = ['abc', 'def'] example_string = 'hello world abc 12...
1
2016-08-01T12:37:23Z
38,699,265
<p>You can abuse list comprehension and slicing:</p> <pre><code>delimiters = ['a', 'b'] s = 'nvcakl' s = [s[:s.index(i) + 1] for i in delimiters if i in s] print(s) &gt;&gt; ['nvca'] </code></pre> <p>This will work even if more than one delimiter is found, each index in the output list will correspond to the found de...
3
2016-08-01T12:44:02Z
[ "python", "regex" ]
Azure Streaming Analytics input/output
38,699,181
<p>I implemented a very simple Streaming Analytics query:</p> <pre><code>SELECT Collect() FROM Input TIMESTAMP BY ts GROUP BY TumblingWindow(second, 3) </code></pre> <p>I produce on an event hub input with a python script:</p> <pre><code>... iso_ts = datetime.fromtimestamp(ts).isoformat() data = dict(ts=...
0
2016-08-01T12:40:48Z
38,706,082
<p>Can you check the Service Bus queue from Azure portal for number of messages received?</p>
0
2016-08-01T18:52:53Z
[ "python", "azure", "azureservicebus", "azure-stream-analytics" ]
Azure Streaming Analytics input/output
38,699,181
<p>I implemented a very simple Streaming Analytics query:</p> <pre><code>SELECT Collect() FROM Input TIMESTAMP BY ts GROUP BY TumblingWindow(second, 3) </code></pre> <p>I produce on an event hub input with a python script:</p> <pre><code>... iso_ts = datetime.fromtimestamp(ts).isoformat() data = dict(ts=...
0
2016-08-01T12:40:48Z
38,718,114
<p>I discovered that my question was a duplicate of <a href="http://stackoverflow.com/questions/31859156/basic-query-with-timestamp-by-not-producing-output">Basic query with TIMESTAMP by not producing output</a>.</p> <p>So, the solution is that you cannot use data from the seventies, because streaming analytics will c...
0
2016-08-02T10:36:09Z
[ "python", "azure", "azureservicebus", "azure-stream-analytics" ]
Alternative to exec
38,699,273
<p>I'm currently trying to code a Python (3.4.4) GUI with tkinter which should allow to fit an arbitrary function to some datapoints. To start easy, I'd like to create some input-function and evaluate it. Later, I would like to plot and fit it using <code>curve_fit</code> from <code>scipy</code>.</p> <p>In order to do...
0
2016-08-01T12:44:44Z
38,699,981
<p>I'm not sure what exactly are you trying to do, i.e. what functions are allowed, what operations are permitted, etc.</p> <p>Here is an example of a function generator with one dynamic parameter:</p> <pre><code>&gt;&gt;&gt; def generator(n): def f(x): return x+n return f &gt;&gt;&gt; plu...
0
2016-08-01T13:17:36Z
[ "python" ]
Alternative to exec
38,699,273
<p>I'm currently trying to code a Python (3.4.4) GUI with tkinter which should allow to fit an arbitrary function to some datapoints. To start easy, I'd like to create some input-function and evaluate it. Later, I would like to plot and fit it using <code>curve_fit</code> from <code>scipy</code>.</p> <p>In order to do...
0
2016-08-01T12:44:44Z
38,700,564
<p>The problem with exec/eval, is that they can execute arbitrary code. So to use <code>exec</code> or <code>eval</code> you need to either carefully parse the code fragment to ensure it doesn't contain malicious code (an incredibly hard task), or be sure that the source of the code can be trusted. If you're making a s...
1
2016-08-01T13:48:01Z
[ "python" ]
TypeError when using a method from a class - python
38,699,332
<p>I have an improved kmeans algorithm (KPlusPlus) that builds on the class kmeans. Detk is another class inherited from KPlusPlus.</p> <p>The objective of the KPlusPlus class is to find out the optimal seeding for finding the kmeans centroids (<a href="https://datasciencelab.wordpress.com/2014/01/15/improved-seeding-...
0
2016-08-01T12:47:41Z
38,740,371
<p>The error is due to the failure of the kmeans algorithm to find the cluster centres when the number of clusters is just 1. Hence the cluster dictionary is not created for this case. So, added an extra line of code in the class <code>DetK</code> which checks if the type of cluster dictionary is <code>'NoneType'</code...
0
2016-08-03T10:00:45Z
[ "python", "k-means" ]
Multi Threading for PuLP library in python
38,699,360
<p>I want to solve an optimisation problem using PuLP library in python. My optimisation problem has >10000 variables and lot of constraints. It takes very long time for PuLP to solve such big problems. Is there any way we can implement multi threading and gain speed ?</p> <p>Any other solution/library for such big op...
0
2016-08-01T12:49:01Z
38,701,095
<p>Linear programming has not been very amenable to paralelisation, so your best bet to make the problem faster is either to use a different solver or to reformulate your problem.</p> <p>You can get a feel for the speed at which other solvers can solve your problem by generating an MPS file (using the <code>writeMPS()...
1
2016-08-01T14:13:16Z
[ "python", "multithreading", "python-3.x", "pulp" ]
Extracting rows from an extremely large (48GB) CSV file based on condition
38,699,520
<p>I have an extremely large CSV file which has more than 500 million rows. </p> <p>But <strong>I only need a few thousand rows from it based on a certain condition.</strong> I am at the moment using:</p> <pre><code>with open('/home/Documents/1681.csv', 'rb') as f: reader = csv.DictReader(f) rows = [row for ...
2
2016-08-01T12:56:28Z
38,699,681
<p>You can do this using <code>pandas</code>:</p> <pre><code>import pandas as pd chunk_list=[] for chunk in pd.read_csv('/home/Documents/1681.csv', chunksize=10000): chunk_list.append(chunk[chunk['flag_central'] == 1]` final_df = pd.concat(chunk_list) </code></pre> <p>Basically this will read 10000 rows at a ti...
3
2016-08-01T13:03:52Z
[ "python", "csv", "for-loop", "condition", "extraction" ]
Extracting rows from an extremely large (48GB) CSV file based on condition
38,699,520
<p>I have an extremely large CSV file which has more than 500 million rows. </p> <p>But <strong>I only need a few thousand rows from it based on a certain condition.</strong> I am at the moment using:</p> <pre><code>with open('/home/Documents/1681.csv', 'rb') as f: reader = csv.DictReader(f) rows = [row for ...
2
2016-08-01T12:56:28Z
38,699,728
<p>You could use <a href="http://pandas.pydata.org/" rel="nofollow">Pandas</a>. The only caveat I would have would be that with such a large file you would need to import the file in portions.</p> <pre><code>import pandas as pd tp = pd.read_csv('/home/Documents/1681.csv', iterator=True, chunksize=10000) df = pd.concat...
2
2016-08-01T13:06:17Z
[ "python", "csv", "for-loop", "condition", "extraction" ]
Extracting rows from an extremely large (48GB) CSV file based on condition
38,699,520
<p>I have an extremely large CSV file which has more than 500 million rows. </p> <p>But <strong>I only need a few thousand rows from it based on a certain condition.</strong> I am at the moment using:</p> <pre><code>with open('/home/Documents/1681.csv', 'rb') as f: reader = csv.DictReader(f) rows = [row for ...
2
2016-08-01T12:56:28Z
38,699,778
<p>If this is a one-time task, I would suggest using unix commands first, then process the extract:</p> <pre><code>cat file | awk -F , '{ if ($5 == "1") print $0 }' &gt; extract.csv </code></pre> <p>where -F specifies the column delimiter and 5 is the column number. figure this out first by </p> <pre><code>cat file ...
1
2016-08-01T13:08:39Z
[ "python", "csv", "for-loop", "condition", "extraction" ]
Extracting rows from an extremely large (48GB) CSV file based on condition
38,699,520
<p>I have an extremely large CSV file which has more than 500 million rows. </p> <p>But <strong>I only need a few thousand rows from it based on a certain condition.</strong> I am at the moment using:</p> <pre><code>with open('/home/Documents/1681.csv', 'rb') as f: reader = csv.DictReader(f) rows = [row for ...
2
2016-08-01T12:56:28Z
38,738,296
<p>If this is a repetitive process and/or you have more complex conditions to process, here is a fast, low-memory approach in Python that will get you there quickly:</p> <pre><code>#!/usr/bin/env python # put this in parsecsv.py, then chmod +x parsecsv.py import sys output = lambda l: sys.stdout.write(l) for line in ...
1
2016-08-03T08:26:44Z
[ "python", "csv", "for-loop", "condition", "extraction" ]
Select rows from a DataFrame by date_range
38,699,561
<p>i have the following dataframe:</p> <pre><code> FAK_ART FAK_DAT LEIST_DAT KD_CRM MW_BW EQ_NR MATERIAL \ 0 ZPAF 2015-05-18 2015-05-31 TMD E 1003507107 G230ETS 1 ZPAF 2015-05-18 2015-05-31 TMD B 1003507107 G230ETS 2 ZPAF 2015-05-18 2015-0...
1
2016-08-01T12:58:14Z
38,699,644
<p>You can <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> from column <code>LEIST_DAT</code> and then select by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ix.html" rel="nofollow"><code>ix</cod...
3
2016-08-01T13:02:16Z
[ "python", "pandas" ]
How to read csv file with date as one of the data?
38,699,581
<p>These are my data both in excel and in csv files:</p> <p>Date,Time,Product_Type 2015-01-02,02:29:45 PM,Cards</p> <p>I've tried this code below and it works well with the excel file but not in CSV file.</p> <pre><code>import numpy as np import pandas as pd df = pd.read_excel('file.xlsx') print(df.head()) </code><...
0
2016-08-01T12:59:23Z
38,700,149
<p>I'm not sure exactly what you plan to do with the data once its pulled from the file so if you need a different format or something let me know. </p> <p>I'm assuming you'll always be working with a CSV for this code. The code below simply opens your file and for every line, splits by the commas, and appends to a ...
0
2016-08-01T13:27:02Z
[ "python", "csv", "pandas", "time-series" ]
How to read csv file with date as one of the data?
38,699,581
<p>These are my data both in excel and in csv files:</p> <p>Date,Time,Product_Type 2015-01-02,02:29:45 PM,Cards</p> <p>I've tried this code below and it works well with the excel file but not in CSV file.</p> <pre><code>import numpy as np import pandas as pd df = pd.read_excel('file.xlsx') print(df.head()) </code><...
0
2016-08-01T12:59:23Z
38,719,714
<p>I have modified and removed the column names on my csv file and used this code below. It works! </p> <p>CSV File Data</p> <pre><code> 2015-01-02,02:29:45 PM,Cards 2015-01-02,05:16:15 PM,Cards 2015-01-02,05:48:46 PM,Cards 2015-01-02,03:18:34 PM,Cards 2015-01-02,05:22:55 PM,Cards </code></pre> <p...
0
2016-08-02T11:52:40Z
[ "python", "csv", "pandas", "time-series" ]
Spliting a string list to floats - memory error
38,699,603
<p>I can't handle with splitting a list of strings to a list of floats. I open a text file (.vol, but it just contains text) which last line is an extremely long line of numbers. </p> <blockquote> <p>Params1 437288.59375000 102574.20312500 -83.30001831<br> Params2 437871.93750000 104981.40625000 362.10000610<br> ...
1
2016-08-01T13:00:25Z
38,700,222
<p>Your problem here (as mentioned in the comments) is:</p> <p>1) In the first case you are trying to index into the string before you split it and you are attempting to convert spaces to floats (hence the <code>ValueError</code>)</p> <p>2) In the second case there are probably too many numbers in the list and you ar...
0
2016-08-01T13:30:43Z
[ "python", "string", "split", "out-of-memory" ]
Spliting a string list to floats - memory error
38,699,603
<p>I can't handle with splitting a list of strings to a list of floats. I open a text file (.vol, but it just contains text) which last line is an extremely long line of numbers. </p> <blockquote> <p>Params1 437288.59375000 102574.20312500 -83.30001831<br> Params2 437871.93750000 104981.40625000 362.10000610<br> ...
1
2016-08-01T13:00:25Z
38,700,568
<p>If I understand it correctly, you cannot make txt[9].split() and map it like this: <code>map(float, txt[9].split())</code> because the txt[9] is too large. </p> <p>You can try this generator:</p> <pre><code>def float_generator(txt): x = '' for c in txt: if c != ' ': x +=...
0
2016-08-01T13:48:08Z
[ "python", "string", "split", "out-of-memory" ]
Removing numbers mixed with letters from string
38,699,616
<p>Suppose I have a string such as :</p> <pre><code>string = 'This string 22 is not yet perfect1234 and 123pretty but it can be.' </code></pre> <p>I want to remove any numbers <strong>which are mixed with words</strong>, such as <code>'perfect1234'</code> and <code>'123pretty'</code>, <strong>but not</strong> <code>'...
-5
2016-08-01T13:00:57Z
38,699,711
<pre><code>import re re.sub(r'\d+', '', string) </code></pre>
1
2016-08-01T13:05:12Z
[ "python", "regex", "string" ]
Removing numbers mixed with letters from string
38,699,616
<p>Suppose I have a string such as :</p> <pre><code>string = 'This string 22 is not yet perfect1234 and 123pretty but it can be.' </code></pre> <p>I want to remove any numbers <strong>which are mixed with words</strong>, such as <code>'perfect1234'</code> and <code>'123pretty'</code>, <strong>but not</strong> <code>'...
-5
2016-08-01T13:00:57Z
38,699,827
<pre><code>s = 'This string 22 is not yet perfect1234 and 123pretty but it can be.' new_s = "" for word in s.split(' '): if any(char.isdigit() for char in word) and any(c.isalpha() for c in word): new_s += ''.join([i for i in word if not i.isdigit()]) else: new_s += word new_s += ' ' </code...
1
2016-08-01T13:11:09Z
[ "python", "regex", "string" ]
Removing numbers mixed with letters from string
38,699,616
<p>Suppose I have a string such as :</p> <pre><code>string = 'This string 22 is not yet perfect1234 and 123pretty but it can be.' </code></pre> <p>I want to remove any numbers <strong>which are mixed with words</strong>, such as <code>'perfect1234'</code> and <code>'123pretty'</code>, <strong>but not</strong> <code>'...
-5
2016-08-01T13:00:57Z
38,699,831
<p>The code below checks each character for a digit. If it isn't a digit, it adds the character to the end of the corrected string. </p> <pre><code>string = 'This string is not yet perfect1234 and 123pretty but it can be.' CorrectedString = "" for characters in string: if characters.isdigit(): continue ...
0
2016-08-01T13:11:16Z
[ "python", "regex", "string" ]
Removing numbers mixed with letters from string
38,699,616
<p>Suppose I have a string such as :</p> <pre><code>string = 'This string 22 is not yet perfect1234 and 123pretty but it can be.' </code></pre> <p>I want to remove any numbers <strong>which are mixed with words</strong>, such as <code>'perfect1234'</code> and <code>'123pretty'</code>, <strong>but not</strong> <code>'...
-5
2016-08-01T13:00:57Z
38,700,037
<p>You can try this by simply join function and as well as nothing to import</p> <pre><code>str_var='This string is not yet perfect1234 and 123pretty but it can be.' str_var = ''.join(x for x in str_var if not x.isdigit()) print str_var </code></pre> <p>output:</p> <pre><code>'This string is not yet perfect and pre...
0
2016-08-01T13:21:00Z
[ "python", "regex", "string" ]
Removing numbers mixed with letters from string
38,699,616
<p>Suppose I have a string such as :</p> <pre><code>string = 'This string 22 is not yet perfect1234 and 123pretty but it can be.' </code></pre> <p>I want to remove any numbers <strong>which are mixed with words</strong>, such as <code>'perfect1234'</code> and <code>'123pretty'</code>, <strong>but not</strong> <code>'...
-5
2016-08-01T13:00:57Z
38,700,096
<p>If you want to preserve digits that are by themselves (not part of a word with alpha characters in it), this regex will do the job (but there probably is a way to make it simpler):</p> <pre><code>import re pattern = re.compile(r"\d*([^\d\W]+)\d*") s = "This string is not yet perfect1234 and 123pretty but it can be....
1
2016-08-01T13:23:53Z
[ "python", "regex", "string" ]
Splitting line with escaped separators in Python
38,699,763
<p>TL; DR:</p> <pre><code>line = "one|two|three\|four\|five" fields = line.split(whatever) </code></pre> <p>for what value of <code>whatever</code> does:</p> <pre><code>fields == ['one', 'two', 'three\|four\|five'] </code></pre> <p>I have a file delimited by pipe characters. Some of the fields in that file also inc...
-2
2016-08-01T13:08:02Z
38,699,865
<p>Maybe you can use something like this : </p> <pre><code>[^\\]\| </code></pre> <p>where <code>[^\\]</code> match any caracter different of <code>\</code>.</p>
0
2016-08-01T13:12:18Z
[ "python", "regex", "split", "negative-lookahead" ]
Splitting line with escaped separators in Python
38,699,763
<p>TL; DR:</p> <pre><code>line = "one|two|three\|four\|five" fields = line.split(whatever) </code></pre> <p>for what value of <code>whatever</code> does:</p> <pre><code>fields == ['one', 'two', 'three\|four\|five'] </code></pre> <p>I have a file delimited by pipe characters. Some of the fields in that file also inc...
-2
2016-08-01T13:08:02Z
38,699,872
<p>You can use a regex like</p> <pre><code>re.split(r'([^|]+[^\\])\|', line) </code></pre> <p>which will use a character group to specify anything except <code>\</code> followed by a <code>|</code> will be used to do the split</p> <p>That will give an extra empty match at the beginning of the list, but hopefully you...
2
2016-08-01T13:12:45Z
[ "python", "regex", "split", "negative-lookahead" ]
Using python hashmap for counting elements
38,699,817
<p>When i need to count elements of different type , i find myself writing something like:</p> <pre><code>if k not in removed: removed[k] = 0 removed[k] = removed[k] + 1 </code></pre> <p>Sometimes i do the same thing with a new empty list that will grow over time. The above code works fine, but it feels like ther...
0
2016-08-01T13:10:56Z
38,700,135
<p>In addition to defaultdict/Counter mentioned in comments, you can also have a default value returned from a failed <code>get</code>. This allows you to set the initial count to 0 if the key lookup fails and immediately increment by 1, or increment by 1 each time the key is found as you loop through.</p> <pre><code>...
1
2016-08-01T13:26:27Z
[ "python", "hashmap" ]
Using python hashmap for counting elements
38,699,817
<p>When i need to count elements of different type , i find myself writing something like:</p> <pre><code>if k not in removed: removed[k] = 0 removed[k] = removed[k] + 1 </code></pre> <p>Sometimes i do the same thing with a new empty list that will grow over time. The above code works fine, but it feels like ther...
0
2016-08-01T13:10:56Z
38,700,665
<p>One way to do it:</p> <pre><code>countdict = dict() for k in inputlist: if k not in countdict.keys(): countdict[k] = inputlist.count(k) </code></pre>
0
2016-08-01T13:51:51Z
[ "python", "hashmap" ]
Using python hashmap for counting elements
38,699,817
<p>When i need to count elements of different type , i find myself writing something like:</p> <pre><code>if k not in removed: removed[k] = 0 removed[k] = removed[k] + 1 </code></pre> <p>Sometimes i do the same thing with a new empty list that will grow over time. The above code works fine, but it feels like ther...
0
2016-08-01T13:10:56Z
38,700,750
<p>This is exactly what the <code>Counter</code> is for! <a href="https://docs.python.org/2/library/collections.html#collections.Counter" rel="nofollow">https://docs.python.org/2/library/collections.html#collections.Counter</a></p>
0
2016-08-01T13:55:47Z
[ "python", "hashmap" ]
Create a vector graphics (svg, eps, pdf) "heatmap" from 2d function with colorbar
38,699,838
<p>I want to plot a 2d hanning window function for a picture with <code>N=512</code> pixels with a colorbar as vector graphics (<code>*.svg</code>, <code>*.eps</code>, (vectorized!) <code>*.pdf</code> or so)... So I need to plot a 2d function</p> <pre><code>w(x,y) = sin(x*pi/N)^2 * sin(y*pi/N)^2 </code></pre> <p>My s...
1
2016-08-01T13:11:25Z
38,700,632
<p>With a PDF, SVG or EPS terminal, gnuplot <strong>does</strong> give you vector graphics. <strong>But</strong> the function has to be represented in some way, and what gnuplot does is a piecewise linear interpolation, that is, the surface is represented by small portions of plane (triangles or quadrangles), the numbe...
1
2016-08-01T13:50:42Z
[ "python", "plot", "gnuplot", "vector-graphics" ]
Series to Dataframe conversion with column indexing
38,699,893
<p>There is a Series called <code>location_ratings</code> as below :</p> <pre><code>location_ratings = location['Location'].value_counts() </code></pre> <p>Below is the location_ratings's sample output:</p> <pre><code> Location Brazil 180 Alaska ...
1
2016-08-01T13:13:41Z
38,700,077
<p>You can first change index name by <a href="http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#changes-to-rename" rel="nofollow"><code>rename_axis</code></a> (new in <code>pandas</code> <code>0.18.0</code>) and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.ht...
0
2016-08-01T13:23:15Z
[ "python", "python-3.x", "pandas", "dataframe", "multiple-columns" ]
Series to Dataframe conversion with column indexing
38,699,893
<p>There is a Series called <code>location_ratings</code> as below :</p> <pre><code>location_ratings = location['Location'].value_counts() </code></pre> <p>Below is the location_ratings's sample output:</p> <pre><code> Location Brazil 180 Alaska ...
1
2016-08-01T13:13:41Z
38,729,396
<pre><code>D1 = location_ratings.rename_axis('Location').reset_index(name='Ratings') </code></pre>
0
2016-08-02T19:57:56Z
[ "python", "python-3.x", "pandas", "dataframe", "multiple-columns" ]
Django: Know when a file is already saved after usign storage.save()
38,699,927
<p>So I've a Django model which has a FileField. This FileField, contains generally an image. After I receipt the picture from a request, I need to run some picture analysis processes. </p> <p>The problem is that sometimes, I need to rotate the picture before running the analysis (which runs in celery, loading the mod...
0
2016-08-01T13:15:12Z
38,701,216
<p>No magic solution here. You have to manage states on your model, specially when working with celery tasks. You might need another field called <code>state</code> with the states: <code>NONE</code> (no action is beeing done), <code>PROCESSING</code> (task was sent to celery to process) and <code>DONE</code> (image wa...
0
2016-08-01T14:18:35Z
[ "python", "django", "amazon-web-services", "amazon-s3" ]
The code does not work when I update a variable
38,700,060
<p>I'm trying to display two images of cards in a simple GUI(can only be accessed online at <a href="http://www.codeskulptor.org/#user41_8Poew9PXI8_1.py" rel="nofollow">http://www.codeskulptor.org/#user41_8Poew9PXI8_1.py</a>)</p> <pre><code>import simplegui #images to be displayed ace_hearts = simplegui.load_image("h...
0
2016-08-01T13:22:18Z
38,700,234
<p>Second and fourth parameter given to <a href="http://www.codeskulptor.org/docs.html#draw_image" rel="nofollow"><code>draw_image</code></a> are <code>center_source</code> and <code>center_dest</code>. When you draw the second image you need to keep <code>center_source</code> the same and only modify <code>center_dest...
1
2016-08-01T13:31:50Z
[ "python", "list", "python-2.7" ]
I want to name my columns the numbers from 2 for loops
38,700,194
<p>I am running a double for loop of the form </p> <pre><code>for i in range (0,5): for j in range (0,5): colname = '%i%j' %{'i':'i','j':'j'} df[colname] = poisson.pmf(i,df['lambda'])*poisson.pmf(j,df['mu']) </code></pre> <p>I would like for the code to return the 36 extra columns of 00 up to 55 ...
-1
2016-08-01T13:29:10Z
38,700,670
<p>I think you need <code>range(6)</code> and <code>%d</code>:</p> <pre><code>for i in range (6): for j in range (6): colname = '%d%d' % (i, j) print (colname) </code></pre> <pre><code>00 01 02 03 04 05 10 11 12 13 14 15 20 21 22 23 24 25 30 31 32 33 34 35 40 41 42 43 44 45 50 51 52 53 54 55 </c...
1
2016-08-01T13:52:03Z
[ "python", "pandas", "for-loop" ]
Pyomo: Access Solution From Python Code
38,700,214
<p>I have a linear integer programme I want to solve. I installed solver glpk (thanks to <a href="http://stackoverflow.com/questions/20690195/how-do-you-install-glpk-solver-along-with-pyomo-in-winpython/37918417#37918417">this answer</a>) and pyomo. I wrote code like this:</p> <pre><code>from pyomo.environ import * fr...
0
2016-08-01T13:30:25Z
38,707,092
<p>I'm not sure if this is what you are looking for, but this is a way that I have some variables being printed in one of my scripts. </p> <pre><code>from pyomo.environ import * from pyomo.opt import SolverFactory from pyomo.core import Var M = AbstractModel() opt = SolverFactory('glpk') # Vars, Params, Objective, C...
2
2016-08-01T19:56:33Z
[ "python", "optimization", "mathematical-optimization", "linear-programming", "pyomo" ]
Pyomo: Access Solution From Python Code
38,700,214
<p>I have a linear integer programme I want to solve. I installed solver glpk (thanks to <a href="http://stackoverflow.com/questions/20690195/how-do-you-install-glpk-solver-along-with-pyomo-in-winpython/37918417#37918417">this answer</a>) and pyomo. I wrote code like this:</p> <pre><code>from pyomo.environ import * fr...
0
2016-08-01T13:30:25Z
39,146,463
<p>Here's a modified version of your script that illustrates two different ways of printing variable values: (1) by explicitly referencing each variable and (2) by iterating over all variables in the model.</p> <pre><code># Pyomo v4.4.1 # Python 2.7 from pyomo.environ import * from pyomo.opt import SolverFactory a =...
0
2016-08-25T13:18:48Z
[ "python", "optimization", "mathematical-optimization", "linear-programming", "pyomo" ]
ValueError: could not convert string to float
38,700,249
<p>So... I have this primitive calculator that runs fine on my cellphone, but when I try to run it on Windows 10 I get...</p> <blockquote> <p>ValueError: could not convert string to float</p> </blockquote> <p>I don't know what the problem is, I've tried using <code>raw_input</code> but it doesn't work ether. Please...
1
2016-08-01T13:32:39Z
38,700,413
<p>your code only convert string that are integers like in below statement</p> <pre><code>num1 = float(input ()) #take a float and store it ex 13 print num1 # output 13.0 </code></pre> <p>if you provide <code>13</code> as a input it will give the output as <code>13.0</code> but if you provide <code>SOMEONEE</code> as...
1
2016-08-01T13:40:29Z
[ "python" ]
ValueError: could not convert string to float
38,700,249
<p>So... I have this primitive calculator that runs fine on my cellphone, but when I try to run it on Windows 10 I get...</p> <blockquote> <p>ValueError: could not convert string to float</p> </blockquote> <p>I don't know what the problem is, I've tried using <code>raw_input</code> but it doesn't work ether. Please...
1
2016-08-01T13:32:39Z
38,700,450
<p>I think this is happening because in some cases 'input' contains non-numerical characters. Python is smart and when a string only contains numbers, it can be converted from string to float. When the string contains non-numerical characters, it is not possible for Python to convert it to a float.</p> <p>You could fi...
0
2016-08-01T13:42:49Z
[ "python" ]
(Python) Converting image time series to ROS bag
38,700,271
<p>I have a set of images with metadata including time stamps and odometry data from a data set. I want to convert this time series of images into a rosbag so I can easily plug it out of the code I'll write and switch in real time data after testing. By the tutorial, the process of programmatically saving data to a ros...
1
2016-08-01T13:33:27Z
38,702,418
<p>Many of the standard message types like <a href="http://docs.ros.org/api/sensor_msgs/html/msg/Image.html" rel="nofollow">sensor_msgs/Image</a> or <a href="http://docs.ros.org/jade/api/nav_msgs/html/msg/Odometry.html" rel="nofollow">nav_msgs/Odometry</a> have an attribute <a href="http://docs.ros.org/api/std_msgs/htm...
1
2016-08-01T15:14:47Z
[ "python", "opencv", "ros" ]
how to put dictionary data in to data frame and can that data frame be converted in csv file?
38,700,299
<pre><code>import random import pandas as pd import numpy as np heart_rate = [random.randrange(45,125) for _ in range(100)] blood_pressure_systolic = [random.randrange(140,230) for _ in range(100)] blood_pressure_dyastolic = [random.randrange(90,140) for _ in range(100)] temperature = [random.randrange(34,42) for _ i...
0
2016-08-01T13:34:42Z
38,700,482
<p>You're almost there. What you want is:</p> <pre><code>vitalsign = {'heart' : heart_rate, 'blood' : blood_pressure_systolic, 'temp' : temperature, 'pulse' : pulse_oximetry} df = pd.DataFrame(vitalsign) </code></pre> <p>To convert this to .csv:</p> <pre><code>df.to_csv('your_f...
0
2016-08-01T13:44:16Z
[ "python", "dataframe" ]
How to filter haystack results with db query
38,700,440
<p>I need to text-search across my model and filter with db queries at the same time.</p> <p>For example:</p> <pre><code>class MyModel(models.Model): text = models.TextField() users = models.ManyToMany(User) class MyModelIndexIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(documen...
7
2016-08-01T13:42:20Z
38,866,990
<p>In the general case, it's (probably) not possible to solve your problem using just one query. For instance, if you are using ElasticSearch as a search backend engine and MySQL for django models, there is no way MySQL and ElasticSearch will communicate to produce a single, common query.</p> <p>However, there should ...
1
2016-08-10T07:35:21Z
[ "python", "django", "django-haystack" ]
Create folder with today's date and move 100's of pdfs
38,700,448
<p>I want to create a new folder each day with the folder title being the date of that day. So today's would be 01082016 and tomorrow will be 02082016 etc. I know how to make this folder but I'm struggling to choose the destination of this folder.</p> <p>Also I'd like to move a large number of PDFs from the FTP fold...
0
2016-08-01T13:42:44Z
38,700,647
<p>You can easily create the folder wherever you like (as long as the permissions are correct). Check if the folder currently exists and create it if not:</p> <pre><code>directory = "example/dir/" + time.strftime("%d%m%y") if not os.path.exists(directory): os.makedirs(directory) </code></pre> <p>Getting the files...
0
2016-08-01T13:51:24Z
[ "python", "pdf", "folders" ]
How (in what form) to share (deliver) a Python function?
38,700,517
<p>The final outcome of my work should be a Python function that takes a JSON object as the only input and return another JSON object as output. To keep it more specific, I am a data scientist, and the function that I am speaking about, is derived from data and it delivers predictions (in other words, it is a machine l...
19
2016-08-01T13:46:07Z
38,771,976
<p>You have the right idea with using a socket but there are tons of frameworks doing exactly what you want. Like <a href="http://stackoverflow.com/users/6464893/hleggs">hleggs</a>, I suggest you checkout <a href="http://flask.pocoo.org/">Flask</a> to build a microservice. This will let the other team post JSON objects...
9
2016-08-04T15:48:25Z
[ "python", "sockets", "deployment", "publish" ]
How (in what form) to share (deliver) a Python function?
38,700,517
<p>The final outcome of my work should be a Python function that takes a JSON object as the only input and return another JSON object as output. To keep it more specific, I am a data scientist, and the function that I am speaking about, is derived from data and it delivers predictions (in other words, it is a machine l...
19
2016-08-01T13:46:07Z
38,778,851
<p>I guess you have 3 possibilities :</p> <ul> <li>convert python function to javascript function:</li> </ul> <p><em>Assuming the "tech-team" use Javascript for web-service, you may try to convert your python function directly to a Javascript function (which will be really easy to integrate on web page) using <a href...
-1
2016-08-04T23:21:19Z
[ "python", "sockets", "deployment", "publish" ]
How (in what form) to share (deliver) a Python function?
38,700,517
<p>The final outcome of my work should be a Python function that takes a JSON object as the only input and return another JSON object as output. To keep it more specific, I am a data scientist, and the function that I am speaking about, is derived from data and it delivers predictions (in other words, it is a machine l...
19
2016-08-01T13:46:07Z
38,821,742
<p>Your task is (in generality) about productionizing a machine learning model, where the consumer of the model may not be working in the same environment as the one which was used to develop the model. I've been trying to tackle this problem since past few years. The problem is faced by many companies and it is aggrav...
0
2016-08-08T05:18:01Z
[ "python", "sockets", "deployment", "publish" ]
How (in what form) to share (deliver) a Python function?
38,700,517
<p>The final outcome of my work should be a Python function that takes a JSON object as the only input and return another JSON object as output. To keep it more specific, I am a data scientist, and the function that I am speaking about, is derived from data and it delivers predictions (in other words, it is a machine l...
19
2016-08-01T13:46:07Z
38,884,914
<p>As already suggested in other answers the best option would be creating a simple web service. Besides Flask you may want to try <a href="http://bottlepy.org" rel="nofollow">bottle</a> which is very thin one-file web framework. Your service may looks as simple as:</p> <pre><code>from bottle import route, run, reques...
0
2016-08-10T23:03:38Z
[ "python", "sockets", "deployment", "publish" ]
How (in what form) to share (deliver) a Python function?
38,700,517
<p>The final outcome of my work should be a Python function that takes a JSON object as the only input and return another JSON object as output. To keep it more specific, I am a data scientist, and the function that I am speaking about, is derived from data and it delivers predictions (in other words, it is a machine l...
19
2016-08-01T13:46:07Z
38,891,638
<p>My understanding of your question boils down to: </p> <p><em>How can I share a Python library with the rest of my team, that may not be using Python otherwise?</em></p> <p><em>And how can I make sure my code and its dependencies are what the receiving team will run?</em></p> <p><em>And that the receiving team can...
2
2016-08-11T08:52:49Z
[ "python", "sockets", "deployment", "publish" ]
One-liner to save value of if statement?
38,700,537
<p>Is there a smart way to write the following code in three or four lines?</p> <pre><code>a=l["artist"] if a: b=a["projects"] if b: c=b["project"] if c: print c </code></pre> <p>So I thought for something like pseudocode:</p> <pre><code>a = l["artist"] if True: </code></pre>
3
2016-08-01T13:46:58Z
38,700,625
<p>I don't necessarily think that this is better but you could do:</p> <pre><code>try: c = l["artist"]["projects"]["project"] except (KeyError, TypeError) as e: print e pass </code></pre>
5
2016-08-01T13:50:23Z
[ "python", "variables", "if-statement" ]
One-liner to save value of if statement?
38,700,537
<p>Is there a smart way to write the following code in three or four lines?</p> <pre><code>a=l["artist"] if a: b=a["projects"] if b: c=b["project"] if c: print c </code></pre> <p>So I thought for something like pseudocode:</p> <pre><code>a = l["artist"] if True: </code></pre>
3
2016-08-01T13:46:58Z
38,700,640
<p>How about:</p> <pre><code>try: print l["artist"]["projects"]["project"] except KeyError: pass except TypeError: pass # None["key"] raises TypeError. </code></pre> <p>This will <code>try</code> to <code>print</code> the value, but if a <code>KeyError</code> is raised, the <code>except</code> block will...
7
2016-08-01T13:51:00Z
[ "python", "variables", "if-statement" ]
One-liner to save value of if statement?
38,700,537
<p>Is there a smart way to write the following code in three or four lines?</p> <pre><code>a=l["artist"] if a: b=a["projects"] if b: c=b["project"] if c: print c </code></pre> <p>So I thought for something like pseudocode:</p> <pre><code>a = l["artist"] if True: </code></pre>
3
2016-08-01T13:46:58Z
38,700,741
<pre><code>p = l.get('artist') and l['artist'].get('projects') and l['artist']['projects'].get('project') if p: print p </code></pre> <p>You can also make a more general function for this purpose:</p> <pre><code>def get_attr(lst, attr): current = lst for a in attr: if current.get(a) is not None: ...
0
2016-08-01T13:55:04Z
[ "python", "variables", "if-statement" ]
One-liner to save value of if statement?
38,700,537
<p>Is there a smart way to write the following code in three or four lines?</p> <pre><code>a=l["artist"] if a: b=a["projects"] if b: c=b["project"] if c: print c </code></pre> <p>So I thought for something like pseudocode:</p> <pre><code>a = l["artist"] if True: </code></pre>
3
2016-08-01T13:46:58Z
38,700,768
<p>One-liner (as in the title) without exceptions:</p> <pre><code>if "artist" in l and l["artist"] and "projects" in l["artist"] and l["artist"]["projects"] and "project" in l["artist"]["projects"]: print l["artist"]["projects"]["project"] </code></pre>
0
2016-08-01T13:56:30Z
[ "python", "variables", "if-statement" ]
One-liner to save value of if statement?
38,700,537
<p>Is there a smart way to write the following code in three or four lines?</p> <pre><code>a=l["artist"] if a: b=a["projects"] if b: c=b["project"] if c: print c </code></pre> <p>So I thought for something like pseudocode:</p> <pre><code>a = l["artist"] if True: </code></pre>
3
2016-08-01T13:46:58Z
38,701,687
<p>Since you're dealing with nested dictionaries, you might find this generic one-liner useful because it will allow you to access values at any level just by passing it more <code>keys</code> arguments:</p> <pre><code>nested_dict_get = lambda item, *keys: reduce(lambda d, k: d.get(k), keys, item) l = {'artist': {'pr...
0
2016-08-01T14:40:47Z
[ "python", "variables", "if-statement" ]
Read image from a path in sys.path inside a Python module
38,700,617
<p>I am very new to python and opencv world. I was just trying to read and show an image but I always get an error:</p> <blockquote> <p>error: D:\Build\OpenCV\opencv-3.1.0\modules\highgui\src\window.cpp:289: error: (-215) size.width>0 &amp;&amp; size.height>0 in function cv::imshow</p> </blockquote> <p>I have c...
0
2016-08-01T13:50:07Z
38,700,765
<p>I'm not sure what you're trying to do in your application but <code>sys.path</code> seems superfluous in the example code. Furthermore, <code>sys.path</code> says in the <a href="https://docs.python.org/2/library/sys.html#sys.path" rel="nofollow">Python documentation</a> that it is </p> <blockquote> <p>A list of...
1
2016-08-01T13:56:24Z
[ "python", "python-3.x", "opencv" ]
Read image from a path in sys.path inside a Python module
38,700,617
<p>I am very new to python and opencv world. I was just trying to read and show an image but I always get an error:</p> <blockquote> <p>error: D:\Build\OpenCV\opencv-3.1.0\modules\highgui\src\window.cpp:289: error: (-215) size.width>0 &amp;&amp; size.height>0 in function cv::imshow</p> </blockquote> <p>I have c...
0
2016-08-01T13:50:07Z
38,701,247
<p>What makes you imagine that <code>sys.path</code> settings will affect the directories from which you read files? It's purely used to locate Python modules for import. So to answer your question, the behaviour you are seeing is normal and expected. If you have a directory in <code>dir</code> and a filename in <code>...
1
2016-08-01T14:20:32Z
[ "python", "python-3.x", "opencv" ]
QCheckBox only executes when checked twice
38,700,666
<p>I have a QCheckBox (<code>deselect_checkbox</code>) which, when checked, sets another QCheckBox (<code>first_checkbox</code>) and itself to <code>False</code>. However, it only works every other time and I'm not sure why. Here is the code:</p> <pre><code>def deselect_func(): if self.dockwidget.deselect_checkbox...
1
2016-08-01T13:51:53Z
38,705,368
<p>You're mixing up "check-state" and "checked".</p> <p>The former can have three states: Unchecked, PartiallyChecked, and Checked, whereas the latter is just True/False. If you call <code>setChecked()</code> instead of <code>setCheckState()</code>, a state-change won't be registered. Thus, on the next click, a <code>...
1
2016-08-01T18:06:27Z
[ "python", "qt-designer", "qcheckbox" ]
Pandas: Set multiple MultiColumns as MultiIndex
38,700,694
<p>I generate an empty data frame as follows:</p> <pre><code>topFields = ['desc', 'desc', 'price', 'price', 'units', 'units'] bottomFields = ['foo', 'bar', 'mean', 'mom_2', 'mean', 'mom_2'] resultsDf = pd.DataFrame(columns=pd.MultiIndex.from_arrays([topFields, bottomFields])) </code></pre> <p>Now I would like to set ...
0
2016-08-01T13:53:23Z
38,700,764
<p>It looks like need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> by tuple:</p> <pre><code>test = resultsDf.set_index(('desc', 'foo')) print (test) Empty DataFrame Columns: [(desc, bar), (price, mean), (price, mom_2), (units,...
1
2016-08-01T13:56:21Z
[ "python", "pandas" ]
How to implement "next" for a dictionary object to be iterable?
38,700,734
<p>I've got the following wrapper for a dictionary:</p> <pre><code>class MyDict: def __init__(self): self.container = {} def __setitem__(self, key, value): self.container[key] = value def __getitem__(self, key): return self.container[key] def __iter__(self): return se...
0
2016-08-01T13:54:55Z
38,700,850
<p>Dictionaries are themselves not an <em>iterator</em> (which can only be iterated over <em>once</em>). You usually make them an <em>iterable</em>, an object for which you can produce multiple <em>iterators</em> instead.</p> <p>Drop the <code>next</code> method altogether, and have <code>__iter__</code> return an ite...
5
2016-08-01T14:00:33Z
[ "python", "python-2.7", "dictionary", "iterator", "iterable" ]
How to implement "next" for a dictionary object to be iterable?
38,700,734
<p>I've got the following wrapper for a dictionary:</p> <pre><code>class MyDict: def __init__(self): self.container = {} def __setitem__(self, key, value): self.container[key] = value def __getitem__(self, key): return self.container[key] def __iter__(self): return se...
0
2016-08-01T13:54:55Z
38,701,186
<p>If you want to be able to use your dict-like object inside nested loops, for example, or any other application that requires multiple iterations over the same object, then you need to implement an <code>__iter__</code> method that returns a newly-created iterator object.</p> <p>Python's iterable objects all do this...
2
2016-08-01T14:17:02Z
[ "python", "python-2.7", "dictionary", "iterator", "iterable" ]
What is the expected packet loss with scapy?
38,700,821
<p>I want to listen to packets on an interface of <code>SystemA</code>. Since it looks like I do not see the vast majority of incoming packets, I used <code>scapy</code> in its simplest form:</p> <pre><code>import scapy.all as scapy def filtre(p): if p.haslayer(scapy.IP): print(p[scapy.IP].src) # Disable...
1
2016-08-01T13:58:54Z
38,869,261
<p> You might want to try with something that does not use the output (as this can be a bottleneck). Also, you can use a BPF filter in case you have unwanted packets on the wire. Moreover, since you don't need to dissect the IP payloads, you can prevent Scapy from parsing the whole packet layers.</p> <pre><code>from c...
0
2016-08-10T09:24:19Z
[ "python", "networking", "scapy" ]
Adding Columns if they exist in the Dataframe: pandas
38,700,848
<p>I have a Dataframe, where I want to add three columns and make it one, and I want it for the columns which exits in the data frame. so for example, I want to add following columns </p> <pre><code>List_ID=['ID1','ID2','ID3'] df # Df is the data frame </code></pre> <p>I am trying following for summing up the "if e...
0
2016-08-01T14:00:32Z
38,701,217
<p>IIUC one possible solution is <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.strip.html" rel="nofollow"><code>strip</code></a> wtihespaces:</p> <pre><code>a=df['Column 1'].str.strip() + df['Column 2'].str.strip() print (a) 0 A 1 F 2 C 3 dtype: object </code></pre> <p...
2
2016-08-01T14:18:35Z
[ "python", "pandas", "if-statement", "for-loop", "dataframe" ]
Python - urllib3 get text from docx using tika server
38,700,924
<p>I am using <code>python3</code>, <code>urllib3</code> and <code>tika-server-1.13</code> in order to get text from different types of files. This is my python code:</p> <pre><code>def get_text(self, input_file_path, text_output_path, content_type): global config headers = util.make_headers() mime_type =...
0
2016-08-01T14:04:08Z
38,719,397
<p>You're not uploading the data in the same way. <code>--data-binary</code> in curl simply uploads the binary data as it is. No encoding. In urllib3, using <code>fields</code> causes urllib3 to generate a <code>multipart/form-encoded</code> message. On top of that, you're preventing urllib3 from properly setting that ...
2
2016-08-02T11:37:48Z
[ "python", "python-3.x", "urllib", "apache-tika", "urllib3" ]
AttributeError: 'Figure' object has no attribute 'plot'
38,701,137
<p>My code</p> <pre><code>import matplotlib.pyplot as plt plt.style.use("ggplot") import numpy as np from mtspec import mtspec from mtspec.util import _load_mtdata data = np.loadtxt('262_V01_C00_R000_TEx_BL_4096H.dat') spec,freq,jackknife,f_statistics,degrees_of_f = mtspec(data=data, delta= 4930.0, time_bandwidth=4 ...
1
2016-08-01T14:15:04Z
38,701,163
<p>You assign <code>ax2</code> to a <code>figure</code> object which doesn't have a <code>plot</code> method defined. You want to create your axes using <code>plt.axes</code> instead</p> <pre><code>ax2 = plt.axes() # Instead of ax2 = fig </code></pre>
3
2016-08-01T14:16:01Z
[ "python", "matplotlib" ]
Error: Missing the OpenSSL lib? while trying to install python in pyenv/ SUSE12 environment
38,701,203
<p>I have tried installing python in pyenv env, in which i am getting the below error. I have added openssl to the path variable as openssl is already available, still it is throwing the same error. </p> <p>Also, now tried with a separate user(not root). Same error! And tried to followup the wiki page, but for OpenSUS...
0
2016-08-01T14:18:01Z
38,701,358
<p>Python makes use of underlying operating system libraries to support some of its libraries, and it appears you don't have these libraries installed. On Ubuntu you should be able to install them with</p> <pre><code>$ sudo apt-get install bzip2 libreadline6 libreadline6-dev openssl </code></pre> <p>For SUSE 12, as y...
1
2016-08-01T14:26:12Z
[ "python", "linux", "opensuse", "pyenv" ]
Insert Ordered Dict values while using MySQL INSERT INTO
38,701,275
<p>I encounter this error when I'm trying to insert some values into a table. Here's my code:</p> <pre><code>def tsx_insert(self, d_list): for item in d_list: query = """ INSERT IGNORE INTO tsx_first_insert(protocollo,procedura,oggetto,priorita, tipo_richiesta,...
-1
2016-08-01T14:21:58Z
38,701,480
<p>You forgot to mention your <code>params</code> dictionary in your <code>self.cursor.execute()</code> method call, so the parameter strings were left in place rather than substituted.</p> <p>Try</p> <pre><code> self.cursor.execute(query, params) </code></pre>
1
2016-08-01T14:31:56Z
[ "python", "mysql", "mysql-python", "mysql-error-1064" ]
Assign into variable value from imported file
38,701,338
<p>I'm trying to assign into variable SQL statement from another file which I imported. Other filename: Table1.py contain variable <code>SQL="Select * from column1"</code> My current script: </p> <pre><code>#!/usr/bin/python datefrom = raw_input("Please enter date from YYYY-MM-DD: ") dateto = raw_input("Please enter...
0
2016-08-01T14:25:22Z
38,701,717
<p>While you are loading modules at runtime you need to store the module object into a variable and then access its variables normally.</p> <pre><code>table_module = __import__(tablename) table_sql = table_module.SQL print table_sql </code></pre> <p>Now, if you want to modify the statement, you can just use simple st...
2
2016-08-01T14:41:56Z
[ "python", "variables", "import" ]
A straightforword method to select columns by position
38,701,400
<p>I am trying to clarify how can I manage pandas methods to call columns and rows in a Dataframe. An example will clarify my issue</p> <pre><code>dic = {'a': [1, 5, 2, 7], 'b': [6, 8, 4, 2], 'c': [5, 3, 2, 7]} df = pd.DataFrame(dic, index = ['e', 'f', 'g', 'h'] ) </code></pre> <p>than</p> <pre><code>df = a b ...
2
2016-08-01T14:28:23Z
38,701,425
<p>You can add <code>:</code> because first argument is position of selected indexes and second position of columns in function <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.iloc.html" rel="nofollow"><code>iloc</code></a>:</p> <p>And <code>:</code> means all indexes in <code>DataFrame...
1
2016-08-01T14:29:33Z
[ "python", "pandas", "dataframe" ]
Resizing Images using Pillow Python
38,701,452
<p>Right now I'm trying to resize a few .jpg files and my script is as following:</p> <pre><code>from PIL import Image def main( ): #{ filename = "amonstercallsmoviestill.jpg" image = Image.open(filename) size = width, height = image.size image.thumbnail((1600,900)) image.show() del image...
0
2016-08-01T14:30:39Z
38,701,832
<p><code>thumbnail</code> only <em>reduces</em> the size of an image. To make it bigger, use <code>resize</code> instead.</p> <pre><code>image = image.resize((1600, 900), PIL.Image.LANCZOS) </code></pre>
3
2016-08-01T14:46:38Z
[ "python", "python-imaging-library", "pillow" ]
Python Flask SQLAlchemy-Paginator Access next page in html view
38,701,565
<p>I have currently a problem to include the pagination function into my project. I know there is <code>LIMIT/OFFSET</code>or <code>yield_per()</code>, but I was not able to implement them.</p> <p>I am using SQLAlchemy not Flask-SQLAlchemy so <code>paginate</code> wont work.</p> <p>My Database is not that big. I am t...
0
2016-08-01T14:35:42Z
38,703,040
<p>Okay here is a solution (which does not use any further methods from the SQLAlchemy-Paginator package). I coded everything myself, but I would still like to know how it is done with <code>page.next_page_number</code> etc.</p> <p><strong>Explained:</strong></p> <p>First of all I added an argument (<code>pagenumber<...
0
2016-08-01T15:46:42Z
[ "python", "html", "pagination", "sqlalchemy" ]
Create dynamic columns in dataframe using pandas
38,701,573
<p>How to create dynamic columns from this pandas dataframe.</p> <pre><code> Name, Sex a, M b, F c, M d, F </code></pre> <p>Expected dataframe:</p> <pre><code>Name, M, F a, 1, 0 b, 0, 1 c, 1, 0 d, 0, 1 </code></pre> <p>I have tried pandas.pivot() but of no use, could you guys suggest something.</p>
0
2016-08-01T14:36:02Z
38,701,630
<p>Use get dummies:</p> <pre><code>pd.concat([df['Name'], df['Sex'].str.get_dummies()], axis=1) Out: Name F M 0 a 0 1 1 b 1 0 2 c 0 1 3 d 1 0 </code></pre> <hr> <p><code>df['Sex'].str.get_dummies()</code> generates the dummies:</p> <pre><code>df['Sex'].str.get_dummies() ...
3
2016-08-01T14:38:34Z
[ "python", "pandas" ]
Create dynamic columns in dataframe using pandas
38,701,573
<p>How to create dynamic columns from this pandas dataframe.</p> <pre><code> Name, Sex a, M b, F c, M d, F </code></pre> <p>Expected dataframe:</p> <pre><code>Name, M, F a, 1, 0 b, 0, 1 c, 1, 0 d, 0, 1 </code></pre> <p>I have tried pandas.pivot() but of no use, could you guys suggest something.</p>
0
2016-08-01T14:36:02Z
38,701,681
<p>You can create a count variable based on the two columns and then do the pivoting, something like:</p> <pre><code>import pandas as pd df.groupby(["Name", "Sex"]).size().unstack(level = 1, fill_value = 0) # Sex F M #Name # a 0 1 # b 1 0 # c 0 1 # d 1 0 </code></pre> <p>Another op...
1
2016-08-01T14:40:18Z
[ "python", "pandas" ]
Pandas: Set MultiColumn values based on flat columned value
38,701,626
<p>I have a MultiColumned data-frame as follows:</p> <pre><code>Out[1]: Empty DataFrame Columns: [(price, mean), (price, mom_2), (units, mean), (units, mom_2)] Index: [] </code></pre> <p>I have some (flat) values for <code>mean</code>, which I would like to put into <code>price</code> and <code>units</code>:</p> <p...
1
2016-08-01T14:38:26Z
38,712,030
<p>You're right, the selection with <code>IndexSlice</code> keeps the levels. I don't know of any neat method here (if at all it exists). </p> <p>A safe workaround would be to reindex the series:</p> <pre><code>value.index = pd.MultiIndex.from_product([value.index, ['mean']]) resultsDf.loc[idx] = value </code></pre> ...
1
2016-08-02T04:55:42Z
[ "python", "pandas" ]
Graphviz: vizualize data from a dataframe
38,701,628
<p>I have dataframe</p> <pre><code>ID domain search_term 111 vk.com вконтакте 111 twitter.com фэйсбук 111 facebook.com твиттер 222 avito.ru купить машину 222 vk.com вконтакте 333 twitter.com твиттер 333 apple.com купить айфон 333 rbk.ru новÐ...
0
2016-08-01T14:38:30Z
38,717,578
<p>You create a new graph on each iteration. Take the creation out of the loop and just add the edges inside:</p> <pre><code>f = Digraph('finite_state_machine', filename='fsm.gv', encoding='utf-8') f.body.extend(['rankdir=LR', 'size="5,5"']) f.attr('node', shape='circle') for i, (id, domain, search_term) in enumerate(...
0
2016-08-02T10:11:06Z
[ "python", "pandas", "graphviz" ]
Cartopy coastlines not showing
38,701,656
<p>I just installed Cartopy and is trying their basic example. The code I'm using is </p> <pre><code>import cartopy.crs as ccrs import matplotlib.pyplot as plt ax = plt.axes(projection=ccrs.PlateCarree()) ax.set_global() ax.coastlines() plt.show() </code></pre> <p>What happens is that no coastlines are drawn, what I ...
0
2016-08-01T14:39:34Z
38,741,626
<p>Have you modified any of the matplotlib <a href="http://matplotlib.org/users/customizing.html" rel="nofollow">rc settings</a>? For instance, having <code>'patch.linewidth'</code> set to zero will prevent coastlines from appearing. </p>
0
2016-08-03T10:57:00Z
[ "python", "cartopy" ]
Renaming certain multiple values in a column of dataframe into another single value
38,701,685
<p>I have a data Frame, which is 1 GB in size, the following is a dummy one</p> <pre><code>df &lt;- data.frame(group=rep(c("A", "B", "C","D","E","F","G","H"), each=4),height=sample(100:150, 16)) df group height 1 A 105 2 A 119 3 B 108 4 B 114 5 C 109 6 C 111 7 D ...
1
2016-08-01T14:40:41Z
38,701,780
<p>Pandas/Numpy solution with <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.where.html" rel="nofollow"><code>numpy.where</code></a> and boolean mask:</p> <pre><code>print (df['group'] =='B') 1 False 2 False 3 False 4 False 5 True 6 True 7 True 8 True 9 ...
1
2016-08-01T14:44:17Z
[ "python", "pandas", "numpy" ]
Renaming certain multiple values in a column of dataframe into another single value
38,701,685
<p>I have a data Frame, which is 1 GB in size, the following is a dummy one</p> <pre><code>df &lt;- data.frame(group=rep(c("A", "B", "C","D","E","F","G","H"), each=4),height=sample(100:150, 16)) df group height 1 A 105 2 A 119 3 B 108 4 B 114 5 C 109 6 C 111 7 D ...
1
2016-08-01T14:40:41Z
38,701,991
<p>In R you can try:</p> <p>Transform to character first and then replace the value directly.</p> <pre><code>df$group &lt;- as.character(df$group); df$group[df$group %in% c("B")] &lt;- "NC" </code></pre> <p>Edit:</p> <p>As you updated your question you can try <code>ifelse</code>. Of course you can also overwrite ...
1
2016-08-01T14:54:23Z
[ "python", "pandas", "numpy" ]
Renaming certain multiple values in a column of dataframe into another single value
38,701,685
<p>I have a data Frame, which is 1 GB in size, the following is a dummy one</p> <pre><code>df &lt;- data.frame(group=rep(c("A", "B", "C","D","E","F","G","H"), each=4),height=sample(100:150, 16)) df group height 1 A 105 2 A 119 3 B 108 4 B 114 5 C 109 6 C 111 7 D ...
1
2016-08-01T14:40:41Z
38,704,521
<p>You can also replace the group names as below</p> <pre><code> df$group=as.character(df$group) df$group[c(3:4,13:16)]='NC' df$group[c(1:2)]='PC' df$group[c(5:12)]='NON' </code></pre>
0
2016-08-01T17:14:41Z
[ "python", "pandas", "numpy" ]
Looking for ForeignKey active and add to QuerySet
38,701,689
<pre><code>class Control(models.Model): period = models.DurationField() active = models.BooleanField() device_collection = models.ForeignKey(DeviceSet) class DeviceSet(models.Model): name = models.CharField() date_last_control = models.DateField() def get_next_control(self): return sel...
0
2016-08-01T14:40:53Z
38,702,104
<p>You are getting errors from what you've attempted because <code>annotate</code> method needs an aggregate function (eg <code>Sum</code>, <code>Count</code> etc) rather than a <code>Q</code> object.</p> <p>Since Django 1.7 it's possible to do what you want using <code>prefetch_related</code>, see docs here: <a href=...
0
2016-08-01T14:59:29Z
[ "python", "django", "annotate" ]
working with groupby multiple columns in Python
38,701,792
<p>I have 3 columns in a dataframe, as:</p> <p>User_ID, Product_Category_1 and Corresponding Purchase amount.</p> <p>I am trying to group by based on User_ID and Product_Category_1 and selecting the average of Purchase amount.</p> <p>So output dataframe will have: User_ID,Product_Category_1 and Avg_Purchase.</p> <p...
0
2016-08-01T14:45:05Z
38,701,958
<p>Ok, This seems to be working:</p> <pre><code> x = train_bk.groupby(["User_ID","Product_Category_1"],as_index=False)['Purchase'].mean() </code></pre>
0
2016-08-01T14:52:29Z
[ "python", "group-by", "multiple-columns" ]
How to learn two sequences simultaenously through LSTM in Tensorflow/TFLearn?
38,701,848
<p>I am learning LSTM based seq2seq model in Tensorflow platform. I can very well train a model on a given simple seq2seq examples. </p> <p>However, in cases where I have to learn two sequences at once from a given sequence (for e.g: learning previous sequence and next sequence from the current sequence simultaneously...
0
2016-08-01T14:47:16Z
38,729,727
<p>It seems to me that you want to have a single encoder and multiple decoders (e.g. 2, for 2 output sequences), right? There is <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/kernel_tests/seq2seq_test.py#L351" rel="nofollow">one2many</a> in seq2seq for exactly this use-case.</p> <p>As...
0
2016-08-02T20:19:17Z
[ "python", "tensorflow", "deep-learning", "lstm", "language-model" ]
Unknown word/character in txt file from word2vec
38,701,947
<p>I recently encountered the <code>&lt;/s&gt;</code> word/character in a vocabulary created by word2vec as a separate word. </p> <p>Although I did tried to search the web for that character, I cannot actually specify that character at the search engines. </p> <p>So, does anyone knows what this character is? </p>
0
2016-08-01T14:52:06Z
38,715,976
<p>If you look at the line 82 of <a href="https://code.google.com/archive/p/word2vec/source/default/source" rel="nofollow">source code</a> of <code>word2vec</code>,</p> <pre><code>if (ch == '\n') { strcpy(word, (char *)"&lt;/s&gt;"); return; } </code></pre> <p><code>&lt;/s&gt;</code> is simply a character used by...
1
2016-08-02T08:57:10Z
[ "python", "word2vec" ]
Passing list names as argument to izip
38,701,952
<p>I have number of lists that is user defined </p> <pre><code>numLists = sys.argv[1] d = [[] for x in xrange(numLists+1)] </code></pre> <p>I'm performing some operations on these lists and I want to pass them at the end to <code>itertools.izip</code> in the following format, for example if the user entered numLists ...
0
2016-08-01T14:52:20Z
38,701,979
<p><a href="https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists" rel="nofollow"><em>Unpack</em></a> the list of lists into positional arguments of <code>izip()</code>:</p> <pre><code>for val in itertools.izip(*d): </code></pre>
2
2016-08-01T14:53:30Z
[ "python", "list", "arguments", "itertools" ]
Dynamic spectrum using plotly
38,701,969
<p>I want to plot time vs frequency as x and y axis, but also a third parameter that is specified by the intensity of plot at (x, y) rather (time, frequency) point. [Actually, instead of going up with third axis in 3D visualisation, I want something like a 2D plot, with amplitude of third axis governed by the intensity...
3
2016-08-01T14:52:45Z
38,702,325
<p>I'd suggest the pcolormesh plot</p> <pre><code>import matplotlib.pyplot as mp import numpy as np # meshgrid your timevector to get it in the desired format X, Y = np.meshgrid(timevector, range(num_of_frequency_bins)) fig1, ax1 = mp.subplots() Plothandle = mp.pcolormesh(X, Y, frequencies, cmap=mp.cm.jet, antialia...
1
2016-08-01T15:10:16Z
[ "python", "plotly" ]
Django template for loop iteration by distinct foreign key
38,702,119
<p>In my app, I have 3 models: Issue, Series, and Character. The Issue model has a Series ForeignKey, and a Character ManyToManyField. Here they are simplified:</p> <pre><code>class Character(models.Model): name = models.CharField('Character name', max_length=200) desc = models.TextField('Description', max_len...
1
2016-08-01T15:00:22Z
38,703,255
<p>I would use a function based view rather than a class based generic view. Reason being that your required behavior is going beyond something generic.</p> <p>In your function you can build the queryset you desire instead of having to fight with the one provided by <code>generic.DetailView</code>.</p> <pre><code>def...
1
2016-08-01T15:59:23Z
[ "python", "django", "for-loop", "django-templates" ]
Selecting a subset of a Pandas DataFrame
38,702,138
<p>I have the following DateFrame: </p> <pre><code> record_id month day year plot species sex wgt 33320 33321 1 12 2002 1 DM M 44 33321 33322 1 12 2002 1 DO M 58 ... ... ... ... ... ... ... ... ... </code></pre> <p>I wa...
1
2016-08-01T15:01:37Z
38,702,168
<blockquote> <p>Is there any way to reduce it to one line?</p> </blockquote> <p>You can easily combine the 2 lines into 1:</p> <pre><code>df_slice = df[df.year == 27].ix[:,'year':] </code></pre>
2
2016-08-01T15:03:08Z
[ "python", "pandas" ]
Selecting a subset of a Pandas DataFrame
38,702,138
<p>I have the following DateFrame: </p> <pre><code> record_id month day year plot species sex wgt 33320 33321 1 12 2002 1 DM M 44 33321 33322 1 12 2002 1 DO M 58 ... ... ... ... ... ... ... ... ... </code></pre> <p>I wa...
1
2016-08-01T15:01:37Z
38,702,190
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ix.html" rel="nofollow"><code>ix</code></a>:</p> <pre><code>print (df.ix[df.year == 27, 'year':]) </code></pre> <p>Sample (value <code>2001</code> was added):</p> <pre><code>print (df) record id month day year p...
2
2016-08-01T15:04:13Z
[ "python", "pandas" ]
Python: Changing value in imported dict has no effect
38,702,175
<p>Here's a fun one. Create a file <code>foo.py</code> with the following contents:</p> <pre><code>OPTIONS = {'x': 0} def get_option(key): from foo import OPTIONS return OPTIONS[key] if __name__ == '__main__': OPTIONS['x'] = 1 print("OPTIONS['x'] is %d" % OPTIONS['x']) print("get_option('x') is %...
1
2016-08-01T15:03:29Z
38,702,464
<p>You are getting this because <code>from foo import OPTIONS</code> line in <code>get_options()</code> function loads a new <em>local</em> <strong>OPTIONS</strong> variable in a memory whose value is <em>{'x':0}</em>. But if you remove/comment that line, then you got your expected result, this is because as <strong>OP...
2
2016-08-01T15:17:50Z
[ "python", "python-2.7", "python-3.4" ]
Python the windows cannot find the path specified
38,702,191
<p>I am trying to configure my own ninja binary and i get the following error. What is the cause of this? Running on windows 7 64-bit.</p> <p><a href="http://i.stack.imgur.com/cKJ5m.png" rel="nofollow"><img src="http://i.stack.imgur.com/cKJ5m.png" alt="Error"></a></p>
0
2016-08-01T15:04:13Z
38,783,055
<p>Via Visual Studio<br></p> <p>Install Visual Studio (Express is fine), Python for Windows<br><br> 1)In a Visual Studio command prompt: <code>python configure.py --bootstrap</code><br> 2)Open cmd, run vsvarsall.bat from the visual studio folder and after, call <br><code>python configure.py --bootstrap</code></p>
0
2016-08-05T06:59:42Z
[ "python", "ninja" ]
Python Dictionary of DefaultDicts
38,702,202
<p>I am trying to build a dictionary containing defaultdicts:</p> <pre><code>from collections import defaultdict my_dict = { 'first_key':defaultdict(list) } my_dict['first_key'].extend('add this to list') </code></pre> <p>...but that returns: <code>AttributeError: 'collections.defaultdict' object has no attribute '...
-2
2016-08-01T15:04:50Z
38,702,294
<p>Correct me if I'm wrong, but I don't think you want a dictionary of defaultdicts for this. What you're trying to do is easily accomplished using the built-in <code>dict</code> method <a href="https://docs.python.org/2/library/stdtypes.html#dict.setdefault" rel="nofollow"><code>setdefault</code></a>:</p> <pre><code>...
2
2016-08-01T15:08:44Z
[ "python" ]
Trying to iterate through a graph breadth first in Python
38,702,217
<p>In my code, I am essentially trying to create an implementation of a data flow network. Although the particularities of how I am going about doing this aren't particularly important, I need some help to make the program go through the graph in a breadth first fashion. When I do this with my code:</p> <pre><code>def...
0
2016-08-01T15:05:19Z
38,704,923
<p>You are mixing BFS (<em>breadth first search</em>) and DFS (<em>depth first search</em>) in your approach.</p> <p>When sending data in your <code>sand_pile</code> method, you iterate horizontally through all children of the current node, which probably is your approach of implementing a BFS. But as soon as the firs...
0
2016-08-01T17:36:38Z
[ "python", "data-transfer" ]
PySpark Hive queries aren't showing output
38,702,279
<p>I am able to create, drop, modify tables using pyspark and hivecontext. I load a list with commands I want to send, in string format, and pass them into this function:</p> <pre><code>def hiveCommands(commands, database): conf = SparkConf().setAppName(database + 'project').setMaster('local') sc = SparkContex...
0
2016-08-01T15:08:09Z
38,706,615
<p>Call <code>show</code> method to see results:</p> <pre><code>for command in commands: df.sql(command).show() </code></pre>
1
2016-08-01T19:24:29Z
[ "python", "apache-spark", "hive", "pyspark" ]
What is the Right Syntax When Using .notnull() in Pandas?
38,702,332
<p>I want to use <code>.notnull()</code> on several columns of a dataframe to eliminate the rows which contain "NaN" values. </p> <p>Let say I have the following <code>df</code>:</p> <pre><code> A B C 0 1 1 1 1 1 NaN 1 2 1 NaN NaN 3 NaN 1 1 </code></pre> <p>I tried to use this syntax but it does not ...
3
2016-08-01T15:10:36Z
38,702,360
<p>You can first select subset of columns by <code>df[['A','B','C']]</code>, then apply <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.notnull.html" rel="nofollow"><code>notnull</code></a> and specify if <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.all...
5
2016-08-01T15:12:19Z
[ "python", "pandas", "dataframe", null ]
What is the Right Syntax When Using .notnull() in Pandas?
38,702,332
<p>I want to use <code>.notnull()</code> on several columns of a dataframe to eliminate the rows which contain "NaN" values. </p> <p>Let say I have the following <code>df</code>:</p> <pre><code> A B C 0 1 1 1 1 1 NaN 1 2 1 NaN NaN 3 NaN 1 1 </code></pre> <p>I tried to use this syntax but it does not ...
3
2016-08-01T15:10:36Z
38,702,457
<p>You can apply multiple conditions by combining them with the <code>&amp;</code> operator (this works not only for the <code>notnull()</code> function).</p> <pre><code>df[(df.A.notnull() &amp; df.B.notnull() &amp; df.C.notnull())] A B C 0 1.0 1.0 1.0 </code></pre> <p>Alternatively, you can just drop a...
1
2016-08-01T15:17:30Z
[ "python", "pandas", "dataframe", null ]
Error appending to list according to state of bool
38,702,353
<p>I am using 2 different libraries and running addresses through them. First i'm using geopy to clean and geocode addresses. Then i'm running the address through pygeocoder to see if the output is a valid address. If the output is valid, i'm appending the address to a list, which I will be returning later. If not, i'm...
0
2016-08-01T15:11:55Z
38,703,495
<p>Solved my problem.</p> <p>I wasn't giving pygeocoder enough information. My address was in the format of street number street name. By appending the city to the end of the address and THEN validating it I solved the problem.</p> <p>Unfortunately, pygeocoder works through Google Maps, which has a relatively low req...
0
2016-08-01T16:12:53Z
[ "python", "geopy" ]
Am I using python's apply_async correctly?
38,702,364
<p>This is my first time trying to use multiprocessing in Python. I'm trying to parallelize my function <code>fun</code> over my dataframe <code>df</code> by row. The callback function is just to append results to an empty list that I'll sort through later. </p> <p>Is this the correct way to use <code>apply_async</cod...
0
2016-08-01T15:12:28Z
38,702,678
<p>It looks like using <a href="https://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.map" rel="nofollow">map</a> or <a href="https://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.imap_unordered" rel="nofollow">imap_unordered</a> (dep...
1
2016-08-01T15:29:03Z
[ "python", "python-2.7", "multiprocessing", "python-multiprocessing" ]
ValueError when trying to convert strings to floating point
38,702,382
<p>I'm having troubles running this program.<br> It tells me I have a</p> <blockquote> <p>ValueError: could not convert string to float</p> </blockquote> <p>The problem is though, that it just skips my input commands and jumps to </p> <pre><code>print("Invalid Response") </code></pre> <p>This program works fine o...
0
2016-08-01T15:13:26Z
38,713,873
<p>This is the desired code. I changed a little bit some indentations are wrong in case of contin() function and some logic. Please refer to this if I am wrong in some place do tell me. Thank you</p> <pre><code>def calc(num1,chars,num2): #The function performing calculation. if chars == "+": result...
0
2016-08-02T07:09:26Z
[ "python" ]