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 |
|---|---|---|---|---|---|---|---|---|---|
Trying to understand recursion in Python | 37,442,445 | <p>I've been trying to understand the following code, it's a recursion example from my Python book:</p>
<pre><code>def mysum(L):
if not L:
return 0
else:
return L[0] + mysum(L[1:])
print(mysum([1, 2, 3, 4, 5]))
</code></pre>
<p><code>output: 15</code></p>
<p>I have a very hard time to under... | 1 | 2016-05-25T16:06:04Z | 37,442,649 | <p>Consider this code:</p>
<pre><code>def mysum0(L):
return 0
def mysum1(L):
return L[0] + mysum0(L[1:])
def mysum2(L):
return L[0] + mysum1(L[1:])
def mysum3(L):
return L[0] + mysum2(L[1:])
def mysum4(L):
return L[0] + mysum3(L[1:])
print(mysum4([1, 2, 3, 4]))
</code></pre>
<p>Each function ... | 0 | 2016-05-25T16:15:33Z | [
"python",
"python-2.7",
"python-3.x"
] |
Trying to understand recursion in Python | 37,442,445 | <p>I've been trying to understand the following code, it's a recursion example from my Python book:</p>
<pre><code>def mysum(L):
if not L:
return 0
else:
return L[0] + mysum(L[1:])
print(mysum([1, 2, 3, 4, 5]))
</code></pre>
<p><code>output: 15</code></p>
<p>I have a very hard time to under... | 1 | 2016-05-25T16:06:04Z | 37,442,693 | <p><code>L[0]</code> is the head of the list and <code>L[1:]</code> is the rest. In each call the function adds the first element and the sum of the remaining list.</p>
<p>So what is happening is:</p>
<pre><code>mysum([1, 2, 3, 4, 5]) => 1 + mysum([2, 3, 4, 5])
mysum([1, 2, 3, 4, 5]) => 2 + mysum([3, 4, 5])
mys... | 2 | 2016-05-25T16:17:47Z | [
"python",
"python-2.7",
"python-3.x"
] |
Trying to understand recursion in Python | 37,442,445 | <p>I've been trying to understand the following code, it's a recursion example from my Python book:</p>
<pre><code>def mysum(L):
if not L:
return 0
else:
return L[0] + mysum(L[1:])
print(mysum([1, 2, 3, 4, 5]))
</code></pre>
<p><code>output: 15</code></p>
<p>I have a very hard time to under... | 1 | 2016-05-25T16:06:04Z | 37,442,723 | <p>You can test the hypothetical question you raised: What happens when the recursion gets to the point that the list has only one element in it?</p>
<pre><code>>>>print(mysum([5]))
</code></pre>
<p>returns:</p>
<pre><code>5
</code></pre>
<p>Because it executes:</p>
<pre><code>return L[0] + mysum(L[1:])
<... | 0 | 2016-05-25T16:18:53Z | [
"python",
"python-2.7",
"python-3.x"
] |
Trying to understand recursion in Python | 37,442,445 | <p>I've been trying to understand the following code, it's a recursion example from my Python book:</p>
<pre><code>def mysum(L):
if not L:
return 0
else:
return L[0] + mysum(L[1:])
print(mysum([1, 2, 3, 4, 5]))
</code></pre>
<p><code>output: 15</code></p>
<p>I have a very hard time to under... | 1 | 2016-05-25T16:06:04Z | 37,442,836 | <blockquote>
<p>it's like it starts to sum backwards.</p>
</blockquote>
<p>Well that's because it kind of does, this is an example of tail recursion which is not optimized in python, imagine replacing the <code>mysum(L[1:])</code> with the result in brackets, you would get something like this:</p>
<pre><code>#L[0] ... | 1 | 2016-05-25T16:24:17Z | [
"python",
"python-2.7",
"python-3.x"
] |
Implementing Client- Sever model using Go and Python on Windows OS | 37,442,476 | <p>I am working on an GUI application, the UI is developed using python(+kivy) and the core is implemented using GoLang.</p>
<p>My Application involves passing data from UI to Core, for which i am using pipes. Following is the snippet of Client and Server code. </p>
<p>Client.py:</p>
<pre><code>p = win32pipe.CreateN... | 2 | 2016-05-25T16:07:59Z | 37,484,655 | <p>i Could not find a solution using pipes, so i moved to sockets and i am able to communicate via sockets. Following is the snippets of the codes</p>
<p><strong>Client.py</strong></p>
<pre><code>import socket
import struct
# create a socket object
requestCore = socket.socket(
socket.AF_INET, socket.... | 2 | 2016-05-27T13:23:30Z | [
"python",
"go",
"client-server",
"named-pipes"
] |
Is it ok having both Anacondas 2.7 and 3.5 installed in the same time? | 37,442,494 | <p>I am using currently Anaconda with Python 2.7, but I will need to use Python 3.5. Is it ok to have them installed both in the same time? Should I expect some problems?<br>
I am on a 64-bit Win8. If any other info are needed just tell me, thanks in advance! </p>
| 4 | 2016-05-25T16:08:38Z | 37,442,560 | <p>My understanding is you don't need to install Anaconda again to start using a different version of python. Instead, conda has the <a href="http://conda.pydata.org/docs/py2or3.html" rel="nofollow">ability to separately manage python 2 and 3 environments</a>.</p>
| 2 | 2016-05-25T16:11:16Z | [
"python",
"anaconda"
] |
Is it ok having both Anacondas 2.7 and 3.5 installed in the same time? | 37,442,494 | <p>I am using currently Anaconda with Python 2.7, but I will need to use Python 3.5. Is it ok to have them installed both in the same time? Should I expect some problems?<br>
I am on a 64-bit Win8. If any other info are needed just tell me, thanks in advance! </p>
| 4 | 2016-05-25T16:08:38Z | 37,442,783 | <p>Yes, It should be alright to have both versions installed. It's actually pretty much expected nowadays. A lot of stuff is written in 2.7, but 3.5 is becoming the norm. I would recommend updating all your python to 3.5 ASAP, though.</p>
| 0 | 2016-05-25T16:21:37Z | [
"python",
"anaconda"
] |
Is it ok having both Anacondas 2.7 and 3.5 installed in the same time? | 37,442,494 | <p>I am using currently Anaconda with Python 2.7, but I will need to use Python 3.5. Is it ok to have them installed both in the same time? Should I expect some problems?<br>
I am on a 64-bit Win8. If any other info are needed just tell me, thanks in advance! </p>
| 4 | 2016-05-25T16:08:38Z | 37,442,942 | <p>I use both depending on who in my department I am helping (Some people prefer 2.7, others 3.5). Anyway, I use the <a href="https://www.continuum.io/downloads" rel="nofollow">Anaconda</a> and my default installation is 3.5. I use environments for other versions of python, packages, etc.. So for example, when I wanted... | 0 | 2016-05-25T16:29:09Z | [
"python",
"anaconda"
] |
Cygwin python installing certificates | 37,442,517 | <p>I am trying to run a script to install pip, and I get:</p>
<pre><code> $ python get-pip.py
Collecting pip
Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [X509] PEM lib (_ssl.c:2825) - skipping
Could not find a version that satisfies the requiremen... | 0 | 2016-05-25T16:09:47Z | 37,528,470 | <p>I was able to install everything in cygwin using answers from the link posted by matzeri with minimal effort:</p>
<p><a href="http://stackoverflow.com/questions/36901613/can-jupyter-notebooks-bash-kernel-b">Can Jupyter notebook's bash_kernel be installed in a windows 7 OS</a>ââ%E2%80%8C%E2%80%8Be-installed-... | 0 | 2016-05-30T14:46:50Z | [
"python",
"ssl",
"cygwin",
"pip"
] |
Name assignment and reuse in python namespace | 37,442,541 | <p>I am currently trying to figure out the internals of mappingproxies and namespaces in python. While testing a bit, I came accross some behavior I did not expect.</p>
<p>I define a class, instantiate it, define another one under the same name and instantiate that one.</p>
<pre><code>class A:
color = 'white'
... | 2 | 2016-05-25T16:10:27Z | 37,442,995 | <p>There is something called multimethods in Python, and the basic idea is that multiple functions can have the same name but are different functions.</p>
<p>I'm not sure if it has any relation to multiple classes of the same name though.</p>
<p>A short blog about it:
<a href="https://alexgaynor.net/2010/jun/26/multi... | -4 | 2016-05-25T16:32:54Z | [
"python",
"python-3.x",
"namespaces"
] |
Name assignment and reuse in python namespace | 37,442,541 | <p>I am currently trying to figure out the internals of mappingproxies and namespaces in python. While testing a bit, I came accross some behavior I did not expect.</p>
<p>I define a class, instantiate it, define another one under the same name and instantiate that one.</p>
<pre><code>class A:
color = 'white'
... | 2 | 2016-05-25T16:10:27Z | 37,446,713 | <p><strong>Is this intended behavior?</strong></p>
<p>Yes.</p>
<p><strong>What is the reasoning behind it?</strong></p>
<p>As Daniel Roseman is getting at in the comments above, this is a specific case of the general rule that everything in Python is an object.</p>
<p>Consider the following code snippet:</p>
<pre>... | 1 | 2016-05-25T20:09:43Z | [
"python",
"python-3.x",
"namespaces"
] |
Python find not working | 37,442,653 | <p>Find in the following program does not seem to be working for '.', '!' and '?' characters. Can someone help me figure out the error.</p>
<p>I've tried the following things:</p>
<p>a. Putting a backslash in the search criteria</p>
<p>b. Putting two backslashes in the search criteria.</p>
<p>If you look at the res... | -4 | 2016-05-25T16:15:44Z | 37,442,930 | <blockquote>
<p><code>find(...)</code></p>
<pre><code>S.find(sub [,start [,end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
</code></pre>
</blockq... | 2 | 2016-05-25T16:28:35Z | [
"python"
] |
How to split list of lists based on the repetitivity of the value of the lists? | 37,442,892 | <p>Let's say I have a list of lists in this format that represents coordinates:</p>
<pre><code>[['1', '1'],
['2', '2'],
['3', '3'],
['1', '1'],
['5', '5'],
['6', '6'],
['7', '7'],
['5', '5'],
['8', '8'],
['9', '9'],
['10', '10'],
['8', '8']]
</code></pre>
<p>I want to split this list of lists in... | 1 | 2016-05-25T16:26:50Z | 37,443,379 | <p>Try this:</p>
<pre><code>t = [['1', '1'],
['2', '2'],
['3', '3'],
['1', '1'],
['5', '5'],
['6', '6'],
['7', '7'],
['5', '5'],
['8', '8'],
['9', '9'],
['10', '10'],
['8', '8']]
ix = 0
tmp = []
while ix < len(t):
tmp.append(t[ix:t.index(t[ix], ix+1)+1])
ix = t.index(t[ix], ix+1) + 1
... | 1 | 2016-05-25T16:56:27Z | [
"python",
"list"
] |
How to split list of lists based on the repetitivity of the value of the lists? | 37,442,892 | <p>Let's say I have a list of lists in this format that represents coordinates:</p>
<pre><code>[['1', '1'],
['2', '2'],
['3', '3'],
['1', '1'],
['5', '5'],
['6', '6'],
['7', '7'],
['5', '5'],
['8', '8'],
['9', '9'],
['10', '10'],
['8', '8']]
</code></pre>
<p>I want to split this list of lists in... | 1 | 2016-05-25T16:26:50Z | 37,443,438 | <p>You could do this:</p>
<pre><code>first = []
all_lists = []
j = 0
for i, item in enumerate(a):
if first == []:
first = a[i]
print(first)
elif first == a[i]:
all_lists.append(a[j:i+1])
j = i + 1
first = []
print(all_lists)
</code></pre>
<p>Its similar to your first at... | 1 | 2016-05-25T16:59:20Z | [
"python",
"list"
] |
How to split list of lists based on the repetitivity of the value of the lists? | 37,442,892 | <p>Let's say I have a list of lists in this format that represents coordinates:</p>
<pre><code>[['1', '1'],
['2', '2'],
['3', '3'],
['1', '1'],
['5', '5'],
['6', '6'],
['7', '7'],
['5', '5'],
['8', '8'],
['9', '9'],
['10', '10'],
['8', '8']]
</code></pre>
<p>I want to split this list of lists in... | 1 | 2016-05-25T16:26:50Z | 37,443,556 | <p><code>list.index()</code> gives the index of element where the element first occurs in the list </p>
<pre><code>temp =[]
while True:
try:
idx = list[1:].index(list[0])
except ValueError:
temp.append(list)
break
if idx == len(list)-2:
temp.append(list)
break
te... | 0 | 2016-05-25T17:05:34Z | [
"python",
"list"
] |
Scrapy: AttributeError: 'list' object has no attribute 'iteritems' | 37,442,907 | <p>This is my first question on stack overflow. Recently I want to use <a href="https://github.com/junks/linkedInScraper">linked-in-scraper</a>, so I downloaded and instruct "scrapy crawl linkedin.com" and get the below error message. For your information, I use anaconda 2.3.0 and python 2.7.11. All the related package... | 5 | 2016-05-25T16:27:24Z | 37,469,195 | <p>This is caused by the linked-in scraper's <a href="https://github.com/junks/linkedInScraper/blob/master/linkedIn/linkedIn/settings.py#L23">settings</a>:</p>
<pre><code>ITEM_PIPELINES = ['linkedIn.pipelines.LinkedinPipeline']
</code></pre>
<p>However, <code>ITEM_PIPELINES</code> is supposed to be a link, <a href="h... | 8 | 2016-05-26T19:10:14Z | [
"python",
"scrapy-spider",
"six"
] |
Scrapy: AttributeError: 'list' object has no attribute 'iteritems' | 37,442,907 | <p>This is my first question on stack overflow. Recently I want to use <a href="https://github.com/junks/linkedInScraper">linked-in-scraper</a>, so I downloaded and instruct "scrapy crawl linkedin.com" and get the below error message. For your information, I use anaconda 2.3.0 and python 2.7.11. All the related package... | 5 | 2016-05-25T16:27:24Z | 39,538,212 | <p>The short answer is the ITEM_PIPELINES should be a dictionary not a list with the key as the pipeline class and value an integer that determines the order in which they run: items go through from lower valued to higher valued classes. Itâs customary to define these numbers in the 0-1000 range. as explained by @val... | 0 | 2016-09-16T18:43:14Z | [
"python",
"scrapy-spider",
"six"
] |
Why is python YouTube Reporting API retrieve reports returning 'No jobs found' even after successfully creating reports? | 37,442,925 | <pre><code>>PS C:\Documents\YouTube\Code> python YouTubeRetrieveReports.py
>No jobs found
>Retrieved reports.
</code></pre>
<p>This is the only thing I get when running the sample script against the YouTube Reporting API to retrieve the reports that I've been creating. The documentation for errors with the... | 0 | 2016-05-25T16:28:17Z | 37,464,011 | <p>To retrieve list of reports, you need to use the Method <a href="https://developers.google.com/youtube/reporting/v1/reference/rest/v1/jobs.reports/list#request" rel="nofollow"><code>jobs.reports.list</code></a>. This method will generate list of reports for the specified reporting job. </p>
<p><strong>HTTP request<... | 0 | 2016-05-26T14:39:36Z | [
"python",
"python-2.7",
"youtube-api",
"youtube-analytics-api"
] |
Python: Sub sequence search | 37,442,948 | <p>I have a sequence 'abccabac' and a subsequence 'abc'.
I need to get indices of all occurences of subsequence 'abc' in the sequence.
What is the memory efficient way of doing it? </p>
<h2><strong>Example:</strong></h2>
<h2>Input:</h2>
<pre><code>**sequence**: 'abccabac' **subsequence**: 'abc'
</code></pre>
<... | 0 | 2016-05-25T16:29:29Z | 37,443,276 | <p>the absolute most strait forward way I can think of is using <a href="https://docs.python.org/3/library/itertools.html#itertools.combinations" rel="nofollow"><code>itertools.combinations</code></a></p>
<pre><code>import itertools
sequence = "abccabac"
subsequence = "abc"
for combo in itertools.combinations(enume... | 2 | 2016-05-25T16:50:25Z | [
"python",
"sequence",
"sequences",
"subsequence"
] |
Adding items from one tkinter listbox to another | 37,442,974 | <p>I have two tkinter listboxes (parent and child) and two buttons (add_button and remove_button).
The child listbox gets items from the parent listbox via the add_button and there is an option of removing the items from
the child listbox via the remove_button.</p>
<p>My problem is that after the GUI is loaded and the... | 0 | 2016-05-25T16:31:50Z | 37,443,209 | <p>Why not replace <code>ACTIVE</code> by <code>curselection</code> - </p>
<pre><code>def add_name():
if len(parent.curselection()) != 0:
x = parent.get(parent.curselection())
child.insert(END, x)
else:
print "select an element first"
def remove_name():
if len(parent.curselection(... | 0 | 2016-05-25T16:46:24Z | [
"python",
"tkinter",
"listbox"
] |
Subprocess Hanging on Wait | 37,442,986 | <p>From the documentation of <code>Popen.wait()</code>, I see</p>
<blockquote>
<p>Warning This will deadlock when using stdout=PIPE and/or stderr=PIPE
and the child process generates enough output to a pipe such that it
blocks waiting for the OS pipe buffer to accept more data. Use
communicate() to avoid that.... | 0 | 2016-05-25T16:32:19Z | 37,557,915 | <p>The second command will not hang because the issue is not with a large amount of data on standard output, but a large amount of data on standard error.</p>
<p>In the former case, standard error is being redirected to standard output, which is being piped to your program. Hence, a large amount of data being produced... | 0 | 2016-06-01T01:07:55Z | [
"python",
"linux"
] |
Leading commas in python/pandas read_csv | 37,442,993 | <p>I have a csv file I wish to load into pandas, but the formatting is giving me some problems. The file is such:</p>
<blockquote>
<p>Version 1</p>
<p>,Date Time,Name,Value</p>
<p>,26/Jan/2016 07:35:52,Name1,340rqi</p>
<p>,26/Jan/2016 07:00:00,Name2,1.00E+005</p>
<p>,26/Jan/2016 07:00:00,Name3,pu... | 2 | 2016-05-25T16:32:51Z | 37,443,202 | <p>try this:</p>
<pre><code>In [313]: df = pd.read_csv('/path/to/file.csv', skiprows=1)
In [314]: df
Out[314]:
Unnamed: 0 Date Time Name Value
0 NaN 26/Jan/2016 07:35:52 Name1 340rqi
1 NaN 26/Jan/2016 07:00:00 Name2 1.00E+005
2 NaN 26/Jan/2016 07:00:00 Name3 ... | 0 | 2016-05-25T16:45:55Z | [
"python",
"csv",
"pandas",
"dataframe"
] |
Leading commas in python/pandas read_csv | 37,442,993 | <p>I have a csv file I wish to load into pandas, but the formatting is giving me some problems. The file is such:</p>
<blockquote>
<p>Version 1</p>
<p>,Date Time,Name,Value</p>
<p>,26/Jan/2016 07:35:52,Name1,340rqi</p>
<p>,26/Jan/2016 07:00:00,Name2,1.00E+005</p>
<p>,26/Jan/2016 07:00:00,Name3,pu... | 2 | 2016-05-25T16:32:51Z | 37,443,949 | <p>Update:</p>
<p>This can be fixed by not specifying the sheet name in the read_csv() command. Obvious 'duh' since the csv file does not have multiple sheets.</p>
| 0 | 2016-05-25T17:27:33Z | [
"python",
"csv",
"pandas",
"dataframe"
] |
Leading commas in python/pandas read_csv | 37,442,993 | <p>I have a csv file I wish to load into pandas, but the formatting is giving me some problems. The file is such:</p>
<blockquote>
<p>Version 1</p>
<p>,Date Time,Name,Value</p>
<p>,26/Jan/2016 07:35:52,Name1,340rqi</p>
<p>,26/Jan/2016 07:00:00,Name2,1.00E+005</p>
<p>,26/Jan/2016 07:00:00,Name3,pu... | 2 | 2016-05-25T16:32:51Z | 37,444,147 | <p>Supplying an alternative argument for the delimiter makes the ',' explicit. </p>
<pre><code>import pandas as pd
filename_cv = '123456789.csv'
sheet_cv = filename_cv[:-4] #trimming off the .csv part
df = pd.read_csv(filename_cv, sheet_cv, engine='python', skiprows=1, delimiter=',')
df = df.filter(regex='^((?!Un... | 0 | 2016-05-25T17:38:22Z | [
"python",
"csv",
"pandas",
"dataframe"
] |
Reading a large number of .csv files in Python pandas and assigning different variable names | 37,443,025 | <p>I have a number of csv files named file0001.csv to file0100.csv
I would like to read each one in turn and assign a variable name to it. I think the best way to do this would be as a loop.
The variable name here should be x1 with the data from file0001.csv inside it</p>
<p>For example:</p>
<pre><code>FileNumber=1
w... | 1 | 2016-05-25T16:35:00Z | 37,443,149 | <p>Usually when you have a lot of data items of the same type, it's advisable to use a list or similar container. I'd do:</p>
<pre><code>file_number = 1
files = []
while file_number <= 100:
file_name = 'C:/file%04d.csv' % file_number
files.append(read_csv(file_name))
file_number += 1
files[0].head()
</... | 1 | 2016-05-25T16:41:49Z | [
"python",
"python-3.x",
"pandas"
] |
Reading a large number of .csv files in Python pandas and assigning different variable names | 37,443,025 | <p>I have a number of csv files named file0001.csv to file0100.csv
I would like to read each one in turn and assign a variable name to it. I think the best way to do this would be as a loop.
The variable name here should be x1 with the data from file0001.csv inside it</p>
<p>For example:</p>
<pre><code>FileNumber=1
w... | 1 | 2016-05-25T16:35:00Z | 37,443,163 | <p>You should try creating a dictionary rather than having tons or variable names</p>
<pre><code>filedict = {}
while FileNumber < 101:
key = 'Filenumber'+str(Filenumber)
value = read_csv('C:/file'+str(FileNumber).zfill(4)+'.csv')
filedict[key] = value
FileNumber += 1
</code></pre>
<p>This way the... | 0 | 2016-05-25T16:42:52Z | [
"python",
"python-3.x",
"pandas"
] |
Using lambda if condition on different columns in Pandas dataframe | 37,443,082 | <p>I have simple dataframe:</p>
<pre><code>import pandas as pd
frame = pd.DataFrame(np.random.randn(4, 3), columns=list('abc'))
</code></pre>
<p>Thus for example:</p>
<pre><code>a b c
0 -0.813530 -1.291862 1.330320
1 -1.066475 0.624504 1.690770
2 1.330330 -0.675750 -1.123389
3 0.400109 -... | 2 | 2016-05-25T16:38:00Z | 37,443,116 | <p>is that what you want?</p>
<pre><code>In [300]: frame[['b','c']].apply(lambda x: x['c'] if x['c']>0 else x['b'], axis=1)
Out[300]:
0 -1.099891
1 0.582815
2 0.901591
3 0.900856
dtype: float64
</code></pre>
| 2 | 2016-05-25T16:40:17Z | [
"python",
"pandas",
"lambda"
] |
Using lambda if condition on different columns in Pandas dataframe | 37,443,082 | <p>I have simple dataframe:</p>
<pre><code>import pandas as pd
frame = pd.DataFrame(np.random.randn(4, 3), columns=list('abc'))
</code></pre>
<p>Thus for example:</p>
<pre><code>a b c
0 -0.813530 -1.291862 1.330320
1 -1.066475 0.624504 1.690770
2 1.330330 -0.675750 -1.123389
3 0.400109 -... | 2 | 2016-05-25T16:38:00Z | 37,443,613 | <h3>Solution</h3>
<p>use a vectorized approach</p>
<pre><code>frame['d'] = frame.b + (frame.c > 0) * (frame.c - frame.b)
</code></pre>
<h3>Explanation</h3>
<p>This is derived from the sum of</p>
<pre><code>(frame.c > 0) * frame.c # frame.c if positive
</code></pre>
<p>Plus</p>
<pre><code>(frame.c <= 0)... | 3 | 2016-05-25T17:08:26Z | [
"python",
"pandas",
"lambda"
] |
Python stemming (with pandas dataframe) | 37,443,138 | <p>I came to the following problem while programming Python: I use a Pandas dataframe containing words that have to stemmed (using SnowballStemmer). I want the words to be stemmed to investigate the results for stemmed vs non stemmed text and for this I will be using a classifier. I use the following code for the stemm... | 1 | 2016-05-25T16:41:21Z | 37,444,102 | <p>You have to apply the stemming on each word and store it into the "stemmed" column.</p>
<p>EDIT</p>
<p>for example : </p>
<pre><code>In [23]: data
Out[23]:
stemmed
0 [amsterdamse, and , yes]
1 [marathon, hello, verbazing]
</code></pre>
<p>Then the following should work</p>
<pre><co... | 3 | 2016-05-25T17:35:33Z | [
"python",
"pandas",
"nlp",
"stemming"
] |
html content not received over get request | 37,443,152 | <p>I need to scrape all the data available on this <a href="https://bpcleproc.in/EPROC/viewtender/13474" rel="nofollow">website</a> </p>
<p>Here is my code </p>
<pre><code>import requests
url = "https://bpcleproc.in/EPROC/viewtender/13474"
r = requests.get(url)
print(r)
print(r.text)
</code></pre>
<p>The resul... | 0 | 2016-05-25T16:42:00Z | 37,443,210 | <p>The website sets a bunch of cookies in a redirect loop before bringing you to your final page, for some reason:</p>
<pre><code>$ curl -vv https://bpcleproc.in/EPROC/viewtender/13474
* Trying 103.231.215.7...
* Connected to bpcleproc.in (103.231.215.7) port 443 (#0)
* TLS 1.0 connection using TLS_ECDHE_RSA_WITH_AE... | 4 | 2016-05-25T16:46:24Z | [
"python",
"python-requests"
] |
Python - Multiprocessing and database entries | 37,443,153 | <p>I'm working on a framework for Digital Forensic Investigators to use to compare files with each other for my Master's capstone project. However, I ran into a bit of a snag...</p>
<p>I'm trying to implement multiprocessing on the comparisons since using a single core seems to be really slow. The trouble I'm having... | 0 | 2016-05-25T16:42:04Z | 37,443,442 | <p>You can make use of Lock. Take a look at <a href="https://docs.python.org/2/library/multiprocessing.html#synchronization-between-processes" rel="nofollow">https://docs.python.org/2/library/multiprocessing.html#synchronization-between-processes</a></p>
| 0 | 2016-05-25T16:59:30Z | [
"python",
"sqlite",
"multiprocessing"
] |
Python - Multiprocessing and database entries | 37,443,153 | <p>I'm working on a framework for Digital Forensic Investigators to use to compare files with each other for my Master's capstone project. However, I ran into a bit of a snag...</p>
<p>I'm trying to implement multiprocessing on the comparisons since using a single core seems to be really slow. The trouble I'm having... | 0 | 2016-05-25T16:42:04Z | 37,444,883 | <p>Your problem is that you are trying to have multiple writers access a toy database -- i.e. sqlite -- which is stored in a single file. Using Lock might help, but it's going to kill your multiprocess throughput because of all the waiting-for-the-lock time. In essence, the lock choke point will serialize your program.... | 0 | 2016-05-25T18:21:00Z | [
"python",
"sqlite",
"multiprocessing"
] |
Pandas - Print multiple dateframes | 37,443,169 | <p>I'm using a Jupyter notebook, and matplotlib has the option to draw a matrix of plots. Is there a similar option to draw multiple tables (from dataframes) like that? I have like 8 pieces of 2x2 dataframes, which I'd like to print in a 4x2 matrix format.</p>
<p>Thank you!</p>
| 1 | 2016-05-25T16:43:15Z | 37,446,122 | <p>Jupyter notebooks can leverage HTML to diplay results. This may not be the most elegant solution, but this may work...</p>
<p>Set up DataFrames:</p>
<pre><code>import pandas as pd
from IPython.display import HTML
%pylab inline
d1=pd.DataFrame(rand(2,2))
d2=pd.DataFrame(rand(2,2))
d3=pd.DataFrame(rand(2,2))
d4=pd... | 2 | 2016-05-25T19:34:37Z | [
"python",
"pandas",
"jupyter-notebook"
] |
Pandas - group by the entire MultiIndex | 37,443,218 | <p>Suppose I have a dataframe indexed by a MultiIndex with 4 levels, and I want to group by the index.</p>
<p>I know I can do</p>
<pre><code>df.groupby(level=[0,1,2,3])...
</code></pre>
<p>But, is there a syntactically better way, so that I don't need to know the size of the MultiIndex in order?</p>
<p>Something li... | 1 | 2016-05-25T16:47:05Z | 37,443,330 | <p>Try:</p>
<pre><code>df.groupby(level=range(len(df.index.levels)))
</code></pre>
<p>Not necessarily pretty, but it's generalized.</p>
| 1 | 2016-05-25T16:53:26Z | [
"python",
"pandas",
"multi-index"
] |
How to input multidimensional data to caffe lmdb? | 37,443,231 | <p>I would like to reproduce the <a href="http://arxiv.org/abs/1406.2199" rel="nofollow">Two-Stream Convolutional Networks for Action Recognition in Videos</a>.</p>
<p>But it feels Like I have Hit a wall when It comes to giving multi frame input to caffe.</p>
<p>As the single frame network gives 50% accuracy.
But whe... | 0 | 2016-05-25T16:48:02Z | 37,529,114 | <p>According to the mentioned article, RGB image is an input for the Spatial stream and stacked optical flow frames for the Temporal stream. So, you should extract optical flow frames first for a temporal stream. Each point of the optical flow frame correspond to vector with x and y components that can be seen
as image... | 0 | 2016-05-30T15:20:09Z | [
"python",
"machine-learning",
"classification",
"deep-learning",
"caffe"
] |
Display images with bounding boxes while running py-faster-rcnn using VGG_CNN_M_1024 | 37,443,237 | <p>I am using the <code>demo.py</code>given in <a href="https://github.com/rbgirshick/py-faster-rcnn/tree/master/tools" rel="nofollow">https://github.com/rbgirshick/py-faster-rcnn/tree/master/tools</a>.</p>
<p>I have modified the code to run <code>VGG_CNN_M_1024</code> as I am using a 2GB GPU. And as per the comments ... | 0 | 2016-05-25T16:48:26Z | 38,712,551 | <p>VGG16_faster_rcnn_final.caffemodel is the model learned via Faster RCNN.
This model would have been initialised using VGG16.caffemodel. </p>
<p>What you're after is a faster rcnn model, which has been initialised using the VGG_CNN_M_1024.caffemodel. Such a model would be called
VGG_CNN_M_1024_faster_rcnn_final.caf... | 1 | 2016-08-02T05:43:34Z | [
"python",
"computer-vision",
"deep-learning",
"caffe"
] |
Token names and keywords when tokenizing Python source file (in Python) | 37,443,274 | <p>Following <a href="http://stackoverflow.com/a/37420819/6182051">this answer</a>, I am trying to get all the token information (i.e. token's exact name, value and position) for a Python source file like the one below.</p>
<pre><code># Python source file
import os
class Test():
"""
This class holds latitude,... | 1 | 2016-05-25T16:50:16Z | 37,470,743 | <p>I believe that what you are interested in can be achieved via A<strong>bstract Syntax Trees</strong>; traversing them and -especially- the leaf nodes of those ASTs, i.e. <strong>tokens</strong> (see the <a href="https://docs.python.org/3.5/library/token.html#module-token" rel="nofollow">token</a> module) which repre... | 1 | 2016-05-26T20:51:20Z | [
"python",
"python-3.x",
"token",
"tokenize"
] |
Non Divisible subset in python | 37,443,282 | <p>I have been given a set S, of n integers, and have to print the size of a maximal subset S' of S where the sum of any 2 numbers in S' are not evenly divisible by k.</p>
<p><strong>Input Format</strong></p>
<p>The first line contains 2 space-separated integers, n and k, respectively.
The second line contains n spa... | 1 | 2016-05-25T16:50:49Z | 37,444,493 | <pre><code># given k, n and a as per your input.
# Will return 0 directly if n == 1
def maxsize(k, n, a):
import itertools
while n > 1:
sets = itertools.combinations(a, n)
for set_ in sets:
if all((u+v) % k for (u, v) in itertools.combinations(set_, 2)):
return n
... | 0 | 2016-05-25T17:57:57Z | [
"python"
] |
Non Divisible subset in python | 37,443,282 | <p>I have been given a set S, of n integers, and have to print the size of a maximal subset S' of S where the sum of any 2 numbers in S' are not evenly divisible by k.</p>
<p><strong>Input Format</strong></p>
<p>The first line contains 2 space-separated integers, n and k, respectively.
The second line contains n spa... | 1 | 2016-05-25T16:50:49Z | 37,446,985 | <p>You can solve it in <code>O(n)</code> time using the following approach:</p>
<pre><code>L = [0]*k
for x in a:
L[x % k] += 1
res = 0
for i in range(k//2+1):
if i == 0 or k == i*2:
res += bool(L[i])
else:
res += max(L[i], L[k-i])
print(res)
</code></pre>
| 8 | 2016-05-25T20:25:55Z | [
"python"
] |
Non Divisible subset in python | 37,443,282 | <p>I have been given a set S, of n integers, and have to print the size of a maximal subset S' of S where the sum of any 2 numbers in S' are not evenly divisible by k.</p>
<p><strong>Input Format</strong></p>
<p>The first line contains 2 space-separated integers, n and k, respectively.
The second line contains n spa... | 1 | 2016-05-25T16:50:49Z | 37,494,978 | <p>Yes O(n) solution for this problem is very much possible. Like planetp rightly pointed out its pretty much the same solution I have coded in java. Added comments for better understanding.</p>
<blockquote>
<p>import java.io.<em>; import java.util.</em>;</p>
<p>public class Solution {</p>
<pre><code>public st... | 0 | 2016-05-28T03:44:01Z | [
"python"
] |
Non Divisible subset in python | 37,443,282 | <p>I have been given a set S, of n integers, and have to print the size of a maximal subset S' of S where the sum of any 2 numbers in S' are not evenly divisible by k.</p>
<p><strong>Input Format</strong></p>
<p>The first line contains 2 space-separated integers, n and k, respectively.
The second line contains n spa... | 1 | 2016-05-25T16:50:49Z | 38,284,931 | <p>Java solution</p>
<pre><code>public class Solution {
static PrintStream out = System.out;
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner (System.in);
i... | 0 | 2016-07-09T18:22:06Z | [
"python"
] |
Finding hour of daily max using Pandas in Python | 37,443,296 | <p>I am trying to find the hour of max demand every day in my demand time series.</p>
<p>I have created a dataframe that looks like..</p>
<pre><code> power
2011-01-01 00:00:00 1015.70
2011-01-01 01:00:00 1015.70
2011-01-01 02:00:00 1010.30
2011-01-01 03:00:00 1010.90
2011-01-01 04:00:00 102... | 3 | 2016-05-25T16:51:44Z | 37,443,548 | <p>try this:</p>
<pre><code>In [376]: df.loc[df.groupby(pd.TimeGrouper('D')).idxmax().iloc[:, 0]]
Out[376]:
power
2011-01-01 06:00:00 1054.6
2011-01-02 06:00:00 2054.6
</code></pre>
<p>data:</p>
<pre><code>In [377]: df
Out[377]:
... | 2 | 2016-05-25T17:05:20Z | [
"python",
"pandas"
] |
Self Avoiding Random Walk in a 3d lattice using pivot algorithm in python | 37,443,386 | <p>I was working on a problem from past few days, It is related to creating a self avoiding random walks using pivot algorithm and then to implement another code which places spherical inclusions in a 3d lattice. I have written two codes one code generates coordinates of the spheres by using Self avoiding random walk a... | 5 | 2016-05-25T16:56:35Z | 37,487,429 | <p>To accommodate non-intersecting spheres with turns of 45,135,225,315 (really, only 45 and 315 are issues), you just need to make your spheres a little bit smaller. Take 3 consecutive sphere-centers, with a 45-degree turn in the middle. In the plane containing the 3 points, that makes an isosceles triangle, with a ... | 2 | 2016-05-27T15:37:14Z | [
"python",
"computational-geometry"
] |
Extract list of objects from another Python list based on attribute | 37,443,447 | <p>I have a Python list filled with instances of a class I defined. </p>
<p>I would like to create a new list with all the instances from the original list that meet a certain criterion in one of their attributes. </p>
<p>That is, for all the elements in <code>list1</code>, filled with instances of some <code>class o... | 0 | 2016-05-25T16:59:40Z | 37,443,662 | <p>There's definitely a more concise way to do it, with a list comprehension:</p>
<pre><code>filtered_list = [obj for obj in list1 if obj.attrib==someValue]
</code></pre>
<p>I don't know if you can go any faster though, because in the problem as you described you'll always have to check every object in the list someh... | 2 | 2016-05-25T17:11:27Z | [
"python"
] |
Extract list of objects from another Python list based on attribute | 37,443,447 | <p>I have a Python list filled with instances of a class I defined. </p>
<p>I would like to create a new list with all the instances from the original list that meet a certain criterion in one of their attributes. </p>
<p>That is, for all the elements in <code>list1</code>, filled with instances of some <code>class o... | 0 | 2016-05-25T16:59:40Z | 37,444,343 | <p>You can perhaps use pandas series. Read your list into a pandas series <code>your_list</code>.
Then you can filter by using the <code>[]</code> syntax and the <code>.apply</code> method:</p>
<pre><code>def check_attrib(obj, value):
return obj.attrib==value
new_list = your_list[your_list.apply(check_attrib)]
</... | 1 | 2016-05-25T17:48:25Z | [
"python"
] |
Extract list of objects from another Python list based on attribute | 37,443,447 | <p>I have a Python list filled with instances of a class I defined. </p>
<p>I would like to create a new list with all the instances from the original list that meet a certain criterion in one of their attributes. </p>
<p>That is, for all the elements in <code>list1</code>, filled with instances of some <code>class o... | 0 | 2016-05-25T16:59:40Z | 37,447,894 | <p>For completeness, you could also use <a href="https://docs.python.org/2/library/functions.html?highlight=filter%20built#filter" rel="nofollow">filter</a> and a <a href="https://docs.python.org/2/reference/expressions.html#lambda" rel="nofollow">lambda expression</a>:</p>
<pre><code>filtered_lst1 = filter(lambda obj... | 1 | 2016-05-25T21:26:18Z | [
"python"
] |
blank django project serving static CSS file | 37,443,451 | <p>I have created a new django project using the command</p>
<pre><code>django-admin startproject mysite
</code></pre>
<p>this created the basic django directory structure. I then added a directory called <code>static</code> under <code>/mysite/mysite/static</code> and then created <code>style.css</code> within this.... | -2 | 2016-05-25T16:59:46Z | 37,443,997 | <p>Ok, on your <code>yourprojectfolder/settings.py</code> you have to set up a couple of variables:</p>
<pre><code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_FOLDER = os.path.abspath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_FOLDER, "static") ... | 1 | 2016-05-25T17:30:41Z | [
"python",
"django",
"windows"
] |
python numpy ndarray element-wise mean | 37,443,565 | <p>I'd like to calculate element-wise average of numpy ndarray.</p>
<pre><code>In [56]: a = np.array([10, 20, 30])
In [57]: b = np.array([30, 20, 20])
In [58]: c = np.array([50, 20, 40])
</code></pre>
<p>What I want:</p>
<pre><code>[30, 20, 30]
</code></pre>
<p>Is there any in-built function for this operation, o... | 0 | 2016-05-25T17:06:12Z | 37,443,624 | <p>You can just use <code>np.mean</code> directly:</p>
<pre class="lang-py prettyprint-override"><code>>>> np.mean([a, b, c], axis=0)
array([ 30., 20., 30.])
</code></pre>
| 3 | 2016-05-25T17:09:12Z | [
"python",
"numpy",
"vectorization"
] |
With threading I pick up 9 'hits', without threading I pick up 214. What's going on? | 37,443,644 | <p>The basic purpose of my script is to filter through a range of numbers (say, 5000),the numbers that are <code>valid</code> are saved to a list called <code>hit_list</code>. The real range I'm looping through is much bigger than 5000, so I need concurrency to make the time manageable. </p>
<p>I don't know the propor... | 0 | 2016-05-25T17:10:15Z | 37,479,132 | <p>This solution is a re-written, rather than debugged version of my original code. Re-building from the ground up was both easier and more educational for me- but I can't tell you what went wrong with the original code. </p>
<p>The script seems to work well- it picks up the magic number of 214 <code>hits</code> in... | 0 | 2016-05-27T08:56:19Z | [
"python",
"multithreading",
"web-scraping",
"concurrent.futures"
] |
adding list values to dict key with a pre-existing list as its value | 37,443,668 | <p>If I have a list of lists and a dictionary with a list as a value:</p>
<pre><code>ll = [['wed', 'thurs'], ['fri', 'sat', 'sun']]
d = {'week1':['mon', 'tues']}
</code></pre>
<p>how do I add additional lists to the same key?
such that I get:</p>
<pre><code>new_d = { 'week1': ['mon', 'tues'], ['wed', 'thurs'], ['fri... | 0 | 2016-05-25T17:11:48Z | 37,443,707 | <p>Build a <em>new</em> tuple holding the old as a nested list, plus the other two. Since you want the whole result to be a tuple, you'll have to convert <code>ll</code> to a tuple too:</p>
<pre><code>new_d = {}
new_d['week1'] = (d['week1'],) + tuple(ll)
</code></pre>
<p>This is no different from building a tuple out... | 0 | 2016-05-25T17:13:42Z | [
"python"
] |
adding list values to dict key with a pre-existing list as its value | 37,443,668 | <p>If I have a list of lists and a dictionary with a list as a value:</p>
<pre><code>ll = [['wed', 'thurs'], ['fri', 'sat', 'sun']]
d = {'week1':['mon', 'tues']}
</code></pre>
<p>how do I add additional lists to the same key?
such that I get:</p>
<pre><code>new_d = { 'week1': ['mon', 'tues'], ['wed', 'thurs'], ['fri... | 0 | 2016-05-25T17:11:48Z | 37,444,228 | <p>You've nearly got it. The crucial piece of information is that your <strong>value</strong> for the dictionary needs to be a single object. </p>
<p>In your example above, you are appending some list objects to the list, giving you the list you described which looked something like this:</p>
<pre><code>[ 'mon',
't... | 0 | 2016-05-25T17:42:37Z | [
"python"
] |
How can I organize my data into a grid using Python Pandas? | 37,443,739 | <p>I'm a newbie at Python. I'm trying to organize a CSV file into a readable grid. When I converted my Excel file to CSV, the output became garbled, a mess of commas and scattered values. I tried list, but it still didn't organize the data the way I wanted it to be. I wanted my code to be organized by categories - suc... | 0 | 2016-05-25T17:16:14Z | 37,446,421 | <p><code>pandas.read_csv()</code> may work better if the data were comma separated. You can specifiy the delimiter used in the data with the <code>delimeter</code> (a.k.a <code>sep</code>) option.</p>
<p>Check out <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">the d... | 1 | 2016-05-25T19:52:14Z | [
"python",
"csv",
"numpy",
"pandas",
"sklearn-pandas"
] |
python name not defined even though it is | 37,443,752 | <p>I know this is basic but i actually don't even know what I've done wrong.</p>
<pre><code>while True:
try:
end=int(input("If You Dont Want To Buy Anything Press 1 To Exit\nOr If You Would Like To Try Again Please Press 2"))
except ValueError:
print("\nPlease Enter Only 1 Or 2")
if end==1:... | 1 | 2016-05-25T17:16:54Z | 37,443,809 | <p><code>end</code> is only assigned to if there was no <code>ValueError</code>. If <code>int()</code> raises an exception, then the assignment <em>never takes place</em>.</p>
<p>Either test for valid <code>end</code> values <strong>inside</strong> the <code>try</code> (so that you know no exception was raised), or as... | 4 | 2016-05-25T17:19:47Z | [
"python",
"nameerror"
] |
python name not defined even though it is | 37,443,752 | <p>I know this is basic but i actually don't even know what I've done wrong.</p>
<pre><code>while True:
try:
end=int(input("If You Dont Want To Buy Anything Press 1 To Exit\nOr If You Would Like To Try Again Please Press 2"))
except ValueError:
print("\nPlease Enter Only 1 Or 2")
if end==1:... | 1 | 2016-05-25T17:16:54Z | 37,443,819 | <p>It tries to assign a value to end, but catches a ValueError and after the except it tries to see what 'end' is however it was never assigned a value due to the Exception.</p>
| 0 | 2016-05-25T17:20:28Z | [
"python",
"nameerror"
] |
python name not defined even though it is | 37,443,752 | <p>I know this is basic but i actually don't even know what I've done wrong.</p>
<pre><code>while True:
try:
end=int(input("If You Dont Want To Buy Anything Press 1 To Exit\nOr If You Would Like To Try Again Please Press 2"))
except ValueError:
print("\nPlease Enter Only 1 Or 2")
if end==1:... | 1 | 2016-05-25T17:16:54Z | 37,443,823 | <p>If <code>int(input(...))</code> fails, a <code>ValueError</code> is raised. That happens before <code>end</code> is assigned. Add another control statement in the error handling, for instance</p>
<pre><code>while True:
try:
end=int(input("If You Dont Want To Buy Anything Press 1 To Exit\nOr If You Would... | 0 | 2016-05-25T17:20:33Z | [
"python",
"nameerror"
] |
python name not defined even though it is | 37,443,752 | <p>I know this is basic but i actually don't even know what I've done wrong.</p>
<pre><code>while True:
try:
end=int(input("If You Dont Want To Buy Anything Press 1 To Exit\nOr If You Would Like To Try Again Please Press 2"))
except ValueError:
print("\nPlease Enter Only 1 Or 2")
if end==1:... | 1 | 2016-05-25T17:16:54Z | 37,443,832 | <p>You should put your <code>if</code>/<code>elif</code> statement inside the <code>try</code> block.</p>
<pre><code>while True:
try:
end=int(input("If You Dont Want To Buy Anything Press 1 To Exit\nOr If You Would Like To Try Again Please Press 2"))
if end==1:
exit()
elif end==... | 3 | 2016-05-25T17:20:47Z | [
"python",
"nameerror"
] |
python name not defined even though it is | 37,443,752 | <p>I know this is basic but i actually don't even know what I've done wrong.</p>
<pre><code>while True:
try:
end=int(input("If You Dont Want To Buy Anything Press 1 To Exit\nOr If You Would Like To Try Again Please Press 2"))
except ValueError:
print("\nPlease Enter Only 1 Or 2")
if end==1:... | 1 | 2016-05-25T17:16:54Z | 37,444,267 | <p>Others have explained the problem; here's a canonical solution. This matches the way many of us regard the process:
- grab a response
- until I get a <em>legal</em> response
- ... tell the user what's wrong
- ... get a new response</p>
<pre><code>input_prompt = "If You Don't Want To Buy Anything Press 1 To Exi... | 1 | 2016-05-25T17:44:36Z | [
"python",
"nameerror"
] |
What's function of spark checkpoint ".bk" and ".crc" file? | 37,443,804 | <p>When we set the checkpoint directory for spark streaming application, it will generate a directory like this:</p>
<pre><code>root@55330815baa7:/usr/local/spark/checkpoint# ll
total 184
drwxr-xr-x 6 root root 4096 May 25 16:35 ./
drwxr-xr-x 18 500 500 4096 May 25 16:19 ../
drwxr-xr-x 2 root root 4096 May 25 1... | 0 | 2016-05-25T17:19:23Z | 37,456,809 | <p>CRC stands for <strong>Cyclic Redundancy Check</strong>. It's an <strong>error detecting code</strong> which is used to <strong>detect accidental changes to raw data</strong>.
<br/><br/><br/>
Example From <a href="https://en.wikipedia.org/wiki/Cyclic_redundancy_check" rel="nofollow">CRC on Wikipedia</a>:<br/><br/>
W... | 1 | 2016-05-26T09:29:16Z | [
"java",
"python",
"scala",
"apache-spark",
"spark-streaming"
] |
keys do not move the object in the game written in python | 37,443,807 | <p>Update: manish kumar gave me the solution for the problem. I had to write event.key instead of event.type in a certain part of the code.
check it out at it below:</p>
<pre><code>for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
if event.type == pygame.KEYD... | 0 | 2016-05-25T17:19:40Z | 37,444,132 | <p>I think the problem lies here:</p>
<pre><code>for event in pygame.event.get():
# modifications to x_change
x += x_change
</code></pre>
<p>If the call to <code>pygame.event.get()</code> returns two events, a KEYDOWN and a KEYUP, then <code>x_change</code> will be set to 5 or -5, but then it will be set back t... | 1 | 2016-05-25T17:37:41Z | [
"python",
"pygame",
"python-3.4"
] |
keys do not move the object in the game written in python | 37,443,807 | <p>Update: manish kumar gave me the solution for the problem. I had to write event.key instead of event.type in a certain part of the code.
check it out at it below:</p>
<pre><code>for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
if event.type == pygame.KEYD... | 0 | 2016-05-25T17:19:40Z | 37,444,187 | <p>you have to use event.key instead of event.type.</p>
<pre><code>if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_change = -5
elif event.key == pygame.K_RIGHT:
x_change = 5
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key... | 4 | 2016-05-25T17:40:25Z | [
"python",
"pygame",
"python-3.4"
] |
Python - pandas, chain indexing error | 37,443,813 | <p>I have PyCharm and Python 3.5 running.
I am try to get (source, destination) from the csv source, and store responses to time, distance columns.</p>
<p>I am trying to replicate this code:
<a href="http://www.analyticsvidhya.com/blog/2015/03/hacking-google-maps-create-distance-features-model-applications/" rel="nofo... | 0 | 2016-05-25T17:20:03Z | 37,444,017 | <p>This is not strictly speaking an error - <code>process finished with exit code 0</code> means that the program terminated successfully.</p>
<p>At the same time, you are not writing any files or issuing any print statements. Presumably you want to record your results somehow, e.g. put <code>cities.to_csv('results.cs... | 1 | 2016-05-25T17:31:52Z | [
"python",
"csv",
"pandas",
"pycharm"
] |
Python object instantiation from within another object - is it a memory leak? | 37,443,830 | <p>Consider the following small Python GUI program, where the user can click a button over and over to cycle between window 1 and window 2:</p>
<pre><code>import tkinter
class Window1:
def __init__(self, parent):
# Initialize a new GUI window
self.parent = parent
self.window = tkinter.Topl... | 0 | 2016-05-25T17:20:44Z | 37,444,506 | <blockquote>
<p>Question 1: Since each new class is being instantiated from within another class, is this a memory leak?</p>
</blockquote>
<p>No. And I think you are confusing between a few things memory leak and object references not being used. @kindall explains it beautifully in his comment under your question.</... | 3 | 2016-05-25T17:59:04Z | [
"python",
"object",
"memory-leaks"
] |
Pyspark: Rename a dictionary key which is within a DataFrame column | 37,443,834 | <p>After some processing I get a dataframe where I have a dictionary within a dataframe column. Now I want to change the key of the dictionary within the column. From <strong>"_1"</strong> to <strong>"product_id"</strong> and <strong>"_2"</strong> to <strong>"timestamp"</strong>.</p>
<p>Here is the code of the proces... | 1 | 2016-05-25T17:20:55Z | 37,450,359 | <p><strong>Spark 2.0+</strong></p>
<p>Use <code>collect_list</code> and <code>struct</code>:</p>
<pre><code>from pyspark.sql.functions import collect_list, struct, col
df = sc.parallelize([
(1, 100, "2012-01-01 00:00:00"),
(1, 200, "2016-04-04 00:00:01")
]).toDF(["user_id","product_id","timestamp_gmt"])
pi ... | 1 | 2016-05-26T02:00:18Z | [
"python",
"dictionary",
"apache-spark",
"dataframe",
"pyspark"
] |
Kivy touch and keyboard events passing through to desktop | 37,443,845 | <p>I am using the <a href="https://kivy.org/#home" rel="nofollow">Kivy</a> framework to develop a UI application in Python 3. The Kivy application is fullscreen. Whenever I perform a touch event or type with my physical keyboard, the underlying desktop environment will receive the touch and keyboard events as well as m... | 0 | 2016-05-25T17:21:33Z | 37,443,963 | <p>I think this is caused by using Kivy's rpi-specific window provider, which uses a low level interface with the hardware in order to perform more efficiently, but in turn doesn't interact with the desktop in a normal way - specifically, input and drawing bypass the normal mechanisms.</p>
<p>If you want to use the ap... | 1 | 2016-05-25T17:28:12Z | [
"python",
"kivy",
"raspbian",
"kivy-language"
] |
Overriding Enum __call__ method | 37,444,002 | <p>I have an <code>Enum</code> like so:</p>
<pre><code>from enum import Enum
class Animal(Enum):
cat = 'meow'
dog = 'woof'
never_heard_of = None
def talk(self):
print(self.value)
</code></pre>
<p>I would like to override the <code>__call__</code> method so that a call like <co... | 1 | 2016-05-25T17:30:57Z | 37,444,678 | <p>To be clear: you want the <code>__call__</code> that is associated with <code>Animal()</code> which is actually on the metaclass (<code>EnumMeta</code> in <code>enum.py</code>).</p>
<p>This is a bag of worms you don't want to get in to, as it is very easy to break things.</p>
<p>See <a href="http://stackoverflow.c... | 1 | 2016-05-25T18:09:41Z | [
"python",
"enums"
] |
Python: How do I use only 1 column when using multiple text files? | 37,444,034 | <p>I am using Python3 Notebook. I am using multiple text files with multiple columns. How do I use only the first column of all 3 text files?</p>
<p>Text File Example:</p>
<pre><code>Corey 1 765
Mike 2 675
John 3 645
Tom 4 234
Ben 5 134
Corey 6 646
Mi... | 1 | 2016-05-25T17:32:30Z | 37,469,101 | <p>Using iPython Panda I was able to easily and quickly analyze all text files.</p>
<p><a href="http://nbviewer.jupyter.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter%202%20-%20Selecting%20data%20&%20finding%20the%20most%20common%20complaint%20type.ipynb" rel="nofollow">Jupyter Notebook</a></p>
<p>Cod... | 0 | 2016-05-26T19:04:34Z | [
"python",
"python-3.x",
"text-files"
] |
Python: How do I use only 1 column when using multiple text files? | 37,444,034 | <p>I am using Python3 Notebook. I am using multiple text files with multiple columns. How do I use only the first column of all 3 text files?</p>
<p>Text File Example:</p>
<pre><code>Corey 1 765
Mike 2 675
John 3 645
Tom 4 234
Ben 5 134
Corey 6 646
Mi... | 1 | 2016-05-25T17:32:30Z | 37,469,837 | <pre><code>import pandas as pd
data = pd.Series()
for file in filelist:
data2 = pd.read_csv(file, sep=" ", header = None, usecols =[0])
data = pd.concat((data,data2[0].str.lower(), axis=0)
yourData = dict(pd.Series(data).value_counts())
</code></pre>
| 1 | 2016-05-26T19:53:01Z | [
"python",
"python-3.x",
"text-files"
] |
Loop through a dataframe that is a result of groupby | 37,444,055 | <pre><code> df2 = df.groupby('ActualDebugData')['HardwareId'].count().to_frame(name='df1')
</code></pre>
<p>The output of dataframe df2 is:</p>
<pre><code> ActualDebugData df1
Bell 3212
Bell Mobile 514
</code></pre>
<p>I would like to loop through the df2 and state that... | 0 | 2016-05-25T17:33:26Z | 37,444,441 | <p>Before you group you could run something like this, assuming you're splitting on spaces:</p>
<pre><code>df['HardwareId_list'] = df['HardwareId'].str.split(' ')
df['hardware_updated'] = df['HardwareId_list'].apply(lambda x: x[0] if type(x) == list else x)
</code></pre>
<p>Then you could group as you had been doing.... | 0 | 2016-05-25T17:54:44Z | [
"python",
"ipython"
] |
search specific tuples in list and dictionaries | 37,444,206 | <p>let's say I have a list like this </p>
<pre><code>liste=[(0,1,45), (0,2,90), (0,3,60), (1,2,50), (1,3,20), (2,3,25)]
</code></pre>
<p>and another list like this : <code>number_list=(0,2)</code></p>
<p>so now, i would like to have a dictionary (or a list) in which i have for each key, the list of my tuples of list... | 0 | 2016-05-25T17:41:22Z | 37,444,327 | <p>You could use a dictionary comprehension:</p>
<pre><code>>>> liste=[(0,1,45), (0,2,90), (0,3,60), (1,2,50), (1,3,20), (2,3,25)]
>>> number_list=(0,2)
>>> d = {str(x):[item for item in liste if x in item] for x in number_list}
>>> d
{'0': [(0, 1, 45), (0, 2, 90), (0, 3, 60)], '2':... | 1 | 2016-05-25T17:47:39Z | [
"python",
"list",
"dictionary"
] |
Issue with crash in TKinter Application | 37,444,218 | <p>I have a program running that is having issues when the timer runs. Every time "start" is hit, the application crashes. Any thoughts?</p>
<pre><code>##-- Imports --##
import time
import openpyxl as xl
from Tkinter import *
##-- Classes --##
class App(Frame):
def startTimer(self):
self.check = True
... | 0 | 2016-05-25T17:41:57Z | 37,444,580 | <p>Looks like you have no way out of your <code>while</code> loop. You'll either need to set <code>self.check</code> to <code>False</code>, or <code>break</code> out of the loop.</p>
<pre><code>while self.check == True:
self.timer.configure(text = self.now)
time.sleep(1)
</code></pre>
| 0 | 2016-05-25T18:03:36Z | [
"python",
"timer",
"tkinter"
] |
Python: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame | 37,444,221 | <p>My pandas dataframe:</p>
<pre><code>dframe = pd.DataFrame({"A":list("abcde"), "B":list("aabbc"), "C":[1,2,3,4,5]}, index=[10,11,12,13,14])
A B C
10 a a 1
11 b a 2
12 c b 3
13 d b 4
14 e c 5
</code></pre>
<p>My desired output:</p>
<pre><code> A B C a b c
10 a a ... | 4 | 2016-05-25T17:42:09Z | 37,444,355 | <p>Start with</p>
<pre><code>to_be_appended = pd.get_dummies(dframe.B).replace(0, np.nan).mul(dframe.C, axis=0)
</code></pre>
<p>Then concat</p>
<pre><code>dframe = pd.concat([dframe, to_be_appended], axis=1)
</code></pre>
<p>Looks like:</p>
<pre><code>print dframe
A B C a b c
10 a a 1 1.0 NaN... | 2 | 2016-05-25T17:49:12Z | [
"python",
"pandas"
] |
Python FileNotFoundError when using open() | 37,444,362 | <p>I'm using <code>with open('myFile', 'rb') as file:</code> to read a file. When running the program with <code>python myProgram.py</code> everything works fine. But as soon I try to run it without <code>cd</code>-ing into the directory of <code>myProgram.py</code> and use an absolute path instead (like <code>python /... | -1 | 2016-05-25T17:49:45Z | 37,444,699 | <blockquote>
<p>So why does open() behave differently depending on how the Python program is started? And is there a way to make things work even if starting with an absolute path?</p>
</blockquote>
<p>Because that is standard behavior. Not just for Python, but for all applications (at least all that I know of). A... | 1 | 2016-05-25T18:10:46Z | [
"python",
"linux",
"command-line"
] |
Python FileNotFoundError when using open() | 37,444,362 | <p>I'm using <code>with open('myFile', 'rb') as file:</code> to read a file. When running the program with <code>python myProgram.py</code> everything works fine. But as soon I try to run it without <code>cd</code>-ing into the directory of <code>myProgram.py</code> and use an absolute path instead (like <code>python /... | -1 | 2016-05-25T17:49:45Z | 37,445,004 | <p>Let's say you run <code>pwd</code> and it returns <code>/home/myName</code>. If you then run <code>/home/myName/code/myProgram.py</code>, the working directory of your program is <em>not</em> <code>/home/myName/code</code>; it's <code>/home/myName</code>. The working directory of a process in inherited from the pare... | 0 | 2016-05-25T18:28:31Z | [
"python",
"linux",
"command-line"
] |
how expensive are RuntimeWarning warnings on performance for computation on big data | 37,444,363 | <p>I have many situations where computations encounter things like:</p>
<pre><code>-divide by zero
-np.nan values in a column that I compute df['col'].quantile(0.5)
-np.nan values in groupby objects that are then used like grouped.agg('sum')
</code></pre>
<p>etc</p>
<p>I don't get any errors but do get <code>Runtime... | 0 | 2016-05-25T17:49:46Z | 37,444,525 | <p>A warning amounts to several simple operations, including hashing to determine if a warning has already been issued and whether that warning should be issued more than once, and where the warning occurred. These are fast, but they aren't free.</p>
<p>All those operations occur regardless of whether a warning is act... | 1 | 2016-05-25T18:00:12Z | [
"python",
"pandas",
"warnings",
"runtimeexception"
] |
AttributeError: '_GzipStreamFile' object has no attribute '_checkReadable | 37,444,369 | <p>I am trying to setup commonsearch and i am the point where backend imports alexa1m data to rocksdb, but it die with error( error below ).</p>
<pre><code> Traceback (most recent call last):
File "urlserver/import.py", line 21, in <module>
ds.import_dump()
File "./urlserver/datasources/__i... | 0 | 2016-05-25T17:50:16Z | 37,482,997 | <p>Found the solution, it was problem in the data parsed to the tool, not the tool itself.</p>
| 0 | 2016-05-27T12:00:38Z | [
"python",
"io",
"gzip",
"rocksdb"
] |
Python flask and restless - how to return gz file of json object | 37,444,370 | <p>I I am using flask-restless. I am trying to respond of a get request of a gz file of a json object from s3 and do not understand how to send a gz file.</p>
<pre><code>class report_download(Resource):
def get(self,report_name):
conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
b... | 0 | 2016-05-25T17:50:21Z | 37,444,735 | <p>Zipped data is binary, so, <code>readlines</code> probably only reads corrupted data.</p>
<p>You can use python module <code>gzip</code>, without the need of any external program:</p>
<pre><code>import gzip
class report_download(Resource):
def get(self,report_name):
conn = boto.connect_s3(AWS_ACCESS_... | 1 | 2016-05-25T18:12:56Z | [
"python",
"flask"
] |
matplotlib twinx inside a loop | 37,444,405 | <p>I have a loop which for a certain condition (occurs e.g 3 times), I'd like to plot two dataset with twinx, so e.g at the end I have 3 plots on left-y and 3 plots on right-y. When I use the usual twinx, the loop takes incorrect values for right-y. How should I modify this example code to get them correct? Thank you v... | 1 | 2016-05-25T17:52:45Z | 37,446,557 | <p>You need to move your "ax2" definition outside the loop (see below). However, this makes seven plots, four on left, three on right. You need to update your "if" condition.</p>
<pre><code>[![import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(0,10,100)
A=5
fig,ax=plt.subplots()
ax2=ax.twinx()
for i... | 2 | 2016-05-25T20:00:58Z | [
"python",
"matplotlib"
] |
Disable caching on celery task | 37,444,492 | <p>I have a celery chain that has multiple tasks, one of which is extracting a tar file and returning the JSON found within that tar file. At completion of the chain, <code>pylibmc</code> raises <code>error 37 from memcached_set: SUCCESS</code> which means that the memcached value associated with that task key is great... | 1 | 2016-05-25T17:57:55Z | 37,447,486 | <p>You can use <code>CELERY_IGNORE_RESULT</code> or <code>Task.ignore_result</code> to not store the result. The value is still returned to the functions in the chain, they just aren't persisted to the cache. Here is an example using <code>ignore_result</code></p>
<pre><code>@task(ignore_result=True)
def your_task():
... | 2 | 2016-05-25T20:57:31Z | [
"python",
"caching",
"memcached",
"celery",
"pylibmc"
] |
Error in package 'requests' the version of python | 37,444,504 | <p>I am using 'requests' on python 3.4
And use this code:</p>
<pre><code>import requests
r = requests.get('https://api.github.com/user')
print(r.status_code)
</code></pre>
<p>I thow exeption:</p>
<blockquote>
<p>Import Error No module named 'ndg'
in pyopenssl.py </p>
</blockquote>
<p>as I understand it, this fi... | 0 | 2016-05-25T17:58:59Z | 37,446,146 | <p>This error caused enabled checkbox in Visual Studio 2015.
<a href="http://i.stack.imgur.com/m7t6m.png" rel="nofollow"><img src="http://i.stack.imgur.com/m7t6m.png" alt="enter image description here"></a></p>
| 0 | 2016-05-25T19:35:57Z | [
"python",
"python-3.x",
"python-requests"
] |
How to iterate through two lists without the use of nested "for" loops | 37,444,508 | <p>How do I iterate through two lists without the use of nested "for" loops?</p>
<p>the index between the two lists doesn't necessarily have to be the same</p>
<p>more specifically I am coding a function that takes a list of strings and a list of banned words. If any of the banned words are in each one of the strings... | 1 | 2016-05-25T17:59:15Z | 37,444,585 | <p>I would probably write something like:</p>
<pre><code>def filter_messages(messages, bannedWords):
for string in messages:
if all(word not in string for word in bannedWords):
yield string
</code></pre>
<p>Now you have a <em>generator function</em> that will only give you good messages. If y... | 1 | 2016-05-25T18:03:58Z | [
"python",
"python-2.7",
"for-loop"
] |
How to iterate through two lists without the use of nested "for" loops | 37,444,508 | <p>How do I iterate through two lists without the use of nested "for" loops?</p>
<p>the index between the two lists doesn't necessarily have to be the same</p>
<p>more specifically I am coding a function that takes a list of strings and a list of banned words. If any of the banned words are in each one of the strings... | 1 | 2016-05-25T17:59:15Z | 37,444,588 | <p>You could probably do it in a line!</p>
<pre><code>messages = [string for string in messages
if not any(word in bannedWords for word in string)]
</code></pre>
| 2 | 2016-05-25T18:04:09Z | [
"python",
"python-2.7",
"for-loop"
] |
How to iterate through two lists without the use of nested "for" loops | 37,444,508 | <p>How do I iterate through two lists without the use of nested "for" loops?</p>
<p>the index between the two lists doesn't necessarily have to be the same</p>
<p>more specifically I am coding a function that takes a list of strings and a list of banned words. If any of the banned words are in each one of the strings... | 1 | 2016-05-25T17:59:15Z | 37,445,363 | <p>Assuming a set of banned words and a list of strings that might contain these bad words:</p>
<pre><code>bannedWords = set("bad", "offensive")
messages = ["message containing a bad word", "i'm clean", "i'm offensive"]
cleaned = [x for x in messages if not any(y for y in bannedWords if y in x)]
</code></pre>
<p>Re... | 0 | 2016-05-25T18:50:14Z | [
"python",
"python-2.7",
"for-loop"
] |
retrieve normal data frame after pivoting a data frame | 37,444,523 | <p>I have a pandas data frame which is a result of pivoting. It has multiple indices. I want to get a "normal" data frame out of this pivoted df...so that I can do some normal operations on the new df.</p>
<p>Here is an example: My pivoted data frame looks like this:</p>
<pre><code> feature_value... | 3 | 2016-05-25T18:00:08Z | 37,444,679 | <p>Brute force:</p>
<pre><code>df.columns = df.columns.droplevel()
df = df.reset_index()
</code></pre>
| 3 | 2016-05-25T18:09:42Z | [
"python",
"pandas",
"pivot"
] |
retrieve normal data frame after pivoting a data frame | 37,444,523 | <p>I have a pandas data frame which is a result of pivoting. It has multiple indices. I want to get a "normal" data frame out of this pivoted df...so that I can do some normal operations on the new df.</p>
<p>Here is an example: My pivoted data frame looks like this:</p>
<pre><code> feature_value... | 3 | 2016-05-25T18:00:08Z | 37,444,817 | <p>When you call <code>pivot_table</code>, make sure you specify the <code>values</code> parameter:</p>
<pre><code>df.pivot_table(index=['time', 'name'], columns=['feature_type'],
values='feature_value')
</code></pre>
<p>without the <code>values='feature_value'</code>, you will get a MultiIndex column... | 4 | 2016-05-25T18:17:40Z | [
"python",
"pandas",
"pivot"
] |
Parsing IMDB with BeautifulSoup | 37,444,700 | <p>I've stripped the following code from IMDB's mobile site using BeautifulSoup, with Python 2.7. </p>
<p>I want to create a separate object for the episode number '1', title 'Winter is Coming', and IMDB score '8.9'. Can't seem to figure out how to split apart the episode number and the title.</p>
<pre><code> <a... | 2 | 2016-05-25T18:11:09Z | 37,445,279 | <p>You can use <code>find</code> to locate the <code>span</code> with the class <code>text-large</code> to the specific element you need. </p>
<p>Once you have your desired <code>span</code>, you can use <code>next</code> to grab the next line, containing the episode number and <code>find</code> to locate the <code>st... | 3 | 2016-05-25T18:45:19Z | [
"python",
"beautifulsoup",
"imdb"
] |
Parsing IMDB with BeautifulSoup | 37,444,700 | <p>I've stripped the following code from IMDB's mobile site using BeautifulSoup, with Python 2.7. </p>
<p>I want to create a separate object for the episode number '1', title 'Winter is Coming', and IMDB score '8.9'. Can't seem to figure out how to split apart the episode number and the title.</p>
<pre><code> <a... | 2 | 2016-05-25T18:11:09Z | 37,445,339 | <p>Once you have each <code>a class="btn-full"</code>, you can use the span classes to get the tags you want, the strong tag is a child of the span with the <code>text-large</code> class so you just need to call <code>.strong.text</code> on the Tag, for the span with the css class <code>mobile-sprite tiny-star</code>,... | 2 | 2016-05-25T18:48:07Z | [
"python",
"beautifulsoup",
"imdb"
] |
How do you close a tkinter window in another function? | 37,444,757 | <p>I want a button in my window to open a new window and close the previous one. Is it possible to have one button do both of these? I've tried in the following code, but it hasn't worked, just told me that window is not defined:</p>
<pre><code>import tkinter
def window1():
window = tkinter.Tk()
tkinter.Button... | 0 | 2016-05-25T18:14:09Z | 37,444,899 | <p>First, you need to return the window object from the first function:</p>
<pre><code>def window1():
window = tkinter.Tk()
tkinter.Button(window, text = "Next", command = lambda: window2(window)).pack()
window.mainloop()
return window
</code></pre>
<p>Then, you need to pass the window as an argument ... | 1 | 2016-05-25T18:22:02Z | [
"python",
"tkinter"
] |
How do you close a tkinter window in another function? | 37,444,757 | <p>I want a button in my window to open a new window and close the previous one. Is it possible to have one button do both of these? I've tried in the following code, but it hasn't worked, just told me that window is not defined:</p>
<pre><code>import tkinter
def window1():
window = tkinter.Tk()
tkinter.Button... | 0 | 2016-05-25T18:14:09Z | 37,445,076 | <p>This is an example using Toplevels, which is usually a better choice than creating, destroying, re-creating Tk() instances. The unique Toplevel ID is passed to the close_it function using partial(). You would, of course, combine them or have the close function call the open function.</p>
<pre><code>try:
import... | 1 | 2016-05-25T18:33:30Z | [
"python",
"tkinter"
] |
Closing a QWidget opened from a QMainWindow | 37,444,760 | <p>I need to show a <code>QWidget</code>, which code is written in another module, when a certain button is pressed. To accomplish this, I wrote this code:</p>
<pre><code>class Window(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
#A lot of stuff in here
#The button is connected to the met... | 0 | 2016-05-25T18:14:22Z | 37,446,014 | <p>You probably want your <code>QWidget</code> to be a <code>QDialog</code>. If it's a temporary modal widget, you should be calling the dialog like this</p>
<pre><code>dialog = LiveData.LiveData(self)
dialog.exec_()
</code></pre>
<p>If you just want to show the dialog at the same time as your main window, and users... | 2 | 2016-05-25T19:28:54Z | [
"python",
"pyqt",
"qwidget"
] |
Regex return everthing but compound expression | 37,444,764 | <p>I'm trying to parse a gcode program to return everything except the comments contained withing (). The non-negated version works: ([(].*[)]) to return the comments ONLY. Why doesn't the pattern below return everything EXCEPT the comments?:</p>
<pre><code>(?!([(].*[)]))
%
O1000
T1 M6
G0 G90 G40 G21 G17 G94 G80
G5... | 2 | 2016-05-25T18:14:32Z | 37,444,812 | <p>Because a negative lookahead isn't used to negate an entire regex (meaning, it's not used to match the oppose of what the given regex is). It's used to say, at this point, assert that looking forward in the text it is not possible to match this regex.</p>
<p>A more simple example, we know that this is used to match... | 1 | 2016-05-25T18:17:24Z | [
"python",
"regex"
] |
Regex return everthing but compound expression | 37,444,764 | <p>I'm trying to parse a gcode program to return everything except the comments contained withing (). The non-negated version works: ([(].*[)]) to return the comments ONLY. Why doesn't the pattern below return everything EXCEPT the comments?:</p>
<pre><code>(?!([(].*[)]))
%
O1000
T1 M6
G0 G90 G40 G21 G17 G94 G80
G5... | 2 | 2016-05-25T18:14:32Z | 37,446,307 | <p>A couple of notes on your regex: <code>(?![(].*[)])</code> matches an empty space that is not followed with <code>(</code>, any 0+ chars other than a newline, up to the last <code>)</code> on the line. So, you only have a zero length match - no wonder you do not get anything.</p>
<p>If comments are the last <code>(... | 2 | 2016-05-25T19:45:01Z | [
"python",
"regex"
] |
How to return only user Path in environment variables without access to Registry? | 37,444,803 | <p>Here is what I want to achieve:
I am coding a Python based software, which will need to append new directories to <strong>PATH</strong> in environment variables in Windows. In order to do that, I first get the path, then modify the string, and last use SETX to update the new PATH.</p>
<p>My problem:
I tried three... | 1 | 2016-05-25T18:17:00Z | 37,556,219 | <pre><code>import _winreg
import unicodedata
keyQ = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, 'Environment', 0, _winreg.KEY_QUERY_VALUE)
path_old, _ = _winreg.QueryValueEx(keyQ, "PATH")
#the result is unicode, need to be converted
unicodedata.normalize('NFKD', path_old).encode('ascii','ignore')
</code></pre>
<p>Altho... | 0 | 2016-05-31T21:52:22Z | [
"python",
"windows",
"batch-file",
"path",
"environment-variables"
] |
Pandas plotting - Subplotting with axed plots | 37,444,876 | <p>I have a few scatterplots with axes added (to color-code the output), and I'd like to put them in a matrix (subplots). However, since they're axed already, I get the error: <code>TypeError: inner() got multiple values for keyword argument 'ax'</code>, as expected, and I get 4x2 empty plots, and the other plots are j... | 2 | 2016-05-25T18:20:35Z | 37,445,405 | <p>You need to add the <code>ax=axes1[0]</code> argument to the first <code>df.plot</code>call,<code>ax=axes1[1]</code> to the second, etc.</p>
<p>EDIT:</p>
<p>What you would like to do should look something like this:</p>
<p><em>Creating some mock dataframes:</em></p>
<pre><code>df1=pd.DataFrame(rand(10,2),columns... | 1 | 2016-05-25T18:52:38Z | [
"python",
"matplotlib",
"plot"
] |
Error when using midasr r package function through rpy2 in python | 37,444,893 | <p>I am trying to access functions in 'midasr' r package in python, here's my code:</p>
<pre><code>from rpy2.robjects import pandas2ri
pandas2ri.activate()
import rpy2.robjects as robjects
from rpy2.robjects.packages import importr
import pandas as pd
....
base = importr('base')
stats = importr('stats')
midasr = impo... | 0 | 2016-05-25T18:21:40Z | 37,449,348 | <p>Consider building your formula, passing in current values and <code>start</code> argument with a passed in Python object:</p>
<pre><code>x = np.random.rand(11256)
y = np.random.rand(1407)
formula = robjects.Formula('y ~ x')
env = formula.environment
env["y"] = y
env["x"] = midasr.mls(x, robjects.IntVector(range(15... | 1 | 2016-05-25T23:43:52Z | [
"python",
"pandas",
"rpy2"
] |
Keeping function call signatures consistent for a function that accepts a superset of another function's arguments | 37,444,910 | <p>I have a function (<code>foo</code>) that is a <s>convenience function</s> wrapper for another function (<code>bar</code>). <code>foo</code> calls <code>bar</code>, then performs another couple of tasks on the output. For example:</p>
<pre><code>def bar(bar_arg, bar_kw=None):
#do some stuff
return ret
de... | 6 | 2016-05-25T18:22:43Z | 37,445,272 | <p>I think the best option is to leave out <code>foo</code>. Keep the API short and sweet with just the simple building blocks that users need so that they can quickly learn how to use your library. Programmers can very easily then create the convenience functions that they actually want and not be distracted by the on... | 0 | 2016-05-25T18:45:06Z | [
"python",
"python-2.7"
] |
Keeping function call signatures consistent for a function that accepts a superset of another function's arguments | 37,444,910 | <p>I have a function (<code>foo</code>) that is a <s>convenience function</s> wrapper for another function (<code>bar</code>). <code>foo</code> calls <code>bar</code>, then performs another couple of tasks on the output. For example:</p>
<pre><code>def bar(bar_arg, bar_kw=None):
#do some stuff
return ret
de... | 6 | 2016-05-25T18:22:43Z | 37,457,542 | <p>Since <code>bar()</code> wraps <code>foo()</code> which calls the <code>ColorbarBase</code> constructor, write a decorator around the <code>foo()</code> call. The decorator makes modifications to the arguments passed into bar before calling <code>foo()</code>.</p>
<pre><code>from matplotlib import pyplot
import mat... | 1 | 2016-05-26T10:01:03Z | [
"python",
"python-2.7"
] |
Sqlalchemy how to filter column which contains both Null and integer values | 37,445,041 | <p>I have table with a nullable column which contains both types of values Null (as default) and integer:</p>
<pre><code>class Node(db.Model):
__tablename__ = "node"
maintenance = db.Column(db.Integer, nullable=True)
</code></pre>
<p>The request is like this one:</p>
<pre><code>maintenance = 1
node_list = No... | 1 | 2016-05-25T18:31:20Z | 37,445,153 | <blockquote>
<p>I need to select all cells which contains 'Null' or '0' values.</p>
</blockquote>
<p><strong>Using <code>|</code> as the logical <code>OR</code></strong></p>
<pre><code>Node.query.filter((Node.maintenance == None) | (Node.maintenance == 0))
</code></pre>
<p><strong>Using <code>is_(None)</code></str... | 1 | 2016-05-25T18:38:02Z | [
"python",
"flask",
"flask-sqlalchemy"
] |
Why isn't my WeakSet empty after deleting the only other reference? | 37,445,080 | <p>I decided I should familiarize myself with the <a href="https://docs.python.org/3/library/weakref.html" rel="nofollow"><code>weakref</code> library</a>, so I started messing around with the collections, thought I was getting the hang of it until this. </p>
<pre><code>>>> import weakref
>>> class ... | 0 | 2016-05-25T18:33:41Z | 37,445,170 | <p>You still have the <code>obj</code> variable from here:</p>
<pre><code>>>> for obj in objs: weak_s.add(obj)
</code></pre>
<p>That variable retains its last value from the loop, so it's still referring to the last <code>Greek</code> instance, keeping it alive and in the <code>WeakSet</code>.</p>
| 2 | 2016-05-25T18:38:50Z | [
"python",
"garbage-collection",
"weak-references"
] |
How to dynamically change depth in Django Rest Framework nested serializers? | 37,445,248 | <p>I have a set of nested serializers which have a <code>depth</code> set on their respective <code>Meta</code> classes. I'd like to programmatically change the depth based on parameters passed into in views.</p>
<pre><code>class ResourceSerializer(serializers.ModelSerializer):
type = serializers.PrimaryKe... | 3 | 2016-05-25T18:43:56Z | 37,572,944 | <p>Here is my code that incorporates including/excluding fields, as well as dynamically adjusting the depth. Adjust it to your taste. :)</p>
<pre><code>class DynamicModelSerializer(serializers.ModelSerializer):
"""
A ModelSerializer that takes an additional `fields` argument that
controls which fields should be displa... | 1 | 2016-06-01T15:28:24Z | [
"python",
"django",
"rest",
"serialization",
"django-rest-framework"
] |
How to split string by space and treat special characters as a separate word in Python? | 37,445,266 | <p>Assume I have a string, </p>
<pre><code>"I want that one, it is great."
</code></pre>
<p>I want to split up this string to be </p>
<pre><code>["I", "want", "that", "one", ",", "it", "is", "great", "."]
</code></pre>
<p>Keeping special characters such as <code>",.:;"</code> and possibly other ones to be treated a... | 1 | 2016-05-25T18:44:35Z | 37,445,407 | <p>See <a href="http://stackoverflow.com/a/2136580/426790">here</a> for a similar question. The answer there applies to you as well:</p>
<pre><code>import re
print re.split('(\W)', "I want that one, it is great.")
print re.split('(\W)', "I don't.")
</code></pre>
<p>You can remove the spaces and empty strings returned... | 1 | 2016-05-25T18:52:50Z | [
"python",
"python-2.7"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.