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
How to create a new column in pandas, containing index difference to the previous specific value?
37,477,623
<p>Having the following dataframe:</p> <pre><code>df = pd.DataFrame(np.ones(10).reshape(10,1), columns=['A']) df.ix[2]['A'] = 0 df.ix[6]['A'] = 0 A 0 1 1 1 2 0 3 1 4 1 5 1 6 0 7 1 8 1 9 1 </code></pre> <p>I am trying to add a new column <code>B</code> which would contain a number of "1"-occurrences in t...
1
2016-05-27T07:41:05Z
37,478,008
<p>You can use:</p> <pre><code>a = df.A.groupby((df.A != df.A.shift()).cumsum()).cumcount() + 1 print (a) 0 1 1 2 2 1 3 1 4 2 5 3 6 1 7 1 8 2 9 3 dtype: int64 b = ((~df.A.astype(bool)).shift(-1).fillna(df.A.iat[-1].astype(bool))) print (b) 0 False 1 True 2 False 3 False 4 ...
2
2016-05-27T08:00:24Z
[ "python", "pandas", "dataframe", "cumsum" ]
Why my regex accept also letters? ^[0-9\-\+_ ]
37,477,625
<p>Why my <code>regex</code> accept also letters? For example:</p> <ul> <li>test123 - it works (displays error message) </li> <li><p>123abc - not working (does not display error message)</p> <pre><code>test = forms.RegexField( max_length=15, regex=r'^[0-9\-\+_ ]', error_message=_(u"Only digits0-9 and +, _...
1
2016-05-27T07:41:11Z
37,477,702
<p>Your regex is only testing the start of the string - in fact it is only testing the first character of the string. If <code>[0-9\-\+_ ]</code> is all you want in the whole string then stick a <code>+$</code> at the end:</p> <pre><code>regex=r'^[0-9\-\+_ ]+$' </code></pre> <p>This says that the whole string, start ...
4
2016-05-27T07:44:35Z
[ "python", "regex", "django" ]
smooth movement in pygame
37,477,736
<p>I have just started trying to learn about pygame, and I've run into some trouble when trying to move my rectangle around the screen. I have it set so that when I press each of the arrow keys, the rectangle will move up, down, left, and right. However, when I hold down the keys, it will not keep moving. I have to ...
1
2016-05-27T07:46:14Z
37,477,859
<p>I had a similar problem, so instead of using get_pressed(), I use a dict and update it whenever a key is pressed:</p> <pre><code>pressed = {} while True: for event in pygame.event.get(): if event.type == KEYUP: pressed[event.key] = False elif event.type == KEYDOWN: press...
0
2016-05-27T07:53:12Z
[ "python", "pygame" ]
Why is my python program on linux not executing after i terminate the program?
37,477,755
<p><a href="http://i.stack.imgur.com/3PXvF.png" rel="nofollow"><img src="http://i.stack.imgur.com/3PXvF.png" alt="Terminal results when running a program"></a>I am running a python script in linux and i am encountering a problem in running a program multiple times. When i execute the program ,the program runs normally ...
-1
2016-05-27T07:47:17Z
37,477,842
<p><code>SIGSTOP</code> does not terminate the program, it pauses it, so it is not killed. you should send <code>SIGCONT</code> to the program or type <code>fg</code> to continue it.</p>
1
2016-05-27T07:52:23Z
[ "python", "linux", "terminal" ]
Why is my python program on linux not executing after i terminate the program?
37,477,755
<p><a href="http://i.stack.imgur.com/3PXvF.png" rel="nofollow"><img src="http://i.stack.imgur.com/3PXvF.png" alt="Terminal results when running a program"></a>I am running a python script in linux and i am encountering a problem in running a program multiple times. When i execute the program ,the program runs normally ...
-1
2016-05-27T07:47:17Z
37,478,333
<p>SIGTSTP OR SIGSTOP signal is suspend, can't kill this program, use SIGCONT signal you can wake and continue it</p> <pre><code>Signal Description Signal number on Linux x86[1] SIGABRT Process aborted 6 SIGALRM Signal raised by alarm 14 SIGBUS Bus error: "access to undefined portion of memory object" 7 SIGCHL...
0
2016-05-27T08:17:19Z
[ "python", "linux", "terminal" ]
Why is my python program on linux not executing after i terminate the program?
37,477,755
<p><a href="http://i.stack.imgur.com/3PXvF.png" rel="nofollow"><img src="http://i.stack.imgur.com/3PXvF.png" alt="Terminal results when running a program"></a>I am running a python script in linux and i am encountering a problem in running a program multiple times. When i execute the program ,the program runs normally ...
-1
2016-05-27T07:47:17Z
37,479,698
<p>Ok,I found the solution.</p> <p>Enter the following command on your linux terminal: </p> <pre><code>ps -ef |grep yourfile.py </code></pre> <p>You will see a number of processes that are still running in the background. To kill them enter the following command:</p> <pre><code>kill -9 pid </code></pre> <p>Don't t...
0
2016-05-27T09:22:40Z
[ "python", "linux", "terminal" ]
Why is my python program on linux not executing after i terminate the program?
37,477,755
<p><a href="http://i.stack.imgur.com/3PXvF.png" rel="nofollow"><img src="http://i.stack.imgur.com/3PXvF.png" alt="Terminal results when running a program"></a>I am running a python script in linux and i am encountering a problem in running a program multiple times. When i execute the program ,the program runs normally ...
-1
2016-05-27T07:47:17Z
37,480,826
<p>You should make sure your threads are running in Daemon mode. This could be what is preventing them from exiting cleanly when you hit <code>ctrl-c</code>. Set them up like this:</p> <pre><code>t = threading.Thread() t.daemon = True // &lt;- this is the important bit... t.start() </code></pre>
0
2016-05-27T10:15:52Z
[ "python", "linux", "terminal" ]
Why is my python program on linux not executing after i terminate the program?
37,477,755
<p><a href="http://i.stack.imgur.com/3PXvF.png" rel="nofollow"><img src="http://i.stack.imgur.com/3PXvF.png" alt="Terminal results when running a program"></a>I am running a python script in linux and i am encountering a problem in running a program multiple times. When i execute the program ,the program runs normally ...
-1
2016-05-27T07:47:17Z
37,525,793
<p>Use the following command to kill all processes and ensure no background processes running. </p> <p>Ctrl+\</p>
0
2016-05-30T12:33:27Z
[ "python", "linux", "terminal" ]
Adding code to a NLTK sentence?
37,478,195
<p>Id like to add a piece of my code in the middle of a NLTK sentence, though i dont know how to properly do it, ive tried almost everything. My current code gives me a syntax error like this:</p> <pre><code>url = raw_input("input") ^ syntax error </code></pre> <p>code:</p> <pre><code>pairs =( (r'Who are...
0
2016-05-27T08:10:38Z
37,601,996
<p>I'm afraid that the best choice is to change the way you're handling the data. Those pairs (I guess) are meant to contain possible answers, while that code would be an action, not an actual answer. So in my opinion you should keep a more consistent philosophy and adopt for example this solution: in a pair, the first...
0
2016-06-02T20:58:38Z
[ "python", "nltk" ]
How to mock a function with specific parameter and return value that calls another function in python unit test?
37,478,198
<p>i am new to python unit testing. Want to mock a function that calls other functions.</p> <p>Here is my function that i want to mock</p> <pre><code>def has_groups(self, group_names): auth_user_id = AuthUser.get_by_email(self.userEmail).id auth_user_groups = AuthUserGroups.get_group_by_user_id(auth_u...
0
2016-05-27T08:10:54Z
37,478,935
<p>As I understand your <code>has_groups</code> function is method. I think it's better to mock whole class or independent function. On this situation you could mock <code>AuthUserGroups</code>, method return value and patch module with <code>has_groups</code> method implementation. So you'll have test like this:</p> ...
0
2016-05-27T08:46:26Z
[ "python", "unit-testing", "mocking" ]
how to get dictionary elements from text file
37,478,264
<p>I need to get dictionary elements from text file using python and i build this python code:</p> <pre><code># -*- coding: utf-8 -*- user_input = raw_input('Write group name: ') data_file = open('data.txt', 'r') d = data_file.read() print d[user_input] </code></pre> <p>data.txt file:</p> <pre><code>group1 = { ...
0
2016-05-27T08:13:39Z
37,478,534
<p><code>d = data_file.read()</code> returns all the data in the file as a string. One way you can assign the variables is using the <code>imp</code> module. This handles the <code>.txt</code> file as a python module:</p> <pre><code>import imp with open('data.txt', 'r') as f: file = imp.load_source('file', '', f) ...
1
2016-05-27T08:27:16Z
[ "python", "python-2.7" ]
how to get dictionary elements from text file
37,478,264
<p>I need to get dictionary elements from text file using python and i build this python code:</p> <pre><code># -*- coding: utf-8 -*- user_input = raw_input('Write group name: ') data_file = open('data.txt', 'r') d = data_file.read() print d[user_input] </code></pre> <p>data.txt file:</p> <pre><code>group1 = { ...
0
2016-05-27T08:13:39Z
37,478,633
<p>data.txt</p> <pre><code>{ "group1": [ " jhon", "sam", "mees" ], "group2": [ "212332" ], "group3": [ "USA", "UK" ] } </code></pre> <p>code:</p> <pre><code>import json data_file = open('data.txt', 'r') d = json.loads(data_file.read().strip()) p...
-1
2016-05-27T08:32:02Z
[ "python", "python-2.7" ]
How to programatically get table structure with pyscopg2
37,478,323
<p>when I execute the program <em>application.py</em> ,I get this error :</p> <pre><code>psycopg2.ProgrammingError ProgrammingError: ERREUR: erreur de syntaxe sur ou près de « "/d" » LINE 1: "/d" carto."BADGES_SFR" </code></pre> <p>(in english "<code>ProgrammingError: ERREUR: syntax error at or near « "/d" » ...
2
2016-05-27T08:16:36Z
37,480,220
<p>First of all it's <code>\d &lt;table_name&gt;</code> (note the backslash <code>\d</code> not <code>/d</code>), but that's only available in the <a href="https://www.postgresql.org/docs/9.4/static/app-psql.html" rel="nofollow"><code>psql</code></a> interactive terminal</p> <blockquote> <p>My [objective] with this ...
1
2016-05-27T09:47:27Z
[ "python", "postgresql", "flask", "psycopg2" ]
How to programatically get table structure with pyscopg2
37,478,323
<p>when I execute the program <em>application.py</em> ,I get this error :</p> <pre><code>psycopg2.ProgrammingError ProgrammingError: ERREUR: erreur de syntaxe sur ou près de « "/d" » LINE 1: "/d" carto."BADGES_SFR" </code></pre> <p>(in english "<code>ProgrammingError: ERREUR: syntax error at or near « "/d" » ...
2
2016-05-27T08:16:36Z
37,481,722
<p>If you only need the columns <a href="http://initd.org/psycopg/docs/cursor.html" rel="nofollow">description</a>:</p> <pre class="lang-python prettyprint-override"><code>&gt;&gt;&gt; cur.execute('select * from t') &gt;&gt;&gt; description = cur.description &gt;&gt;&gt; print description (Column(name='record_timestam...
0
2016-05-27T10:58:05Z
[ "python", "postgresql", "flask", "psycopg2" ]
convert to ascii or string in Python 2.7
37,478,374
<p>I'm reading and parsing a csv file into a dictionary. However, one of the values is this <code>'\xe2\x80\x94'</code> instead of this <code>'-'</code>. How can I convert the value to its proper format? <code>type('\xe2\x80\x94')</code> says it's a string because of the quotes but in the file it's a hyphen character. ...
0
2016-05-27T08:19:12Z
37,479,022
<h1>The character is <em>em-dash</em>, not <em>hyphen</em></h1> <p>And it is working correctly.</p> <p>Only thing that is troubling you is representation of dictionaries</p> <pre><code>&gt;&gt;&gt; print '\xe2\x80\x94' — &gt;&gt;&gt; print {1: '\xe2\x80\x94'} {1: '\xe2\x80\x94'} </code></pre> <p>To print the dict...
1
2016-05-27T08:50:41Z
[ "python", "python-2.7", "csv", "encoding" ]
Matplotlib: how to add a base image to a 3D plot?
37,478,460
<p>This topic has been touched <a href="http://stackoverflow.com/questions/23785408/3d-cartopy-similar-to-matplotlib-basemap">here</a>, but no indications were given as to how to create a 3D plot and insert an image in the <code>(x,y)</code> plane, at a specified <code>z</code> height.</p> <p>So to come up with a simp...
1
2016-05-27T08:23:40Z
37,480,529
<p>Use <code>plot_surface</code> to draw image via <code>facecolors</code> argument.</p> <pre><code>from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import LinearLocator, FormatStrFormatter import matplotlib.pyplot as plt import numpy as np from matplotlib._png import read_png f...
1
2016-05-27T10:01:20Z
[ "python", "image", "matplotlib", "plot", "3d" ]
How to iterate Data in python-django
37,478,657
<p>I am having following data:</p> <pre><code> [{ 'mp': [ &lt; MpbMealPlan: MpbMealPlan object &gt; , &lt; MpbMealPlan: MpbMealPlan object &gt; ], 'user': [ &lt; User: mpowner mpowner &gt; ] }, { 'mp': [ &lt; MpbMealPlan: MpbMealPlan object &gt; , &lt; MpbMealPlan: MpbMealPlan object &gt; ], 'user': ...
0
2016-05-27T08:33:17Z
37,478,697
<p>For Python3, calling <code>.items()</code> gives you the items.</p> <pre><code>for key, item in data.items(): </code></pre> <p>For Python2 use <code>iteritems()</code>:</p> <pre><code>for k, v in knights.iteritems(): </code></pre> <p>In Django template:</p> <pre><code>&lt;div&gt; {% for k,v in test.items %} ...
1
2016-05-27T08:35:47Z
[ "python", "django", "iteration" ]
How to iterate Data in python-django
37,478,657
<p>I am having following data:</p> <pre><code> [{ 'mp': [ &lt; MpbMealPlan: MpbMealPlan object &gt; , &lt; MpbMealPlan: MpbMealPlan object &gt; ], 'user': [ &lt; User: mpowner mpowner &gt; ] }, { 'mp': [ &lt; MpbMealPlan: MpbMealPlan object &gt; , &lt; MpbMealPlan: MpbMealPlan object &gt; ], 'user': ...
0
2016-05-27T08:33:17Z
37,486,108
<p>From what I'm seeing based on your error, is that you're trying to iterate over mp which has a value with dictionaries and lists in them. Because of the different data types, you cannot just use <code>.items()</code> only. You'll need to use <code>.items()</code> to get the mp's value in key,value. then you'll ha...
1
2016-05-27T14:31:36Z
[ "python", "django", "iteration" ]
My class is callable at the begining of my code, but not while my tests loops
37,478,844
<p>I've got 2 files : main.py and batsol.py</p> <p>batsol.py contains a class and main.py is creating some instances from the class Batsol. So I'll show you a concise version of my code...</p> <pre><code>class Batsol: def __init__(self, addressCan = None, name = None) : self.addressCan = addressCan self.nam...
1
2016-05-27T08:42:17Z
37,507,832
<p>Your shadowing occurs in this code fragment:</p> <pre><code>if len(listener.ring_buffer) == 0 : for Batsol in tab_BS : try: print(tab_BS[Batsol]) except (IndexError): pass time.sleep(4) </code></pre> <p><code>for-in</code> construct on sequences works as following:</p> ...
0
2016-05-29T08:34:56Z
[ "python", "class", "callable" ]
Multilevel neural network
37,479,033
<p>I am attempting to complete the following tensorflow tutorial and (attempting problem 4): <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/3_regularization.ipynb" rel="nofollow">https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/3_regularization....
0
2016-05-27T08:51:37Z
37,479,254
<p>You should better initialize your weights:</p> <pre><code>tf.truncated_normal([hidden_layer[i], hidden_layer[i+1]], stddev=0.1) </code></pre> <p>And most of all, you should <strong>lower your learning rate</strong> to something around <code>0.01</code>, <code>0.001</code>...</p> <p>I think your get a loss of <cod...
1
2016-05-27T09:02:41Z
[ "python", "tensorflow" ]
pip installs modules for python2.7 instead of python3.4
37,479,175
<p>I have an Amazon EC2 instance. On that was just python 2.7 installed. So I installed Python3 with the command "sudo yum install python34".</p> <p>Then I tried to install modules with "pip install package". The terminal told me, that I can upgrade pip. So i upgraded pip. No my instance either find the command pip or...
1
2016-05-27T08:58:35Z
37,479,404
<ol> <li>try <code># pip install --upgrade pip</code>. this would upgrade pip8.1.1(for python2.7) to 8.1.2(for python3) or</li> <li>try this <a href="https://bootstrap.pypa.io/get-pip.py" rel="nofollow">https://bootstrap.pypa.io/get-pip.py</a>, it would install pip2 and pip3 as well as setup properly, so this is recomm...
1
2016-05-27T09:09:31Z
[ "python", "python-2.7", "python-3.x", "amazon-ec2" ]
Converting from .xls to .csv and saving the dates in the correct format
37,479,223
<p>Having a .xls with the following structure</p> <pre><code>Matching Fields Date Person 1 2015-02-10 Bob 2 2015-01-27 Billy </code></pre> <p>I'm trying to convert it to .csv and I was having problems converting the dates, because for example the <code>...
0
2016-05-27T09:01:11Z
37,479,591
<p>wr.writerow([py_date] + [unicode(val).encode('utf8') for val in sh.row_values(rownum)][1:]) else:</p> <p>Says to write the date as the first column in the row, which I don't think is what you want. Then it looks like you split the row from the 2nd column until the end and convert them to UTF8 strings. Since...
0
2016-05-27T09:17:39Z
[ "python", "excel", "csv" ]
Different results using IDLE and running the .py file by double-clicking on it
37,479,274
<p>I am using Python 2.7.3, and in my file, I also use UTF-8 coding. The source code includes the </p> <pre><code># -*- coding: utf-8 -*- </code></pre> <p>Using a dictionary, the file translates the sentences of a .txt file from english into hungarian. As hungarian has got some extra characters (ex:ű,é,á,Á,Ö,Ó)...
1
2016-05-27T09:03:45Z
37,479,846
<p>I assume that your code output result on the console. If you are on Windows, the console can't print non-ascii chars, but idle can.</p>
0
2016-05-27T09:29:33Z
[ "python" ]
python - matplotlib - segmentation fault with figsize
37,479,304
<p>I don't understand why if I uncomment line 3 of the following code</p> <pre><code>from matplotlib import pyplot pyplot.clf() #pyplot.figure(figsize=(400, 200)) pyplot.plot(range(0,len(x)),x,label="x") pyplot.legend(loc='best', fancybox=True, shadow=True) pyplot.savefig("/home/user/ooo.png", dpi=600) </code></pre> ...
1
2016-05-27T09:04:59Z
37,479,598
<p>400 inches by 200 inches is too big, so you may want to reduce the figure size.</p> <p>If you need to scale your image, I recommend to save it in a vector format (see <a href="http://stackoverflow.com/questions/9266150/matplotlib-generating-vector-plot">matplotlib: generating vector plot</a>).</p>
1
2016-05-27T09:17:58Z
[ "python", "matplotlib" ]
How to remove a contour inside contour in Python OpenCV?
37,479,338
<p>OpenCV in Python provides the following code:</p> <pre><code>regions, hierarchy = cv2.findContours(binary_image, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) for region in regions: x, y, w, h = cv2.boundingRect(region) cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 1) </code></pre> <p>This gives s...
2
2016-05-27T09:06:45Z
37,479,964
<p>For that, you should take a look at <a href="http://docs.opencv.org/3.1.0/d9/d8b/tutorial_py_contours_hierarchy.html" rel="nofollow">this tutorial</a> on how to use the <code>hierarchy</code> object returned by the method <code>findContours</code> . </p> <p>The main point is that you should use <code>cv2.RETR_TREE<...
1
2016-05-27T09:34:48Z
[ "python", "opencv", "contour" ]
SimpleIDML How to convert IDML to PDF?
37,479,362
<p>I am new to INDD CC Server. I have Implemented <a href="http://www.adobe.com/in/products/indesignserver.html" rel="nofollow">Indesign server</a> running on <strong>Windows</strong>. I need to convert <strong>IDML to PDF</strong> but having issues. </p> <p>I have used <a href="https://pypi.python.org/pypi/SimpleIDML...
2
2016-05-27T09:07:52Z
37,487,866
<p>You wrote, </p> <blockquote> <p>Manually I can see dynamically created dir tmp9LVUWj inside server dir.</p> </blockquote> <p>That is true, but that is not the error. It is stating that it cannot find a JSX file named save_as.jsx <em>within</em> that directory. Is that in fact the name of the JSX file that you ...
0
2016-05-27T16:00:28Z
[ "python", "pdf-generation", "indesign-server", "idml" ]
Expected condition: wait until one element clickable while other- dissapeared
37,479,398
<p>I face the following issue: there is a page (unfortunately it's not public) with a <code>Register request</code> and a <code>Approve request</code> button. Clicking on a button leads to opening a transparent <code>div</code> with a pop-up. </p> <p>Algorithm is as following: 1) Click <code>Register</code>; 2) Fill...
0
2016-05-27T09:09:22Z
37,486,368
<p>Understandably using a time.sleep() is something you want to avoid. Since it clicks on the modal I am assuming the button is considered clickable even though the modal isn't fully disappeared yet. In this case I would add another wait that waits till the modal is no longer visible.</p> <pre><code>wait = WebDriverWa...
3
2016-05-27T14:43:39Z
[ "python", "selenium", "selenium-webdriver", "selenium-chromedriver" ]
Caffe Python API reference?
37,479,400
<p>My main gripe about Caffe is that although there are a few examples in the documentation, there is no definitive reference guide. This applies especially to the Python interface (which would be great if there was a reference guide), and also to prototxt. It seems that in order to use Caffe properly, the user must al...
1
2016-05-27T09:09:25Z
37,506,939
<p>The protobuffer definition of caffe can be found at <a href="https://github.com/BVLC/caffe/blob/master/src/caffe/proto/caffe.proto" rel="nofollow"><code>$CAFFE_ROOT/src/caffe/proto/caffe.proto</code></a> there you can see the different parameters and their accepted value.</p> <p>To create <code>"HDF5Data"</code> la...
2
2016-05-29T06:29:24Z
[ "python", "neural-network", "deep-learning", "caffe", "pycaffe" ]
Update library versions in virtualenv Python
37,479,485
<p>I created a virtualenv on a remote Linux machine. I have the Python 2.6.7 version, and I've put in the requirements.txt file all the libraries and their versions that my application needs :</p> <pre><code> argcomplete==1.0.0 docutils==0.12 ...
0
2016-05-27T09:12:26Z
37,479,800
<p>You should create virtualenv with flag <code>--no-site-packages</code> like this:</p> <pre><code>virtualenv --no-site-packages venv </code></pre>
1
2016-05-27T09:27:15Z
[ "python", "numpy", "virtualenv" ]
Python: How to input numbers in list between two numbers based on user input?
37,479,524
<pre><code>start = int(input("Enter starting number: ")) stop = int(input("Enter number to stop viewing at: ")) numbers = [start:stop] </code></pre> <p>This gives me a syntax error. I can't even use <code>numbers.append[start:stop]</code> Any way I can use something <em>like</em> list slicing to <em>input</em> numbers...
0
2016-05-27T09:14:24Z
37,479,608
<p>if my comment is the case, you can append items in your list, based on range as follows:</p> <pre><code>start = int(input("Enter starting number: ")) stop = int(input("Enter number to stop viewing at: ")) numbers=[] for i in range(start, stop+1): numbers.append(i) print list </code></pre> <p>for <a href="http...
0
2016-05-27T09:18:42Z
[ "python", "list", "python-3.x", "input" ]
Python: How to input numbers in list between two numbers based on user input?
37,479,524
<pre><code>start = int(input("Enter starting number: ")) stop = int(input("Enter number to stop viewing at: ")) numbers = [start:stop] </code></pre> <p>This gives me a syntax error. I can't even use <code>numbers.append[start:stop]</code> Any way I can use something <em>like</em> list slicing to <em>input</em> numbers...
0
2016-05-27T09:14:24Z
37,479,651
<p>That is not the correct way to generate a list. If you want a list of numbers based on input you can use this:</p> <pre><code>start = int(input("Enter starting number: ")) stop = int(input("Enter number to stop viewing at: ")) numbers = [i for i in range(start,stop+1)] </code></pre> <p>You might want to read up on...
1
2016-05-27T09:20:19Z
[ "python", "list", "python-3.x", "input" ]
Pandas apply a change which affects 2 columns at the same time
37,479,532
<p>I have the dataframe below. bet_pl and co_pl keep track of the daily changes in the 2 balances. I have updated co_balance based on co_pl and the cumsum.</p> <pre><code>init_balance = D('100.0') co_thresh = D('1.05') * init_balance def get_pl_co(row): if row['eod_bet_balance'] &gt; co_thresh: diff = row...
1
2016-05-27T09:14:39Z
37,482,771
<p>First, you don't need to apply a custom function to get <code>co_pl</code>, it could be done like so:</p> <pre class="lang-py prettyprint-override"><code>df['co_pl'] = (df['eod_bet_balance'] - co_thresh).clip_lower(0) </code></pre> <p>As for updating the other column, if I understand correctly you want something l...
1
2016-05-27T11:49:02Z
[ "python", "pandas" ]
Merge two lists of dicts in python using pandas
37,479,756
<p>I have two lists of dicts: one which has monthly data, and another which has quarterly data as follows:</p> <pre><code>monthly = [ { "name": "Boston", "month": "2015-May", "total_monthly": 2 }, { "name": "Boston", "month": "2015-June", "total_monthly": 8 }, { "name": "Chicago", ...
0
2016-05-27T09:24:54Z
37,482,448
<p>You have to do something like this:</p> <pre><code>import pandas as pd df_monthly = pd.DataFrame(monthly) df_quarterly = pd.DataFrame(quarterly) df = pd.concat([df_monthly, df_quarterly]) # This part does not group correctly, please edit for your needs result = [] dict_monthly = dict(list(df[df.month.notnull()][...
0
2016-05-27T11:34:02Z
[ "python", "python-2.7", "dictionary", "pandas" ]
Convert a list of string into tuples
37,480,031
<p>I have this list of strings : </p> <pre><code>['(39.2947500000, -76.6565600000)', '(39.3423900000, -76.5698300000)', '(39.3199500000, -76.6222000000)', '(39.2533200000, -76.6263600000)', '(39.3068100000, -76.6549700000)', '(39.2937500000, -76.6233700000)', '(39.3146700000, -76.6425300000)', '(39.3073300000, -76.601...
1
2016-05-27T09:37:47Z
37,480,111
<pre><code>&gt;&gt;&gt; L=['(39.2947500000, -76.6565600000)', '(39.3423900000, -76.5698300000)', '(39.3199500000, -76.6222000000)', '(39.2533200000, -76.6263600000)', '(39.3068100000, -76.6549700000)', '(39.2937500000, -76.6233700000)', '(39.3146700000, -76.6425300000)', '(39.3073300000, -76.6015900000)', '(39.24519000...
6
2016-05-27T09:42:26Z
[ "python", "list", "python-2.7", "floating-point", "tuples" ]
Convert a list of string into tuples
37,480,031
<p>I have this list of strings : </p> <pre><code>['(39.2947500000, -76.6565600000)', '(39.3423900000, -76.5698300000)', '(39.3199500000, -76.6222000000)', '(39.2533200000, -76.6263600000)', '(39.3068100000, -76.6549700000)', '(39.2937500000, -76.6233700000)', '(39.3146700000, -76.6425300000)', '(39.3073300000, -76.601...
1
2016-05-27T09:37:47Z
37,480,123
<p>You could use <code>eval</code>:</p> <pre><code>a = ['(39.2947500000, -76.6565600000)', '(39.3423900000, -76.5698300000)', '(39.3199500000, -76.6222000000)', '(39.2533200000, -76.6263600000)', '(39.3068100000, -76.6549700000)', '(39.2937500000, -76.6233700000)', '(39.3146700000, -76.6425300000)', '(39.3073300000, -...
2
2016-05-27T09:42:59Z
[ "python", "list", "python-2.7", "floating-point", "tuples" ]
Convert a list of string into tuples
37,480,031
<p>I have this list of strings : </p> <pre><code>['(39.2947500000, -76.6565600000)', '(39.3423900000, -76.5698300000)', '(39.3199500000, -76.6222000000)', '(39.2533200000, -76.6263600000)', '(39.3068100000, -76.6549700000)', '(39.2937500000, -76.6233700000)', '(39.3146700000, -76.6425300000)', '(39.3073300000, -76.601...
1
2016-05-27T09:37:47Z
37,480,126
<pre><code>my_list = ['(39.2947500000, -76.6565600000)', '(39.3423900000, -76.5698300000)'] print [(float(x.split(',')[0][1:]), float(x.split(',')[1][1:-1])) for x in my_list] </code></pre> <p>This solution does not use eval (which I dislike using), it iterates over the strings, splits them on the ',', substrings them...
1
2016-05-27T09:43:24Z
[ "python", "list", "python-2.7", "floating-point", "tuples" ]
Convert a list of string into tuples
37,480,031
<p>I have this list of strings : </p> <pre><code>['(39.2947500000, -76.6565600000)', '(39.3423900000, -76.5698300000)', '(39.3199500000, -76.6222000000)', '(39.2533200000, -76.6263600000)', '(39.3068100000, -76.6549700000)', '(39.2937500000, -76.6233700000)', '(39.3146700000, -76.6425300000)', '(39.3073300000, -76.601...
1
2016-05-27T09:37:47Z
37,501,648
<p>If you wish to avoid <code>import</code>s and you feel<br> this may be the place to avoid list comprehension in favour of clarity*:</p> <pre><code>lst = ['(39.2947500000, -76.6565600000)', '(39.3423900000, -76.5698300000)', '(39.3199500000, -76.6222000000)', '(39.2533200000, -76.6263600000)', '(39.3068100000, -76.6...
0
2016-05-28T16:58:22Z
[ "python", "list", "python-2.7", "floating-point", "tuples" ]
Write a sympy matrix to a python file
37,480,194
<p>I have a script that automatically generates equations and adds them to a list.</p> <p>e.g. :</p> <pre><code>eq = [a*b, a + b*c -d, c**2 + a, d*a - 2] </code></pre> <p>with a, b, c, d all sympy symbols.</p> <p>It then converts the list to a sympy matrix and calculates the jacobian matrix</p> <pre><code>eq = sym...
1
2016-05-27T09:46:09Z
37,481,480
<h1>I can make your code little simple</h1> <p>The job can be done without 'for loop':</p> <pre><code>variable_list = [a, b, c, d] jacobian_lines = ["def jacobian(variables):", ' """ Returns the evaluated jacobian matrix', ' :param variables: a list of nume...
0
2016-05-27T10:47:26Z
[ "python", "sympy" ]
Write a sympy matrix to a python file
37,480,194
<p>I have a script that automatically generates equations and adds them to a list.</p> <p>e.g. :</p> <pre><code>eq = [a*b, a + b*c -d, c**2 + a, d*a - 2] </code></pre> <p>with a, b, c, d all sympy symbols.</p> <p>It then converts the list to a sympy matrix and calculates the jacobian matrix</p> <pre><code>eq = sym...
1
2016-05-27T09:46:09Z
37,483,704
<p>Not sure if you've came across this before but you can write arbitrary Python objects to a file using the <a href="https://docs.python.org/3.5/library/pickle.html" rel="nofollow">pickle module</a> from the standard library. This would allow you to do the following to save the jacobian:</p> <pre><code>import pickle ...
0
2016-05-27T12:32:50Z
[ "python", "sympy" ]
Mocking side_effect while autospeccing gives the function additional argument
37,480,330
<p>So the example code is very basic:</p> <pre><code>@mock.patch.object(BookForm, 'is_valid') def test_edit(self, mocked_is_valid): create_superuser() self.client.login(username="test", password="test") book = Book() book.save() mocked_is_valid.side_effect = lambda: True self.client.post(rev...
5
2016-05-27T09:52:58Z
38,088,479
<p>You are misunderstanding the documentation. Without <code>autospec</code>, the <code>side_effect</code> that is being called is literally as is without inspecting the original declaration. Let's create a better minimum example to demonstrate this issue.</p> <pre><code>class Book(object): def __init__(self): ...
0
2016-06-29T00:40:37Z
[ "python", "unit-testing", "mocking" ]
File read Python - IndexError: list index out of range
37,480,360
<pre><code>def compare(): file1=open("Rules.txt") for rules in file1: rule = rules.split(",") break membersFile=open("Members.txt") for members in membersFile: member = members.split(',') break print (rule[0] + "," +member[1] + ","+...
-3
2016-05-27T09:54:33Z
37,481,398
<p>You need to actually read the file. Some thing like this:</p> <pre><code>def compare(): with open("Rules.txt") as file1: for rules in file1.readlines(): // &lt;-note readlines() rule = rules.split(",") break with open("Members.txt") as membersFile: ...
0
2016-05-27T10:43:26Z
[ "python" ]
How to correctly import modules on engines in Jupyter Notebook for parallel processing?
37,480,402
<p>I wish to run an embarrassingly parallel function that creates plots (and eventually will save them to a file) using Jupyter Notebook with Python (edit - I found a much simpler way to do exactly this <a href="http://stackoverflow.com/questions/18871376/how-to-run-an-ipython-notebook-in-parallel-just-changing-some-pa...
0
2016-05-27T09:56:00Z
37,483,001
<h1>Short answer</h1> <p>sync_imports is unnecessary when you use module functions. This should be sufficient:</p> <pre><code># notebook: import ipyparallel as ipp client = ipp.Client() dview = client[:] import module dview.map_sync(module.pll, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) </code></pre> <p>and</p> <pre><cod...
2
2016-05-27T12:00:49Z
[ "python", "python-3.x", "ipython", "jupyter-notebook", "ipython-parallel" ]
Insult Generator Gone Wrong
37,480,466
<p>I am making an insult generator for class that uses one word from three lists within a tuple named <code>allWords</code>. For some reason, while my <code>generateInsult()</code> function generates an insult, my <code>generateInsults()</code> function generates <code>"Thou A l l!"</code></p> <p>Does anybody have any...
0
2016-05-27T09:58:59Z
37,480,583
<p>You take a random choice out of a single character.</p> <p>The character with index zero, the character with index 1 and the character with index 2.</p>
0
2016-05-27T10:03:45Z
[ "python", "python-3.x" ]
Insult Generator Gone Wrong
37,480,466
<p>I am making an insult generator for class that uses one word from three lists within a tuple named <code>allWords</code>. For some reason, while my <code>generateInsult()</code> function generates an insult, my <code>generateInsults()</code> function generates <code>"Thou A l l!"</code></p> <p>Does anybody have any...
0
2016-05-27T09:58:59Z
37,480,719
<p>I understand that you have a 3-tuple of lists called <code>allWords</code>. You should remove the quotes around the default argument, ie change the following lines:</p> <pre><code>def generateInsult(word=allWords): ... def generateInsults(word=allWords): ... insults.append(generateInsult(word)) </code>...
1
2016-05-27T10:10:15Z
[ "python", "python-3.x" ]
Retrieve value of links from Google Sheet?
37,480,644
<p>I have some values in a Google Sheet, some of which are hyperlinked, like the third one here:</p> <p><a href="http://i.stack.imgur.com/2ArrK.png" rel="nofollow"><img src="http://i.stack.imgur.com/2ArrK.png" alt="enter image description here"></a></p> <p>I want to retrieve the text value of each cell, and the hyper...
3
2016-05-27T10:06:35Z
37,483,940
<p>In <code>gspread</code>, a <code>Cell</code> instance has an undocumented attribute <code>input_value</code> that gives you access to the formula.</p> <pre><code>&gt;&gt;&gt; formula = mycell.input_value &gt;&gt;&gt; formula '=HYPERLINK("https://url.com","Link Text")' &gt;&gt;&gt; lst = formula.split('"') &gt;&gt;&...
1
2016-05-27T12:45:20Z
[ "python", "google-spreadsheet", "gspread" ]
How to create a column depending on the row index values in a multiindex pandas dataframe?
37,480,701
<p>Let's suppose that you have the following dataframe:</p> <pre><code>ridx = pd.MultiIndex.from_tuples([('Tom','apple'),('Tom','banana'),('Anna','banana'),('Anna','citrus')], names=['basket', 'fruit']) df = pd.DataFrame({'Quantity' : [1, 2, 3, 4]}, index=ridx) df </code></pre> <p><a href="http://i.stack.imgur.com/w...
1
2016-05-27T10:09:12Z
37,480,702
<p>You can retrieve an array of index values with <code>df.index.get_level_values()</code> and then use <code>np.vectorize()</code> over the get method of the dictionary in order to perform the map: </p> <pre><code>fruits = df.index.get_level_values('fruit').values fruits_sugar = np.vectorize(sugar_content.get)(fruit...
0
2016-05-27T10:09:12Z
[ "python", "numpy", "pandas" ]
How to create a column depending on the row index values in a multiindex pandas dataframe?
37,480,701
<p>Let's suppose that you have the following dataframe:</p> <pre><code>ridx = pd.MultiIndex.from_tuples([('Tom','apple'),('Tom','banana'),('Anna','banana'),('Anna','citrus')], names=['basket', 'fruit']) df = pd.DataFrame({'Quantity' : [1, 2, 3, 4]}, index=ridx) df </code></pre> <p><a href="http://i.stack.imgur.com/w...
1
2016-05-27T10:09:12Z
37,482,346
<p>bit faster way to do this:</p> <pre><code>In [58]: df['sugar_content'] = df.reset_index()['fruit'].map(sugar_content).to_frame().set_index(df.index) In [59]: df Out[59]: Quantity sugar_content basket fruit Tom apple 1 3 banana 2 10 Anna banana ...
1
2016-05-27T11:29:25Z
[ "python", "numpy", "pandas" ]
convert exponential to float in time.clock()
37,480,724
<p>Here is my code </p> <pre><code>import time t0=time.clock() t1=time.clock() time_difference = t1-t0 print time_difference </code></pre> <p>and output is </p> <pre><code>9.99999999998e-07 </code></pre> <p>i want to assign value of t1-t0 to time_difference in float format having 2 digits after decimal how can i do...
0
2016-05-27T10:10:23Z
37,480,783
<p>If you wish to print the value, you can use formatted output. This will print float values with two decimal digits after the dot: <code>print "%.2f" % time_difference</code>.</p> <p>If you wish to update <code>time_difference</code> as a float value with two digits, you can use the <code>round</code> function (see ...
1
2016-05-27T10:13:51Z
[ "python", "python-2.7" ]
how to access a particular column of a particular csv file from many imported csv files
37,480,728
<p>Suppose that i have multiple .csv files with columns of same kind . If i wanted to access data of a particular column from a specified .csv file , how is it possible?</p> <p>All .csv files have been stored in list.data for ex:</p> <p>Suppose that here , list.data[1] gives me the first .csv file. How will i access ...
0
2016-05-27T10:10:31Z
37,480,887
<p>you can use list.data[[1]]$name1</p>
0
2016-05-27T10:18:46Z
[ "python", "csv" ]
Caffe Python Layer for input, set data type to uint8
37,480,762
<p>I am trying to train a CNN in caffe. I wanted to do a lot of data augmentation, so I'm using a <code>"Python"</code> layer for input, as suggested <a href="http://stackoverflow.com/questions/34996075/caffe-data-layer-example-step-by-step">here</a>.</p> <p>However, I see from the log that Caffe is using the datatyp...
2
2016-05-27T10:13:00Z
37,507,092
<p>AFAIK, caffe is currently compiled to support only float32 or float64. I suppose <code>lmdb</code>/<code>leveldb</code> data can be stored in <code>uint8</code> format, but caffe converts it internally to <code>float32</code> upon reading.<br> The fact that your input data is <code>uint8</code> does not mean the ent...
1
2016-05-29T06:54:50Z
[ "python", "machine-learning", "computer-vision", "caffe", "pycaffe" ]
Error when using django formset
37,480,860
<p>I need to clone form as many times as i want. My goal is: user choose how many stocks he needs then redirect to page with same number of forms (probably i shoud use something like Ajax but for now its too hard for me). Found out that i should use <code>formset</code>. For now i have error <code>ManagementForm data i...
0
2016-05-27T10:17:31Z
37,481,643
<p>I think the issue is with the way you are trying to render the formset forms using crispy forms. </p> <p>Specifically you need to set <code>form_tag</code> to <code>False</code> in the helper, as currently it will be rendering a separate <code>&lt;form&gt;</code> tag for each form in the set, which will thoroughly ...
0
2016-05-27T10:55:07Z
[ "python", "django" ]
Anaconda + Spark - changing python version for ipython notebooks
37,481,150
<p>I installed Anaconda, and try to work with spark on top. When I launch spark with Ipython_OPTS="notebook", the python version is the one associated with anaconda's version of python for the notebook.</p> <pre><code>$ conda search python Using Anaconda Cloud api site https://api.anaconda.org Fetching package metada...
1
2016-05-27T10:31:15Z
39,302,962
<p>Similar to how you are setting the <code>PYSPARK_PYTHON</code> environment variable for the <code>pyspark</code> shell, you can also set this environment variable in your IPython/Jupyter notebook using:</p> <pre><code>import os os.environ["PYSPARK_PYTHON"] = "/Applications/anaconda/anaconda/envs/vingt-sept/bin/pyth...
0
2016-09-03T03:29:33Z
[ "python", "apache-spark", "anaconda" ]
Replacing cells in a dataframe column based on one or more condition
37,481,161
<p>I've a dataframe from which I need to access and replace certain cell values based on conditions: </p> <pre><code>entries_and_exits = pd.DataFrame({ 'ENTRIESn': [3144312, 3144335, 3144353, 3144424, 3144594, 3144808, 3144895, 3144905, 3144941, 3145094], 'EXITSn': [1088151, 0, 1088177, 1088231, 10882...
1
2016-05-27T10:31:39Z
37,481,203
<p>mask the df using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html" rel="nofollow"><code>isin</code></a> passing a list of the values of interest, this will return a boolean mask which you can use to only replace the values where the condition is met:</p> <pre><code>In [66]: en...
0
2016-05-27T10:33:25Z
[ "python", "pandas" ]
can anyone help me in resolving the error which I am getting while running this tensorflow program
37,481,333
<pre><code>program for applying linear regression on dataset using tensorflow # About housing_data: # dataset characterisitics:multivariate #Associate task: regression #Number of instance: 506 #number of attribut: 14 #Attribute Information: #1. CRIM: per capita crime rate by town #2. ZN: proportio...
1
2016-05-27T10:40:19Z
37,481,821
<p>Maybe instead of <code>x_batch,y_batch=features[indices],MEDV[indices]</code> you can try</p> <pre><code>x_batch,y_batch = [], [] for index in indices: x_batch.append(features[index]) y_batch.append(MEDV[index]) </code></pre>
0
2016-05-27T11:03:10Z
[ "python", "tensorflow" ]
can anyone help me in resolving the error which I am getting while running this tensorflow program
37,481,333
<pre><code>program for applying linear regression on dataset using tensorflow # About housing_data: # dataset characterisitics:multivariate #Associate task: regression #Number of instance: 506 #number of attribut: 14 #Attribute Information: #1. CRIM: per capita crime rate by town #2. ZN: proportio...
1
2016-05-27T10:40:19Z
37,483,659
<p>this code is working but I want to know if we want to test some new data then how we will test or how to split the data into training set and test set</p> <pre><code>import tensorflow as tf import numpy as np import matplotlib.pyplot as plt batch_size=50 filename_queue = tf.train.string_input_producer( tf.tra...
0
2016-05-27T12:30:49Z
[ "python", "tensorflow" ]
Getting TypeError: 'list' object is not callable when setting index in Pandas Dataframe
37,481,563
<p>I have simple Pandas Dataframe:</p> <pre><code>data.head(5) &gt; Date Time Open High Low Close Vol OI &gt; 0 02/02/1993 16:00 44.23 44.38 44.13 44.34 201300 0 &gt; 1 02/03/1993 16:00 44.41 44.84 44.38 44.82 529400 0 &gt; 2 02/04/1993 16:00 44.97 45.10 44.88 45.00 531...
0
2016-05-27T10:51:14Z
37,481,575
<p>I think you have to add parameter <code>inplace=True</code> to <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a>:</p> <pre><code>data.set_index('Date', inplace=True) </code></pre> <p>Another solution is:</p> <pre><code>data = ...
0
2016-05-27T10:51:58Z
[ "python", "pandas", "indexing", "set" ]
What does ${python3:Depends} mean in a debian source-package control file?
37,481,583
<p>I'm trying to build a .deb from a python package. In order to do so I have to configure a <code>control</code> file. The control file contains a line where you can define dependencies for your package, e.g:</p> <pre><code>Depends: python-appindicator, python3-yaml (&gt;=3.11), ${misc:Depends}, ${python3:Depends} </...
3
2016-05-27T10:52:31Z
37,483,511
<p>This means that during build process variable <code>${python3:Depends}</code> will be replaced with guessed py3 dependencies for that package. <code>dh_python3</code> will help to do that. It's trying to guess what are the dependencies of package which contains such entry by looking for <code>requires.txt</code> fil...
3
2016-05-27T12:23:45Z
[ "python", "debian", "packaging", "deb" ]
Python: DES-ECB encryption with two different keys result in the same ciphertext
37,481,692
<p>I'am trying to encrypt the plaintext <code>6d65737361676531</code> (which is in hexadecimal) with the keys <code>0000000000000000</code> and <code>0000000000000001</code> (both in hexadecimal) using the DES cipher in ECB mode from Crypto.Cipher. But for some reason both <code>ciphertext1_hex</code> and <code>ciphert...
0
2016-05-27T10:57:00Z
37,484,019
<p>In a DES key it's only the first 7 bits of each byte that are actual key material (giving a DES key of 56 bit) .. the last bit of each byte is a parity bit. So the two keys are actually the same key. Some implementations would complain if the parity bit ain't correct. But this one apparently don't.</p>
2
2016-05-27T12:49:27Z
[ "python", "encryption", "des" ]
Convertig an int item from list for mysql command[python , mysql ]
37,481,752
<p>I am writing a script for an MySql-Server and i need an int-variable from a list of integers for an mysql command.</p> <p>The list ID looks like that <code>(2028,) (1029,) (4000,)</code></p> <p>If i use for example <code>ID[1]</code> and put this into the command i get an error , because the Server needs a pure in...
-1
2016-05-27T10:59:49Z
37,481,826
<p>Try print (ID[1][0]). List is of tuples which contains int.</p>
0
2016-05-27T11:03:25Z
[ "python", "mysql", "apache", "list" ]
Convertig an int item from list for mysql command[python , mysql ]
37,481,752
<p>I am writing a script for an MySql-Server and i need an int-variable from a list of integers for an mysql command.</p> <p>The list ID looks like that <code>(2028,) (1029,) (4000,)</code></p> <p>If i use for example <code>ID[1]</code> and put this into the command i get an error , because the Server needs a pure in...
-1
2016-05-27T10:59:49Z
37,481,899
<p>You can convert your list of tuples into list of integers.</p> <p>For example if you have</p> <pre><code>data = [(2028,), (1029,), (4000,)] </code></pre> <p>you can do</p> <pre><code>&gt;&gt;&gt; print [entry[0] for entry in data] [2028, 1029, 4000] </code></pre>
0
2016-05-27T11:06:36Z
[ "python", "mysql", "apache", "list" ]
Convert Kivy python app to and apk for Android
37,481,778
<p>I'm working in an app that provides you an icalendar file with a schedule of some subjects. I have done the app through kivy in python and it works in Python, but when I tried to pass to an apk with Buildozer module I realized that it didn't work properly. The fact is that when the file with the calendar is created ...
0
2016-05-27T11:00:42Z
37,913,172
<p>If we go step by step,your first problem is to locate the apk file.That gets created inside bin directory of the app folder if you run this command</p> <pre><code>buildozer android debug </code></pre> <p>you can then copy the apk file in your android phone and manually install it by setting the option to install 3...
0
2016-06-20T00:17:51Z
[ "android", "python", "file", "save", "buildozer" ]
Python requests module, need to encode the body, why?
37,481,882
<p>I was struggling with sending a request to a web service using the requests module. I'm using Python 3.5.1-32 bit on Windows.</p> <p>Whenever I request something that contains, for example, a latin accented character such as "á" then I need to encode my string variable explicitly as utf-8. Can someone explain why ...
1
2016-05-27T11:05:47Z
37,482,657
<p><strong>requests</strong> doc says:</p> <pre><code>:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. </code></pre> <p>In <strong>Python 3</strong> <code>body='á'</code> is a unicode string. With the method <code>encode()</code> you are converting it to byt...
1
2016-05-27T11:43:28Z
[ "python", "python-3.x", "request" ]
plot different subplots with windroses using windrose module in python. Use sleep with matplotlib
37,482,079
<p>I am trying to plot wind roses in subplots by using the module windrose in python</p> <p><a href="https://pypi.python.org/pypi/windrose/" rel="nofollow">https://pypi.python.org/pypi/windrose/</a></p> <p>Apart from some examples there is not too much documentation so I do not know how to use it to plot different su...
1
2016-05-27T11:15:15Z
37,493,099
<p>First question: You can not put another <code>figure</code> to existing <code>figure</code> as <code>subplot</code> (unfortunately <code>WindroseAxes.from_ax()</code> create a new <code>figure</code> and does not change only <code>axis</code> instance).</p> <p>If you write </p> <pre><code>fig = plt.figure(figsize=...
1
2016-05-27T22:23:48Z
[ "python", "matplotlib", "sleep" ]
Unable to install python library from github
37,482,104
<p>My OS is OSX 10.10.5 and I use Anaconda distribution for python. I am trying to install the following library from github: <a href="https://github.com/gmum/pykernels" rel="nofollow">https://github.com/gmum/pykernels</a></p> <p>When I try to use pip install:</p> <pre><code>pip install git+https://github.com/gmum/p...
1
2016-05-27T11:16:02Z
37,482,211
<p>The problem is, that library doesn't have a <code>setup.py</code> file. pip executes/follows this file. so that library cannot be installed using pip. You can, however, download and put that library (the pykernels folder inside the repo) in your current folder or add it's path to <code>sys.path</code> like this:</p>...
3
2016-05-27T11:22:55Z
[ "python", "osx", "pip" ]
Unable to install python library from github
37,482,104
<p>My OS is OSX 10.10.5 and I use Anaconda distribution for python. I am trying to install the following library from github: <a href="https://github.com/gmum/pykernels" rel="nofollow">https://github.com/gmum/pykernels</a></p> <p>When I try to use pip install:</p> <pre><code>pip install git+https://github.com/gmum/p...
1
2016-05-27T11:16:02Z
37,482,230
<p>Seems that <a href="https://github.com/gmum/pykernels.git" rel="nofollow">https://github.com/gmum/pykernels.git</a> does not contain valid installable python package. There is no <code>setup.py</code> file in repo root directory but <code>setup.py</code> is required to installation.</p>
1
2016-05-27T11:23:46Z
[ "python", "osx", "pip" ]
Unable to install python library from github
37,482,104
<p>My OS is OSX 10.10.5 and I use Anaconda distribution for python. I am trying to install the following library from github: <a href="https://github.com/gmum/pykernels" rel="nofollow">https://github.com/gmum/pykernels</a></p> <p>When I try to use pip install:</p> <pre><code>pip install git+https://github.com/gmum/p...
1
2016-05-27T11:16:02Z
37,482,273
<p>The repository is missing a setup.py file. Without this <em>pip</em> does not know how to install the module/package.</p> <p>It looks like it's just a plain package without any setup scripts. You'll need to clone it and use it by copy/pasting it into your project or write your own setup.py file.</p> <p>Here's the ...
1
2016-05-27T11:25:59Z
[ "python", "osx", "pip" ]
external application started by os.system() and subprocess.Popen() runs slower on Linux
37,482,229
<p>I've wrote a python script to start other application by using os.system(app_path) or subprocess.Popen(app_path, shell=False), but the application run slower than start the application directly from the shell (its a application with GUI so I can feel it obviously). is it the right way to start other application this...
0
2016-05-27T11:23:45Z
37,482,364
<p>you can use <code>os.spawnl</code>, like this:</p> <pre><code>os.spawnl(os.P_NOWAIT, "path to script") </code></pre>
0
2016-05-27T11:30:18Z
[ "python", "linux", "process" ]
Checking whether a bunch of intervals are overlapping
37,482,304
<p>I don't know what to search for... What is a nice way to check whether a bunch of intervals are not overlapping?</p> <p>Everything is fine:</p> <pre><code>a, b = 0.2, 0.3 c, d = 0.4, 0.6 e, f = 0.9, 1.0 </code></pre> <p>Not good:</p> <pre><code>a, b = 0.2, 0.3 c, d = 0.25, 0.5 </code></pre> <p>Evil²:</p> <pre...
0
2016-05-27T11:27:13Z
37,482,336
<p>Sort the intervals by start value (if they're just 2-tuples this is automatic) and iterate through the list, ensuring that the end value of one is always less than (or equal to, depending on your problem) the start value of the next.</p> <pre><code>intervals = [(0.2, 0.3), (0.8, 1.0), (0.4...
1
2016-05-27T11:29:00Z
[ "python", "python-2.7", "ironpython" ]
Comparing List and get indices in python
37,482,313
<p>I have a dataframe <code>A['name', 'frequency']</code> and a list B of 'name' Both are quite long. B is smaller one which I get on daily basis. I have to check whether element of B which is 'name' is there in DataFrame. <code>A['name']</code> if it is there i have to update the frequency of that 'name' in the datafr...
4
2016-05-27T11:27:55Z
37,484,115
<p>This is the initial dataframe:</p> <pre><code>mac_list mac_address frequency 0 20c9d0892feb 2 1 28e34789c4c2 1 2 3480b3d51d5f 1 3 4480ebb4e28c 1 4 4c60de5dad72 1 5 4ca56dab4550 1 </code></pre> <p>And the new list:</p> <pre><code>new_mac_list = ['20...
2
2016-05-27T12:54:56Z
[ "python", "python-2.7", "pandas", "anaconda" ]
Comparing List and get indices in python
37,482,313
<p>I have a dataframe <code>A['name', 'frequency']</code> and a list B of 'name' Both are quite long. B is smaller one which I get on daily basis. I have to check whether element of B which is 'name' is there in DataFrame. <code>A['name']</code> if it is there i have to update the frequency of that 'name' in the datafr...
4
2016-05-27T11:27:55Z
37,484,287
<h1>Create index</h1> <p>If you talk efficiency, the index is the first thing that should come to mind. I assume mac addresses are unique.</p> <pre><code>A = A.set_index("mac_address") </code></pre> <p>and access the items</p> <pre><code>A.loc[i] </code></pre> <p>the iteration over B is of minor relevance</p>
0
2016-05-27T13:04:43Z
[ "python", "python-2.7", "pandas", "anaconda" ]
python xarray concat groupby in datetime64 dimensions
37,482,398
<p>I have a xarray dataset that is:</p> <pre><code>ds &lt;xarray.Dataset&gt; Dimensions: (lat: 360, lon: 720, time: 3652) Coordinates: * lon (lon) float32 -179.75 -179.25 -178.75 -178.25 -177.75 -177.25 ... * lat (lat) float32 89.75 89.25 88.75 88.25 87.75 87.25 86.75 86.25 ... * time (time)...
0
2016-05-27T11:32:08Z
37,489,499
<p>To avoid aggregating over all dimensions in each sub-arrays, you need to supply the list of dimensions explicitly:</p> <pre><code>ds.dis.groupby('time.month').mean('time') </code></pre> <p>(At one point we contemplated making this the default behavior for groupby operations, since it is usually what is desired, bu...
1
2016-05-27T17:45:43Z
[ "python", "datetime64", "python-xarray" ]
UnboundLocalError at /blog/search/ local variable 'cd' referenced before assignment
37,482,461
<p>I am trying to set up django-haystack with solr,,,but I just keep get the error:</p> <blockquote> <p>UnboundLocalError at /blog/search/ local variable 'cd' referenced before assignment</p> </blockquote> <p>I think might be my </p> <blockquote> <p>views.py</p> </blockquote> <p>something wrong,,,. my app nam...
0
2016-05-27T11:34:25Z
37,510,804
<p>In your <code>post_search</code> view you're defining <code>cd</code> only if the <code>form.is_valid()</code>.</p> <p>When the GET request doesn't contains the <code>query</code> variable, you don't have the <code>cd</code> variable, that's why the error is happening. </p> <p>Try to indent the <code>return render...
1
2016-05-29T14:02:06Z
[ "python", "solr", "django-views", "django-haystack", "django-settings" ]
UnboundLocalError at /blog/search/ local variable 'cd' referenced before assignment
37,482,461
<p>I am trying to set up django-haystack with solr,,,but I just keep get the error:</p> <blockquote> <p>UnboundLocalError at /blog/search/ local variable 'cd' referenced before assignment</p> </blockquote> <p>I think might be my </p> <blockquote> <p>views.py</p> </blockquote> <p>something wrong,,,. my app nam...
0
2016-05-27T11:34:25Z
37,516,929
<p>first, thanks for Andre answer to me,,,here is my new </p> <blockquote> <p>views.py</p> </blockquote> <pre><code>....... def post_search(request): form = SearchForm() if 'query' in request.GET: form = SearchForm(request.GET) if form.is_valid(): cd = form.cleaned_data ...
0
2016-05-30T02:41:16Z
[ "python", "solr", "django-views", "django-haystack", "django-settings" ]
passing arguments to python script from command line
37,482,540
<p>I am really new to python and pandas, I am trying to execute a python script using arguments in the command line but I got an error, here is my script</p> <pre><code> #!/usr/bin/python import sys, pandas as pd df1 = pd.read_table(sys.argv[0], sep="\t", header=0) df2 = pd.read_table(sys.argv[1], sep="\t", header...
2
2016-05-27T11:37:45Z
37,482,611
<p>increase all your indexes by 1, because <code>sys.argv[0]</code> - is a name of the python script.</p> <p>I.e.</p> <pre><code>df1 = pd.read_table(sys.argv[1], sep="\t", header=0) df2 = pd.read_table(sys.argv[2], sep="\t", header=0) </code></pre> <p>and so on</p>
0
2016-05-27T11:40:53Z
[ "python", "pandas" ]
passing arguments to python script from command line
37,482,540
<p>I am really new to python and pandas, I am trying to execute a python script using arguments in the command line but I got an error, here is my script</p> <pre><code> #!/usr/bin/python import sys, pandas as pd df1 = pd.read_table(sys.argv[0], sep="\t", header=0) df2 = pd.read_table(sys.argv[1], sep="\t", header...
2
2016-05-27T11:37:45Z
37,482,613
<p><code>sys.argv[0]</code> is the name of the script, i.e. <code>merge_files.py</code>. You can see this by inserting <code>print(sys.argv)</code> at the beginning of your script. Try increasing all your indices by 1.</p>
3
2016-05-27T11:40:55Z
[ "python", "pandas" ]
passing arguments to python script from command line
37,482,540
<p>I am really new to python and pandas, I am trying to execute a python script using arguments in the command line but I got an error, here is my script</p> <pre><code> #!/usr/bin/python import sys, pandas as pd df1 = pd.read_table(sys.argv[0], sep="\t", header=0) df2 = pd.read_table(sys.argv[1], sep="\t", header...
2
2016-05-27T11:37:45Z
37,482,640
<p>The first argument <code>sys.argv[0]</code> is the name of the script. </p> <blockquote> <p><strong>sys.argv</strong>: The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not).</p> </blockquote> <p>Ple...
1
2016-05-27T11:42:25Z
[ "python", "pandas" ]
TypeError: unsupported operand type(s) for -: 'float' and 'builtin_function_or_method'
37,482,719
<p>I am writing TRW algorithm in POX controller using python where i am assigning a time period to a host first time a sender is sending actually TRW algorithm says that first packet sent from internal host to external host will sent to destination without installing any flow rule hence i have wrtn a function to do tha...
0
2016-05-27T11:46:06Z
37,482,970
<p>What python is telling you is that you are trying to use the <code>-</code> operator on a <code>float</code> (your <code>time.clock()</code>) and on an uncalled <code>function</code> (<code>localhostrecord[address].FCC_Queue[index].whenInitiated</code>)</p> <p>Make sure to call your function to use it's return valu...
0
2016-05-27T11:59:21Z
[ "python", "python-2.7", "pox" ]
Selecting top n elements from each group in pandas groupby
37,482,733
<p>I have a dataframe which looks roughly like this:</p> <pre><code>&gt;&gt;&gt; data price currency id 2 1050 EU 5 1400 EU 4 1750 EU 8 4000 EU 7 630 GBP 1 1000 GBP 9 1400 GBP 3 2000 USD 6 7000 USD </code></pre> <p>I...
3
2016-05-27T11:46:57Z
37,483,528
<p>Here is a solution:</p> <pre><code>select_number = select_number['number_to_select'] # easier to select from series df.groupby('currency').apply( lambda dfg: dfg.nlargest(select_number[dfg.name], columns='price') ) </code></pre> <p><strong>Edit</strong> - I got my answer from <a href="http://stackoverflow.co...
2
2016-05-27T12:24:37Z
[ "python", "pandas", "dataframe" ]
Selecting top n elements from each group in pandas groupby
37,482,733
<p>I have a dataframe which looks roughly like this:</p> <pre><code>&gt;&gt;&gt; data price currency id 2 1050 EU 5 1400 EU 4 1750 EU 8 4000 EU 7 630 GBP 1 1000 GBP 9 1400 GBP 3 2000 USD 6 7000 USD </code></pre> <p>I...
3
2016-05-27T11:46:57Z
37,483,548
<p>you can do it this way:</p> <pre><code>df['rn'] = (df.sort_values(['price'], ascending=False) .groupby('currency').cumcount() + 1 ) qry = (select_number .reset_index() .astype(str) .apply(lambda x: '((currency=="{0[0]}") &amp; (rn&lt;={0[1]}))'.format(x), axis=1) .str.cat(...
1
2016-05-27T12:25:28Z
[ "python", "pandas", "dataframe" ]
Selecting top n elements from each group in pandas groupby
37,482,733
<p>I have a dataframe which looks roughly like this:</p> <pre><code>&gt;&gt;&gt; data price currency id 2 1050 EU 5 1400 EU 4 1750 EU 8 4000 EU 7 630 GBP 1 1000 GBP 9 1400 GBP 3 2000 USD 6 7000 USD </code></pre> <p>I...
3
2016-05-27T11:46:57Z
37,484,610
<p>You can use:</p> <pre><code>data = pd.DataFrame({'id': {0: 2, 1: 5, 2: 4, 3: 8, 4: 7, 5: 1, 6: 9, 7: 3, 8: 6}, 'price': {0: 1050, 1: 1400, 2: 1750, 3: 4000, 4: 630, 5: 1000, 6: 1400, 7: 2000, 8: 7000}, 'currency': {0: 'EU', 1: 'EU', 2: 'EU', 3: 'EU', 4: 'GBP', 5: 'GBP', 6: 'GBP', 7: 'USD', 8: 'USD'}}) select_number...
3
2016-05-27T13:21:06Z
[ "python", "pandas", "dataframe" ]
'instanceIndex=(0,)' caused exception SmiError as "ValueRangeConstraint(1, 2147483647) failed at: "0"" at Integer32
37,482,742
<p>I am new for python and SNMP (as well as pysnmp). After two weeks study, I wrote a piece of python code which try to send a trap message. The NotificationType was created by code:</p> <pre><code> notification = NotificationType(ObjectIdentity('MY_MIB_FILE','myAlarmCleared'), i...
0
2016-05-27T11:47:20Z
37,491,973
<p>One update for this: Even the exception shows the problem is caused by 'myAlarmTime'</p> <pre><code>pysnmp.smi.error.SmiError: Instance index (0,) to OID convertion failure at object 'myAlarmTime': ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(), ValueRangeConstraint(-2147483648, 214748364...
0
2016-05-27T20:44:40Z
[ "python", "snmp", "pysnmp" ]
Python schedule script running in IDLE but not in Visual Studio Code
37,482,756
<p>The following test code runs perfectly in Python IDLE but in Visual Studio Code I get an error message that says:</p> <p>"AttributeError: 'module' object has no attribute 'every' ..." </p> <pre><code>import schedule import time def job(t): print "I'm working..." , t return schedule.every().day...
0
2016-05-27T11:48:12Z
37,482,880
<p>Can you do:</p> <pre><code>from schedule import * import schedule </code></pre> <p>Print:</p> <pre><code>print schedule.__file__ </code></pre> <p><strong>Also Be sure</strong> your file name, is not named: "schedule.py"</p>
0
2016-05-27T11:54:29Z
[ "python", "scheduling", "vscode" ]
How to split a string in words that is tab separted in Python
37,482,778
<p>I have a list of lines where words in each line are separated by tab characters as follows:</p> <pre><code> ajay vijay 0.6 vijay ajay 0.7 ravi vijay 0.8 swati swapnesh 0.4 </code></pre> <p>Then how I can extract words from each of the line in Python. </p>
-2
2016-05-27T11:49:23Z
37,482,835
<p><code>your_string.split("\t")</code> should return you a list of words.</p>
0
2016-05-27T11:52:29Z
[ "python" ]
How to split a string in words that is tab separted in Python
37,482,778
<p>I have a list of lines where words in each line are separated by tab characters as follows:</p> <pre><code> ajay vijay 0.6 vijay ajay 0.7 ravi vijay 0.8 swati swapnesh 0.4 </code></pre> <p>Then how I can extract words from each of the line in Python. </p>
-2
2016-05-27T11:49:23Z
37,482,871
<p>Learn <code>split</code> function : <a href="http://www.tutorialspoint.com/python/string_split.htm" rel="nofollow">http://www.tutorialspoint.com/python/string_split.htm</a></p> <p>So if your string is "A B C",</p> <pre><code>str = "A B c" li = list(str.split("\t")) </code></pre> <p><code>\t</code> i...
2
2016-05-27T11:54:05Z
[ "python" ]
Error saying a variable is not defined?
37,482,800
<pre><code>#Intro import time import random def restart(): bowlSize = random.randint(1,100) bowlStrawberries = 0 def lel(): while bowlSize &gt; bowlStrawberries: if (addCheck + bowlStrawberries) &gt; bowlSize: print('You´re filling the bowl..') time.sleep(2) pr...
0
2016-05-27T11:50:51Z
37,482,859
<p><code>addCheck</code> is a local variable in <code>addStrawberries</code>, meaning it can't be seen outside of the function. I recommend passing it as an argument to <code>lel</code>, i.e. call <code>lel(addCheck)</code> and define <code>lel</code> as <code>def lel(addCheck)</code>. Alternatively you could make <cod...
0
2016-05-27T11:53:30Z
[ "python", "call" ]
how to create a sha1 hash in python
37,482,854
<p>My objective is to perform "Hashsigning" using smart card in python. there are hashlib's used but there is no specific SHA1 or SHA256 functions in python. My Work:</p> <pre><code>hash_object = hashlib.sha1(b'HelWorld') pbHash = hash_object.hexdigest() </code></pre> <p>but the length of the hash object I get is 2...
0
2016-05-27T11:53:17Z
37,483,576
<p>You're actually getting 40, which in hex is <code>0x28</code>. Decode the hash in hexadecimal to ASCII as follows </p> <pre><code>&gt;&gt;&gt; import hashlib &gt;&gt;&gt; hash_object = hashlib.sha1(b'HelWorld') &gt;&gt;&gt; pbHash = hash_object.hexdigest() &gt;&gt;&gt; length = len(pbHash.decode("hex")) &gt;&gt;&g...
1
2016-05-27T12:26:45Z
[ "python", "smartcard", "apdu", "pyscard" ]
I don't know what the output code is. The compiler says there is an invalid character in identifier of line 3
37,482,960
<pre><code>b = 0 for a in range(0, 10, 2): b += a − 1 print(a," ",b) </code></pre> <p>I am practicing on a past paper. Please help. And can someone please explain the break and continue functions.</p>
0
2016-05-27T11:58:56Z
37,483,114
<p>Character <code>−</code> is not a correct python identifier for minus operator, you need <code>-</code> instead:</p> <pre><code>&gt;&gt;&gt; 3 − 1 File "&lt;stdin&gt;", line 1 3 − 1 ^ SyntaxError: invalid character in identifier &gt;&gt;&gt; &gt;&gt;&gt; 3 - 1 2 </code></pre> <p>It's actually a ...
1
2016-05-27T12:05:13Z
[ "python", "python-3.x" ]
What is a "good" palette for divergent colors in R? (or: can viridis and magma be combined together?)
37,482,977
<p>I am interested in having a "good" divergent color pallette. One could obviously use just red, white, and blue:</p> <pre><code>img &lt;- function(obj, nam) { image(1:length(obj), 1, as.matrix(1:length(obj)), col=obj, main = nam, ylab = "", xaxt = "n", yaxt = "n", bty = "n") } rwb &lt;- colorRampPalette(...
6
2016-05-27T11:59:38Z
37,483,747
<p>Library <code>RColorBrewer</code> provides beautiful palettes for =&lt;13 colors. For example, palette <code>BrBG</code> shows diverging colors from brown to green.</p> <pre><code>library(RColorBrewer) display.brewer.pal(11, "BrBG") </code></pre> <p><a href="http://i.stack.imgur.com/8U77f.png" rel="nofollow"><img ...
3
2016-05-27T12:35:10Z
[ "python", "matplotlib", "color-scheme", "viridis" ]
Overflow: length too large
37,482,981
<p>I'm receiving the error: <code>OverflowError: length too large</code></p> <p>I'm trying to read a 24GB csv on this vm that has 30GB memory: <code>Linux indexer 3.19.0-59-generic #66~14.04.1-Ubuntu SMP Fri May 13 17:27:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux</code></p> <p>What are my possible solutions? I'm not ...
-1
2016-05-27T11:59:43Z
37,483,079
<p>Remove <code>.read().splitlines()</code> because that will read the entire file into memory in one go and that's too much. The file object <code>media</code> is already an iterator of lines as is so <code>csv.reader</code> will handle that correctly. Then iterate over the reader and do whatever you need row by row.<...
3
2016-05-27T12:03:48Z
[ "python", "python-2.7", "ubuntu" ]
ReviewBoard pip installation failure
37,483,060
<p>I am trying to install ReviewBoard on 14.04.1-Ubuntu and I get the error below. I have used commands:</p> <pre><code>sudo apt-get install python-setuptools python-dev memcached patch libjpeg-dev sudo pip install -U pip sudo easy_install pip sudo apt-get install python-mysqldb sudo pip install ReviewBoard File "/us...
0
2016-05-27T12:03:09Z
37,484,756
<p>Installed pillow using (<a href="https://discuss.erpnext.com/t/new-python-dependency-pillow-if-you-get-error-during-update-see-this-post/7900" rel="nofollow">https://discuss.erpnext.com/t/new-python-dependency-pillow-if-you-get-error-during-update-see-this-post/7900</a>):</p> <pre><code>sudo apt-get install -y libt...
0
2016-05-27T13:28:12Z
[ "python", "installation", "pip", "apt-get", "review-board" ]
ReviewBoard pip installation failure
37,483,060
<p>I am trying to install ReviewBoard on 14.04.1-Ubuntu and I get the error below. I have used commands:</p> <pre><code>sudo apt-get install python-setuptools python-dev memcached patch libjpeg-dev sudo pip install -U pip sudo easy_install pip sudo apt-get install python-mysqldb sudo pip install ReviewBoard File "/us...
0
2016-05-27T12:03:09Z
37,484,766
<p>Have you tried to install <code>libffi-devel</code></p> <pre><code>apt-get install libffi-dev </code></pre> <p>Sometime to fix pip issues its useful to install <code>build-essential</code> and <code>python-dev</code></p> <pre><code>apt-get install python-dev &amp;&amp; apt-get install build-essential </code></pre...
1
2016-05-27T13:28:40Z
[ "python", "installation", "pip", "apt-get", "review-board" ]
ImportError: C extension: DLL load failed: %1 win32
37,483,238
<p>I try to install <code>numpy+mkl</code> and <code>scipy</code> and after that I got an error</p> <pre><code>ImportError: C extension: DLL load failed: %1 Win32. not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions firs...
0
2016-05-27T12:10:55Z
37,510,984
<p>I would recommend you to use <a href="https://winpython.github.io/" rel="nofollow">WinPython</a> if you are running in Windows. It is a free open-source portable distribution of the Python programming language for Windows 7/8/10. The thing is that after you install (actually is just extract), you would have all of t...
0
2016-05-29T14:20:33Z
[ "python", "pandas" ]
Pydrive: export doc as html
37,483,268
<p>I'm trying to export a .doc file as html from Google Drive into. Here is my code. I don't see anything in the documentation on how to download a doc as html. But here is my code so far from the examples. I'm not sure what the <code>docsfile</code> is referring to.</p> <pre><code>from pydrive.auth import GoogleAuth ...
1
2016-05-27T12:11:56Z
37,525,423
<p>First of all <code>docsfile</code> is the file you are intending to export, in your case the <code>.doc</code> file that already are in Google Drive.</p> <pre><code>docsfile = drive.CreateFile({'id': &lt;ID of your file&gt;) </code></pre> <p>You can see more about how to download files <a href="http://pythonhosted...
2
2016-05-30T12:15:05Z
[ "python", "pydrive" ]
Custom flask application running fine on localhost but returning 500 response to external visitors
37,483,354
<p><strong><em>Latest update</strong>: The problem had indeed to do with permission and user groups, today I learned why we do not simply use root for everything. Thanks to <a href="http://stackoverflow.com/users/397331/jakub-p">Jakub P.</a> for reminding me to look into the apache error logs and thanks to <a href="htt...
3
2016-05-27T12:16:26Z
37,483,937
<p>Seems like the following line could be a problem:</p> <pre><code>log_file = open(LOG + '//captains_log.txt', 'a') </code></pre> <p>if the path its looking for is: <code>'/var/www/flaskapp/flaskapp/log//captains_log.txt'</code></p> <p>that would make sense that an exception is thrown there. Possible that the f...
1
2016-05-27T12:45:18Z
[ "python", "apache", "flask", "digital-ocean", "http-status-code-500" ]
Sorting matrix without flattening, numpy
37,483,463
<p>This was an exercise in scipy lectures(3.2.5)</p> <p>Q: Combine ravel , sort and reshape .</p> <p>A: <code>np.reshape(np.sort(np.ravel(a)), a.shape)</code></p> <p>Q: Look at the axis keyword for sort and rewrite the previous exercise.</p> <p>A: ?</p>
1
2016-05-27T12:21:07Z
37,483,829
<p>from <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.sort.html" rel="nofollow"><code>np.sort</code></a> you can use <code>axis=None</code> to flat the array. Try:</p> <pre><code>import numpy as np np.sort(a, axis=None).reshape(a.shape) </code></pre>
2
2016-05-27T12:39:58Z
[ "python", "numpy" ]
How to calculate number of words in a string in DataFrame?
37,483,470
<p>Suppose we have simple Dataframe</p> <pre><code>df = pd.DataFrame(['one apple','banana','box of oranges','pile of fruits outside', 'one banana', 'fruits']) df.columns = ['fruits'] </code></pre> <p>how to calculate number of words in keywords, similar to:</p> <pre><code>1 word: 2 2 words: 2 3 words: 1 4 words: 1 <...
2
2016-05-27T12:21:19Z
37,483,537
<p>IIUC then you can do the following:</p> <pre><code>In [89]: count = df['fruits'].str.split().apply(len).value_counts() count.index = count.index.astype(str) + ' words:' count.sort_index(inplace=True) count Out[89]: 1 words: 2 2 words: 2 3 words: 1 4 words: 1 Name: fruits, dtype: int64 </code></pre> <p...
4
2016-05-27T12:24:59Z
[ "python", "pandas", "dataframe" ]
Changes to a Merged CSV file not saving
37,483,500
<p>I am merging two csv files that relate to a system process. However I want to make a like change to the Header. Examples of csv file I'm using (example process: 'python'):</p> <pre><code>Date, Process(python)\% Processor Time, Process(python)\Thread Count, Process(python)\Working Set xx/xx/xx xxxx ...
0
2016-05-27T12:22:55Z
37,489,171
<p>You are making changes to csvReader but not to <code>merged</code>. If all you want to do adjust the header row, you can replace:</p> <pre><code>csvReader = csv.reader(merged) for row in csvReader: #Changes 'Process(python)\% Processor Time' into '% Processor Time' row = truncate_string(row[0],"\\",1) p...
0
2016-05-27T17:22:13Z
[ "python", "csv", "pandas", "merge", "editing" ]
How do I make pyinstaller include my database?
37,483,516
<p>I've got a PyQt4 application which makes use of sqlite3. I have two seperate files currently: a .py file and a .db file. Originally I took the .py file and tried to create an executable just using that thinking maybe it would link somehow but when I run the .exe it breaks when it gets to database related code. How d...
0
2016-05-27T12:23:57Z
37,483,783
<p>You need to use a specfile. Have a look at the <a href="https://pythonhosted.org/PyInstaller/spec-files.html#adding-data-files" rel="nofollow">documentation</a>.</p> <p>pyinstaller creates those file automatically. You just need to edit it. Have a look at the example from the docs. To add a README file you just nee...
0
2016-05-27T12:37:04Z
[ "python", "sqlite3", "pyqt4", "pyinstaller" ]
Tensorflow first layer neuron's weights don't change
37,483,520
<p>Is it ok if my first layer neuron's weights don't change ?</p> <p>I'm on the MNIST network on Tensorflow and I've tried to get the neuron's weights like this in the "inference" function:</p> <pre><code>def inference(images, hidden1_units, hidden2_units): weights = [] # Hidden 1 with tf.name_scope('hi...
0
2016-05-27T12:24:12Z
37,489,797
<p>I wrapped your code up in a training harness and ran it without issue.</p> <p>I think the problem here is not your code but the interpretation of the results. Numpy summarizes large arrays in the way you've shown, by displaying the first couple and last couple elements. (The elements of your <code>poids</code> list...
2
2016-05-27T18:04:24Z
[ "python", "tensorflow" ]
Continue when element is not found in selenium
37,483,664
<pre><code>up_key.click() item = WebDriverWait(driver, 5).until(lambda driver: driver.find_element_by_xpath(element_xpath)) if item.text == 'awesome text': driver.quit() </code></pre> <p>The <code>up_key.click()</code> clicks on the up key image on the site, it sometimes creates a new element in AJAX which is disp...
1
2016-05-27T12:30:57Z
37,483,812
<p>To do this you have to surround the text with a try block</p> <pre><code>while True: try: up_key.click() item = WebDriverWait(driver, 5).until(lambda driver: driver.find_element_by_xpath(element_xpath)) if item.text != 'awesome text': continue driver.close() excep...
1
2016-05-27T12:38:50Z
[ "python", "selenium" ]