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 can I move the turtle every few seconds without using time.sleep()?
37,598,593
<p>I'm making a Tetris like game, with turtle.</p> <p>When the block goes down, I use time.sleep() to make it wait for a few seconds before it goes down. But, the time.sleep() make the ENTIRE code stop, I want only the defintion to stop:</p> <pre><code>def moveDown(): time.sleep(2) turtle(sety(100) time.s...
0
2016-06-02T17:34:28Z
37,598,761
<p>time.clock() can report the number of seconds since it has started so you can check against it to see if you will allow the user to input commands for a certain interval once it is on the bottom</p> <pre><code>import time junk = time.clock() pause_at_bottom = 0.5 ## code till it hits the bottom at_bottom = time.clo...
0
2016-06-02T17:43:56Z
[ "python", "turtle-graphics" ]
How can I move the turtle every few seconds without using time.sleep()?
37,598,593
<p>I'm making a Tetris like game, with turtle.</p> <p>When the block goes down, I use time.sleep() to make it wait for a few seconds before it goes down. But, the time.sleep() make the ENTIRE code stop, I want only the defintion to stop:</p> <pre><code>def moveDown(): time.sleep(2) turtle(sety(100) time.s...
0
2016-06-02T17:34:28Z
37,599,211
<p>What is going on with time.sleep() is that it is what is known as a "blocking call" meaning that when it is called, your process will not proceed until it is done. You need to have another thread/process to run in the background to cause it to move. Something like this:</p> <pre><code>def moveDown(): turtle.set...
0
2016-06-02T18:08:38Z
[ "python", "turtle-graphics" ]
How to plot a value_counts in pandas that has a huge number of different counts not distributed evenly
37,598,665
<p>Lets say I have the following data:</p> <pre><code>s2 = pd.Series([1,2,3,4,5,2,3,333,2,123,434,1,2,3,1,11,11,432,3,2,4,3,3,3,54,34,24,2,223,2535334,3,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,30000, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]) s2.value_counts(normalize=True).plot() </code></pre> <p>Wh...
0
2016-06-02T17:38:45Z
37,599,000
<p>You could keep the normalized value counts above a certain <code>threshold</code>. Then sum together the values below the <code>threshold</code> and clump them together in one category which could be called, say, "other".</p> <p>By choosing <code>threshold</code> high enough, you will able to display the most impor...
3
2016-06-02T17:57:31Z
[ "python", "pandas", "plot" ]
How to plot a value_counts in pandas that has a huge number of different counts not distributed evenly
37,598,665
<p>Lets say I have the following data:</p> <pre><code>s2 = pd.Series([1,2,3,4,5,2,3,333,2,123,434,1,2,3,1,11,11,432,3,2,4,3,3,3,54,34,24,2,223,2535334,3,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,30000, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]) s2.value_counts(normalize=True).plot() </code></pre> <p>Wh...
0
2016-06-02T17:38:45Z
37,599,068
<p>Just log the axis (I have no panda, but it should be similar):</p> <pre><code>import numpy as np import matplotlib.pyplot as plt s2 = np.log([1,2,3,4,5,2,3,333,2,123,434,1,2,3,1,11,11,432,3,2,4,3,3,3,54,34,24,2,223,2535334,3,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,30000, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2...
0
2016-06-02T18:00:44Z
[ "python", "pandas", "plot" ]
Determine read or write query neo4j
37,598,689
<p>Given a string containing a Neo4j cypher query, how to determine <strong><em>quickly</em></strong> in python it is db read or db write.</p> <p>Currently I have thought of two ways of seeing this -</p> <ol> <li>Check for keywords like <strong>CREATE, DELETE</strong> etc to tag write queries and<br> <strong>MATCH, ...
0
2016-06-02T17:40:10Z
37,606,476
<p>You can use <a href="http://neo4j.com/docs/developer-manual/current/#how-do-i-profile-a-query" rel="nofollow"><code>EXPLAIN</code></a> option and inspect <code>operatorType</code> of the execution plan:</p> <pre><code>EXPLAIN MERGE (n:Person) </code></pre> <p>and find and check for possible values for writing, upd...
2
2016-06-03T05:20:46Z
[ "python", "neo4j", "cypher" ]
Using an entire eclipse project in py4j
37,598,736
<p>I have a bunch of Java code in an eclipse project folder that I'd like to be able to use in python development using py4j. </p> <p>Is there any canonical way to connect the Java project to python 3.0 (anaconda)? So far, my understanding is that I'd have to create an entry point for every class in the project, then ...
1
2016-06-02T17:42:40Z
37,611,690
<p>You only need one GatewayServer in your Java project. Entry points are optional and only needed if you want to manage state on the Java side, for example, share an instance between multiple Python interpreters. You can always call constructors on the Python side.</p> <p>For example, from Python, you could do this w...
1
2016-06-03T10:15:32Z
[ "java", "python", "py4j" ]
Kv language doesn't see the file in the directory
37,598,863
<p>I have textures for my buttons grouped in a folder <code>textures\button</code> (relative to the code file). Throughout my code, I have specified this path in several places, in the kv and in Python code. The Python code seemed to recognize the textures just fine, while the kv failed to find them. What's up with tha...
1
2016-06-02T17:49:25Z
37,599,072
<p>You should replace the <code>\\</code> in your path with <code>/</code>, i.e., use: </p> <pre><code>Builder.load_string(''' &lt;MyButton&gt;: background_normal: "textures/button/normal.png" ''') </code></pre> <p>In my experience, kv expects paths to be in the format shown above, and if this works for you I wil...
1
2016-06-02T18:01:07Z
[ "python", "python-3.x", "kivy" ]
Python Pandas - how to apply boolean series to extract rows from dataframe
37,598,952
<p>I have a boolean series that I got from using .duplicated. I'm trying to figure out what rows of my dataframe are returning True (and what the data is in those rows). How can I use this boolean series to extract those rows?</p> <p>Thanks - KC</p> <p>EDIT- Data sample:</p> <pre><code>level_0 index ID dat...
1
2016-06-02T17:55:13Z
37,599,021
<p>use <code>keep=False</code> parameter when calling <code>.duplicated()</code></p> <pre><code>df[df.duplicated(subset='date_time', keep=False)] </code></pre> <p>Test:</p> <pre><code>In [53]: df Out[53]: evel_0 index ID date_time value 0 54967 54967 54967 2016-01-06 19:30:00 1.0 1 54968 ...
1
2016-06-02T17:58:35Z
[ "python", "pandas" ]
Array Modification from 3D to 2D while Removing Data
37,598,976
<p>Sorry if this seems like a basic question, but I'm struggling here... I've got a 3-Dimensional array in Python that I only want to pull some data from, going from 3D to 2D. This is not a reshape.</p> <p>I'm beginning with a 3D array (2x3x5):</p> <pre><code>a = [[[0 0 0 0 0] [1 1 1 1 1] [2 2 2...
0
2016-06-02T17:56:27Z
37,624,192
<p>Alright, figured it out...</p> <p>I had been trying <code>a[:][0][:]</code>, when I simply needed <code>a[:,0,:]</code></p>
0
2016-06-03T22:10:56Z
[ "python", "multidimensional-array" ]
Reducing noise on Data
37,598,986
<p>I have 2 lists with data points in them.</p> <pre><code>x = ["bunch of data points"] y = ["bunch of data points"] </code></pre> <p>I've generated a graph using matplotlib in python</p> <pre><code>import matplotlib.pyplot as plt plt.plot(x, y, linewidth=2, linestyle="-", c="b") plt.show() plt.close() </code></pre...
1
2016-06-02T17:56:51Z
37,599,921
<p>It depends how you define the "noise" and how it is caused. Since you didn't provide much information about your case, I'll take your question as "how to make the curve smooth". Kalman filter can do this, but it's too complex, I'd prefer simple IIR filter</p> <pre><code>mu, sigma = 0, 500 x = np.arange(1,100,0.1...
3
2016-06-02T18:49:40Z
[ "python", "noise", "kalman-filter" ]
How to plot two specific columns from a csv file in python
37,598,991
<p>I am new to python and may be missing some details when attempting to plot. I am trying to call upon a specific csv file and plot two columns form the file. I have successfully called upon those columns and converted irrelevant values to NaN. I am now attempting to plot the columns in a line graph to obtain a time s...
0
2016-06-02T17:57:00Z
37,600,083
<p>Can you check the type of the elements of your list with </p> <pre><code>print type(ozone[0]) </code></pre> <p>maybe then you can see where the error originates from</p> <p>tldr comments: The ozone values were integer types, the included NaN values were floats. Seemingly you cannot plot two different types. Thi...
1
2016-06-02T19:00:17Z
[ "python", "numpy", "matplotlib", "plot", "floating-point" ]
TypeError from matplotlib Button instantiation
37,599,013
<p>I'm getting a mysterious error when I try to create a Matplotlib button.</p> <p>I have a class which has a number of Matplotlib axes as instance attributes. I am instantiating the button with the following call:</p> <p><code>Button(self.energy_diagram, 'Show Attractors')</code></p> <p>And I get the following erro...
0
2016-06-02T17:58:04Z
37,669,083
<p>First, your error message. It's surprising, but fairly clear. Your note about the problematic axes being the only 3d one is the key. Two minimal examples with and without the error:</p> <pre><code>import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import matplotlib.widgets as widgets hf1,ha1 =...
1
2016-06-07T01:17:59Z
[ "python", "python-3.x", "matplotlib" ]
Splitting a tuple in a function call
37,599,115
<p>Update: By referencing this previous post I made my ultimate goal is much clearer. <a href="http://stackoverflow.com/questions/37592787/combing-2d-list-of-tuples-and-then-sorting-them-in-python/37593267?noredirect=1#comment62676460_37593267">Combing 2D list of tuples and then sorting them in Python</a></p> <p>With ...
0
2016-06-02T18:03:13Z
37,599,595
<p><code>section</code> accepts a string containing integers separated by dots, but in your code, you're passing it a list. A correct way to use it would be something like:</p> <p><code>result = list(zip(*sorted(zip(l1, l2, l3, files_good_list), key = lambda x: section(x[0]))))</code></p> <p>But then again, I'm not r...
2
2016-06-02T18:30:47Z
[ "python", "sorting" ]
Splitting a tuple in a function call
37,599,115
<p>Update: By referencing this previous post I made my ultimate goal is much clearer. <a href="http://stackoverflow.com/questions/37592787/combing-2d-list-of-tuples-and-then-sorting-them-in-python/37593267?noredirect=1#comment62676460_37593267">Combing 2D list of tuples and then sorting them in Python</a></p> <p>With ...
0
2016-06-02T18:03:13Z
37,599,795
<p>I'll give you a quick example of what you want. Pretty much you have two portions to a section (at least in this example). You have <code>x.y</code> where <code>x</code> can be any number and I'm going to assume that <code>y</code> can be <code>1-10</code>. In this case you can make a custom comparison function that...
0
2016-06-02T18:41:25Z
[ "python", "sorting" ]
Error running Google's Cloud Vision API Example (Face Detection)
37,599,208
<p>I am trying to run the Face Detection Example in Google's Cloud Vision API. I am trying to run [faces.py here][1].</p> <p>When I run the following:</p> <blockquote> <p>faces.py demo-picture.jpg</p> </blockquote> <p>below is the error I get:</p> <pre><code>ubuntu@ubuntu-VirtualBox:~/Documents/code/python- st...
0
2016-06-02T18:08:28Z
37,849,171
<p>You need to download the service-account key; typically a JSON file. If you have not created the credentials/obtained the key, follow the steps:<br><br> Go to your API manager;<br> Create credentials;<br> Choose "Service Account Key";<br> Select "Key Type" as JSON.<br></p> <p>After this point, you should obtain a J...
0
2016-06-16T02:59:56Z
[ "python", "python-2.7", "ubuntu", "google-cloud-vision" ]
Can't get CKEditor to work in Django with zinnia-wysiwyg-ckeditor
37,599,233
<p>First of all excuse my English is really bad, but I'll try to explain as best I can.</p> <p>I´m working in a blog, with <code>django-blog-zinnia</code>, so far so good. Now I try to integrate <code>CKEditor</code> with </p> <p><a href="https://github.com/django-blog-zinnia/zinnia-wysiwyg-ckeditor" rel="nofollow">...
1
2016-06-02T18:09:46Z
37,933,991
<p>Since there's an expected change to your admin models, did you run <code>python manage.py makemigrations</code> and <code>python manage.py migrate</code>? </p> <p>EDIT:</p> <p>After going through the installation process again, I'd advise against messing with the <code>'zinnia-content'</code> portion of the toolba...
0
2016-06-21T00:50:54Z
[ "python", "django", "ckeditor", "zinnia" ]
Can't get CKEditor to work in Django with zinnia-wysiwyg-ckeditor
37,599,233
<p>First of all excuse my English is really bad, but I'll try to explain as best I can.</p> <p>I´m working in a blog, with <code>django-blog-zinnia</code>, so far so good. Now I try to integrate <code>CKEditor</code> with </p> <p><a href="https://github.com/django-blog-zinnia/zinnia-wysiwyg-ckeditor" rel="nofollow">...
1
2016-06-02T18:09:46Z
38,442,524
<p>This is what I did to make my Zinnia-CKEditor work.</p> <p>First, remove the CKEditor <code>default</code> configuration. It is overwritten by the second toolbar declaration <code>'toolbar': 'Zinnia',</code>.</p> <p><code>CKEDITOR_IMAGE_BACKEND = "pillow"</code> is important for image rendering in the editor itsel...
0
2016-07-18T17:17:33Z
[ "python", "django", "ckeditor", "zinnia" ]
Initializing Radio Buttons Tkinter
37,599,242
<p>I am trying to create a selection menu for questions with four options. I am instantiating four radio buttons, one for each choice. For some reason when the form shows up, the last three are already selected. When you click on one, only that button is selected, and there others become deselected. I would like it so ...
0
2016-06-02T18:10:25Z
37,599,479
<p>The variable that you need to give to Radiobutton should be Tkinters <code>IntVar()</code>. So instead of:</p> <pre><code>self.answer = 0 </code></pre> <p>put:</p> <pre><code>self.answer = IntVar() #We declare it like this self.answer.set(-1) #If you wont none of your radionbuttons to be se...
3
2016-06-02T18:24:32Z
[ "python", "tkinter", "radio-button" ]
Index error for list in python
37,599,353
<p>I've written the following code to iterate through folders and their files and to rename each file in each folder as the file's index in the folder. E.g The first file in each folder will be named <code>1.JPG</code>, the second <code>2.JPG</code> and so on. The folder names are integers from 1 to 82. I need the fold...
0
2016-06-02T18:17:04Z
37,599,740
<p>I assume you want something like this?</p> <pre><code># Import the os module, for the os.walk function import os # Set the directory you want to start from rootDir = '/Users/heinst' for dirName, subdirList, fileList in os.walk(rootDir): print('Found directory: %s' % dirName) i = 0 for fname in fileList...
1
2016-06-02T18:38:19Z
[ "python", "os.walk" ]
Least common multiple of n numbers, using recursion
37,599,568
<p>I need to write a recursive function, which finds the least common multiple elements of the list with n length. My code: </p> <pre><code>import random def random_num(n): return [random.randint(-20,20) for i in range(n)] def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) ...
1
2016-06-02T18:29:35Z
37,599,797
<p>You need something to recur through a list, such as the following. If there are 2 elements in the list, do your normal LCM. If it's longer, then recur on the list tail, and then do LCM with that result and the first element.</p> <pre><code>def lcm(in_list): if len(in_list) == 2: # Do your normal LCM c...
1
2016-06-02T18:41:38Z
[ "python", "function", "recursion", "random", "numbers" ]
Least common multiple of n numbers, using recursion
37,599,568
<p>I need to write a recursive function, which finds the least common multiple elements of the list with n length. My code: </p> <pre><code>import random def random_num(n): return [random.randint(-20,20) for i in range(n)] def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) ...
1
2016-06-02T18:29:35Z
37,600,337
<p>you need to find to LCM of the whole list. let "l" be the LCM of the whole array and if we pick any 2 random numbers from array, they will have a LCM say "l1" and so on and so forth "l2","l3","l4".... the LCM of these will also be the LCM of the whole array.</p> <pre><code># we can find LCM of two numbers by the ba...
1
2016-06-02T19:13:55Z
[ "python", "function", "recursion", "random", "numbers" ]
Least common multiple of n numbers, using recursion
37,599,568
<p>I need to write a recursive function, which finds the least common multiple elements of the list with n length. My code: </p> <pre><code>import random def random_num(n): return [random.randint(-20,20) for i in range(n)] def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) ...
1
2016-06-02T18:29:35Z
37,602,213
<p>My code, the last return doesn't work correct.</p> <pre><code>import random def nod(a, b): if b == 0: return a else: return nod(b, a % b) def nok(a, b): return a * b / nod(a, b) def nok_of_array(n): if len(n) == 2: return nok(n[1], n[2]) else: return nok(nok_of_array[0:len(n)/...
0
2016-06-02T21:13:33Z
[ "python", "function", "recursion", "random", "numbers" ]
Group by and aggregate problems for numpy arrays over word vectors
37,599,647
<p>My pandas data frame looks something like this:</p> <pre><code>Movieid review movieRating wordEmbeddingVector 1 "text" 4 [100 dimensional vector] </code></pre> <p>I am trying to run a doc2vec implementation and I want to be able to group by movie ids and the take the sum of the vectors in w...
0
2016-06-02T18:33:28Z
37,609,702
<p>There is a bug in your code. Inside your lambda function you sum across the entire dataframe instead of just the group. This should fix things:</p> <pre><code>movie_groupby = movie_data.groupby('movie_id').agg(lambda v: np.sum(v['textvec'])) </code></pre> <p>Note: I replaced <code>hotel_data</code> with <code>movi...
0
2016-06-03T08:36:44Z
[ "python", "pandas", "machine-learning", "word2vec", "doc2vec" ]
How to write data from 1D array to an excel file from python?
37,599,722
<p>I'm new to python and I have to change this code to have a 1D array not a 2D array.This code is perfectly working to write data to an excel file. Please help me to change this in to a 1D array.</p> <pre><code>eg: only to enter as 1D array as below expenses = [ [1000], [100], [300], ...
0
2016-06-02T18:37:35Z
37,600,119
<p>This question basically comes down to tuple unpacking, the for loop in the original code was basically doing this for each item in <code>expenses</code>:</p> <pre><code>item, cost = ['Rent', 1000] #unpacks 'Rent' to item and 1000 to cost </code></pre> <p>if each element of <code>expenses</code> consisted of only a...
1
2016-06-02T19:01:57Z
[ "python", "arrays", "excel", "xlsxwriter" ]
Why print statement produces a newline without any tags in python?
37,599,746
<p>Here's the code - </p> <pre><code>import os file = open("list.txt", "rw+") text = file.readline() print "ffmpeg -loop 1 -i image.jpg -i \""+text+"\" -vf scale=1280:720 -shortest -acodec copy -vcodec mpeg4 \""+text+".mp4\"" os.system("ffmpeg -loop 1 -i image.jpg -i \""+text+"\" -vf scale=1280:720 -shortest -acodec...
2
2016-06-02T18:38:37Z
37,599,796
<p>Because your file has a new line character (<code>'\n'</code>) in the end of the line,<br> so <code>text</code> is <code>"some-file-path\n"</code>. </p> <p>You should change <code>text = file.readline()</code> to <code>text = file.readline().strip()</code>.</p>
5
2016-06-02T18:41:28Z
[ "python", "python-2.7" ]
Why print statement produces a newline without any tags in python?
37,599,746
<p>Here's the code - </p> <pre><code>import os file = open("list.txt", "rw+") text = file.readline() print "ffmpeg -loop 1 -i image.jpg -i \""+text+"\" -vf scale=1280:720 -shortest -acodec copy -vcodec mpeg4 \""+text+".mp4\"" os.system("ffmpeg -loop 1 -i image.jpg -i \""+text+"\" -vf scale=1280:720 -shortest -acodec...
2
2016-06-02T18:38:37Z
37,600,559
<p>ALl lines in textfiles (when python reads them at least) end in "\n"</p> <p>easy solution</p> <pre><code>text = file.readline()[:-1] </code></pre> <p>this will trim the last character "\n" from the line. careful when doing this, since if you want to write the line back, you need to append a "\n" to it (when usei...
-2
2016-06-02T19:28:29Z
[ "python", "python-2.7" ]
python find string pattern in numpy array of strings
37,599,764
<p>I have a numpy array of strings 'A' of length 100 and they are sentences of different sizes. It is string NOT numpy strings</p> <pre><code>&gt;&gt;&gt; type(A[0]) &lt;type 'str'&gt; </code></pre> <p>I want to find the location of strings in A which contain certain pattern like 'zzz' in them.</p> <p>I tried</p> <...
2
2016-06-02T18:39:28Z
37,599,917
<p>No need to be fancy with this, you can get the list of indicies with a list comprehension and the <code>in</code> operator:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; lst = ["aaa","aazzz","zzz"] &gt;&gt;&gt; n = np.array(lst) &gt;&gt;&gt; [i for i,item in enumerate(n) if "zzz" in item] [1, 2] </cod...
4
2016-06-02T18:49:13Z
[ "python", "string", "numpy" ]
python find string pattern in numpy array of strings
37,599,764
<p>I have a numpy array of strings 'A' of length 100 and they are sentences of different sizes. It is string NOT numpy strings</p> <pre><code>&gt;&gt;&gt; type(A[0]) &lt;type 'str'&gt; </code></pre> <p>I want to find the location of strings in A which contain certain pattern like 'zzz' in them.</p> <p>I tried</p> <...
2
2016-06-02T18:39:28Z
37,600,503
<p>The issue here is the nature of your array of strings.</p> <p>If I make the array like:</p> <pre><code>In [362]: x=np.array(['one','two','three']) In [363]: x Out[363]: array(['one', 'two', 'three'], dtype='&lt;U5') In [364]: type(x[0]) Out[364]: numpy.str_ </code></pre> <p>The elements are special kind...
0
2016-06-02T19:25:23Z
[ "python", "string", "numpy" ]
How to convert date and time from a line in a text file?
37,599,818
<p>I was wondering if there is a way to convert date and time from a pre-set value in a line from a text file. </p> <p>For the date conversion, I need the day of the year. I found a way to get the current day of the year with this code:</p> <pre><code>from datetime import datetime day_of_year = datetime.now().timetup...
2
2016-06-02T18:42:43Z
37,599,925
<p>well once you've gotten the <code>1993-02-09T00:00Z</code> string, you can just do </p> <pre><code>import time, datetime d = datetime.datetime.fromtimestamp(time.strptime('1993-02-09T00:00Z', '%Y-%m-%dT%H:%MZ')) </code></pre> <p>which will give you a <code>datetime</code> object, which you can use accordingly</p> ...
1
2016-06-02T18:49:51Z
[ "python", "python-2.7", "python-3.x" ]
How to convert date and time from a line in a text file?
37,599,818
<p>I was wondering if there is a way to convert date and time from a pre-set value in a line from a text file. </p> <p>For the date conversion, I need the day of the year. I found a way to get the current day of the year with this code:</p> <pre><code>from datetime import datetime day_of_year = datetime.now().timetup...
2
2016-06-02T18:42:43Z
37,600,851
<p>Your times are formatted according to the <a href="https://en.wikipedia.org/wiki/ISO_8601" rel="nofollow">iso 8601</a> specification.</p> <p>You can use <a href="https://dateutil.readthedocs.io/en/stable/parser.html" rel="nofollow">dateutil</a> to parse iso8601 formatted datetimes.</p> <pre><code>data = """ 1.a D...
0
2016-06-02T19:48:51Z
[ "python", "python-2.7", "python-3.x" ]
How to convert date and time from a line in a text file?
37,599,818
<p>I was wondering if there is a way to convert date and time from a pre-set value in a line from a text file. </p> <p>For the date conversion, I need the day of the year. I found a way to get the current day of the year with this code:</p> <pre><code>from datetime import datetime day_of_year = datetime.now().timetup...
2
2016-06-02T18:42:43Z
37,604,007
<p>If all dates are in the same format then it is easy to extract them from the file (not tested):</p> <pre><code>#!/usr/bin/env python from datetime import datetime dates = {} # date -&gt; label with open('datetime.txt') as file: for line in file: label, colon, date_string = line.partition(':') i...
0
2016-06-03T00:05:39Z
[ "python", "python-2.7", "python-3.x" ]
Flask-Admin: Custom Query for Select Field with Peewee?
37,599,846
<p>I have a model with a ForeignKeyField which gets rendered as a select field in the create/edit form in Flask-Admin. I would like to restrict the choices in the select field with a custom query so the user only has access to their own source addresses.</p> <p>All answers point I've found point in the direction of WT...
0
2016-06-02T18:44:32Z
37,663,561
<p>It is pretty simple, actually:</p> <p>Just override <code>edit_form</code> in the <code>ModelView</code> and create the field there with the query passed in <code>choices</code>, as seen in the <a href="http://wtforms.simplecodes.com/docs/0.6/fields.html#wtforms.fields.SelectField" rel="nofollow">docs</a>:</p> <pr...
1
2016-06-06T17:33:08Z
[ "python", "flask", "peewee", "flask-admin" ]
Getting list based on text lxml
37,599,859
<p>I have some html like: </p> <pre><code>... &lt;table width="100%"&gt; &lt;tr class="blueborder"&gt; &lt;td colspan="2" class="blackbold"&gt;Some Other Text&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table width="100%"&gt; &lt;tr class="upcom...
1
2016-06-02T18:45:09Z
37,600,003
<p>You can select the following td after the tr with the text <code>Signaling Text</code>:</p> <pre><code>h = """ &lt;table width="100%"&gt; &lt;tr class="blueborder"&gt; &lt;td colspan="2" class="blackbold"&gt;Some Other Text&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; ...
0
2016-06-02T18:54:53Z
[ "python", "web-scraping", "lxml" ]
PyDev in Eclipse - packages displayed as regular folders
37,599,867
<p>Usually this is cause by the <strong>init</strong>.py missing in the package. But I do have all my <strong>init</strong>.py into place. In the PyDev package explorer, packages are displayed as yellow rectangles, just like regular folders, rather than with the package icon. Why is this? I've tried clean all, build al...
0
2016-06-02T18:45:51Z
37,603,520
<p>Sounds like an issue with the indexer, or PYTHONPATH. Try <code>Project -&gt; Properties -&gt; PyDev -PYTHONPATH, "add source folder"</code></p>
1
2016-06-02T23:06:22Z
[ "python", "eclipse", "pydev", "package-explorer" ]
Django ORM group by one column and return other
37,599,943
<p>In simple worlds I try to write in Django a query which will return results</p> <p>Similar to this:</p> <pre><code>select id, max(score), screen, details from results group by screen where user_id=123 order by score desc, screen </code></pre> <p>My code:</p> <pre><code>results = Results.objects.filter(user=user)...
0
2016-06-02T18:51:04Z
37,600,713
<p>It is the <a href="https://docs.djangoproject.com/en/1.9/ref/models/querysets/#django.db.models.query.QuerySet.values" rel="nofollow"><code>values()</code></a> call that turns your <code>QuerySet</code> into a list of <code>dicts</code>. </p> <p>If you want to keep it a <code>QuerySet</code>, but only retrieve the...
0
2016-06-02T19:39:28Z
[ "python", "django", "orm" ]
Pandas duplicated indexes still shows correct elements
37,600,029
<p>I have a pandas <code>DataFrame</code> like this:</p> <pre><code>test = pd.DataFrame({'score1' : pandas.Series(['a', 'b', 'c', 'd', 'e']), 'score2' : pandas.Series(['b', 'a', 'k', 'n', 'c'])}) </code></pre> <p>Output:</p> <pre><code> score1 score2 0 a b 1 b a 2 c k 3 d n 4 e ...
0
2016-06-02T18:56:28Z
37,600,875
<p>This is into the internals (i.e., don't rely on this API!) but the way it works now is that there is a <code>Grouping</code> object which stores the groups in terms of positions, rather than index labels.</p> <pre><code>In [25]: gb = test.groupby('score1') In [26]: gb.grouper Out[26]: &lt;pandas.core.groupby.BaseG...
0
2016-06-02T19:50:15Z
[ "python", "pandas" ]
isnull(col1,col2) equivalent in pandas
37,600,041
<p>How can I write an equivalent statement to the below SQL query?</p> <pre><code>SELECT ISNULL(df2.id, df1.id) as new_id FROM dataframe1 df1 LEFT JOIN dataframe2 df2 ON df1.id = df2.id </code></pre>
1
2016-06-02T18:57:28Z
37,603,792
<p>One such equivalent would be:</p> <pre><code>df2.set_index('id').combine_first(df1.set_index('id')).reset_index() </code></pre>
0
2016-06-02T23:38:01Z
[ "python", "sql", "pandas" ]
Python Pandas read_csv reads only single line from CSV file
37,600,076
<p>I am writing a code to read and extract parameters from each row of a CSV file. </p> <p>From each row, I get a list of parameter values arranged by datestamps and values. An example csv file is as below: </p> <pre><code>Row1: 'Fanspeed','Value=32','Datetime=05-01-2015','Fanspeed','Value=32','Datetime=05-02-2015' ...
0
2016-06-02T18:59:53Z
37,603,934
<p>First of all , you can try to pass 'header=None' to indicate the first row will be data instead of the headers. </p> <pre><code>csv_f = pd.read_csv('test.csv', header=None) print csv_f </code></pre> <p>Secondly, what the read_csc returns is already a DataFrame, so you should directly working on it. More informat...
0
2016-06-02T23:54:33Z
[ "python", "csv", "pandas" ]
Python Pandas read_csv reads only single line from CSV file
37,600,076
<p>I am writing a code to read and extract parameters from each row of a CSV file. </p> <p>From each row, I get a list of parameter values arranged by datestamps and values. An example csv file is as below: </p> <pre><code>Row1: 'Fanspeed','Value=32','Datetime=05-01-2015','Fanspeed','Value=32','Datetime=05-02-2015' ...
0
2016-06-02T18:59:53Z
37,605,497
<p>Try this: </p> <pre><code> csv_f = pd.read_csv('test.csv') print csv_f.head() #for row in csv_f: #csv_f = pd.read_csv('test.csv') #print csv_f </code></pre>
0
2016-06-03T03:32:23Z
[ "python", "csv", "pandas" ]
Can I loop .kv?
37,600,104
<p>I have some .kv that I'm frequently changing, which has multiple identical sections (but with different ids). Eg:</p> <pre><code>GridLayout: cols: 1 Button: id: button1 text: 'Button 1' on_press: app.buttonpressed(1) Button: id: button2 text: 'Button 2' ...
1
2016-06-02T19:01:18Z
37,600,212
<p>You can use kivy dynamic classes (and templates for older versions). </p> <p>Here's an example from the documentation (<a href="https://kivy.org/docs/guide/lang.html#dynamic-classes" rel="nofollow">https://kivy.org/docs/guide/lang.html#dynamic-classes</a>). </p> <pre><code>&lt;CustomButton@Button&gt;: text_siz...
0
2016-06-02T19:06:52Z
[ "python", "kivy" ]
python collecting data from dataframe at specific row location
37,600,150
<p>I am importing a data set with about 200 columns with unique column names into pandas dataframe using read_csv. </p> <pre><code>Data.columns Index([u'SAVERECORDER', u'SAVECHANNEL', u'STARTTIME', u'INT001', u'INT002', u'INT003', u'INT004', u'INT005', u'INT006', u'INT007', ... u'INT092', u'INT093...
1
2016-06-02T19:04:01Z
37,600,420
<p>I would use a generator to create a list of all the columns you want like </p> <pre><code> from string import zfill import numpy as np cols = ['INT0' + zfill(str(i), 2) for i in np.arange(1, 100, 1)] </code></pre> <p>Then you can use pandas .iloc to index by integer location as read in <a href="http://...
1
2016-06-02T19:19:30Z
[ "python", "pandas" ]
python collecting data from dataframe at specific row location
37,600,150
<p>I am importing a data set with about 200 columns with unique column names into pandas dataframe using read_csv. </p> <pre><code>Data.columns Index([u'SAVERECORDER', u'SAVECHANNEL', u'STARTTIME', u'INT001', u'INT002', u'INT003', u'INT004', u'INT005', u'INT006', u'INT007', ... u'INT092', u'INT093...
1
2016-06-02T19:04:01Z
37,600,572
<p>data:</p> <pre><code>In [24]: df Out[24]: a b c INT001 INT002 INT003 0 8 1 1 4 2 6 1 2 9 2 5 3 6 2 4 2 9 3 5 2 3 3 2 9 9 2 7 4 4 4 3 7 8 9 5 1 5 6 3 9 8 6 2 2 9 6 1 ...
1
2016-06-02T19:29:19Z
[ "python", "pandas" ]
Check if an element in one list has the same index as another element in another list
37,600,155
<p>I am making the mastermind game on python with numbers. I have a problem with checking the elements if they are in an incorrect place. </p> <p>So basically, if the code generated by the computer has no duplicates but the user used some in their input like (COMP: 1 2 3 4 &amp; USER: 1 2 2 3). I can't check the posit...
0
2016-06-02T19:04:12Z
37,600,403
<p>Based on a little bit of research into what <a href="https://en.wikipedia.org/wiki/Mastermind_(board_game)" rel="nofollow">Mastermind</a> is and the fact that the function in your OP returns an integer, my guess is that you want to compare a computer-generated list to a user-generated list of the same size and see h...
1
2016-06-02T19:18:31Z
[ "python" ]
Check if an element in one list has the same index as another element in another list
37,600,155
<p>I am making the mastermind game on python with numbers. I have a problem with checking the elements if they are in an incorrect place. </p> <p>So basically, if the code generated by the computer has no duplicates but the user used some in their input like (COMP: 1 2 3 4 &amp; USER: 1 2 2 3). I can't check the posit...
0
2016-06-02T19:04:12Z
37,601,417
<p>I understood your question after reading Two-Bit Alchemist's answer. Here's my try:</p> <pre><code>def list_differences(list_a, list_b): # Subtract list_b from list_a, element by element. The subtraction # will result in non-zero values for elements that were different. return [bool(list_a[i]-list_b[i]...
0
2016-06-02T20:22:03Z
[ "python" ]
Where is operator.idiv in python3?
37,600,171
<p>The function operator.idiv in python2.7 seems to be not present in python 3.4. Is the function gone or where can it be found now?</p> <pre><code>import operator operator.idiv &gt;&gt;&gt; AttributeError: module 'operator' has no attribute 'idiv' </code></pre>
1
2016-06-02T19:04:43Z
37,603,036
<p>In Python 3, in accordance to <a href="https://www.python.org/dev/peps/pep-0238/" rel="nofollow">PEP 238</a>, the default division operator <code>/</code> was modified to always return a float result, regardless of the input types. So while in Python 2 <code>3 / 2</code> and <code>3.0 / 2</code> would return differe...
3
2016-06-02T22:15:39Z
[ "python", "python-3.x" ]
Class Members -- Java vs. Python
37,600,192
<p>I am coming from Java and learning Python, now. I try to understand the concept of class members in Python.</p> <p>Here is an example program in Java:</p> <pre><code>class Hello { int x = 0; void ex() { x = 7; } public static void main(String args[]) { Hello h = new Hello(); ...
6
2016-06-02T19:05:58Z
37,600,300
<p>First, your python code is correct. </p> <p>It's just a matter about how the languages is designed. Java uses a kind of automatic inference of a reference to the object. It can lead sometimes to strange behaviours for non-java experts: </p> <pre><code>private int a; public int add(int a, int b){ return a+b; /...
5
2016-06-02T19:12:12Z
[ "java", "python" ]
Class Members -- Java vs. Python
37,600,192
<p>I am coming from Java and learning Python, now. I try to understand the concept of class members in Python.</p> <p>Here is an example program in Java:</p> <pre><code>class Hello { int x = 0; void ex() { x = 7; } public static void main(String args[]) { Hello h = new Hello(); ...
6
2016-06-02T19:05:58Z
37,600,473
<p>So in java the structure is generally </p> <pre><code>Class private data (aka the "struct") public data constructors (__init__ in python) functions etc </code></pre> <p>its very similar in python. same structure just for any functions working with the data you need to put self as an argumen...
0
2016-06-02T19:23:32Z
[ "java", "python" ]
Class Members -- Java vs. Python
37,600,192
<p>I am coming from Java and learning Python, now. I try to understand the concept of class members in Python.</p> <p>Here is an example program in Java:</p> <pre><code>class Hello { int x = 0; void ex() { x = 7; } public static void main(String args[]) { Hello h = new Hello(); ...
6
2016-06-02T19:05:58Z
37,600,510
<p>2.)Python is a high level language. where java is more mid-high im guessing. kind of new to java. </p> <p>python goes by white space, where java requires more formatting.</p> <p>3.) the self parameter can be removed. replace with whatever you want to call it. </p>
-2
2016-06-02T19:25:45Z
[ "java", "python" ]
Custom Python gTTS voice
37,600,197
<p>I have been using the gTTS module for python 3.4 to make mp3 files of spoken text. It has been working, but all of the speech is in a certain adult female voice. Is there a way to customize the voice that gTTS reads the text in?</p>
0
2016-06-02T19:06:26Z
37,600,512
<p>Unfortunately it does not appear you can do that. The script uses <a href="https://translate.google.com/" rel="nofollow">this webpage</a> to grab voice from, and it appears all you can do is have one voice per language.</p> <p>Reading the <a href="https://github.com/pndurette/gTTS/blob/master/gtts/tts.py" rel="nofo...
1
2016-06-02T19:26:04Z
[ "python", "python-3.x", "text-to-speech", "google-text-to-speech" ]
Python text Categorization using TFIDF
37,600,213
<p>I have a dataset like below</p> <pre><code>**ID** **Text** **Category** 1 jake loves me more than john loves me Romance 2 july likes me more than robert loves me Friendship 3 He likes videogames more than baseball ...
2
2016-06-02T19:06:54Z
37,720,971
<p>You can use the libsvm with python. </p> <p>1.The first thing to do is to represent your document by respecting the format of the file provided by libsvm.</p> <p>2.Then, your read the data :</p> <pre><code>from libsvm import * prob = svm_problem(your data…) </code></pre> <p>3.You set the svm parameters </p> <...
0
2016-06-09T08:43:55Z
[ "python", "python-3.x", "tf-idf", "text-classification", "document-classification" ]
cannot locate element within a web page using selenium python
37,600,281
<p>I just want to write a simple log in code for one website. However, I think the log in page was written in JS. It's really hard to locate the elements with selenium. The web page I am going to play with is: "<a href="https://www.nike.com/snkrs/login?returnUrl=%2F" rel="nofollow">https://www.nike.com/snkrs/login?re...
0
2016-06-02T19:11:02Z
37,601,857
<p>Try changing the code : </p> <pre><code>elem =driver.find_element_by_xpath("//*[@id='ce3feab5-6156-441a-970e-23544473a623']") </code></pre> <p>to </p> <pre><code>elem =driver.find_element_by_xpath("//*[@type='email']") </code></pre>
0
2016-06-02T20:49:14Z
[ "python", "selenium" ]
cannot locate element within a web page using selenium python
37,600,281
<p>I just want to write a simple log in code for one website. However, I think the log in page was written in JS. It's really hard to locate the elements with selenium. The web page I am going to play with is: "<a href="https://www.nike.com/snkrs/login?returnUrl=%2F" rel="nofollow">https://www.nike.com/snkrs/login?re...
0
2016-06-02T19:11:02Z
37,601,869
<p>My guess (and observation) is that the id changes each time you visit the page. The id looks auto-generated, and when I go to the page multiple times, the id is different each time.</p> <p>You'll need to search for something that doesn't change. For example, you can search for the <code>name</code> attribute, which...
0
2016-06-02T20:49:44Z
[ "python", "selenium" ]
Django using a variable in multiple views/templates
37,600,305
<p>I have a table with results from a search. This means there are no models here. The problem is that i'd like to go to a detail page for a clicked item, but I am not sure if I can do that without putting it in the URL.</p> <p>Right now it is done like this:</p> <p>In my .html for each item in the table:</p> <pre><...
0
2016-06-02T19:12:21Z
37,605,171
<p>The right way to do this is to define a <a href="https://docs.djangoproject.com/en/1.9/ref/models/instances/#get-absolute-url" rel="nofollow"><code>get_absolute_url</code></a> method on the model class for your <code>item</code> model. This is typically done using <code>reverse</code>, so it would look something lik...
0
2016-06-03T02:46:57Z
[ "python", "django" ]
Django- How to add user data in different models?
37,600,467
<p>I am a beginner in Django and I'm trying to make an app that stores attendance status of a user in various courses. I have an idea about how to make a Userprofile model and add one or two extra fields when user registers.<br> I want to make a separate model for attendance that contains several columns (course code, ...
0
2016-06-02T19:22:52Z
37,601,829
<p>You're using the wrong relationship between your models. You don't need a separate 'table' per user, you need an attendance record for each user. Something like the below should get you on the right track.</p> <pre><code>from django.db import models class Userprofile(models.Model): first_name = models.CharFi...
0
2016-06-02T20:47:23Z
[ "python", "django" ]
QtUdpSocket still listening on port after closing MainWindow
37,600,483
<p>I have a <code>QWidget</code> (<code>udpWidget</code>) instantiated in a <code>QMainWindow</code> (<code>udpMainWindow</code>). I am creating <code>udpMainWindow</code> from another <code>QMainWindow</code></p> <p>There is some <code>ValueError</code> exception occurring (which I am going to fix). When I close the ...
0
2016-06-02T19:24:18Z
37,764,149
<p>It is normal that if you don't close the socket then it will not be closed until you exit from the application. Closing a window is not enough, the socket belongs to the application and not to the window (the two windows are in the same process). If you want to close the socket, you must decide where to do it.</p> ...
2
2016-06-11T13:13:19Z
[ "python", "python-2.7", "pyside" ]
Can't import matplotlib under Ipython notebook anaconda
37,600,606
<p>I have downloaded and installed anaconda. But when I run jupyter notebook and import matplotlib , it doesn't work. Below are some commands</p> <p><code>which -a python</code></p> <pre><code>/home/user/anaconda3/bin/python /usr/bin/python </code></pre> <p><code>which -a jupyter</code></p> <pre><code>/home/user/an...
0
2016-06-02T19:32:32Z
37,605,542
<p>It worked after changing <code>/usr/local/share/jupyter/kernels/python3/kernel.json</code> . The path there was /usr/bin/python , changed it to anaconda one.</p>
1
2016-06-03T03:40:18Z
[ "python", "matplotlib", "ipython", "anaconda", "jupyter-notebook" ]
How can I fix the following error AttributeError: 'dict' object has no attribute 'text'
37,600,656
<p>I am a few months into programming. I am currently in the process of learning how to automate certain things in a project. My goal is to scrape text, src, and href and store the data in my site's database,but when I try I get this error</p> <pre><code>AttributeError: 'dict' object has no attribute 'text' </code></p...
0
2016-06-02T19:35:40Z
37,600,690
<p>You have to access dictionary keys like this:</p> <pre><code>entry['text'] entry['src'] </code></pre> <p>Not like this</p> <pre><code>entry.text entry.src </code></pre>
2
2016-06-02T19:38:03Z
[ "python", "database", "screen-scraping" ]
How can I fix the following error AttributeError: 'dict' object has no attribute 'text'
37,600,656
<p>I am a few months into programming. I am currently in the process of learning how to automate certain things in a project. My goal is to scrape text, src, and href and store the data in my site's database,but when I try I get this error</p> <pre><code>AttributeError: 'dict' object has no attribute 'text' </code></p...
0
2016-06-02T19:35:40Z
37,600,775
<p>In python you cannot access dictionary items using the syntax dict.key , If entry is a dictionary, you can use </p> <ul> <li><code>entry['key1']</code></li> <li><code>entry.get('key')</code></li> </ul>
0
2016-06-02T19:43:41Z
[ "python", "database", "screen-scraping" ]
Set Up a Simple Server in Python
37,600,674
<p>I have recently starting learning network programming with python. Here is a simple server I tried to write:</p> <pre><code>import socket def server(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('127.0.0.1', 1024)) while True: data, address = sock.recvfrom(65535) ...
0
2016-06-02T19:37:01Z
37,600,699
<p>You're not actually calling <code>server()</code>.</p> <p>Add this after the function definition:</p> <pre><code>if __name__ == '__main__': server() </code></pre>
3
2016-06-02T19:38:49Z
[ "python" ]
Pandas split Column into multiple columns by comma
37,600,711
<p>I am trying to split a column into multiple columns based off comma/space seperation.</p> <p>my dataframe currently looks like</p> <pre><code> KEYS 1 0 FIT-4270 4000.0439 1 FIT-4269 ...
0
2016-06-02T19:39:24Z
37,603,761
<p>Using Edchums answer of</p> <pre><code>pd.concat([df[[0]], df[1].str.split(', ', expand=True)], axis=1) </code></pre> <p>I was able to solve it by substituting my variables.</p> <pre><code>dfcleancsv = pd.concat([dfcleancsv['KEYS'], dfcleancsv[1].str.split(', ', expand=True)], axis=1) </code></pre>
0
2016-06-02T23:33:21Z
[ "python", "csv", "pandas" ]
Pandas split Column into multiple columns by comma
37,600,711
<p>I am trying to split a column into multiple columns based off comma/space seperation.</p> <p>my dataframe currently looks like</p> <pre><code> KEYS 1 0 FIT-4270 4000.0439 1 FIT-4269 ...
0
2016-06-02T19:39:24Z
37,637,939
<p>maybe this should work:</p> <pre><code>df = pd.concat([df['KEYS'],df[1].apply(pd.Series)],axis=1) </code></pre>
0
2016-06-05T02:42:25Z
[ "python", "csv", "pandas" ]
Flask HTTPException being swallowed
37,600,731
<p>When declaring a function with <code>before_request</code> Flask is swallowing HTTPExceptions and not propagating them:</p> <pre><code>from flask import Flask from werkzeug.exceptions import HTTPException app = Flask(__name__) @app.before_request def f(): raise HTTPException("This is not propagated") @app.ro...
0
2016-06-02T19:40:34Z
37,601,880
<p>The likely reason isn't that you aren't supposed to raise <code>HTTPException</code> itself. <code>HTTPException</code> is itself supposed to be a <em>base class</em> for other exceptions, such as <code>BadRequest</code> or <code>NotFound</code>.</p> <p>Since <code>HTTPException</code> <em>has no HTTP code to retur...
0
2016-06-02T20:50:48Z
[ "python", "exception", "flask", "werkzeug" ]
How to read the readonly status on psycopg2?
37,600,809
<p>On <code>psycopg2</code>, I can put the connection on read only mode with: <code>connection.set_session(readonly=True)</code></p> <p>But how do i know if the connection is in read-only mode?</p>
0
2016-06-02T19:45:59Z
37,602,150
<p>Try it:</p> <pre><code>conn.set_session(readonly=True) try: cursor.execute('create table xyz (a int)') cursor.execute('drop table xyz') except psycopg2.InternalError, e: print e.message </code></pre> <p>Output:</p> <pre><code>cannot execute CREATE TABLE in a read-only transaction </code></pre>
0
2016-06-02T21:09:30Z
[ "python", "postgresql", "psycopg2" ]
Write Parquet Output in a Hadoop Streaming job
37,600,845
<p>Is there a way to write text data into a parquet file with hadoop-streaming using python.</p> <p>Basically, I have a string being emitted from my IdentityMapper which I want to store as a parquet file.</p> <p>inputs or examples would be really helpful</p>
2
2016-06-02T19:48:29Z
37,716,237
<p>I suspect there's no builtin way of doing this using built Hadoop Streaming (I couldn't find one), however, depending on your data sets you may use a 3rd party package as </p> <p><a href="https://github.com/whale2/iow-hadoop-streaming" rel="nofollow">https://github.com/whale2/iow-hadoop-streaming</a></p> <p>To gen...
1
2016-06-09T03:22:39Z
[ "python", "hadoop-streaming", "parquet", "outputformat" ]
Can't install modules for python3
37,600,956
<p>I'm using Amazon ec2 (red-hat based), recently I've installed python3 (also have python 2.7 as default) and used </p> <pre><code>$ curl -O https://bootstrap.pypa.io/get-pip.py $ sudo python3.2 get-pip.py </code></pre> <p>to install pip3.</p> <p><code>pip3</code> is working, but <code>sudo pip3</code> throws <code...
-3
2016-06-02T19:54:40Z
37,618,921
<p>Finally I've found solution:</p> <pre><code>sudo python3 -m pip install cherrypy </code></pre>
1
2016-06-03T16:03:31Z
[ "python", "amazon-ec2" ]
anacondo env couldn't import any of the packages
37,600,960
<p><strong>pip list inside conda env:</strong> pip list matplotlib (1.4.0) nose (1.3.7) numpy (1.9.1) pandas (0.15.2) pip (8.1.2) pyparsing (2.0.1) python-dateutil (2.4.1) pytz (2016.4) scikit-learn (0.15.2) scipy (0.14.0) setuptools (21.2.1) six (1.10.0) wheel (0.29.0)</p> <p><strong>which python:</strong></p> <p>/U...
0
2016-06-02T19:54:48Z
37,614,696
<p>Finally, I figured out the answer. It is all about the PATH variable. It was pointing to os python rather than anaconda python. Thanks all for your time.</p>
0
2016-06-03T12:42:34Z
[ "python", "python-3.x", "anaconda", "conda" ]
Matplotlib Histogram not showing graph properly
37,601,014
<p>I have a list of timestamp in this format: datetime.datetime(2016, 5, 10, 6, 54, 46, 535000) for a day. </p> <p>I want to create a histogram for every 15mins in the day i.e.e 00:00-00:15, 00:15-00:30,00:30-00:45 etc. In all there will be 96 bins (24 hrs*4 bins). </p> <p>This is my code:</p> <pre><code>plt.figure(...
0
2016-06-02T19:57:40Z
37,610,465
<p>By default, <code>hist</code> scales the bins' range to the minimum and maximum of your data. According to <a href="http://matplotlib.org/1.2.1/api/pyplot_api.html#matplotlib.pyplot.hist" rel="nofollow">the hist API</a>, you can change this by passing in a <code>range</code> keyword argument, e.g., <code>range=[begi...
0
2016-06-03T09:15:59Z
[ "python", "datetime", "matplotlib" ]
Pandas conditional cumulative sum
37,601,017
<p>I'm working with data that has null values in between. I intend to construct a time-series plot out of cumulative sum of a particular column <code>sales</code>. Conditions for cumulative sum on <code>sales</code>: (1.) if first row is null, <code>fillna(0)</code>, then <code>cumsum()</code> so plot can always start ...
1
2016-06-02T19:57:44Z
37,601,362
<p>So I figured it'd be best to change data in dictionary before you make dataframe. Most optimal way to do this is to traverse list in reverse order ignoring all <code>None</code> values until first numerical value is met. After that point all <code>None</code> values should be changed to <code>0</code>.</p> <p>This ...
1
2016-06-02T20:18:41Z
[ "python", "pandas" ]
Pandas conditional cumulative sum
37,601,017
<p>I'm working with data that has null values in between. I intend to construct a time-series plot out of cumulative sum of a particular column <code>sales</code>. Conditions for cumulative sum on <code>sales</code>: (1.) if first row is null, <code>fillna(0)</code>, then <code>cumsum()</code> so plot can always start ...
1
2016-06-02T19:57:44Z
37,602,684
<p><strong>UPDATE:</strong> <em>Could you please give an example how to implement your solution as function?</em></p> <pre><code>def set_col_last_valid(df, col, new_col): df.loc[(df.index &lt;= df[col].last_valid_index()) &amp; (pd.isnull(df[col])), col] = 0 df[new_col] = df[col].cumsum() return df In [17...
1
2016-06-02T21:47:06Z
[ "python", "pandas" ]
Pandas conditional cumulative sum
37,601,017
<p>I'm working with data that has null values in between. I intend to construct a time-series plot out of cumulative sum of a particular column <code>sales</code>. Conditions for cumulative sum on <code>sales</code>: (1.) if first row is null, <code>fillna(0)</code>, then <code>cumsum()</code> so plot can always start ...
1
2016-06-02T19:57:44Z
37,603,422
<p>We're going to use a combination of <code>bfill</code> and <code>combine_first</code>. As we backfill the sales column, we fill in any missing values that are followed by non-missing data, thus satisfying condition (2). However, I use this only to identify those positions that <strong>do</strong> satisfy condition...
2
2016-06-02T22:56:03Z
[ "python", "pandas" ]
Python: select a line if specific characters spaced by tab at end of line
37,601,072
<p>I am trying to find out how to best select specific lines from multiple txt files in Python. One way could be to use regex, but I have read that this would probably be a 'heavy' solution for a simpler selection process of lines. Another possibility may be string.split() but it seems that I would have to split all li...
0
2016-06-02T20:01:30Z
37,601,161
<p><code>endswith</code> is enough to solve your selection problem:</p> <p><code>\t</code> is a nice way to represent a <code>tab</code> in a python string:</p> <pre><code>&gt;&gt;&gt; print('a\ta\t') a a </code></pre> <p>And <code>endswith</code> match it nicely:</p> <pre><code>&gt;&gt;&gt; print('foob...
2
2016-06-02T20:06:48Z
[ "python", "regex", "python-2.7" ]
Sort arbitrary values given from command line
37,601,218
<p>I need to be able to accept arbitrary values (ints, floats) in any order in the command line and then sort and print them. I can do it easily with just ints or just floats but I'm stuck on trying to read both. I have the args reading showing as <code>Namespace(floats=[6.5], integers=[5, 10, 8, 4])</code>. I need all...
0
2016-06-02T20:10:29Z
37,601,433
<p>In python you can access the arguments thanks to sys. Just do:</p> <pre><code>import sys print sys.argv </code></pre> <p>and it should show all the arguments in the right order, the fact is that you will have the file name in the argv list which is bad ! </p> <p>So you can remove it thanks to</p> <pre><code>num...
0
2016-06-02T20:22:44Z
[ "python", "sorting", "floating-point", "int" ]
Convert signed binary number into integer in Python
37,601,263
<ol> <li><p>I found out that in python, if you use <code>bin</code>:</p> <pre><code>&gt;&gt;&gt; bin(4) '0b100' &gt;&gt;&gt; bin(-4) '-0b100' </code></pre></li> <li><p>but if you try this: </p> <pre><code>-4 &gt;&gt; 8 =&gt; -1 </code></pre></li> </ol> <p>in fact, when right shift more than 3 bits, the answer is ...
1
2016-06-02T20:12:39Z
37,601,468
<p>Bit manipulation on Python are easily done with <a href="https://docs.python.org/3/library/stdtypes.html#int.from_bytes" rel="nofollow">int.from_bytes</a> and <a href="https://docs.python.org/3/library/stdtypes.html#int.to_bytes" rel="nofollow">int.to_bytes</a>.</p> <p>On the other hand, solving the "find the value...
3
2016-06-02T20:24:42Z
[ "python", "bit-manipulation" ]
multi-stage dialogue with Telegram bot
37,601,272
<p>I'm new in programming and I would like to write bot for Telegram. I need to pass arguments to several reports. In telegram it should look like this:</p> <pre><code>`$user -&gt;&gt; "/work" $bot -&gt;&gt; Input your name $user -&gt;&gt; &lt;Name&gt; $bot -&gt;&gt; Input your code $user -&gt;&gt; &lt;code&gt; ....
-1
2016-06-02T20:13:05Z
37,602,323
<p>In order to implement an state machine you should keep track of your state either in your client or server. This can be achieved by using a persistent or temporary data storage. For instance you can keep track of your procedure for each user in a simple database on the server, your states can be defined in a list li...
0
2016-06-02T21:20:46Z
[ "python", "state-machines", "telegram-bot" ]
Text clustering using arbitrary metrics with sklearn kmeans
37,601,294
<p>I'm running text clustering on a table that contains medical terms, I want to cluster strings that have similar words, if two have have two words or more, should be included in one cluster more likely than if they only have one word in common.</p> <p>I tried many techniques and I'm not getting any efficient results...
2
2016-06-02T20:14:37Z
37,622,697
<p>k-means is based on <strong>variance minimization</strong>.</p> <p>It minimizes the <strong>sum of squared deviations</strong>, <code>(x[i]-center[i])**2</code> for every object <code>x</code>, the dimensions <code>i</code> and the optimum (smallest cost) center <code>center</code>. It <em>cannot</em> minimize arbi...
0
2016-06-03T20:16:01Z
[ "python", "cluster-analysis", "k-means", "cosine-similarity" ]
Light a LED with a Raspberry Pi when a call is made to a web service (Flask, python)
37,601,342
<p>Each time a call is made on a web service on our backend, I want to blink a LED.</p> <p>It's working, but only for few hours, after that, it just stops working.</p> <p>Each time we post on this URL (<a href="http://IP_ADRESS:PORT/scan">http://IP_ADRESS:PORT/scan</a>), our LED is blinking. </p> <p>I'm wondering wh...
1
2016-06-02T20:17:37Z
37,622,763
<p>Found the bug!</p> <p>The problem is in the <code>rainbow()</code> function.</p> <p>This function is called severals time, and at a certain time, it stops working.</p> <p>Here is what the function do:</p> <pre><code>def rainbow(): RED, GREEN, BLUE = initializeGPIO() # setup the GPIO, outputs, and PWM #...
0
2016-06-03T20:22:35Z
[ "python", "flask", "raspberry-pi", "webserver", "crontab" ]
Arraylist of Arrays with Java Stream
37,601,428
<p>i got a method which returns a ArrayList with Arrays, like this inside:</p> <pre><code>{1,2,3}, {4,5,6}, {7,8,9}.... public int[] simulatePlays(BitBoard board, int number){ int[] count = {0,0,0}; while (number &gt; 0){ BitBoard b = new BitBoard(board); count[playRandomly(b)+1] += 1; ...
-1
2016-06-02T20:22:36Z
37,602,385
<p>when you want to use Stream you can do it like this.</p> <pre><code>ArrayList&lt;Integer&gt; values = new ArrayList&lt;&gt;(Arrays.asList(new Integer[]{1,2,3})); int valueindex = values.indexOf(values.get(2));//to get the index // Integer v = values.get(2); Integer s = values.stream().reduce((a,b)-&gt; b...
0
2016-06-02T21:24:57Z
[ "java", "python", "arrays", "arraylist", "java-stream" ]
Arraylist of Arrays with Java Stream
37,601,428
<p>i got a method which returns a ArrayList with Arrays, like this inside:</p> <pre><code>{1,2,3}, {4,5,6}, {7,8,9}.... public int[] simulatePlays(BitBoard board, int number){ int[] count = {0,0,0}; while (number &gt; 0){ BitBoard b = new BitBoard(board); count[playRandomly(b)+1] += 1; ...
-1
2016-06-02T20:22:36Z
37,602,571
<p>Due to nature of java streams it is not possible to retrieve element index from source. For example, you could use <code>parallelStream()</code> instead of <code>stream</code> and due to source would be splitted by <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Spliterator.html" rel="nofollow">Splitera...
1
2016-06-02T21:39:17Z
[ "java", "python", "arrays", "arraylist", "java-stream" ]
Filter Data Frame by dates in another dataframe
37,601,460
<p>I have a dataframe <code>query2</code>:</p> <pre><code> Site TripDate Volume 0 003l 1990-06-10 2202.571850 1 003l 1991-07-26 2543.566201 2 003l 1991-11-01 1702.228651 3 003l 1992-10-15 2753.163510 4 003l 1993-04-01 2550.538237 5 003l 1993-10-08 2241.329021 </code></pre> <p>And another ...
3
2016-06-02T20:24:16Z
37,601,601
<p>You're looking for <a href="http://pandas.pydata.org/pandas-docs/stable/merging.html#database-style-dataframe-joining-merging" rel="nofollow">merge</a>:</p> <pre><code>In [11]: t1.merge(q2) Out[11]: TripDate Count Site Volume 0 1990-06-10 35 003l 2202.571850 1 1991-07-26 35 003l 2543.5662...
4
2016-06-02T20:33:43Z
[ "python", "pandas", "filter", "dataframe" ]
pip install lxml error with x86_64
37,601,583
<p>I have Redhat CEL6 running on the x86_64 box. I am trying to install "lxml" and keep on getting the following error. Tried installing all dependent packages and dev packages but still couldn't get a way to resolve this.</p> <p>I tried re-installing gcc which didn't help either.</p> <p>Any thoughts here ? Here is t...
0
2016-06-02T20:32:53Z
37,601,596
<p>You will need to install all the development libraries, but in this case it looks like you are trying to compile the 32bit version of the library, as you most likely have the 32bit version of Python installed.</p> <pre><code>sudo yum install zlib-devel.i686 libxslt.i686 libxml2-devel.i686 libxslt-devel.i686 python...
0
2016-06-02T20:33:35Z
[ "python", "pip", "lxml" ]
pip install lxml error with x86_64
37,601,583
<p>I have Redhat CEL6 running on the x86_64 box. I am trying to install "lxml" and keep on getting the following error. Tried installing all dependent packages and dev packages but still couldn't get a way to resolve this.</p> <p>I tried re-installing gcc which didn't help either.</p> <p>Any thoughts here ? Here is t...
0
2016-06-02T20:32:53Z
39,827,607
<p>I faced similar problem (but 64bit issue) on my RH5.7. Your problem is 32bit lxml on your Linux.</p> <p>@eandersson 's advice is useful , I think.</p> <p>Can you check following command?</p> <ol> <li>find /usr/lib* -name libxslt.so</li> <li>yum list installed libxslt libxslt-devel libxml2 libxml2-devel</li> </ol...
0
2016-10-03T08:44:23Z
[ "python", "pip", "lxml" ]
How to have multiple text colors within the same paragraph in ReportLab?
37,601,615
<p>I would like to create a paragraph as follows:</p> <pre><code>step = str(StepNumber) #StepNumber is an int if flag == True: color = "green" sv = "[S]" else: color = "red" sv = "[V]" P = Paragraph('&lt;font color = "black&gt;step&lt;/font&gt;' + '&lt;font color = color&gt;sv&lt;/font&gt;', styl...
0
2016-06-02T20:34:45Z
37,607,747
<p>The reason it is printed as XML is because you supply exactly that. So we have to format the string correctly as follows:</p> <pre><code>step = str(StepNumber) # StepNumber is an int if flag: color = "green" sv = "[S]" else: color = "red" sv = "[V]" P = Paragraph('&lt;font color="black"&gt;{step}...
1
2016-06-03T06:50:09Z
[ "python", "xml", "reportlab" ]
Pandas Dataframe duplicate records picking up incorrect records
37,601,668
<p>I am using Pandas, Jupyter Notebooks and Python. I have a dataset with with 4 columns and 10000 records. Currently when I use the following code to pick up duplicates, somehow the code is picking up incorrect records. FYI: the datatype of the columns are as follow:</p> <pre><code>Initial_Date = int64 Final_Date = i...
2
2016-06-02T20:37:13Z
37,601,751
<p>pay attention at the <code>keep</code> parameter:</p> <pre><code>In [116]: s = pd.Series([1,1,1,2,3]) In [117]: s Out[117]: 0 1 1 1 2 1 3 2 4 3 dtype: int64 In [118]: s.duplicated(keep='first') Out[118]: 0 False 1 True 2 True 3 False 4 False dtype: bool In [119]: s.duplicated(keep...
3
2016-06-02T20:41:36Z
[ "python", "pandas", "dataframe", "duplicates", "jupyter" ]
"TypeError: string argument without an encoding", but the string is encoded?
37,601,804
<p>I am working on converting an <a href="https://github.com/kabniel/last2libre/blob/master/scrobble.py#L34" rel="nofollow">existing program</a> from Python2 to Python3. One of the methods in the program authenticates the user with a remote server. It will prompt the user to enter in a password.</p> <pre><code>def _ha...
1
2016-06-02T20:46:00Z
37,601,966
<p>This error is due to how you create bytes in python 3. </p> <p>You will not do <code>bytes("bla bla")</code> but just <code>b"blabla"</code> or you need to specify and encoding type like <code>bytes("bla bla","utf-8")</code> because it needs to know what was the original encoding before turning it into an array of ...
0
2016-06-02T20:56:49Z
[ "python", "string", "python-3.x", "encoding", "utf-8" ]
How to count the matches between two files in python?
37,601,825
<p>i'm new using python and the question is that i dont know where i can start to solve the following issue</p> <p>i have 3 files</p> <p>1 file contains something like that :</p> <pre><code>pm_rpm@fences pm_rpm@fences-dpms pm_rpm@modeset-lpsp-stress pm_rpm@modeset-non-lpsp-stress pm_rpm@modeset-lpsp-stress-no-wait p...
0
2016-06-02T20:47:14Z
37,603,917
<p>Here is a very dumb solution to do this using python2.7:</p> <pre><code>import re def findCommon(a,b): allmatches=[] for test in b: if "*" in test or "?" in test: reg=re.compile(test) matches=[line for line in a for m in [reg.search(line)] if m] else: mat...
0
2016-06-02T23:52:58Z
[ "python" ]
How to count the matches between two files in python?
37,601,825
<p>i'm new using python and the question is that i dont know where i can start to solve the following issue</p> <p>i have 3 files</p> <p>1 file contains something like that :</p> <pre><code>pm_rpm@fences pm_rpm@fences-dpms pm_rpm@modeset-lpsp-stress pm_rpm@modeset-non-lpsp-stress pm_rpm@modeset-lpsp-stress-no-wait p...
0
2016-06-02T20:47:14Z
37,611,127
<p>I've written these programs using python 3, the fist only includes the tests after the '@' symbol, the second includes the whole test name:</p> <pre><code>file1=open("file1.txt") file2=open("file2.txt") file3=open("file3.txt") f1=file1.read().split("\n") f2=file2.read().split("\n") f3=file3.read().split("\n") file1...
2
2016-06-03T09:49:39Z
[ "python" ]
unclear python data structure and parse python
37,601,973
<p>I have a small dataset that i'm using to get the global alignment results with BioPython's pairwise2 module. I have gotten so far to get the alignment and score results, and <strong>now i have questions about the structure of the results and how i can parse them</strong></p> <p>below is my code:</p> <pre><code>imp...
0
2016-06-02T20:57:01Z
37,602,072
<p>In your case you have a list of tuples.</p> <p>To access to the first element of each list you can just do: </p> <pre><code>list[0] </code></pre> <p>Because the list contains tuples it will return the complete tuple. </p> <p>Then once you get your tuple you can take the first two values as:</p> <pre><code>seq0 ...
1
2016-06-02T21:03:50Z
[ "python", "biopython" ]
unclear python data structure and parse python
37,601,973
<p>I have a small dataset that i'm using to get the global alignment results with BioPython's pairwise2 module. I have gotten so far to get the alignment and score results, and <strong>now i have questions about the structure of the results and how i can parse them</strong></p> <p>below is my code:</p> <pre><code>imp...
0
2016-06-02T20:57:01Z
37,602,112
<p>Look like a <code>list</code> <em>[]</em> of <code>tuples</code> <em>()</em>.</p> <p>If you're sure you want to keep the first, keep the first:</p> <pre><code>sequences = [] for seq0 in df.CD: alns = pairwise2.align.globalms(seq, seq0, match, mismatch, gap_open, gap_extend) sequences.append(alns[0]) </...
1
2016-06-02T21:06:57Z
[ "python", "biopython" ]
unclear python data structure and parse python
37,601,973
<p>I have a small dataset that i'm using to get the global alignment results with BioPython's pairwise2 module. I have gotten so far to get the alignment and score results, and <strong>now i have questions about the structure of the results and how i can parse them</strong></p> <p>below is my code:</p> <pre><code>imp...
0
2016-06-02T20:57:01Z
37,602,163
<p>It looks to me that they are lists of tuples. </p> <p>[] means list </p> <p>() means tuple (read-only list)</p> <p>The simpliest way to achieve what you are asking for is to index the items out of the list like so:</p> <pre><code># Renamed seq0 so it doesn't interfere with below variable for sequence0 in df.CD: ...
2
2016-06-02T21:10:36Z
[ "python", "biopython" ]
unclear python data structure and parse python
37,601,973
<p>I have a small dataset that i'm using to get the global alignment results with BioPython's pairwise2 module. I have gotten so far to get the alignment and score results, and <strong>now i have questions about the structure of the results and how i can parse them</strong></p> <p>below is my code:</p> <pre><code>imp...
0
2016-06-02T20:57:01Z
37,602,320
<p>If you really want them stored in variables named <code>seq0</code>and <code>seq1</code>(and we ignore the invalid sample display of the <code>alns</code> content / output from your program in the question:</p> <pre><code>#! /usr/bin/env python from __future__ import print_function alns_seq = ( [('GCACGCATAAGT...
1
2016-06-02T21:20:38Z
[ "python", "biopython" ]
How to populate choice form from db in Django?
37,601,979
<p>I can't figure out how to populate <code>choice form</code> from <code>db</code>. I know about <code>ModelChoiceForm</code> but the problem seems to be slightly different. </p> <p>I want <code>user</code> to choose which sector does he work in. For example: 'Finance','Electronics' etc. which I would do simple:</p> ...
0
2016-06-02T20:57:27Z
37,602,761
<p>I would just override the delete_model as custom action and there check if the selected sector object is in use. </p> <pre><code>def delete_model(modeladmin, request, queryset): for obj in queryset: if UserModel.objects.filter(sector=obj).exists(): # do not delete, just add some message warn...
1
2016-06-02T21:51:07Z
[ "python", "django", "django-models" ]
index confusing with python and matplotlib
37,602,142
<p>It's so confusing with the index of python and matplotlib.</p> <pre><code>import matplotlib as plt </code></pre> <p>I read an image I where I is an matrix. First, I used <code>plt.imshow()</code> to show the image. </p> <p>There is a line on that image and I have the x- and y- coordinates of a line <code>L: x=[x0...
0
2016-06-02T21:09:00Z
37,602,308
<blockquote> <p>So, first question, which should I use, <code>I[x,y]</code> or <code>I[y,x]</code>?</p> </blockquote> <p>Always use <code>I[x,y]</code>. This notation is standard in all computational libraries and branches of math. </p> <p><code>plt.plot(x,y)</code> expects a sequence. I believe, <code>I[a,b]</code...
0
2016-06-02T21:19:40Z
[ "python", "matplotlib", "plot" ]
index confusing with python and matplotlib
37,602,142
<p>It's so confusing with the index of python and matplotlib.</p> <pre><code>import matplotlib as plt </code></pre> <p>I read an image I where I is an matrix. First, I used <code>plt.imshow()</code> to show the image. </p> <p>There is a line on that image and I have the x- and y- coordinates of a line <code>L: x=[x0...
0
2016-06-02T21:09:00Z
37,607,656
<p>As you have probably guessed, there are two conventions at work here.</p> <p>First, there is the mathematical convention of coordinates in graphs, where <code>(x,y) = (0,0)</code> is at the <strong>lower</strong> left corner:</p> <p><a href="http://i.stack.imgur.com/OcLc4.png" rel="nofollow"><img src="http://i.sta...
0
2016-06-03T06:45:29Z
[ "python", "matplotlib", "plot" ]
Changing Python indentation amount in Emacs
37,602,217
<p>Because I have </p> <pre><code>(setq python-indent-offset 4) </code></pre> <p>in my .emacs, when I start with code such as </p> <pre><code>def fn(): foo = bar() if bar1 == bar2: if blah1 == blah2: return yay </code></pre> <p>and mark-whole-buffer (C-x h) followed by indent-region (C-M-\ ), I am exp...
3
2016-06-02T21:13:56Z
37,618,719
<p>I'm not sure if this is a perfect solution and as such I would not want to push this as a patch to emacs-devel but since the issue is in <code>python-indent-region</code> (I left a note about this as a comment). We can try to redefine that function as such:</p> <pre><code>(defun python-indent-region (start end) "...
1
2016-06-03T15:52:12Z
[ "python", "emacs" ]
Changing Python indentation amount in Emacs
37,602,217
<p>Because I have </p> <pre><code>(setq python-indent-offset 4) </code></pre> <p>in my .emacs, when I start with code such as </p> <pre><code>def fn(): foo = bar() if bar1 == bar2: if blah1 == blah2: return yay </code></pre> <p>and mark-whole-buffer (C-x h) followed by indent-region (C-M-\ ), I am exp...
3
2016-06-02T21:13:56Z
37,624,975
<p>Alternatively you can call the python package from within emacs and have it replace the buffer.</p> <pre><code>(defun my-py-reindent () "Reindent the current file with pypi's reindent." (interactive) (shell-command-to-string (format "reindent %s" (buffer-file-name))) (revert-...
0
2016-06-03T23:50:10Z
[ "python", "emacs" ]
Drop duplicates in pandas time series dataframe
37,602,233
<p>I have time series data in a data frame that looks like this:</p> <pre><code>Index Time Value_A Value_B 0 1 A A 1 2 A A 2 2 B A 3 3 A A 4 5 A A </code></pre> <p>I want to drop duplicate in the Value_A and Value_B columns such that duplicates are only...
3
2016-06-02T21:14:49Z
37,602,345
<p>The usual trick to detect contiguous groups is to compare something with a shifted version of itself. For example:</p> <pre><code>In [137]: cols = ["Value_A", "Value_B"] In [138]: df[~(df[cols] == df[cols].shift()).all(axis=1)] Out[138]: Time Value_A Value_B Index 0 1 A...
9
2016-06-02T21:22:20Z
[ "python", "pandas", "dataframe", "time-series" ]
In C/C++ extensions to Python, what reference count should a returned PyObject* have?
37,602,307
<p>Lets say you wrote a C++ (or C) extension to python, called <code>module</code>. It returns an array of arrays. What should the returned array, and its arrays, have as reference counts?</p> <p>The python code would be something like</p> <pre><code>import my_module from sys import getrefcount as g # will use ...
0
2016-06-02T21:19:38Z
37,602,498
<p>If no other references to the returned object exist, the refcount should be 1. If the refcount were 0, the object would get deallocated.</p>
0
2016-06-02T21:33:52Z
[ "python", "c++", "c", "reference-counting", "python-c-extension" ]
python - call a function from a list item
37,602,337
<p>I want to call a function named in the dictionary depending on the key called.</p> <p>Example:</p> <pre><code>start_options = {'left': 'octopus', 'right': 'lion', 'small': 'pit', 'small door': 'pit'} choice = raw_input("What do you want to do? ").lower() if choice in dictionary: print "found: ...
1
2016-06-02T21:21:38Z
37,602,396
<p>If you define the functions beforehand, you can then refer to them directly in your dictionary as opposed to string representations:</p> <pre><code>def yada(): print("Yada!") def blah(): print("Blah!") start_options = {'test1': yada, 'test2': blah} start_options['test1']() </code></pre> <p>Running this c...
2
2016-06-02T21:25:34Z
[ "python" ]
Sum Each Column of CSV file
37,602,344
<p>I have a large CSV file with 32 column headers. I'd like to sum up each column and the result be 32 individual summations of each column header. I have access to both python and powershell. Any help would be appreciated.</p> <p>The furthest I got was this site: <a href="http://stackoverflow.com/questions/33542977/p...
0
2016-06-02T21:22:19Z
37,602,539
<p>You can use <code>read_csv</code> in pandas to read the file, and then just use <code>sum()</code> on the dataframe.</p> <pre><code>import pandas as pd filename = r'folder/file.txt' df = pd.read_csv(filename) total = df.sum() </code></pre>
0
2016-06-02T21:37:22Z
[ "python", "powershell" ]
Sum Each Column of CSV file
37,602,344
<p>I have a large CSV file with 32 column headers. I'd like to sum up each column and the result be 32 individual summations of each column header. I have access to both python and powershell. Any help would be appreciated.</p> <p>The furthest I got was this site: <a href="http://stackoverflow.com/questions/33542977/p...
0
2016-06-02T21:22:19Z
37,602,715
<p>A simple way using only builtins on this sample data file:</p> <pre><code>#! /usr/bin/env python from __future__ import print_function sep = ';' with open('32_numeric_columns.csv', 'rt') as f: columns = f.readline().strip().split(sep) rows = [0] * len(columns) for line in f.readlines(): data = ...
0
2016-06-02T21:48:25Z
[ "python", "powershell" ]