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 process takes time to start in django project running on nginx and uwsgi | 38,891,879 | <p>I am starting a process using python's multiprocessing module. The process is invoked by a post request sent in a django project. When I use development server (python manage.py runserver), the post request takes no time to start the process and finishes immediately.</p>
<p>I deployed the project on production usin... | 4 | 2016-08-11T09:04:21Z | 39,093,474 | <p>I figured out a workaround (Don't know if it will qualify as an answer).
I wrote the background process as a job in database and used a cronjob to check if I have any job pending and if there are any the cron will start a background process for that job and will exit.</p>
<p>The cron will run every minute so that t... | 0 | 2016-08-23T06:04:35Z | [
"python",
"django",
"nginx",
"process",
"uwsgi"
] |
Reading/Writing python Dictionary to Redis cache on aws crashes server | 38,891,893 | <p>I am developing a computation intensive django application. Using Celery, to perform time taking tasks, and using Redis as a broker, and for cache puposes. </p>
<p>Redis cache is used to share a large dictionary structure across celery tasks.</p>
<p>I have a rest api to frequently write/update a python dictionary ... | 0 | 2016-08-11T09:05:00Z | 38,906,242 | <p>From the documentation:</p>
<p>Don't use more memory than the specified amount of bytes.
When the memory limit is reached Redis will try to remove keys
according to the eviction policy selected (see maxmemory-policy).</p>
<p>If Redis can't remove keys according to the policy, or if the policy is
set to 'noevict... | 0 | 2016-08-11T21:12:07Z | [
"python",
"django",
"amazon-web-services",
"redis",
"celery"
] |
Python script is called but not executed from batch file | 38,891,928 | <p>i have a python script that when is run from eclipse it does what i want without any errors or anything.
I want now to create a batch file, that will run my script in a loop (infinitely).
The first problem is that i when i run the bat file, i get a second cmd window that shows the logging from my python script (whic... | 0 | 2016-08-11T09:06:08Z | 38,896,865 | <p>Ok it seems that the .exe in the script was returning an error and that is why it the script was finishing so fast. I thought that the bat file did not wait. I should have placed the .bat file in the .exe folder and now the whole thing runs perfect.</p>
| 0 | 2016-08-11T12:48:54Z | [
"python",
"batch-file"
] |
Creating a Cumulative Frequency Column in a Dataframe Python | 38,891,974 | <p>I am trying to create a new column named 'Cumulative Frequency' in a data frame where it consists of all the previous frequencies to the frequency for the current row as shown here.</p>
<p><a href="http://i.stack.imgur.com/jQ39A.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/jQ39A.jpg" alt="enter image desc... | 0 | 2016-08-11T09:08:22Z | 38,892,108 | <p>You want <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.cumsum.html" rel="nofollow"><code>cumsum</code></a>:</p>
<pre><code>df['Cumulative Frequency'] = df['Frequency'].cumsum()
</code></pre>
<p>Example:</p>
<pre><code>In [23]:
df = pd.DataFrame({'Frequency':np.arange(10)})
df
Out[2... | 2 | 2016-08-11T09:13:54Z | [
"python",
"pandas",
"dataframe"
] |
How to convert id into referenced field in Web2py? | 38,892,120 | <p>Consider the 3 tables below (<code>A</code>, <code>B</code> & <code>C</code>) where table <code>C</code> has 2 fields referenced to table <code>A</code> and <code>B</code>. </p>
<p>Model:</p>
<pre><code>db.define_table('A',
Field('A1', 'string', required =True),
Field('A2', 'string', required =True),
Field('A3... | 0 | 2016-08-11T09:14:26Z | 38,908,849 | <p>The web2py syntax to define reference fields is the following, as far as I know:</p>
<pre><code>Field('C1', 'reference A'),
Field('C2', 'reference B'),
</code></pre>
<p>Then, in your view, <code>x.C1</code> will be a <code>Row</code> object from the <code>A</code> table, so:</p>
<pre><code><td>{{=x.C1.A1}},... | 0 | 2016-08-12T02:17:04Z | [
"python",
"web2py"
] |
How to convert id into referenced field in Web2py? | 38,892,120 | <p>Consider the 3 tables below (<code>A</code>, <code>B</code> & <code>C</code>) where table <code>C</code> has 2 fields referenced to table <code>A</code> and <code>B</code>. </p>
<p>Model:</p>
<pre><code>db.define_table('A',
Field('A1', 'string', required =True),
Field('A2', 'string', required =True),
Field('A3... | 0 | 2016-08-11T09:14:26Z | 38,912,459 | <p>You need to use <em><code>format: Record representation</code></em> correctly and use <code>render()</code> to convert ids into their respective representation.</p>
<p>Your model will look like this:</p>
<pre><code>db.define_table('A',
Field('A1', 'string', required=True),
Field('A2... | 0 | 2016-08-12T07:37:07Z | [
"python",
"web2py"
] |
what is the best pratice of nested dict for mongoengine ODM? | 38,892,192 | <p>I have some data like this in my MongoDB:</p>
<pre><code> "FetchedZipSize" : {
"a" : 1,
"b" : 2,
"c" : 3,
"d" : 4,
"e" : 5
},
</code></pre>
<p>how to I modeling it with mongoengine ODM?</p>
| 0 | 2016-08-11T09:18:01Z | 38,892,310 | <p>You can use <a href="http://docs.mongoengine.org/guide/defining-documents.html#embedded-documents" rel="nofollow" title="Embedded documents">embedded document</a> field to create a nested structure of dictionaries. Something like this should work:</p>
<pre><code>from mongoengine import Document, EmbeddedDocument
cl... | 0 | 2016-08-11T09:23:23Z | [
"python",
"mongodb",
"dictionary",
"mongoengine"
] |
Python oneliner with if statement | 38,892,336 | <p>I am wondering if it is possible to write the following python if statement in one line. I would also like to know why I am getting the error below:</p>
<pre><code>python -c 'a=1; if True: print a; else: a=a+1'
File "<string>", line 1
a=1; if True: print a; else: a=a+1
^
SyntaxError: invalid ... | 1 | 2016-08-11T09:24:58Z | 38,892,554 | <p>Only <a href="https://docs.python.org/3/reference/compound_stmts.html#grammar-token-stmt_list" rel="nofollow">simple statements can appear in a semicolon-separate statement list</a>:</p>
<pre><code>stmt_list ::= simple_stmt (";" simple_stmt)* [";"]
</code></pre>
<p>An <code>if</code> statement is a compound s... | 4 | 2016-08-11T09:35:12Z | [
"python",
"if-statement"
] |
Sort each row individually between two columns | 38,892,353 | <p>I have the following pandas dataframe:</p>
<pre><code>column_01 column_02 value
ccc aaa 1
bbb ddd 34
ddd aaa 98
</code></pre>
<p>I need to re-organise the dataframe such that <code>column_01</code> contains which ever value comes first alphabetically between <c... | 1 | 2016-08-11T09:25:22Z | 38,892,408 | <p>You can use:</p>
<pre><code>df[['column_01','column_02']] =
df[['column_01','column_02']].apply(lambda x: sorted(x.values), axis=1)
print (df)
column_01 column_02 value
0 aaa ccc 1
1 bbb ddd 34
2 aaa ddd 98
</code></pre>
<p>Another solutions:</p>
<pre><code>df... | 2 | 2016-08-11T09:27:53Z | [
"python",
"sorting",
"pandas",
"dataframe",
"multiple-columns"
] |
Python 3: maketime() | 38,892,363 | <p>Rookie question:</p>
<p>the following works:</p>
<pre><code>import time
# create time
dztupel = 1971, 1, 1, 0, 0, 1, 0, 0, 0
print(time.strftime("%d.%m.%Y %H:%M:%S", dztupel))
damals = time.mktime(dztupel)
# output
lt = time.localtime(damals)
wtage = ["Montag", "Dienstag", "Mittwoch","Donnerstag","Freitag","Sa... | 1 | 2016-08-11T09:25:55Z | 38,892,537 | <p>In your second snippet, check out what the <code>time.mktime()</code> function returns, given that <code>dztupel</code> represents a datetime of 11:01am UTC on 1/1/1969 (shows as one hour ahead because of BST (i.e., UTC+0100) locally on my system):</p>
<pre><code>>>> import time
>>> dztupel = 1970... | 1 | 2016-08-11T09:34:39Z | [
"python"
] |
Scypy: Wilcoxon test: Compare distribution with a single value | 38,892,385 | <p>I was applying the t-student test in order to evaluate whether or not a value was belonging to a given sample. Since I cannot assume normality, now I want to apply the <code>Wilcoxon</code> test from <code>scypy</code>.</p>
<p>Is it possible to compare a sample with a single value?</p>
<p>If I do:
<code>stats.wilc... | 0 | 2016-08-11T09:26:41Z | 38,892,824 | <p>You can't use wilcoxon for that. Those are to compare distributions.</p>
<p>You can't know whether or not a value may belong to a given sample. If your sample is large enough you can say that the probability of that happening is <code>sum(sample_array>single_value)/len(sample_array)</code> (or <code><</code> ... | 0 | 2016-08-11T09:46:34Z | [
"python",
"statistics"
] |
Calling PHP script from inside a Django project: Could not open input file | 38,892,437 | <p>I wrote a PHP script that processes some task for me (specifically, encoding videos on a media server). I tested calling this script via python like so:</p>
<pre><code>proc = subprocess.Popen("php vodworkflow_drm_playready_widevine.php videos " +str(video), shell=True, stdout=subprocess.PIPE)
</code></pre>
<p>This... | 0 | 2016-08-11T09:29:09Z | 38,893,658 | <p>Point the php file to php binary by its full path.</p>
<pre><code>proc = subprocess.Popen("php /root/www/bla_bla/vodworkflow_drm_playready_widevine.php videos " +str(video), shell=True, stdout=subprocess.PIPE)
</code></pre>
<p>Alternatively, Popen takes an cwd argument. Specify the path to it. </p>
<p><a href="ht... | 1 | 2016-08-11T10:22:49Z | [
"php",
"python",
"django"
] |
how to install wordcloud package in python? | 38,892,509 | <pre><code>pip install wordcloud
File "<ipython-input-130-12ee30540bab>", line 1
pip install wordcloud
^
SyntaxError: invalid syntax
</code></pre>
<p>This is the problem I am facing while using <code>pip install wordcloud</code>.</p>
| 0 | 2016-08-11T09:33:03Z | 38,892,671 | <p><code>pip</code> is a tool used for installing python packages. You should not use this command inside the python interactive shell. </p>
<p>Instead, exit out of it and write <code>pip install wordcloud</code> on the main shell.</p>
| 0 | 2016-08-11T09:40:31Z | [
"python",
"word-cloud"
] |
Sorting a python dictionary by one value, then two value in list values | 38,892,697 | <p>struct product: sku, quantity, price, group</p>
<p>key: list(values)</p>
<pre><code>dic = {'product1': ['m1', 2, 101, 'g500'], 'product4': ['m112', 2, 101, 'g700'], 'product5': ['m343', 2, 101, 'g500'], 'product2': ['m765', 2, 101, 'g500'], 'product3': ['m4346', 2, 101, 'g700']}
</code></pre>
<p>Order by key (or ... | -1 | 2016-08-11T09:41:46Z | 38,892,858 | <pre><code>OrderedDict(sorted(dic.items(), key=lambda t: (t[1][3], t[1][0]),))
</code></pre>
| 1 | 2016-08-11T09:47:51Z | [
"python",
"list",
"sorting",
"dictionary"
] |
Why is there a gap at the side of my graph? (matplotlib/py) | 38,892,982 | <p>Got a list of 5 elements which represents sequences of objects. i.e. element 0 represents the number 1, and so on. Consequently I had to do this to have these numbers represented properly on the graph:</p>
<pre><code>higher_chances.insert(0, 0)
plt.xlim(1,len(higher_chances))
plt.xticks(range(1, len(higher_chances)... | -1 | 2016-08-11T09:53:18Z | 38,894,180 | <p>Change: </p>
<pre><code>plt.xlim(1,len(higher_chances))
</code></pre>
<p>To:</p>
<pre><code>plt.xlim(1,len(higher_chances)-1)
</code></pre>
<p><a href="http://i.stack.imgur.com/6ftMt.png" rel="nofollow"><img src="http://i.stack.imgur.com/6ftMt.png" alt="enter image description here"></a></p>
<p>But leave the fo... | 0 | 2016-08-11T10:44:04Z | [
"python",
"matplotlib"
] |
Error "Your requirements.txt is invalid" when following tutorial AWS Elastic Beanstalk's Flask tutorial | 38,893,004 | <p>I'm following AWS Elastic Beanstalk's <a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html" rel="nofollow">Flask tutorial</a> to deploy the sample application.</p>
<p>Though I get error <strong>Your requirements.txt is invalid</strong> - in full as below. I <a href="https:/... | 0 | 2016-08-11T09:54:13Z | 38,927,554 | <p>I tested locally and was able to replicate your problem. To get more information about what went wrong on instance I used <code>eb logs</code> to view the logs currently on the EC2 instances. From that I was able to see the full stack in the <code>eb-activity.log</code></p>
<pre><code> Collecting pkg-resources==0.0... | 2 | 2016-08-12T23:05:54Z | [
"python",
"elastic-beanstalk"
] |
How to name a file using a value in a list in a dictionary? | 38,893,080 | <p>For example I have a list inside a dictionary:</p>
<pre><code>{'results': [{'name': 'sarah', 'age': '18'}]}
</code></pre>
<p>I want make a text file and the name of file must be the value of dict <code>'name'</code>
ex: <code>sarah.txt</code>.</p>
<p>How should I code it in python?</p>
| -5 | 2016-08-11T09:57:26Z | 39,112,093 | <p>Something like this:</p>
<pre><code>dictionary = {'results': [{'name': 'sarah', 'age': '18'}]}
name = dictionary['results'][0]['names'] + '.txt'
open(name, "w")
</code></pre>
<p>Opening a file in the <code>w</code>rite mode, if it doesn't exist already, will create a new file with that name.</p>
| 0 | 2016-08-23T23:14:27Z | [
"python",
"list",
"file",
"dictionary",
"filenames"
] |
Password system. How do I allow 3 incorrect guesses while allowing the program to continue if the guess is correct | 38,893,099 | <p>The program needs to allow the user 3 incorrect attempts to write the password. However if they get the password attempt right, I want the program to print 'nice'.</p>
<p><strong>Here is what I have so far:</strong></p>
<pre><code>def main():
n = 2
for i in range(0, 3, 1):
attempt = input('Enter... | 0 | 2016-08-11T09:58:15Z | 38,893,256 | <pre><code>n = 2
for i in range(0, 3, 1):
attempt = raw_input('Enter password: ')
if attempt != 'password':
print('Incorrect. ' + str(n) + ' attempts left')
n = int(n) - 1
elif n > 0:
print('nice')
else:
print('no attempts left')
</code></pre>
| -1 | 2016-08-11T10:05:00Z | [
"python",
"loops",
"passwords"
] |
Password system. How do I allow 3 incorrect guesses while allowing the program to continue if the guess is correct | 38,893,099 | <p>The program needs to allow the user 3 incorrect attempts to write the password. However if they get the password attempt right, I want the program to print 'nice'.</p>
<p><strong>Here is what I have so far:</strong></p>
<pre><code>def main():
n = 2
for i in range(0, 3, 1):
attempt = input('Enter... | 0 | 2016-08-11T09:58:15Z | 38,893,540 | <pre><code>for x in range(3):
pass_correct=False
password = "password"
attempt=raw_input("Enter password: ")
if attempt == password:
pass_correct=True
break
else:
print "incorrect, " + str(2-x) + " attempts left"
if pass_correct:
print "nice"
else:
print "no attempts left"
</code></pre>
<p>succin... | -1 | 2016-08-11T10:17:02Z | [
"python",
"loops",
"passwords"
] |
Password system. How do I allow 3 incorrect guesses while allowing the program to continue if the guess is correct | 38,893,099 | <p>The program needs to allow the user 3 incorrect attempts to write the password. However if they get the password attempt right, I want the program to print 'nice'.</p>
<p><strong>Here is what I have so far:</strong></p>
<pre><code>def main():
n = 2
for i in range(0, 3, 1):
attempt = input('Enter... | 0 | 2016-08-11T09:58:15Z | 38,893,551 | <pre><code>max_retries = 3
for i in range(max_retries):
passwd = input('\nEnter password: ')
if passwd == 'password':
print('\nnice')
break
print('Incorrect. %d attempts left' % (max_retries-i-1))
</code></pre>
| 1 | 2016-08-11T10:17:42Z | [
"python",
"loops",
"passwords"
] |
python matplotlib edit histogram | 38,893,125 | <p>I used matplotlib to create a histogram. There are still problems I couldn't solve on my own or with the help of the internet.</p>
<ol>
<li><p>How can I change the color of certain bins? In detail I want to change the color of bins with: a.) value bin < 1.15 red, b.) value 1.15 < bin < 1.25
c.) value > 1... | 0 | 2016-08-11T09:59:49Z | 38,893,261 | <p>Something like this (there may be some bugs):</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
import csv
from matplotlib.ticker import FormatStrFormatter
thickness = [] #gets thickness from list
bins = [1.00,1.01,1.02,1.03,1.04,1.05,1.06,1.07,1.08,1.09,1.10,1.11,1.12,1.13,1.14,1.15,1.16,1.17,1.... | 0 | 2016-08-11T10:05:15Z | [
"python",
"matplotlib",
"colors",
"decimal",
"bins"
] |
Rounding up a column | 38,893,170 | <p>I am new to pandas python and I am having difficulties trying to round up all the values in the column. For example,</p>
<pre><code>Example
88.9
88.1
90.2
45.1
</code></pre>
<p>I tried using my current code below, but it gave me:</p>
<blockquote>
<p>AttributeError: 'str' object has no attribute 'rint'</p>
</blo... | 1 | 2016-08-11T10:01:39Z | 38,893,248 | <p>You can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ceil.html#numpy.ceil" rel="nofollow"><code>numpy.ceil</code></a>:</p>
<pre><code>In [80]: import numpy as np
In [81]: np.ceil(df.Example)
Out[81]:
0 89.0
1 89.0
2 91.0
3 46.0
Name: Example, dtype: float64
</code></pre>
<p>... | 1 | 2016-08-11T10:04:39Z | [
"python",
"pandas"
] |
I can't upgrade pip on my raspberry pi | 38,893,188 | <p>I want to install simpleaudio but can't upgrade or install anything with pip, here's what it gives me:</p>
<pre><code>Downloading/unpacking pip from https://pypi.python.org/packages/9c/32/004ce0852e0a127f07f358b715015763273799b d798956fa930814b60f39/pip-8.1.2-py2.py3-none-any.whl#md5=0570520434c5b60... | 0 | 2016-08-11T10:02:09Z | 38,893,393 | <p><code>pip</code> fails to access some system paths and shows clearly that the user used to run <code>pip</code> <em>does not have enough privileges</em> to access them.</p>
<p>To solve this, try to run these commands as root using <code>sudo</code>:</p>
<pre><code>sudo pip <options>
</code></pre>
<p>Otherwi... | 1 | 2016-08-11T10:10:05Z | [
"python",
"pip"
] |
Resetting Python to system Python in Ubuntu 14.04 LTS | 38,893,325 | <p>I've been trying to get <code>mysql-workbench</code> to work, and having a ton of issues. Running it from terminal gives me the following:</p>
<pre><code>File "/home/{My_username}/.linuxbrew/Cellar/python/2.7.12_1/lib/python2.7/hmac.py", line 8, in <module>
from operator import _compare_digest as compare_dig... | 0 | 2016-08-11T10:07:36Z | 38,893,856 | <p>It turns out that when I installed linuxbrew I had to add '/home/{username}/.linuxbrew/bin' to my PATH in '~/.profile' to get brew to work, but added it in front:</p>
<pre><code>PATH="$HOME/.linuxbrew/bin:$PATH"
</code></pre>
<p>This meant that the linuxbrew version of python became the default which causes lots o... | 0 | 2016-08-11T10:32:06Z | [
"python",
"mysql",
"ubuntu"
] |
Resetting Python to system Python in Ubuntu 14.04 LTS | 38,893,325 | <p>I've been trying to get <code>mysql-workbench</code> to work, and having a ton of issues. Running it from terminal gives me the following:</p>
<pre><code>File "/home/{My_username}/.linuxbrew/Cellar/python/2.7.12_1/lib/python2.7/hmac.py", line 8, in <module>
from operator import _compare_digest as compare_dig... | 0 | 2016-08-11T10:07:36Z | 38,894,050 | <p>To confirm which python location is in use you can use:
<code>which python</code></p>
<p>To change the version per user:</p>
<pre><code> alias python='/usr/bin/python3.4'
</code></pre>
<p>Once you make the above change, re-login or source your .bashrc file:</p>
<pre><code>$ . ~/.bashrc
</code></pre>
<p>Check y... | 0 | 2016-08-11T10:39:43Z | [
"python",
"mysql",
"ubuntu"
] |
LabelEncoder specify classes in DataFrame | 38,893,374 | <p>Iâm applying a LabelEncoder to a pandas DataFrame, <code>df</code></p>
<pre><code>Feat1 Feat2 Feat3 Feat4 Feat5
A A A A E
B B C C E
C D C C E
D A C D E
</code></pre>
<p>I'm applying a label encoder to a dataframe like thi... | 2 | 2016-08-11T10:09:17Z | 38,894,053 | <p>You could <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html#sklearn.preprocessing.LabelEncoder.fit" rel="nofollow"><code>fit</code></a> the label encoder and later <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html#sklearn... | 4 | 2016-08-11T10:39:45Z | [
"python",
"pandas",
"machine-learning",
"scikit-learn"
] |
Bokeh + interactive widgets + PythonAnywhere | 38,893,389 | <p>I was unable to find a minimal working example for an interactive web app using bokeh and bokeh widgets that runs on PythonAnywhere.</p>
<p>Ideally, I would like to have a simple plot of a relatively complicated function (which I do not know analytically, but I have SymPy compute that for me) which should be replot... | 1 | 2016-08-11T10:09:57Z | 38,895,793 | <p>Here is a working example of Jupyter notebook with interactive widgets on pythonanywhere:</p>
<pre><code>%pylab inline
import matplotlib.pyplot as plt
from ipywidgets import interact
def plot_power_function(k):
xs = range(50)
dynamic_ys = [x ** k for x in xs]
plt.plot(xs, dynamic_ys)
interact(plot_pow... | 2 | 2016-08-11T12:00:15Z | [
"python",
"bokeh",
"pythonanywhere"
] |
How to install python cgi on apache2? | 38,893,438 | <p>I want to call a Python script using javascript.
For this I need to install cgi on my apache server to call python script. (Maybe I wrong, I'm beginner and I'm little lost...)
But I don't know how to do this... </p>
<p>I have this in my <code>000-default.conf</code> : </p>
<pre><code><VirtualHost *:80>
D... | 1 | 2016-08-11T10:12:36Z | 38,976,058 | <p>You can follow <a href="https://www.linux.com/blog/configuring-apache2-run-python-scripts" rel="nofollow">this link</a>.
But in short you have to add this</p>
<pre><code>ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
Options +ExecCGI
AddHandler cgi-script .py
Options FollowSymLin... | 0 | 2016-08-16T13:17:46Z | [
"python",
"apache",
"install",
"cgi"
] |
Python ,TypeError: not all arguments converted during string formatting, SMB mount command | 38,893,494 | <p>I am trying to smb mount using below script but facing "TypeError" issue can someone please help me to solve this.
the actual command i want to execute is
mount -t cifs //111.11.111.111/SMBShare /mnt -o username=admin,password=admin,vers=3.0 </p>
<p>python code:</p>
<p>#!/usr/bin/env python</p>
<pre><code> def ... | 0 | 2016-08-11T10:14:45Z | 38,893,623 | <p>You do the conversion on the last element in the list:</p>
<pre><code>'username=admin,password=admin,vers=3.0' %(dx_ip, share)
</code></pre>
<p>Which has no %s at all.</p>
<p>you probably want to do something like:</p>
<pre><code>co.clients[0].execute(['mount' ,'-t' ,'cifs' ,'//%s/%s' % (dx_ip, share) ,'/mnt', '... | 3 | 2016-08-11T10:21:19Z | [
"python",
"python-2.7",
"mount",
"smb",
"libsmbclient"
] |
What's the meaning of tf.nn.embedding_lookup_sparse in TensorFlow? | 38,893,526 | <p>We spend a lot of time in reading the API document of <a href="https://www.tensorflow.org/versions/master/api_docs/python/nn.html#embedding_lookup_sparse" rel="nofollow">tf.nn.embedding_lookup_sparse</a>. The meaning of <code>embedding_lookup_sparse</code> is confusing and it seems quite different from <code>embeddi... | 1 | 2016-08-11T10:16:30Z | 38,900,894 | <p>The main difference between embedding lookup and embedding lookup sparse is that the sparse version expects the id's and weights to be of type SparseTensor.</p>
<p>Do you also not understand how embedding lookup works? </p>
<p>You pass in a tensor of some size and will multiply the slices of the tensors be some we... | 0 | 2016-08-11T15:45:42Z | [
"python",
"tensorflow",
"embedding"
] |
ndarray(numpy,python) assignment assigns array of 0s : why? | 38,893,592 | <p>So in this simple code the line</p>
<pre><code>result[columnNumber] = column #this assignment fails for some reason!
</code></pre>
<p>fails, and specifically it simply assigns array of zeroes instead of what it is supposed to assign, and I have no idea why! So this is the full code:</p>
<pre><code> """Softmax.... | 1 | 2016-08-11T10:19:15Z | 38,893,751 | <p>In your example, the input <code>scores</code> is all integers, so the data type of the <code>data</code> array is integer. Therefore <code>result</code> is also an integer array. You can't assign a floating point value into an integer array--numpy arrays have homogeneous data types which can not be dynamically ch... | 2 | 2016-08-11T10:27:33Z | [
"python",
"numpy"
] |
ndarray(numpy,python) assignment assigns array of 0s : why? | 38,893,592 | <p>So in this simple code the line</p>
<pre><code>result[columnNumber] = column #this assignment fails for some reason!
</code></pre>
<p>fails, and specifically it simply assigns array of zeroes instead of what it is supposed to assign, and I have no idea why! So this is the full code:</p>
<pre><code> """Softmax.... | 1 | 2016-08-11T10:19:15Z | 38,893,771 | <p>Your array <code>result</code> has type <code>int</code> so all your floats are automatically converted to <code>int</code>'s, in this case <code>0</code>. Use this <code>result = data.astype(float)</code>.</p>
| 0 | 2016-08-11T10:28:22Z | [
"python",
"numpy"
] |
scraping craigslist results "Page not found" using python | 38,893,777 | <p>I tried to fetch the contents of CL page and display it as a separate html page using python's BeautifulSoup.</p>
<p>But it results in "page not found".</p>
<pre><code>d={'query':'doctor'}
encoder=urllib.urlencode(d).encode('ASCII')
page1=urllib.urlopen('chennai.craigslist.co.in/search',encoder)
content=page1.read... | -4 | 2016-08-11T10:28:35Z | 38,896,657 | <p>The code works in python version 3.. Thanks for the contributions.</p>
| -1 | 2016-08-11T12:38:41Z | [
"python",
"web-scraping"
] |
Why does not threading make it faster to iterate on a numpy array? | 38,894,032 | <p>My question is about multi-threading in python. The problem I am working on is finding 80 percent similar arrays(lengths are 64) to a given array with the same length from 10 Million arrays. The problem is that although my code executes in 12.148 seconds when I iterate linearly inside a while loop, it doesn't execut... | 0 | 2016-08-11T10:38:58Z | 38,894,938 | <p>I solved the problem. I found out that threading is blocked by GIL which never allows to use more that the current processor. However using multiprocessing module worked. Here is the modification I made:</p>
<pre><code>import numpy as np
import multiprocessing
import timeit
start = timeit.default_timer()
ph = np.l... | 0 | 2016-08-11T11:19:26Z | [
"python",
"multithreading",
"performance",
"gil",
"hamming-distance"
] |
Python subprocess.Popen() - subprocess causes sockets to remain open | 38,894,081 | <p>I have a Python2.7 script that does some parallelism magic and finally enters Flask gui_loop. At some point a thread creates a background process with subprocess.Popen. This works. </p>
<p>When my script exits and if the subprocess is still running, I can't run my script again, as flask gui_loop fails with:</p>
<... | 0 | 2016-08-11T10:41:00Z | 38,899,156 | <p>You could try using the <strong><em>with</em></strong> statement. Some documentation here:</p>
<pre><code>http://preshing.com/20110920/the-python-with-statement-by-example/
https://www.python.org/dev/peps/pep-0343/
</code></pre>
<p>This does open/close cleanup for you.</p>
| 1 | 2016-08-11T14:27:16Z | [
"python",
"python-2.7",
"sockets",
"subprocess"
] |
Python subprocess.Popen() - subprocess causes sockets to remain open | 38,894,081 | <p>I have a Python2.7 script that does some parallelism magic and finally enters Flask gui_loop. At some point a thread creates a background process with subprocess.Popen. This works. </p>
<p>When my script exits and if the subprocess is still running, I can't run my script again, as flask gui_loop fails with:</p>
<... | 0 | 2016-08-11T10:41:00Z | 38,899,412 | <p>You should use <a href="https://docs.python.org/2/library/subprocess.html#popen-constructor" rel="nofollow"><code>close_fds=True</code></a> when creating the subproces, which will cause all file descriptors (and therfore open sockets) to be closed in the child process (except for stdin/stdout/stderr).</p>
<p>In new... | 2 | 2016-08-11T14:37:53Z | [
"python",
"python-2.7",
"sockets",
"subprocess"
] |
Can't access dataframe columns | 38,894,098 | <p>I'm importing a dataframe from a csv file, but cannot access some of it's columns by name. What's going on?</p>
<p>In more concrete terms:</p>
<pre><code>> import pandas
> jobNames = pandas.read_csv("job_names.csv")
> print(jobNames)
job_id job_name num_judgements
0 933985 Foo ... | 1 | 2016-08-11T10:41:53Z | 38,894,099 | <p>Another (perhaps inferior) approach is to remove the spaces from the column names:</p>
<pre><code>> jobNames.columns = map(lambda s:s.strip(), jobNames.columns)
> jobNames.job_name
0 Foo
1 Moo
2 Goo
3 Flue
4 Tru
Name: job_name, dtype: object
</code></pre>
| 0 | 2016-08-11T10:41:53Z | [
"python",
"csv",
"pandas",
"dataframe",
"removing-whitespace"
] |
Can't access dataframe columns | 38,894,098 | <p>I'm importing a dataframe from a csv file, but cannot access some of it's columns by name. What's going on?</p>
<p>In more concrete terms:</p>
<pre><code>> import pandas
> jobNames = pandas.read_csv("job_names.csv")
> print(jobNames)
job_id job_name num_judgements
0 933985 Foo ... | 1 | 2016-08-11T10:41:53Z | 38,894,182 | <p>Another solution for removing whitespaces from column names is <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.strip.html" rel="nofollow"><code>str.strip</code></a>:</p>
<pre><code>jobNames.columns = jobNames.columns.str.strip()
print (jobNames.job_name)
0 Foo
1 Moo
2 G... | 1 | 2016-08-11T10:44:10Z | [
"python",
"csv",
"pandas",
"dataframe",
"removing-whitespace"
] |
Can't access dataframe columns | 38,894,098 | <p>I'm importing a dataframe from a csv file, but cannot access some of it's columns by name. What's going on?</p>
<p>In more concrete terms:</p>
<pre><code>> import pandas
> jobNames = pandas.read_csv("job_names.csv")
> print(jobNames)
job_id job_name num_judgements
0 933985 Foo ... | 1 | 2016-08-11T10:41:53Z | 38,894,205 | <p>When using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>pandas.read_csv</code></a> pass in <code>skipinitialspace=True</code> flag to remove whitespace after CSV delimiters.</p>
| 2 | 2016-08-11T10:45:25Z | [
"python",
"csv",
"pandas",
"dataframe",
"removing-whitespace"
] |
Operation on numpy arrays contain rows with different size | 38,894,291 | <p>I have two lists, looking like this:</p>
<pre><code>a= [[1,2,3,4], [2,3,4,5],[3,4,5,6,7]], b= [[5,6,7,8], [9,1,2,3], [4,5,6,7,8]]
</code></pre>
<p>which I want to subtract from each other element by element for an Output like this:</p>
<pre><code>a-b= [[-4,-4,-4,-4],[7,2,2,2],[-1,-1,-1,-1,-1]]
</code></pre>
<p>I... | 8 | 2016-08-11T10:49:20Z | 38,894,480 | <p>The dimensions of your two arrays don't match, i.e. the first two sublists of <code>a</code> have 4 elements, but the third has 5 and ditto with <code>b</code>. If you convert the lists to <code>numpy arrays</code>, <code>numpy</code> silently gives you something like this:</p>
<pre><code>In [346]: aa = np.array(a)... | 1 | 2016-08-11T10:59:04Z | [
"python",
"arrays",
"numpy"
] |
Operation on numpy arrays contain rows with different size | 38,894,291 | <p>I have two lists, looking like this:</p>
<pre><code>a= [[1,2,3,4], [2,3,4,5],[3,4,5,6,7]], b= [[5,6,7,8], [9,1,2,3], [4,5,6,7,8]]
</code></pre>
<p>which I want to subtract from each other element by element for an Output like this:</p>
<pre><code>a-b= [[-4,-4,-4,-4],[7,2,2,2],[-1,-1,-1,-1,-1]]
</code></pre>
<p>I... | 8 | 2016-08-11T10:49:20Z | 38,894,750 | <p>You can try:</p>
<pre><code>>>> a= [[1,2,3,4], [2,3,4,5],[3,4,5,6,7]]
>>> b= [[5,6,7,8], [9,1,2,3], [4,5,6,7,8]]
>>>
>>> c =[]
>>> for i in range(len(a)):
c.append([A - B for A, B in zip(a[i], b[i])])
>>> print c
[[-4, -4, -4, -4], [-7, 2, 2, 2], [-1, -1,... | 1 | 2016-08-11T11:11:04Z | [
"python",
"arrays",
"numpy"
] |
Operation on numpy arrays contain rows with different size | 38,894,291 | <p>I have two lists, looking like this:</p>
<pre><code>a= [[1,2,3,4], [2,3,4,5],[3,4,5,6,7]], b= [[5,6,7,8], [9,1,2,3], [4,5,6,7,8]]
</code></pre>
<p>which I want to subtract from each other element by element for an Output like this:</p>
<pre><code>a-b= [[-4,-4,-4,-4],[7,2,2,2],[-1,-1,-1,-1,-1]]
</code></pre>
<p>I... | 8 | 2016-08-11T10:49:20Z | 38,894,774 | <p>Without NumPy:</p>
<pre><code>result = []
for (m, n) in (zip(a, b)):
result.append([i - j for i, j in zip(m, n)])
</code></pre>
<p>See also <a href="http://stackoverflow.com/questions/534855">this question</a> and <a href="http://stackoverflow.com/questions/1663807">this one</a>.</p>
| 0 | 2016-08-11T11:12:16Z | [
"python",
"arrays",
"numpy"
] |
Operation on numpy arrays contain rows with different size | 38,894,291 | <p>I have two lists, looking like this:</p>
<pre><code>a= [[1,2,3,4], [2,3,4,5],[3,4,5,6,7]], b= [[5,6,7,8], [9,1,2,3], [4,5,6,7,8]]
</code></pre>
<p>which I want to subtract from each other element by element for an Output like this:</p>
<pre><code>a-b= [[-4,-4,-4,-4],[7,2,2,2],[-1,-1,-1,-1,-1]]
</code></pre>
<p>I... | 8 | 2016-08-11T10:49:20Z | 38,894,828 | <p>What about a custom function such as:</p>
<pre><code>import numpy as np
a = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6, 7]]
b = [[5, 6, 7, 8], [9, 1, 2, 3], [4, 5, 6, 7, 8]]
def np_substract(l1, l2):
return np.array([np.array(l1[i]) - np.array(l2[i]) for i in range(len(l1))])
print np_substract(a, b)
</code><... | 0 | 2016-08-11T11:14:44Z | [
"python",
"arrays",
"numpy"
] |
Operation on numpy arrays contain rows with different size | 38,894,291 | <p>I have two lists, looking like this:</p>
<pre><code>a= [[1,2,3,4], [2,3,4,5],[3,4,5,6,7]], b= [[5,6,7,8], [9,1,2,3], [4,5,6,7,8]]
</code></pre>
<p>which I want to subtract from each other element by element for an Output like this:</p>
<pre><code>a-b= [[-4,-4,-4,-4],[7,2,2,2],[-1,-1,-1,-1,-1]]
</code></pre>
<p>I... | 8 | 2016-08-11T10:49:20Z | 38,894,930 | <p>Here is a Numpythonic way:</p>
<pre><code>>>> y = map(len, a)
>>> a = np.hstack(np.array(a))
>>> b = np.hstack(np.array(b))
>>> np.split(a-b, np.cumsum(y))
[array([-4, -4, -4, -4]), array([-7, 2, 2, 2]), array([-1, -1, -1, -1, -1]), array([], dtype=float64)]
>>>
</... | 5 | 2016-08-11T11:19:04Z | [
"python",
"arrays",
"numpy"
] |
Operation on numpy arrays contain rows with different size | 38,894,291 | <p>I have two lists, looking like this:</p>
<pre><code>a= [[1,2,3,4], [2,3,4,5],[3,4,5,6,7]], b= [[5,6,7,8], [9,1,2,3], [4,5,6,7,8]]
</code></pre>
<p>which I want to subtract from each other element by element for an Output like this:</p>
<pre><code>a-b= [[-4,-4,-4,-4],[7,2,2,2],[-1,-1,-1,-1,-1]]
</code></pre>
<p>I... | 8 | 2016-08-11T10:49:20Z | 38,894,934 | <p>You are getting the error, because your code is trying to subtract sublist from sublist, if you want to make it work, you can do the same in following manner:</p>
<pre><code>import numpy as np
a= [[1,2,3,4], [2,3,4,5],[3,4,5,6,7]]
b= [[5,6,7,8], [9,1,2,3], [4,5,6,7,8]]
#You can apply different condition here, like... | 0 | 2016-08-11T11:19:12Z | [
"python",
"arrays",
"numpy"
] |
Operation on numpy arrays contain rows with different size | 38,894,291 | <p>I have two lists, looking like this:</p>
<pre><code>a= [[1,2,3,4], [2,3,4,5],[3,4,5,6,7]], b= [[5,6,7,8], [9,1,2,3], [4,5,6,7,8]]
</code></pre>
<p>which I want to subtract from each other element by element for an Output like this:</p>
<pre><code>a-b= [[-4,-4,-4,-4],[7,2,2,2],[-1,-1,-1,-1,-1]]
</code></pre>
<p>I... | 8 | 2016-08-11T10:49:20Z | 38,901,165 | <p>A nested list comprehension will do the job:</p>
<pre><code>In [102]: [[i2-j2 for i2,j2 in zip(i1,j1)] for i1,j1 in zip(a,b)]
Out[102]: [[-4, -4, -4, -4], [-7, 2, 2, 2], [-1, -1, -1, -1, -1]]
</code></pre>
<p>The problem with <code>np.array(a)-np.array(b)</code> is that the sublists differ in length, so the resul... | 0 | 2016-08-11T15:59:23Z | [
"python",
"arrays",
"numpy"
] |
Error while trying to add column in inherited view Odoo | 38,894,397 | <p>I'm trying to add a column in a existing view , I'm new with odoo , this is my xml code </p>
<pre><code> <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="mrp_form_view">
<field name="name"> mrp.fleuret.form</field>
<field name=... | 1 | 2016-08-11T10:54:34Z | 38,895,616 | <p>You just need to update your xml code, issue was there in xpath.</p>
<p>You should try following, </p>
<pre><code><record model="ir.ui.view" id="mrp_form_view">
<field name="name"> mrp.fleuret.form</field>
<field name="model"> mrp.bom</field>
<field name="type">form&... | 1 | 2016-08-11T11:52:05Z | [
"python",
"xml",
"xpath",
"openerp"
] |
How to name a dataframe column filled by numpy array? | 38,894,418 | <p>I am filling a DataFrame by transposing some numpy array :</p>
<pre><code> for symbol in syms[:5]:
price_p = Share(symbol)
closes_p = [c['Close'] for c in price_p.get_historical(startdate_s, enddate_s)]
dump = np.array(closes_p)
na_price_ar.append(dump)
print symbol
df = pd.DataFrame(na_pric... | 1 | 2016-08-11T10:55:26Z | 38,894,526 | <p>You can use:</p>
<pre><code>na_price_ar = [['A','B','C'],[0,2,3],[1,2,4],[5,2,3],[8,2,3]]
syms = ['q','w','e','r','t','y','u']
df = pd.DataFrame(na_price_ar, index=syms[:5]).transpose()
print (df)
q w e r t
0 A 0 1 5 8
1 B 2 2 2 2
2 C 3 4 3 3
</code></pre>
| 0 | 2016-08-11T11:01:31Z | [
"python",
"arrays",
"pandas",
"numpy",
"dataframe"
] |
How to name a dataframe column filled by numpy array? | 38,894,418 | <p>I am filling a DataFrame by transposing some numpy array :</p>
<pre><code> for symbol in syms[:5]:
price_p = Share(symbol)
closes_p = [c['Close'] for c in price_p.get_historical(startdate_s, enddate_s)]
dump = np.array(closes_p)
na_price_ar.append(dump)
print symbol
df = pd.DataFrame(na_pric... | 1 | 2016-08-11T10:55:26Z | 38,894,588 | <p>Instead of using a list of arrays and transposing, you could build the DataFrame from a dict whose keys are symbols and whose values are arrays of <em>column</em> values:</p>
<pre><code>import numpy as np
import pandas as pd
np.random.seed(2016)
syms = 'abcde'
na_price_ar = {}
for symbol in syms[:5]:
# price_p ... | 3 | 2016-08-11T11:04:17Z | [
"python",
"arrays",
"pandas",
"numpy",
"dataframe"
] |
How to name a dataframe column filled by numpy array? | 38,894,418 | <p>I am filling a DataFrame by transposing some numpy array :</p>
<pre><code> for symbol in syms[:5]:
price_p = Share(symbol)
closes_p = [c['Close'] for c in price_p.get_historical(startdate_s, enddate_s)]
dump = np.array(closes_p)
na_price_ar.append(dump)
print symbol
df = pd.DataFrame(na_pric... | 1 | 2016-08-11T10:55:26Z | 38,918,996 | <p>You may use as dictionary key into the .rename() method the df.columns[ number ] statement</p>
<pre><code>dic = {'a': [4, 1, 3, 1], 'b': [4, 2, 1, 4], 'c': [5, 7, 9, 1], 'd': [4, 1, 3, 1], 'e': [5, 2, 6, 0]}
df = pd.DataFrame(dic)
number = 0
for symbol in syms[:5]:
df.rename( columns = { df.columns[number]: sym... | 0 | 2016-08-12T13:18:35Z | [
"python",
"arrays",
"pandas",
"numpy",
"dataframe"
] |
Apply alignments on Reportlab SimpleDocTemplate to append multiple barcodes in number of rows | 38,894,523 | <p>I am using Reportlab <code>SimpleDocTemplate</code> to create a pdf file. I have to write (draw) multiple images row-wise so that I can adjust many images within the file.</p>
<pre><code>class PrintBarCodes(View):
def get(self, request, format=None):
response = HttpResponse(content_type='application/p... | 1 | 2016-08-11T11:01:28Z | 38,913,180 | <p>As your question suggest that you need flexibility I think the most sensible approach is using <code>Flowable</code>'s. The barcode normally isn't one but we can <a href="http://stackoverflow.com/questions/18569682/use-qrcodewidget-or-plotarea-with-platypus">make it one</a> pretty easily. By doing so we can let <a h... | 0 | 2016-08-12T08:17:42Z | [
"python",
"django",
"barcode",
"reportlab"
] |
How to update model object in django? | 38,894,573 | <p>I am using below code for update the status.</p>
<pre><code>current_challenge = UserChallengeSummary.objects.filter(user_challenge_id=user_challenge_id).latest('id')
current_challenge.update(status=str(request.data['status']))
</code></pre>
<p>I am getting below error:</p>
<blockquote>
<p>'UserChallengeSummary'... | 0 | 2016-08-11T11:03:52Z | 38,894,777 | <p><a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#latest" rel="nofollow">latest()</a> method returns the latest object which is an instance of <code>UserChallengeSummary</code>, which doesn't have an update method.</p>
<p>For updating single objects, your method is standard.</p>
<p><a href="htt... | 0 | 2016-08-11T11:12:18Z | [
"python",
"django",
"django-models"
] |
How to update model object in django? | 38,894,573 | <p>I am using below code for update the status.</p>
<pre><code>current_challenge = UserChallengeSummary.objects.filter(user_challenge_id=user_challenge_id).latest('id')
current_challenge.update(status=str(request.data['status']))
</code></pre>
<p>I am getting below error:</p>
<blockquote>
<p>'UserChallengeSummary'... | 0 | 2016-08-11T11:03:52Z | 38,894,937 | <p>Your working solution is the way usually used in Django, as @Compadre already said.</p>
<p>But sometimes (for example, in tests) it's useful to be able to update multiple fields at once. For such cases I've written simple helper:</p>
<pre><code>def update_attrs(instance, **kwargs):
""" Updates model instance a... | 1 | 2016-08-11T11:19:20Z | [
"python",
"django",
"django-models"
] |
Sklearn Fit model multiple times | 38,894,576 | <p>Origin of the problem is common: </p>
<p>presence of a lot of train data, which was read in chunks. Point of interest is to fit sequentially the desired model on chunked data sets, keeping states of previous fitting.</p>
<p>Are there any methods except <code>partial_fit()</code> to fit model using sklearn on diff... | 0 | 2016-08-11T11:03:55Z | 38,922,782 | <p>There is a reason why some models expose <code>partial_fit()</code> and others don't. Every model is a different machine learning algorithm and for many of these algorithms there is just no way to add an element without recalculating the model from scratch.</p>
<p>So, if you have to fit the models incrementally, pi... | 0 | 2016-08-12T16:37:32Z | [
"python",
"scikit-learn"
] |
unable to access spreadsheet data | 38,894,636 | <blockquote>
<blockquote>
<blockquote>
<p>=== RESTART: C:\Users\sandesh patil\Desktop\pythan_practice\quickstart.py ===
username, password:</p>
</blockquote>
</blockquote>
</blockquote>
<p>Traceback (most recent call last):
File "C:\Users\sandesh patil\Desktop\pythan_practice\quickstart.py", ... | -2 | 2016-08-11T11:06:23Z | 38,894,738 | <p>you can use pandas in python and access a spreadsheet as </p>
<pre><code>dataframe = pandas.read_csv('/path to file.csv', engine='python')
dataset = dataframe.values
</code></pre>
| 0 | 2016-08-11T11:10:33Z | [
"python"
] |
How to make log file copy in python? | 38,894,722 | <p>I want to make log file in python same as in log4j,
meaning as soon the <strong>logger.log</strong> file get's to a size of 1K make a copy of this file and call it <strong>logger(1).log</strong> , In case <strong>logger(1)</strong>,log already exists create <strong>logger(2).log</strong> and of course delete logger.... | 0 | 2016-08-11T11:09:51Z | 38,894,890 | <p>You need to setup a <a href="https://docs.python.org/2/library/logging.handlers.html#rotatingfilehandler" rel="nofollow">RotatingFileHandler</a>:</p>
<pre><code>import logging
from logging import handlers
logger = logging.getLogger(__name__)
handler = handlers.RotatingFileHandler('logger.log', maxBytes=1000, backu... | 3 | 2016-08-11T11:17:11Z | [
"python",
"logging"
] |
How to make log file copy in python? | 38,894,722 | <p>I want to make log file in python same as in log4j,
meaning as soon the <strong>logger.log</strong> file get's to a size of 1K make a copy of this file and call it <strong>logger(1).log</strong> , In case <strong>logger(1)</strong>,log already exists create <strong>logger(2).log</strong> and of course delete logger.... | 0 | 2016-08-11T11:09:51Z | 38,894,904 | <p>Try using python logging module with <a href="https://docs.python.org/2/library/logging.handlers.html#rotatingfilehandler" rel="nofollow">TimedRotatingFileHandler</a> handler.</p>
| 0 | 2016-08-11T11:17:34Z | [
"python",
"logging"
] |
How to make log file copy in python? | 38,894,722 | <p>I want to make log file in python same as in log4j,
meaning as soon the <strong>logger.log</strong> file get's to a size of 1K make a copy of this file and call it <strong>logger(1).log</strong> , In case <strong>logger(1)</strong>,log already exists create <strong>logger(2).log</strong> and of course delete logger.... | 0 | 2016-08-11T11:09:51Z | 38,894,941 | <p>You can use a <a href="https://docs.python.org/2/library/logging.handlers.html#rotatingfilehandler" rel="nofollow">RotatingFileHandler</a>.</p>
<p>Such a handler can be added by doing something like this:</p>
<pre><code>import logging
logger = logging.getLogger(__name__)
logger.addHandler(RotatingFileHandler(filen... | 1 | 2016-08-11T11:19:29Z | [
"python",
"logging"
] |
Transform x,y numpy matrixes into a list of (x,y) points | 38,895,040 | <p>I have</p>
<pre><code>x=np.array([[1,2,3],[3,4,5],[5,7,8]])
y=np.array([[5,2,5],[1,1,1],[2,2,2]])
</code></pre>
<p>I'd like to get</p>
<pre><code>xy=[(1,5),(2,2),(3,5),(3,1),(4,1),(5,1),(5,2),(7,2),(8,2)]
</code></pre>
<p>What's the best (quick and clean) way to do so? Also, once I have <code>xy</code>, how do I... | 0 | 2016-08-11T11:24:58Z | 38,895,081 | <p>Transpose or use <code>nop.dstack()</code>:</p>
<pre><code>>>> np.dstack((x.ravel(), y.ravel()))[0]
array([[1, 5],
[2, 2],
[3, 5],
[3, 1],
[4, 1],
[5, 1],
[5, 2],
[7, 2],
[8, 2]])
>>>
>>>
>>> np.array((x.ravel(), y.ravel()... | 0 | 2016-08-11T11:26:36Z | [
"python",
"numpy",
"matrix"
] |
Transform x,y numpy matrixes into a list of (x,y) points | 38,895,040 | <p>I have</p>
<pre><code>x=np.array([[1,2,3],[3,4,5],[5,7,8]])
y=np.array([[5,2,5],[1,1,1],[2,2,2]])
</code></pre>
<p>I'd like to get</p>
<pre><code>xy=[(1,5),(2,2),(3,5),(3,1),(4,1),(5,1),(5,2),(7,2),(8,2)]
</code></pre>
<p>What's the best (quick and clean) way to do so? Also, once I have <code>xy</code>, how do I... | 0 | 2016-08-11T11:24:58Z | 38,895,120 | <p>You can use this approach to get <code>xy</code>:</p>
<pre><code>zip(x.flatten(),y.flatten())
#[(1, 5), (2, 2), (3, 5), (3, 1), (4, 1), (5, 1), (5, 2), (7, 2), (8, 2)]
</code></pre>
| 2 | 2016-08-11T11:28:14Z | [
"python",
"numpy",
"matrix"
] |
Transform x,y numpy matrixes into a list of (x,y) points | 38,895,040 | <p>I have</p>
<pre><code>x=np.array([[1,2,3],[3,4,5],[5,7,8]])
y=np.array([[5,2,5],[1,1,1],[2,2,2]])
</code></pre>
<p>I'd like to get</p>
<pre><code>xy=[(1,5),(2,2),(3,5),(3,1),(4,1),(5,1),(5,2),(7,2),(8,2)]
</code></pre>
<p>What's the best (quick and clean) way to do so? Also, once I have <code>xy</code>, how do I... | 0 | 2016-08-11T11:24:58Z | 38,895,273 | <p>You can try:</p>
<pre><code>>>> x = [[1,2,3],[3,4,5],[5,7,8]]
>>> y = [[5,2,5],[1,1,1],[2,2,2]]
>>> x1 = [val for x_data in x for val in x_data]
>>> y1 = [val for y_data in y for val in y_data]
>>> final = [(a,b) for a, b in zip(x1, y1)]
>>> print final
[(1, 5),... | 1 | 2016-08-11T11:36:18Z | [
"python",
"numpy",
"matrix"
] |
django post request data | 38,895,105 | <p>I have the following POST request</p>
<pre><code>curl -v --dump-header --H "Content-Type: application/json" -X POST --data '{"name": "John", "age": 27}' "http://localhost:8300/api/v1/create_contact?username=gegham&api_key=3efc6df6023534279d2183a696044a8cfec964a9"
</code></pre>
<p>Result after I'm printing requ... | 0 | 2016-08-11T11:27:36Z | 38,895,250 | <p>Because you're sending JSON, not form data. Use <code>request.body</code> and deserialize it with <code>json.loads</code>.</p>
| 3 | 2016-08-11T11:35:29Z | [
"python",
"django",
"curl",
"django-models"
] |
pandas reshape date sequence | 38,895,121 | <p>I have table with factor and time interval. What I want to do is to get long table with each date in interval between <code>START_DATE</code> and <code>END_DATE</code>.</p>
<pre><code>dt_in = pd.DataFrame({'factor':['A','B'],
'START_DATE':[pd.Timestamp('2015-01-01'),pd.Timestamp('2016-02-05')],
... | 1 | 2016-08-11T11:28:24Z | 38,895,277 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.melt.html" rel="nofollow"><code>melt</code></a> for reshaping and then <code>groupby</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.resample.html" rel="nofollow"><code>re... | 2 | 2016-08-11T11:36:31Z | [
"python",
"datetime",
"pandas",
"reshape",
"melt"
] |
Change tkinter canvas's text outside the class | 38,895,188 | <pre><code> from tkinter import *
class MainBattle(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
global canvas
self.parent.title('Python')
self.pack(fill = BOTH, expand = 1)
... | 0 | 2016-08-11T11:32:22Z | 38,895,546 | <p>If your question is "can I use global to set variable values from outside the class" then yes.
Whenever you want to change the value of a global variable you need to write global. </p>
<pre><code>def changetext():
global label_text
label_text = "new text"
</code></pre>
| 1 | 2016-08-11T11:48:59Z | [
"python",
"class",
"tkinter",
"label",
"self"
] |
Change tkinter canvas's text outside the class | 38,895,188 | <pre><code> from tkinter import *
class MainBattle(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
global canvas
self.parent.title('Python')
self.pack(fill = BOTH, expand = 1)
... | 0 | 2016-08-11T11:32:22Z | 38,895,599 | <p>You don't need global variables. You have a reference to the instance, which allows you to access all instance variables:</p>
<pre><code>ex.Label_My["text"] = "HisObject"
</code></pre>
| 2 | 2016-08-11T11:51:13Z | [
"python",
"class",
"tkinter",
"label",
"self"
] |
SIGKILL adding column in a simple python script | 38,895,211 | <p>I have a file that has a oneline header and a long column with values. I want to add a second column with values since 10981 (step = 1) until the end of the file (ommiting the header, of course). The problem is that the script needs a lot of memory and my pc crashes, probably due to the script is not well made (sorr... | 1 | 2016-08-11T11:33:22Z | 38,895,373 | <p>It is difficult to verify if it works without the .txt, but give a try to that one</p>
<pre><code>f = open(os.path.join(data_path, 'chr1.phyloP46way.placental2.wigFix'), 'r')
lines = f.readlines()
num = 10981
for line_num in range(len(lines)):
line_in = lines[line_num]
num = num + 1
print line_in.str... | 1 | 2016-08-11T11:40:45Z | [
"python",
"file-processing"
] |
SIGKILL adding column in a simple python script | 38,895,211 | <p>I have a file that has a oneline header and a long column with values. I want to add a second column with values since 10981 (step = 1) until the end of the file (ommiting the header, of course). The problem is that the script needs a lot of memory and my pc crashes, probably due to the script is not well made (sorr... | 1 | 2016-08-11T11:33:22Z | 38,896,307 | <p>If your system is running out of resources, the likely culprit is the <code>readlines()</code> call, which causes Python to try to load the entire file into memory. There's no need to do this... a file object can itself be used as an iterator to read the file line by line:</p>
<pre><code>with open ('chr1.phyloP46wa... | 2 | 2016-08-11T12:23:17Z | [
"python",
"file-processing"
] |
How to add my added environment variable? | 38,895,282 | <p>I am trying to add an environmental variable. When I write <code>set</code> in cmd I want it to be there. How do I add it there?</p>
<p>I tried doing like this:</p>
<pre><code>def read_json_dump():
with open("apa.json") as f:
a = json.load(f)
for key, value in a.items():
project_rec... | 0 | 2016-08-11T11:36:40Z | 38,895,464 | <p><code>os.environ</code> sets environment variable only for the duration of the python program execution.</p>
<p>It won't be reflected outside.</p>
| 0 | 2016-08-11T11:45:05Z | [
"python",
"windows"
] |
How to add my added environment variable? | 38,895,282 | <p>I am trying to add an environmental variable. When I write <code>set</code> in cmd I want it to be there. How do I add it there?</p>
<p>I tried doing like this:</p>
<pre><code>def read_json_dump():
with open("apa.json") as f:
a = json.load(f)
for key, value in a.items():
project_rec... | 0 | 2016-08-11T11:36:40Z | 38,895,484 | <p>Using os.environ won't be enough, those env vars won't persist, on windows if you want to persist variables you can use <a href="http://ss64.com/nt/setx.html" rel="nofollow">setx</a> command, for example:</p>
<pre><code>import os
os.system("setx $DEFAULT_RECIPIENTS foo@foo.com")
</code></pre>
| 3 | 2016-08-11T11:46:12Z | [
"python",
"windows"
] |
How to add my added environment variable? | 38,895,282 | <p>I am trying to add an environmental variable. When I write <code>set</code> in cmd I want it to be there. How do I add it there?</p>
<p>I tried doing like this:</p>
<pre><code>def read_json_dump():
with open("apa.json") as f:
a = json.load(f)
for key, value in a.items():
project_rec... | 0 | 2016-08-11T11:36:40Z | 38,899,299 | <p>Per <a href="http://code.activestate.com/recipes/159462-how-to-set-environment-variables/" rel="nofollow">http://code.activestate.com/recipes/159462-how-to-set-environment-variables/</a> it looks like you can't modify the current program's environment variables from python and have them persist, but there is a work ... | 2 | 2016-08-11T14:33:11Z | [
"python",
"windows"
] |
Python, subtract two different times in the format (HH:MM:SS - HH:MM:SS) | 38,895,336 | <p>I need to subtract two different times, to get the difference. For example say I have message.start and message.end, both of which are a date and time (but they are of type 'time'. I checked this using <code>type(message.start)</code> in python) and are in the following format: 'month/day/year HH:MM:SS' so for examp... | 0 | 2016-08-11T11:39:24Z | 38,895,789 | <p>You need <code>strptime</code>method from <code>datetime</code>. </p>
<pre><code>import datetime
format = '%m/%d/%y %H:%M:%S'
startDateTime = datetime.datetime.strptime(message.start, format)
endDateTime = datetime.datetime.strptime(message.end, format)
diff = endDateTime - startDateTime
</code></pre>
<p><b>out... | 2 | 2016-08-11T12:00:11Z | [
"python",
"date",
"datetime",
"time"
] |
Display count variable from background task in main task (Tkinter GUI) | 38,895,552 | <p>I am trying to display a count variable from a background task in the main task which is my tkinter GUI. Why? I want to display that the long time taking background task is performing and later use this count variable to visualize it with a progress bar.</p>
<p>My problem is, that even when using a <code>Queue</cod... | 2 | 2016-08-11T11:49:16Z | 38,897,027 | <p>The reason the count variable isn't being displayed is due to the </p>
<pre><code> x = loop.loop_simulation().start_counting()
</code></pre>
<p>statement in <code>thread_proc1()</code>. This creates a <code>loop_simulation</code> instance and calls its <code>start_counting()</code> method. However, other than a... | 0 | 2016-08-11T12:55:45Z | [
"python",
"multithreading",
"python-2.7",
"user-interface",
"tkinter"
] |
Error reading csv file unicodeescape | 38,895,583 | <p>I have this program</p>
<pre><code>import csv
with open("C:\Users\frederic\Desktop\WinPython-64bit-3.4.4.3Qt5\notebooks\scores.txt","r") as scoreFile:
# write = w, read = r, append = a
scoreFileReader = csv.reader(scoreFile)
scoreList = []
for row in scoreFileReader:
if len (row) != 0:
... | 0 | 2016-08-11T11:50:36Z | 38,902,527 | <p>you may try this:</p>
<pre><code>import csv
import io
def guess_encoding(csv_file):
"""guess the encoding of the given file"""
with io.open(csv_file, "rb") as f:
data = f.read(5)
if data.startswith(b"\xEF\xBB\xBF"): # UTF-8 with a "BOM"
return ["utf-8-sig"]
elif data.startswith(b"\... | 0 | 2016-08-11T17:20:21Z | [
"python",
"csv",
"unicode-escapes"
] |
Error reading csv file unicodeescape | 38,895,583 | <p>I have this program</p>
<pre><code>import csv
with open("C:\Users\frederic\Desktop\WinPython-64bit-3.4.4.3Qt5\notebooks\scores.txt","r") as scoreFile:
# write = w, read = r, append = a
scoreFileReader = csv.reader(scoreFile)
scoreList = []
for row in scoreFileReader:
if len (row) != 0:
... | 0 | 2016-08-11T11:50:36Z | 38,903,169 | <p>Answer from <a href="http://stackoverflow.com/questions/20588840/unicode-error-opening-txt-files-with-python">@Tim Pietzcker</a></p>
<p>You need to use raw strings with Windows-style filenames:</p>
<pre><code>with open(r"C:\Users\frederic\Desktop\WinPython-64bit-3.4.4.3Qt5\notebooks\scores.txt", 'r') as scoreFile... | 0 | 2016-08-11T17:58:54Z | [
"python",
"csv",
"unicode-escapes"
] |
Python tkinter NameError when using lambda command | 38,895,697 | <p>I am new to Python's <code>tkinter</code> module so I would be grateful for any help, even an explanation as to why this is simply not possible (if that is the case).</p>
<p>I have a list of 4-tuples of the form <code>(foo, bar, x, y)</code>; something like this:</p>
<pre><code> TUPLE_LIST = [('Hello', 'World',... | 0 | 2016-08-11T11:55:59Z | 38,896,077 | <p>This is a very bad idea. There's simply no reason to dry to dynamically create variable names. It makes your code more complex, harder to maintain, and harder to read.</p>
<p>If you want to reference widgets by name, use a dictionary:</p>
<pre><code>buttons = {}
for foo, bar, x, y in TUPLE_LIST:
buttons[foo] =... | 1 | 2016-08-11T12:13:06Z | [
"python",
"lambda",
"tkinter",
"nameerror"
] |
python pandas dataframe, is it pass-by-value or pass-by-reference | 38,895,768 | <p>If I pass a dataframe to a function and modify it inside the function, is it pass-by-value or pass-by-reference?</p>
<p>I run the following code</p>
<pre><code>a = pd.DataFrame({'a':[1,2], 'b':[3,4]})
def letgo(df):
df = df.drop('b',axis=1)
letgo(a)
</code></pre>
<p>the value of <code>a</code> does not change... | 2 | 2016-08-11T11:59:13Z | 38,895,844 | <p>Here is the doc for drop:</p>
<blockquote>
<p>Return new object with labels in requested axis removed.</p>
</blockquote>
<p>So a new dataframe is created. The original has not changed.</p>
<p>But as for all objects in python, the data frame is passed to the function by reference.</p>
| 0 | 2016-08-11T12:02:25Z | [
"python",
"pandas",
"pass-by-reference",
"pass-by-value"
] |
python pandas dataframe, is it pass-by-value or pass-by-reference | 38,895,768 | <p>If I pass a dataframe to a function and modify it inside the function, is it pass-by-value or pass-by-reference?</p>
<p>I run the following code</p>
<pre><code>a = pd.DataFrame({'a':[1,2], 'b':[3,4]})
def letgo(df):
df = df.drop('b',axis=1)
letgo(a)
</code></pre>
<p>the value of <code>a</code> does not change... | 2 | 2016-08-11T11:59:13Z | 38,895,926 | <p>you need to make 'a' global at the start of the function otherwise it is a local variable and does not change the 'a' in the main code.</p>
| 0 | 2016-08-11T12:06:22Z | [
"python",
"pandas",
"pass-by-reference",
"pass-by-value"
] |
python pandas dataframe, is it pass-by-value or pass-by-reference | 38,895,768 | <p>If I pass a dataframe to a function and modify it inside the function, is it pass-by-value or pass-by-reference?</p>
<p>I run the following code</p>
<pre><code>a = pd.DataFrame({'a':[1,2], 'b':[3,4]})
def letgo(df):
df = df.drop('b',axis=1)
letgo(a)
</code></pre>
<p>the value of <code>a</code> does not change... | 2 | 2016-08-11T11:59:13Z | 38,896,256 | <p>The question isn't PBV vs. PBR. These names only cause confusion in a language like Python; they were invented for languages that work like C or like Fortran (as the quintessential PBV and PBR languages). It is true, but not enlightening, that Python always passes by value. The question here is whether the value its... | 3 | 2016-08-11T12:21:29Z | [
"python",
"pandas",
"pass-by-reference",
"pass-by-value"
] |
python pandas dataframe, is it pass-by-value or pass-by-reference | 38,895,768 | <p>If I pass a dataframe to a function and modify it inside the function, is it pass-by-value or pass-by-reference?</p>
<p>I run the following code</p>
<pre><code>a = pd.DataFrame({'a':[1,2], 'b':[3,4]})
def letgo(df):
df = df.drop('b',axis=1)
letgo(a)
</code></pre>
<p>the value of <code>a</code> does not change... | 2 | 2016-08-11T11:59:13Z | 38,924,624 | <p>To add to @Mike Graham's answer, who pointed to a very good read:</p>
<p>In your case, what is important to remember is the difference between <em>names</em> and <em>values</em>. <code>a</code>, <code>df</code>, <code>xx</code>, <code>x</code>, are all <em>names</em>, but they refer to the same or different <em>val... | 1 | 2016-08-12T18:48:00Z | [
"python",
"pandas",
"pass-by-reference",
"pass-by-value"
] |
python pandas dataframe, is it pass-by-value or pass-by-reference | 38,895,768 | <p>If I pass a dataframe to a function and modify it inside the function, is it pass-by-value or pass-by-reference?</p>
<p>I run the following code</p>
<pre><code>a = pd.DataFrame({'a':[1,2], 'b':[3,4]})
def letgo(df):
df = df.drop('b',axis=1)
letgo(a)
</code></pre>
<p>the value of <code>a</code> does not change... | 2 | 2016-08-11T11:59:13Z | 38,925,257 | <p>The short answer is, Python always does pass-by-value, but every Python variable is actually a pointer to some object, so sometimes it looks like pass-by-reference.</p>
<p>In Python every object is either mutable or non-mutable. e.g., lists, dicts, modules and Pandas data frames are mutable, and ints, strings and t... | 3 | 2016-08-12T19:30:41Z | [
"python",
"pandas",
"pass-by-reference",
"pass-by-value"
] |
Multiple Slices With Python | 38,895,781 | <p>I need to extract data from multiple positions in an array.</p>
<p>A simple array would be:-</p>
<pre><code>listing = (4, 22, 24, 34, 46, 56)
</code></pre>
<p>I am familiar with slicing. For instance:-</p>
<pre><code>listing[0:3]
</code></pre>
<p>would give me:-</p>
<pre><code>(4, 22, 24)
</code></pre>
<p>How... | 0 | 2016-08-11T11:59:56Z | 38,895,812 | <p>You can slice twice and join them.</p>
<pre><code>listing[0:3] + listing[4:5]
</code></pre>
| 3 | 2016-08-11T12:01:33Z | [
"python"
] |
Multiple Slices With Python | 38,895,781 | <p>I need to extract data from multiple positions in an array.</p>
<p>A simple array would be:-</p>
<pre><code>listing = (4, 22, 24, 34, 46, 56)
</code></pre>
<p>I am familiar with slicing. For instance:-</p>
<pre><code>listing[0:3]
</code></pre>
<p>would give me:-</p>
<pre><code>(4, 22, 24)
</code></pre>
<p>How... | 0 | 2016-08-11T11:59:56Z | 38,895,829 | <p>Try:</p>
<pre><code>>>> listing = (4, 22, 24, 34, 46, 56)
>>> listing[0:3], listing[4:5]
((4, 22, 24), (46,))
</code></pre>
| 0 | 2016-08-11T12:01:57Z | [
"python"
] |
Web scraping with lxml and requests | 38,895,790 | <p>I have a <a href="http://www.booking.com/searchresults.et.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5vcmVmaEKIAQGYAQu4AQbIAQzYAQHoAQH4AQuoAgM&sid=1bc09296ee139ec3cb0edce87d7fb20a&dcid=1&class_interval=1&dest_id=67&dest_type=country&dtdisc=0&group_adults=2&group_children=0&hlrd=0&... | 0 | 2016-08-11T12:00:11Z | 38,896,962 | <p>You need to add a user-agent:</p>
<pre><code>from lxml import html
import requests
headers= {"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36"}
page = requests.get('http://www.booking.com/searchresults.et.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5... | 0 | 2016-08-11T12:52:57Z | [
"python",
"web",
"request",
"lxml",
"screen-scraping"
] |
Web scraping with lxml and requests | 38,895,790 | <p>I have a <a href="http://www.booking.com/searchresults.et.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5vcmVmaEKIAQGYAQu4AQbIAQzYAQHoAQH4AQuoAgM&sid=1bc09296ee139ec3cb0edce87d7fb20a&dcid=1&class_interval=1&dest_id=67&dest_type=country&dtdisc=0&group_adults=2&group_children=0&hlrd=0&... | 0 | 2016-08-11T12:00:11Z | 38,897,472 | <p>You retrieving an empty list because the html is generated by JavaScript.</p>
<p>So to proceed a bit of a roadmap:</p>
<ol>
<li>Use google inspect XHR;</li>
<li>Determine the parameters & header to execute the javascript</li>
<li>Passing <a href="http://docs.python-requests.org/en/master/user/quickstart/#passi... | 0 | 2016-08-11T13:15:26Z | [
"python",
"web",
"request",
"lxml",
"screen-scraping"
] |
Running python scripts with microsoft azure machine learning | 38,895,822 | <p>I'm working on a microsoft azure machine learning web service.
I made a first version that takes a data set as an input and returns JSON that contains predictions.
I want to add some python scripts that can process the predictions to change the output of the algorithm and replace it by another JSON file.
I want al... | 1 | 2016-08-11T12:01:46Z | 38,898,871 | <p>If I understood you right, you want to do predictions on x1, x2 and x3. You also want to load x4 and x5.</p>
<p>First, you can do your predictions on x1, x2 and x3 and generate y.</p>
<p>After that you only have to add another "Execute Python Script", input x4, x5, insert your condition on them and then send eithe... | 2 | 2016-08-11T14:15:08Z | [
"python",
"json",
"web-services",
"azure",
"machine-learning"
] |
Python Pandas : How to compile all lists in a column into one unique list | 38,895,856 | <p>I have a pandas dataframe as below:</p>
<p><a href="http://i.stack.imgur.com/ZbPhn.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZbPhn.png" alt="enter image description here"></a></p>
<p>How can I combine all the lists (in the 'val' column) into a unique list (set), e.g. <code>[val1, val2, val33, val9, va... | 3 | 2016-08-11T12:03:07Z | 38,896,038 | <p>Convert that column into a DataFrame with <code>.apply(pd.Series)</code>. If you stack the columns, you can call the <code>unique</code> method on the returned Series.</p>
<pre><code>df
Out[123]:
val
0 [v1, v2]
1 [v3, v2]
2 [v4, v3, v2]
</code></pre>
<hr>
<pre><code>df['val'].apply(pd.Seri... | 2 | 2016-08-11T12:11:16Z | [
"python",
"list",
"pandas",
"merge",
"unique"
] |
Python Pandas : How to compile all lists in a column into one unique list | 38,895,856 | <p>I have a pandas dataframe as below:</p>
<p><a href="http://i.stack.imgur.com/ZbPhn.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZbPhn.png" alt="enter image description here"></a></p>
<p>How can I combine all the lists (in the 'val' column) into a unique list (set), e.g. <code>[val1, val2, val33, val9, va... | 3 | 2016-08-11T12:03:07Z | 38,896,116 | <p>Another solution with exporting <code>Series</code> to nested <code>lists</code> and then apply <code>set</code> to flatten list:</p>
<pre><code>df = pd.DataFrame({'id':['a','b', 'c'], 'val':[['val1','val2'],
['val33','val9','val6'],
... | 2 | 2016-08-11T12:14:46Z | [
"python",
"list",
"pandas",
"merge",
"unique"
] |
Python Pandas : How to compile all lists in a column into one unique list | 38,895,856 | <p>I have a pandas dataframe as below:</p>
<p><a href="http://i.stack.imgur.com/ZbPhn.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZbPhn.png" alt="enter image description here"></a></p>
<p>How can I combine all the lists (in the 'val' column) into a unique list (set), e.g. <code>[val1, val2, val33, val9, va... | 3 | 2016-08-11T12:03:07Z | 38,896,618 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.cat.html" rel="nofollow"><code>str.concat</code></a> followed by some <code>string</code> manipulations to obtain the desired <code>list</code>.</p>
<pre><code>In [60]: import re
...: from collections import OrderedDict... | 1 | 2016-08-11T12:37:12Z | [
"python",
"list",
"pandas",
"merge",
"unique"
] |
Python Pandas : How to compile all lists in a column into one unique list | 38,895,856 | <p>I have a pandas dataframe as below:</p>
<p><a href="http://i.stack.imgur.com/ZbPhn.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZbPhn.png" alt="enter image description here"></a></p>
<p>How can I combine all the lists (in the 'val' column) into a unique list (set), e.g. <code>[val1, val2, val33, val9, va... | 3 | 2016-08-11T12:03:07Z | 38,897,193 | <p>One way would be to extract those elements into an array using <code>np.hstack</code> and then using <code>np.unique</code> to give us an array of such unique elements, like so -</p>
<pre><code>np.unique(np.hstack(df.val))
</code></pre>
<p>If you want a list as output, append with <code>.tolist()</code> -</p>
<pr... | 0 | 2016-08-11T13:02:32Z | [
"python",
"list",
"pandas",
"merge",
"unique"
] |
Asyncio and rabbitmq (asynqp): how to consume from multiple queues concurrently | 38,895,872 | <p>I'm trying to consume multiple queues concurrently using python, asyncio and <a href="http://asynqp.readthedocs.io/en/v0.4/" rel="nofollow">asynqp</a>.</p>
<p>I don't understand why my <code>asyncio.sleep()</code> function call does not have any effect. The code doesn't pause there. To be fair, I actually don't und... | 0 | 2016-08-11T12:04:06Z | 38,898,514 | <p>See <a href="https://github.com/benjamin-hodgson/asynqp/issues/84" rel="nofollow">Drizzt1991's response</a> on github for a solution.</p>
| 1 | 2016-08-11T14:00:04Z | [
"python",
"python-3.x",
"rabbitmq",
"python-asyncio",
"aiohttp"
] |
Asyncio and rabbitmq (asynqp): how to consume from multiple queues concurrently | 38,895,872 | <p>I'm trying to consume multiple queues concurrently using python, asyncio and <a href="http://asynqp.readthedocs.io/en/v0.4/" rel="nofollow">asynqp</a>.</p>
<p>I don't understand why my <code>asyncio.sleep()</code> function call does not have any effect. The code doesn't pause there. To be fair, I actually don't und... | 0 | 2016-08-11T12:04:06Z | 38,899,329 | <blockquote>
<p>I don't understand why my asyncio.sleep() function call does not have
any effect.</p>
</blockquote>
<p>Because <code>asyncio.sleep()</code> returns a future object that has to be used in combination with an event loop (or <code>async/await</code> semantics).</p>
<p>You can't use <code>await</code>... | 0 | 2016-08-11T14:34:21Z | [
"python",
"python-3.x",
"rabbitmq",
"python-asyncio",
"aiohttp"
] |
The R equivalent of the Python plotly.tools.FigureFactory.create_scatterplotmatrix? | 38,896,011 | <p>I'm trying to recreate in R the scatterplotmatrix from the Python plotly tutorial:</p>
<p><a href="http://moderndata.plot.ly/using-plotly-in-jupyter-notebooks-on-microsoft-azure/" rel="nofollow">http://moderndata.plot.ly/using-plotly-in-jupyter-notebooks-on-microsoft-azure/</a></p>
<p>I have the dataframe in R, bu... | 1 | 2016-08-11T12:10:02Z | 38,938,038 | <p>The <code>ggairs()</code> function in the GGally package makes it easy to create generalized pairs plots (e.g. scatterplot matrix) via ggplot2, and <code>ggplotly()</code> knows how to translate them to plotly.</p>
<pre><code>library(GGally)
library(plotly)
ggplotly(ggpairs(iris))
</code></pre>
| 1 | 2016-08-14T00:07:00Z | [
"python",
"plotly"
] |
Read Authenticated User Object in ViewSet (Django Rest-Framework) | 38,896,056 | <p>What i want to do is to filter the queryset for every action on the resource by the authenticated user's ID which is a foreign key on the model, how can I read it when defining the query set?</p>
<pre><code>class RunSessionViewSet(viewsets.ModelViewSet):
"""API endpoint for listing and creating sprints."""
... | 0 | 2016-08-11T12:12:07Z | 38,896,292 | <p>You should override <code>get_queryset()</code> method as described in the <a href="http://www.django-rest-framework.org/api-guide/filtering/#filtering-against-the-current-user" rel="nofollow">docs</a></p>
<pre><code>def get_queryset(self):
user = self.request.user
return RunningSession.objects.filter(forei... | 1 | 2016-08-11T12:22:53Z | [
"python",
"django",
"django-rest-framework"
] |
Counting holes in a mesh | 38,896,066 | <p>I have a special kind of triangular mesh. (i.e. I haven't used a regular algorithm to triangulate the set of points I have, but I followed a special algorithm to do this for chemical data). The result is a complicated 3D shape consits of a lot of triangles and tetrahesrons.</p>
<p>Before I can proceed my task, I ne... | 1 | 2016-08-11T12:12:26Z | 39,012,836 | <p>It seems that the quantities you are trying to compute are the first and second <a href="https://en.wikipedia.org/wiki/Betti_number" rel="nofollow">Betti numbers</a> of a simplicial complex. If you do a google search, you will find some literature on various ways to compute such things. A lot of them seem to be matr... | 1 | 2016-08-18T08:02:08Z | [
"python",
"geometry",
"triangulation",
"triangular"
] |
trying to get tweets from the full day on a specific date but it wont write out to the CSV file | 38,896,121 | <p>Trying to get tweepy to get all the tweets that were published by accounts to write to a CSV file.</p>
<p>Program downloads the tweets but will not write them to the CSV file </p>
<p>how can i get the tweets to be written to the CSV file</p>
<pre><code>d1 = datetime.date(2016, 8, 4)
for tweet in alltweets:
... | 0 | 2016-08-11T12:14:52Z | 38,896,905 | <p>try the following (in this example, to get tweets with the word 'Barry'):</p>
<pre><code>from tweepy.streaming import Stream
from tweepy import OAuthHandler
from tweepy import StreamListener
ckey='yourCkey'
csecret='yourCsecret'
atoken='yourAtoken'
asecret='yourAsecret'
class listener(StreamListener):
def on... | 0 | 2016-08-11T12:50:47Z | [
"python",
"python-3.x",
"csv",
"twitter",
"tweepy"
] |
Is there a way to classify a batch of images with the pretrained Inception-v3 network? | 38,896,331 | <p>I'm trying to classify images with TensorFlow.</p>
<p>In the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/imagenet/classify_image.py#L172" rel="nofollow">example code on GitHub</a> is something like this:</p>
<pre><code>predictions = sess.run(softmax_tensor, {'DecodeJpeg/co... | 1 | 2016-08-11T12:24:20Z | 38,916,792 | <p>So after a lot of trial and error I found a solution which has the right behavior for me.
But I'm not sure if it's the most elegant one.</p>
<pre><code>pool = ThreadPool()
def operation(sess, softmax, image, image_number):
prediction = sess.run(softmax, {'DecodeJpeg:0': image})
return prediction, image_num... | 0 | 2016-08-12T11:22:43Z | [
"python",
"tensorflow",
"gpgpu",
"image-recognition"
] |
Is there a way to classify a batch of images with the pretrained Inception-v3 network? | 38,896,331 | <p>I'm trying to classify images with TensorFlow.</p>
<p>In the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/imagenet/classify_image.py#L172" rel="nofollow">example code on GitHub</a> is something like this:</p>
<pre><code>predictions = sess.run(softmax_tensor, {'DecodeJpeg/co... | 1 | 2016-08-11T12:24:20Z | 38,928,840 | <p>Take a look at Google's github for their <a href="https://github.com/tensorflow/models/tree/master/inception" rel="nofollow">Inception</a> Deep CNN Classifier.</p>
<p>By following their guide, I was able to fine-tune the network to classify wine bottle labels. You can classify many images in one run by just settin... | 1 | 2016-08-13T03:15:15Z | [
"python",
"tensorflow",
"gpgpu",
"image-recognition"
] |
AttributeError: _fields_ is final (in python) | 38,896,335 | <p>While writing a python script using ctypes, I'm getting an error :AttributeError: <em>fields</em> is final </p>
<pre><code>//demo.h
typedef struct data
{
char * status;
}
//python script
import ctypes
import sys
from ctypes import *
class data(Structure):pass
data._fields_ = [('Status',POINTER(c_char))]
</code>... | 0 | 2016-08-11T12:24:33Z | 38,896,463 | <p>You can't change the <code>_fields_</code> attribute of a <code>Structure</code> after the class has been created. The correct declaration would be:</p>
<pre><code>class data(Structure):
_fields_ = [('Status',POINTER(c_char))]
</code></pre>
| 0 | 2016-08-11T12:29:52Z | [
"python",
"ctypes"
] |
tensorflow not found in pip | 38,896,424 | <p>I'm trying to intstall tensorflow</p>
<pre><code> pip install tensorflow --user
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
</code></pre>
<p>What am I doing wrong? So far I've used Python and pip and w... | 0 | 2016-08-11T12:28:24Z | 38,900,276 | <p>TensorFlow is not yet in the <a href="https://pypi.python.org/pypi" rel="nofollow">PyPI</a> repository, so you have to specify the URL to the appropriate "wheel file" for your operating system and Python version.</p>
<p>The full list of supported configurations is listed on the <a href="https://www.tensorflow.org/v... | 2 | 2016-08-11T15:17:20Z | [
"python",
"machine-learning",
"pip",
"tensorflow"
] |
Python's smtplib module violating Gmail's terms of use | 38,896,488 | <p><strong>How can I avoid violating Gmail's terms of use when using Python's <code>smtplib</code>?</strong></p>
<p>I would like to send internal emails using Python. After 2 days of fighting with the Gmail API, I gave up. Then I found the <code>smtplib</code> module, which looked simple and promising.</p>
<p>Followi... | 0 | 2016-08-11T12:31:31Z | 38,896,782 | <p>It could be because you are indiscriminately making connections with EHLO, you should be using HELO.</p>
<p>If the server supports EHLO, the client can use EHLO instead of HELO as its first request.
On the other hand, if the server does not support EHLO, and the client sends EHLO, the server will reject EHLO. The c... | 0 | 2016-08-11T12:44:44Z | [
"python",
"email",
"gmail",
"policy",
"smtplib"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.