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 |
|---|---|---|---|---|---|---|---|---|---|
Pip installing to wrong virtual environment | 38,933,360 | <p>I have two Django projects each with a virtual environment called <code>myvenv</code>. I am trying to use pip to install a package called psycopg2. It is installing to the wrong virtual environment even though the <code>which pip</code> command confirms that pip is being run within the correct virtual environment.</... | 0 | 2016-08-13T13:45:28Z | 38,933,486 | <p>I think when you created your second virtualenv you did so with the first already activated, and possibly chained them together. Try to recreate your virtual environments, and when you create the second one <strong>make sure</strong> you deactivate the first one you created first.</p>
| 1 | 2016-08-13T14:00:51Z | [
"python",
"django",
"osx",
"virtualenv"
] |
Python operation data List in loop | 38,933,384 | <p>I want to solve my programming problem, the problem goes like so:</p>
<pre><code>input: 3 #if i input as first input example 3, output is [1, 2, 3]
[1, 2, 3]
input: 2 #2nd input example 2 output is [1, 2] + [1, 2, 3] = [2, 4, 6]
[2, 4, 3]
input: 6 #3rd input [2, 4, 6] + [1, 2, 3, 4, 5, 6] = [3, 6, 6, 4, 5, 6]
[3,... | 2 | 2016-08-13T13:48:36Z | 38,933,490 | <p>Building on your existing code, I would use <a href="https://docs.python.org/2/library/itertools.html#itertools.izip_longest" rel="nofollow"><code>itertools.izip_longest</code></a> (Python 2, for 3 use <code>zip.longest</code>):</p>
<pre><code>>>> import itertools
>>> nxt = []
>>> while T... | 3 | 2016-08-13T14:01:42Z | [
"python",
"list",
"loops",
"sum",
"condition"
] |
Python operation data List in loop | 38,933,384 | <p>I want to solve my programming problem, the problem goes like so:</p>
<pre><code>input: 3 #if i input as first input example 3, output is [1, 2, 3]
[1, 2, 3]
input: 2 #2nd input example 2 output is [1, 2] + [1, 2, 3] = [2, 4, 6]
[2, 4, 3]
input: 6 #3rd input [2, 4, 6] + [1, 2, 3, 4, 5, 6] = [3, 6, 6, 4, 5, 6]
[3,... | 2 | 2016-08-13T13:48:36Z | 38,933,577 | <p>You can use map</p>
<pre><code>result = []
while True:
a = input('Input : ')
n = range(1, a+1)
result = [(x or 0) + (y or 0) for x,y in map(None, n, result)]
print result
</code></pre>
<p>and result would be:</p>
<pre><code>Input : 3
[1, 2, 3]
Input : 2
[2, 4, 3]
Input : 6
[3, 6, 6, 4, 5, 6]
</cod... | 1 | 2016-08-13T14:12:10Z | [
"python",
"list",
"loops",
"sum",
"condition"
] |
Python operation data List in loop | 38,933,384 | <p>I want to solve my programming problem, the problem goes like so:</p>
<pre><code>input: 3 #if i input as first input example 3, output is [1, 2, 3]
[1, 2, 3]
input: 2 #2nd input example 2 output is [1, 2] + [1, 2, 3] = [2, 4, 6]
[2, 4, 3]
input: 6 #3rd input [2, 4, 6] + [1, 2, 3, 4, 5, 6] = [3, 6, 6, 4, 5, 6]
[3,... | 2 | 2016-08-13T13:48:36Z | 38,933,849 | <blockquote>
<p>but i can not use external code</p>
</blockquote>
<p>Then you can write some code that does exactly what <code>izip_longest</code> does with the zero padding when the new entry is lengthier than the previous result. </p>
<p>The sums are performed in a <em>list comprehension</em> where the values and... | 0 | 2016-08-13T14:44:22Z | [
"python",
"list",
"loops",
"sum",
"condition"
] |
How do I count the number of times a function is called? | 38,933,393 | <p>Here is my code, what I am trying to do is to apply a function written by me to a numpy array column-wisely. To know the progress of the program, I want to do similar thing as I can do in for loop with if <code>i % 100 == 0: print i</code></p>
<pre><code>from sklearn.mixture import GMM
gmm = GMM(n_components=2)
d... | 1 | 2016-08-13T13:49:30Z | 38,933,443 | <p>There's no such facility â in fact, there can't be, because <code>apply_along_axis</code> is a monolithic call (and that's a good thing, for performance reasons) that mostly happens in C/CPython. There's no facility to communicate the amount of already "processed" items back to python â in fact, when considering... | 1 | 2016-08-13T13:55:00Z | [
"python",
"numpy"
] |
How do I count the number of times a function is called? | 38,933,393 | <p>Here is my code, what I am trying to do is to apply a function written by me to a numpy array column-wisely. To know the progress of the program, I want to do similar thing as I can do in for loop with if <code>i % 100 == 0: print i</code></p>
<pre><code>from sklearn.mixture import GMM
gmm = GMM(n_components=2)
d... | 1 | 2016-08-13T13:49:30Z | 38,933,493 | <p>You could try writing a decorator for your function.</p>
<pre><code>from functools import wraps
from sklearn.mixture import GMM
gmm = GMM(n_components=2)
def log_every(n):
def decorator(fn)
counter = 0
@wraps(fn)
def wrapper(*args, **kwargs):
counter += 1
if cou... | 2 | 2016-08-13T14:02:08Z | [
"python",
"numpy"
] |
How do I count the number of times a function is called? | 38,933,393 | <p>Here is my code, what I am trying to do is to apply a function written by me to a numpy array column-wisely. To know the progress of the program, I want to do similar thing as I can do in for loop with if <code>i % 100 == 0: print i</code></p>
<pre><code>from sklearn.mixture import GMM
gmm = GMM(n_components=2)
d... | 1 | 2016-08-13T13:49:30Z | 38,934,312 | <p>A <code>global</code> counter should work, so would a mutable counter</p>
<pre><code>Out[1471]: array([12, 15, 18, 21])
In [1472]: A=np.arange(12).reshape(3,4)
In [1473]: def foo(x):
...: counter[0] +=1
...: print(counter)
...: return sum(x)
...:
In [1474]: counter=[0]
In [1475]... | 1 | 2016-08-13T15:36:34Z | [
"python",
"numpy"
] |
How to make your character move without tapping repeatedly on buttons? | 38,933,399 | <p>I'm working on a racing game. I have been using this code but my player keeps moving once only. How do I solve this problem?</p>
<pre><code>change = 7
dist = 7
change_r = 0
change_l = 0
dist_u = 0
dist_d = 0
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if... | 1 | 2016-08-13T13:49:52Z | 38,933,461 | <p>You should have a global loop irrespective of your event handling. You should place your clock.tick() and your movement there. Namely:</p>
<pre><code>#some constants here
while True:
pygame.display.update()
clock.tick(60)
#update you game state
if change_r == True:
x += change
if c... | 0 | 2016-08-13T13:58:00Z | [
"python",
"pygame",
"keydown"
] |
How to make your character move without tapping repeatedly on buttons? | 38,933,399 | <p>I'm working on a racing game. I have been using this code but my player keeps moving once only. How do I solve this problem?</p>
<pre><code>change = 7
dist = 7
change_r = 0
change_l = 0
dist_u = 0
dist_d = 0
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if... | 1 | 2016-08-13T13:49:52Z | 38,935,542 | <p>There are different ways you could go about making move-able shapes/sprites using Pygame. The code you posted in your question seems overly complex. I'll give you two different ways that are simpler, and easier to use. Using a sprite class, and using a function.</p>
<p>It may not seem like I'm answering your questi... | 1 | 2016-08-13T18:03:34Z | [
"python",
"pygame",
"keydown"
] |
python setup.py - how to show message after install | 38,933,402 | <p>I am developing a PyQt5 app and making it available via <code>pip install</code> now that pip in python3 can install pyqt5 as dependence. I made an entry point to launch my package, and told setup.py that it's a gui_scripts. </p>
<p>What I would like to do now, is after the person typing <code>pip install package</... | 0 | 2016-08-13T13:50:25Z | 38,933,723 | <p>The <strong>setup.py</strong> is almost a regular Python script.
Just use the <code>print()</code> function at the end of your <strong>setup.py</strong> file.
In this example the file structure is somedir/setup.py, somedir/test/ and test/<strong>init</strong>.py</p>
<h3>Simple solution</h3>
<pre><code>from setupto... | 1 | 2016-08-13T14:30:18Z | [
"python",
"python-3.x",
"setup.py"
] |
Curl to requests; max retries exceeded | 38,933,668 | <p>I've seen this:
<a href="http://stackoverflow.com/questions/31041994/python-requests-equivalent-to-curl-h">python requests equivalent to curl -H</a></p>
<p>but when I try and make my own python request I get the "Max retries exceeded with url:" error.</p>
<p>I am trying to convert this command</p>
<pre><code>curl... | 0 | 2016-08-13T14:24:44Z | 38,935,076 | <p>Try <code>requests.get</code> instead of <code>requests.post</code>, that curl command is probably calling GET and not POST.</p>
| 0 | 2016-08-13T17:03:16Z | [
"python",
"curl"
] |
Removing brackets in a list of tuples | 38,933,747 | <p>I have a list of tuple as below. </p>
<pre><code>>>>> date_lst
[(2013, 8, 13, 17),
(2013, 8, 5, 17),
(2013, 6, 26, 17),
(2013, 8, 7, 17),
(2013, 8, 7, 18),
(2013, 8, 8, 16),
(2013, 8, 8, 18),
(2013, 8, 7, 17),
(2013, 8, 7, 17)]
</code></pre>
<p>I want this list to print output as below. I wou... | -3 | 2016-08-13T14:32:52Z | 38,933,777 | <p>The brackets aren't in the data, so there is nothing to remove. The brackets and parenthesis only show up when you try to print the data. You simply need to extract the data from the list:</p>
<pre><code>for data in data_lst:
print("%s, %s, %s, %s" % data)
</code></pre>
| 0 | 2016-08-13T14:36:25Z | [
"python"
] |
Removing brackets in a list of tuples | 38,933,747 | <p>I have a list of tuple as below. </p>
<pre><code>>>>> date_lst
[(2013, 8, 13, 17),
(2013, 8, 5, 17),
(2013, 6, 26, 17),
(2013, 8, 7, 17),
(2013, 8, 7, 18),
(2013, 8, 8, 16),
(2013, 8, 8, 18),
(2013, 8, 7, 17),
(2013, 8, 7, 17)]
</code></pre>
<p>I want this list to print output as below. I wou... | -3 | 2016-08-13T14:32:52Z | 38,933,806 | <p>Cast every item in tuple to string, then join them.</p>
<pre><code>[', '.join(map(str, x)) for x in date_lst]
</code></pre>
| 0 | 2016-08-13T14:38:39Z | [
"python"
] |
cant get wsgi and python to work in wamp | 38,933,789 | <p>wamp version : <strong>2.5 , 64 bit</strong> <br>
python version : <strong>3.5.2 , 64 bit</strong><br>
windows version: <strong> 10 ,64 bit</strong><br>
apache version: <strong> 2.4.9</strong><br>
mod_wsgi: <strong>4.4.23 </strong>
<br><br>
I am trying to make python and flask work in wamp , so I read online and it ... | 0 | 2016-08-13T14:37:25Z | 38,936,929 | <p>So basicaly i disabled cgi , because when i put wsgi wamp was yellow so when i disabled cgi wamp became green so i thought cgi was the problem , now i was giving up so i said lets return everything to how it was i turned on cgi and wamp went yellow then </p>
<h1>GREEN</h1>
<p><code>I DONT KNOW WHY</code> after tha... | 0 | 2016-08-13T20:55:06Z | [
"python",
"apache",
"flask",
"wamp",
"wsgi"
] |
How to find the minimum number of tiles needed to cover holes in a roof | 38,933,872 | <p>I'm just learning about dynamic programming, and I've stumbled upon a problem which I am not sure how to formulate in Python:</p>
<blockquote>
<p>Given a binary array <code>H</code> of length 55, a <code>1</code> indicates a hole in the roof, <code>0</code> indicates no hole.
The tails you can use have length 1... | 1 | 2016-08-13T14:47:17Z | 38,934,300 | <p>Lets say cost[i] - best cost to cover first i elements of the roof.
Obviously cost[0] = 0 (we don't need any money to cover 0 tiles).</p>
<p>Lets describe our state as (position, cost).</p>
<p>From state (i,cost[i]) we can get to 4 different potential states:</p>
<ul>
<li>(i + 1, cost[i] + 3) (when we use tile of... | 3 | 2016-08-13T15:34:50Z | [
"python",
"algorithm",
"dynamic-programming"
] |
Python regex for removing scraping results according to substrings? | 38,933,897 | <p>I have a written a scraper in python. I have a group of strings which i want to search on the page and from the result of that, i want to remove those results which contains words from another group of strings i have.</p>
<p>Here is the code - </p>
<pre><code>def find_jobs(self, company, soup):
allowed = r... | 0 | 2016-08-13T14:50:25Z | 38,933,937 | <p>It looks like your are writing your notallowed regex wrongly. Your notallowed regex is actually looking for those words to be the only item on the line.</p>
<p><code>re.compile(r'^something_i_dont_like$')</code> is going to match something_i_dont_like if it is the only item on the line</p>
<p>if you want to omit s... | 1 | 2016-08-13T14:55:26Z | [
"python",
"regex",
"string",
"web-scraping"
] |
Python regex for removing scraping results according to substrings? | 38,933,897 | <p>I have a written a scraper in python. I have a group of strings which i want to search on the page and from the result of that, i want to remove those results which contains words from another group of strings i have.</p>
<p>Here is the code - </p>
<pre><code>def find_jobs(self, company, soup):
allowed = r... | 0 | 2016-08-13T14:50:25Z | 38,933,960 | <p>The regex</p>
<pre><code>^ability$
</code></pre>
<p>Means "the line consists only of the word "ability". If you want sub-strings, just change to</p>
<pre><code>ability
</code></pre>
<p>If you want to omit the word "ability", but not "disability", then use something like</p>
<pre><code>\bability\b
</code></pre>... | 0 | 2016-08-13T14:57:32Z | [
"python",
"regex",
"string",
"web-scraping"
] |
Py2Exe error: error: [Errno 2] No such file or directory: run-py3.5-win32.exe' | 38,934,129 | <p>Similar Questions have been asked to this before, however I have tried quite a lot and nothing seems to be working my exact error is:</p>
<pre><code>error: [Errno 2] No such file or directory: 'C:\\Users\\Byron\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\py2exe\\run-py3.5-win32.exe'
</code><... | 0 | 2016-08-13T15:15:58Z | 39,207,226 | <p>Py2exe does not support python 3.5 so the file doesn't exist yet.</p>
| 0 | 2016-08-29T13:13:22Z | [
"python",
"windows",
"exe",
"py2exe"
] |
How to use typeshed with mypy? | 38,934,177 | <p>I cloned <a href="https://github.com/python/typeshed/tree/master/stdlib/3.5" rel="nofollow">typeshed</a> but I can't figure out how to tell mypy to use the type hints it contains, I see no option in mypy --help. The mypy repo does contain reference to the typeshed repo, but pip installing it doesn't not download it.... | 0 | 2016-08-13T15:21:19Z | 38,934,841 | <p>Mypy comes bundled with typeshed by default, so you shouldn't need to do anything -- simply doing <code>pip install mypy-lang</code> will install it correctly. </p>
<p>Note that typeshed is not a Python module, so it isn't possible to import it or otherwise access it from a Python program unless you literally look ... | 1 | 2016-08-13T16:40:58Z | [
"python",
"type-hinting",
"mypy"
] |
I keep getting 'AttributeError: 'int' object has no attribute 'isdecimal'' not sure how to correct | 38,934,197 | <p>I have been working through a book called How to Automate the boring stuff Python tutorial book and I have come across an example that does not seem to run.</p>
<p>Here is my code:</p>
<pre><code>while True:
print 'Enter your age:'
age = input()
if age.isdecimal():
break
print 'Please enter a number for your a... | -2 | 2016-08-13T15:23:38Z | 39,321,945 | <p>Your indentation is off. Also the book uses Python 3.5, where print is followed by () with the code inside.</p>
<pre><code>while True:
print('Enter your age:')
age = input()
if age.isdecimal():
break
print('Please enter a number for your age.')
while True:
print('Select a new password (... | 1 | 2016-09-04T22:12:49Z | [
"python"
] |
Obtain expression inside one parenthesis inside double parenthesis in python | 38,934,220 | <p>Suppose there is the following code</p>
<pre><code>s= 'hello {world {123} }'
print s[s.find("{")+1:s.find("}")]
</code></pre>
<p>it gives me </p>
<pre><code>"world {123"
</code></pre>
<p>What should I do to obtain </p>
<pre><code>world {123}
</code></pre>
<p>?</p>
| -1 | 2016-08-13T15:26:28Z | 38,934,295 | <p>When slicing the <code>end</code> argument is exclusive, so you will need to add 1 to the result of <code>find</code>:</p>
<pre><code>print s[s.find("{") + 1: s.find("}") + 1]
</code></pre>
| 0 | 2016-08-13T15:33:58Z | [
"python",
"string",
"parentheses"
] |
Obtain expression inside one parenthesis inside double parenthesis in python | 38,934,220 | <p>Suppose there is the following code</p>
<pre><code>s= 'hello {world {123} }'
print s[s.find("{")+1:s.find("}")]
</code></pre>
<p>it gives me </p>
<pre><code>"world {123"
</code></pre>
<p>What should I do to obtain </p>
<pre><code>world {123}
</code></pre>
<p>?</p>
| -1 | 2016-08-13T15:26:28Z | 38,934,330 | <p>Well, I've never used this find method before, but I messed around a little bit and I've found if you use:</p>
<pre><code>print s[s.find("{")+1:s.find("}")+1]
</code></pre>
<p>it will return the results you're looking for.
Thanks for helping me learn something new.</p>
| 0 | 2016-08-13T15:38:30Z | [
"python",
"string",
"parentheses"
] |
Why is this parameter invalid in sklearn's Pipeline? | 38,934,236 | <p>I am getting the following error for the below code, but cannot figure out why my parameter is invalid. <code>SelectFromModel</code> is a valid input in a Pipeline as it has a fit and transform function. </p>
<pre><code>ValueError: Invalid parameter sfm_threshold for estimator Pipeline.
Check the list of available ... | 0 | 2016-08-13T15:27:32Z | 38,942,257 | <p>This is simple typographical error, you pass <code>sfm_threshold</code> and you should <code>sfm__threshold</code> (notice <strong>double</strong> underscore). At least this is what the error at the very beginning shows. </p>
| 1 | 2016-08-14T12:27:46Z | [
"python",
"machine-learning",
"scikit-learn"
] |
Set default date with Django SelectDateWidget | 38,934,402 | <p>Firstly, this question has already been asked <a href="http://stackoverflow.com/questions/8709116/how-to-set-defult-date-in-selectdatewidget-in-django">here</a>, however the answer does not work, and is also for Django 1.3. Having done extensive research on similar questions on SO, the Django Docs, and general Googl... | 0 | 2016-08-13T15:48:10Z | 38,935,327 | <p>Looks like there's a subtle difference when setting the the default time for <code>DateTimeField</code> and <code>DateField</code>.</p>
<blockquote>
<p>DateField.auto_now_add Automatically set the field to now when the
object is first created. Useful for creation of timestamps. Note that
the current date is a... | 0 | 2016-08-13T17:34:11Z | [
"python",
"django",
"django-models",
"django-forms"
] |
Python code between django "autoescape off" marks can not be executed | 38,934,414 | <p>I am trying to establish a blog using Django. I directly stored HTML into models. And I used <code>{% autoescape off %}</code> and <code>{% endautoescape %}</code> marks in HTML files that tells Python do not autoescape HTML code to string. Between the marks, I used codes like <code>{{ article.content }}</code> to l... | 0 | 2016-08-13T15:49:28Z | 38,934,633 | <p>This doesn't really have anything to do with autoescaping. When Django outputs a variable, it doesn't do anything to interpret whatever is in that variable; so putting template tags into a model field won't work.</p>
<p>You would need to do something to render that data yourself manually; perhaps a custom template ... | 0 | 2016-08-13T16:14:43Z | [
"python",
"html",
"django"
] |
How to substract values in DataFrames omiting some solumns | 38,934,415 | <p>I created two dataFrames and I want to subtract their values omitting two first columns in the first DataFrame.</p>
<pre><code>df = pd.DataFrame({'sys':[23,24,27,30],'dis': [0.8, 0.8, 1.0,1.0], 'Country':['US', 'England', 'US', 'Germany'], 'Price':[500, 1000, 1500, 2000]})
print df
index = {'sys':[23,24,27,30]}
df... | 0 | 2016-08-13T15:49:41Z | 38,934,525 | <p>Maybe, this is what you are looking for?</p>
<pre><code>>>> df
England Germany US
0 23 0.8 0.0 0.0 500.0
1 24 0.8 1000.0 0.0 0.0
2 27 1.0 0.0 0.0 1500.0
3 30 1.0 0.0 2000.0 0.0
>>> infile_slice
Benchmark
0 3.3199
1 -4... | 1 | 2016-08-13T16:01:08Z | [
"python",
"pandas"
] |
How to substract values in DataFrames omiting some solumns | 38,934,415 | <p>I created two dataFrames and I want to subtract their values omitting two first columns in the first DataFrame.</p>
<pre><code>df = pd.DataFrame({'sys':[23,24,27,30],'dis': [0.8, 0.8, 1.0,1.0], 'Country':['US', 'England', 'US', 'Germany'], 'Price':[500, 1000, 1500, 2000]})
print df
index = {'sys':[23,24,27,30]}
df... | 0 | 2016-08-13T15:49:41Z | 38,934,612 | <p>You could use <code>iloc</code> as follows:</p>
<pre><code>df_0_2 = df.iloc[:,0:2] # First 2 columns
df_2_end = df.iloc[:,2:].sub(infile_slice['Benchmark'].values, axis=0)
pd.concat([df_0_2, df_2_end], axis=1)
England Germany US
0 23 0.8 -3.3199 -3.3199 496.6801
1 24 0.8 ... | 0 | 2016-08-13T16:11:22Z | [
"python",
"pandas"
] |
Maximum recursion depth exceeded when using scipy.io.savemat() | 38,934,433 | <p>I'm trying to save a matrix using the scipy.io.savemat() function. However, I'm getting the following error:</p>
<p><code>RuntimeError: maximum recursion depth exceeded while calling a Python object</code></p>
<p>Here's the complete error I'm getting:</p>
<pre><code>scipy.io.savemat('path/to/file.mat',dict__)
F... | 0 | 2016-08-13T15:51:15Z | 38,936,386 | <p>Okay so just for the record, the cause of the problem is two variables in <code>dict__</code> that were being converted to <code>object</code> (normally they're supposed to be <code>float64</code>). When I was trying to save <code>dict__</code> in file.mat using <code>scipy.io.savemat()</code>, the error above was o... | 1 | 2016-08-13T19:46:08Z | [
"python",
"python-2.7",
"recursion",
"scipy",
"runtime-error"
] |
Regex with HTML tags and escaped characters | 38,934,445 | <p>I have this text:</p>
<p></p>
<pre><code><h5 class="subblocksubhead subsubsectionhead first"><b>Messaggi inseriti</b></h5>
<dl class="blockrow stats">
<dt><b>Messaggi inseriti</b></dt>
<dd> 81</dd>
</dl>
<dl class="blockrow stats"&g... | 0 | 2016-08-13T15:52:36Z | 38,934,515 | <p>Use an HTML Parser instead, like <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow"><code>BeautifulSoup</code></a>.</p>
<p>Adapting the <a class='doc-link' href="http://stackoverflow.com/documentation/beautifulsoup/1940/locating-elements/6339/locate-a-text-after-an-element-in-beautifuls... | 0 | 2016-08-13T15:59:59Z | [
"python",
"html",
"regex"
] |
A function that wont stop/pause my script | 38,934,457 | <p>I have a <code>for</code> loop, inside the loop I check something with <code>if</code> and, when the conditions are met, I launch a function. The thing is this function includes a waiting period (<code>time.sleep</code>) and I noticed the loop is paused until that function is finished.</p>
<p>Is there any way to ha... | -1 | 2016-08-13T15:54:24Z | 38,934,933 | <p>The problem you describe can be fairly trivially solved with simple threading like so:</p>
<pre><code>import time
import threading
def myfunction():
time.sleep(30)
print("waited 30 seconds.")
# do whatever else
num = 0
mythreads = []
while(True): # Just loop forever for demo purposes
num += 1
... | 0 | 2016-08-13T16:49:46Z | [
"python",
"subprocess"
] |
Tkinter labels change window size even after resizable | 38,934,494 | <p>I want to know if there is a way to make labels NOT change the window size. I've tried master.resizable(width=False, height=False) but it doesn't work. Same with adding buttons, the window size still changes. Also, I want it to work with <code>.grid</code> and not only <code>.pack</code>. Here's an example:</p>
<pr... | 0 | 2016-08-13T15:58:23Z | 38,934,582 | <p>Maybe you want this?</p>
<pre><code>master.geometry('{}x{}'.format(500, 500))
</code></pre>
<p><a href="http://i.stack.imgur.com/TCJz0.png" rel="nofollow"><img src="http://i.stack.imgur.com/TCJz0.png" alt="enter image description here"></a></p>
| 3 | 2016-08-13T16:08:09Z | [
"python",
"tkinter"
] |
Passing Json While running python script from terminal | 38,934,578 | <p>I want to pass JSON as a parameter while running the python script from the terminal. Can I pass JSON Object from terminal. However, I can only pass string from the terminal but I need JSON instead of that.</p>
<p>My tried passing string as follows which gave expected result.</p>
<pre><code> $ python test.py 'Pa... | 1 | 2016-08-13T16:07:40Z | 38,934,647 | <p>Two ways of doing this:</p>
<pre><code>$ cat a.py
import json
import sys
print json.loads(sys.stdin.read().strip())
$ python a.py <<< '{ "a":1, "b":2 }'
{u'a': 1, u'b': 2}
$ echo '{ "a":1, "b":2 }' | python a.py
{u'a': 1, u'b': 2}
$ cat c.py
import json
import sys
print json.loads(sys.argv[1])
$ python c.... | 1 | 2016-08-13T16:16:23Z | [
"python",
"json",
"shell"
] |
How to add a column of random numbers based on two conditions? | 38,934,684 | <p>I have a data frame in python containing the following information:</p>
<pre><code>Day Type
Weekday 1
Weekday 2
Weekday 3
Weekday 1
Weekend 2
Weekend 1
</code></pre>
<p>I want to add a new column by generating a Weibull random number but each pair of "D... | 0 | 2016-08-13T16:20:32Z | 38,934,803 | <p>Define a function that generates the random number you want and apply it to the rows.</p>
<pre><code>import io
import random
import math
import pandas as pd
data = io.StringIO('''\
Day Type
Weekday 1
Weekday 2
Weekday 3
Weekday 1
Weekend 2
Weekend 1
'''... | 1 | 2016-08-13T16:36:38Z | [
"python",
"pandas"
] |
How to compare and then concatenate information from two different rows using python pandas data frames | 38,934,732 | <p>I have written this code:</p>
<pre><code>import pandas as pd
import numpy as np
input_table = {'W' : pd.Series([1.1,2.1,3.1,4.1,5.1,6.1], index = ['1','2','3','4','5','6']),
'X' : pd.Series([7.,8.,9.,10.,11.,12.], index = ['1','2','3','4','5','6']),
'Y' : pd.Series(['A','B','C','D','E','E'], index = ['1'... | 2 | 2016-08-13T16:26:52Z | 38,935,015 | <p>Iterate over the rows of your DataFrame and set the value of the <code>Flowpath</code> column following the logic you outline in the OP.</p>
<pre><code>import pandas as pd
output_table = pd.DataFrame({'W' :[1.1, 2.1, 3.1, 4.1, 5.1, 6.1],
'X': [7., 8., 9., 10., 11., 12.],
... | 1 | 2016-08-13T16:56:53Z | [
"python",
"pandas"
] |
How to compare and then concatenate information from two different rows using python pandas data frames | 38,934,732 | <p>I have written this code:</p>
<pre><code>import pandas as pd
import numpy as np
input_table = {'W' : pd.Series([1.1,2.1,3.1,4.1,5.1,6.1], index = ['1','2','3','4','5','6']),
'X' : pd.Series([7.,8.,9.,10.,11.,12.], index = ['1','2','3','4','5','6']),
'Y' : pd.Series(['A','B','C','D','E','E'], index = ['1'... | 2 | 2016-08-13T16:26:52Z | 38,935,088 | <p>So bad things will happen if <code>Z['1']!='First'</code> but for your case this works. I understand you want something more Pandas-ish so I'm sorry that this answer is pretty plain python...</p>
<pre><code>import pandas as pd
import numpy as np
input_table = {'W' : pd.Series([1.1,2.1,3.1,4.1,5.1,6.1], index = ['1... | 0 | 2016-08-13T17:04:54Z | [
"python",
"pandas"
] |
How to compare and then concatenate information from two different rows using python pandas data frames | 38,934,732 | <p>I have written this code:</p>
<pre><code>import pandas as pd
import numpy as np
input_table = {'W' : pd.Series([1.1,2.1,3.1,4.1,5.1,6.1], index = ['1','2','3','4','5','6']),
'X' : pd.Series([7.,8.,9.,10.,11.,12.], index = ['1','2','3','4','5','6']),
'Y' : pd.Series(['A','B','C','D','E','E'], index = ['1'... | 2 | 2016-08-13T16:26:52Z | 38,935,108 | <p>You can calculate a group variable by <code>cumsum</code> on the condition vector where <code>Z</code> is <code>first</code> to satisfy the first and second conditions and replace the same value as previous one with empty string so that you can do <code>cumsum</code> on the Y column which should give the expected ou... | 1 | 2016-08-13T17:07:33Z | [
"python",
"pandas"
] |
How to compare and then concatenate information from two different rows using python pandas data frames | 38,934,732 | <p>I have written this code:</p>
<pre><code>import pandas as pd
import numpy as np
input_table = {'W' : pd.Series([1.1,2.1,3.1,4.1,5.1,6.1], index = ['1','2','3','4','5','6']),
'X' : pd.Series([7.,8.,9.,10.,11.,12.], index = ['1','2','3','4','5','6']),
'Y' : pd.Series(['A','B','C','D','E','E'], index = ['1'... | 2 | 2016-08-13T16:26:52Z | 38,935,720 | <pre><code>for index, row in output_table.iterrows():
prev_index = str(int(index) - 1)
if row['Z'] == 'First':
output_table.set_value(index, 'Flowpath', row['Y'])
elif output_table['Y'][prev_index] == row['Y']:
output_table.set_value(index, 'Flowpath', output_table['Flowpath'][prev_index])
els... | 1 | 2016-08-13T18:25:47Z | [
"python",
"pandas"
] |
Need warning message if count of each country code is less than 5 | 38,935,005 | <p>I am trying to get a warning or print message if count or frequency of a particular country code is less than 5.</p>
<pre><code>QuoteID
1500759-BE
1500759-BE
1500759-BE
1500759-BE
1605101-FR
1605101-FR
1605101-FR
1605119-FR
1605119-FR
1605119-FR
1605119-FR
1605119-FR
1600896-NL
1600896-NL
1600896-NL
1600898-NL
1600... | 0 | 2016-08-13T16:56:13Z | 38,935,144 | <p>You can use a <code>Counter</code> provided by Python's <code>collections</code> module to count the occurrences of the elements in a list.
In addition you can extract the country codes given in your sample data by splitting all lines and strip off the last two elements of each line (which is the country code).</p>
... | 0 | 2016-08-13T17:11:09Z | [
"python",
"loops",
"pandas",
"dataframe"
] |
Need warning message if count of each country code is less than 5 | 38,935,005 | <p>I am trying to get a warning or print message if count or frequency of a particular country code is less than 5.</p>
<pre><code>QuoteID
1500759-BE
1500759-BE
1500759-BE
1500759-BE
1605101-FR
1605101-FR
1605101-FR
1605119-FR
1605119-FR
1605119-FR
1605119-FR
1605119-FR
1600896-NL
1600896-NL
1600896-NL
1600898-NL
1600... | 0 | 2016-08-13T16:56:13Z | 38,935,254 | <p>what is the type of QuoteID if its type is string then it works fine </p>
<pre><code>alist = "1500759-BE1500759-BE1500759-BE1500759-BE1605101-FR1605101-FR1605101-FR1605119-FR1605119-FR1605119-FR1605119-FR1605119-FR1600896-NL1600896-NL1600896-NL1600898-NL1600898-NL1600898-NL1600898-NL1600898-NL1600898-NL"
chars=('B... | 0 | 2016-08-13T17:25:32Z | [
"python",
"loops",
"pandas",
"dataframe"
] |
Need warning message if count of each country code is less than 5 | 38,935,005 | <p>I am trying to get a warning or print message if count or frequency of a particular country code is less than 5.</p>
<pre><code>QuoteID
1500759-BE
1500759-BE
1500759-BE
1500759-BE
1605101-FR
1605101-FR
1605101-FR
1605119-FR
1605119-FR
1605119-FR
1605119-FR
1605119-FR
1600896-NL
1600896-NL
1600896-NL
1600898-NL
1600... | 0 | 2016-08-13T16:56:13Z | 38,935,341 | <p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.extract.html" rel="nofollow"><code>str.extract</code></a> to extract the country codes from each <code>QuoteID</code> string as follows:</p>
<pre><code>In [16]: df['CountryCode'] = df['QuoteID'].str.extract('(?P<letter... | 0 | 2016-08-13T17:36:00Z | [
"python",
"loops",
"pandas",
"dataframe"
] |
Mocking ReviewBoard third party library using python and mock | 38,935,061 | <p>I use ReviewBoard API library and today I moved the code to separate class and wanted to cover the logic with some tests. I understand mocks and testing but I am clearly not much experienced with the python and it's libraries. Here's the chunk of the real code:</p>
<pre><code><!-- language: python -->
from rb... | 1 | 2016-08-13T17:02:12Z | 39,061,758 | <p>In the example from your post, the order of the mocking is reversed:</p>
<pre><code>test_client_connect(self, mock_client, mock_method)
</code></pre>
<p>The client is actually being mocked as the second argument and the method call is being mocked as the first argument. </p>
<p>However, to properly mock the clien... | 1 | 2016-08-21T07:13:04Z | [
"python",
"mocking",
"python-unittest",
"review-board"
] |
Import at the top of the file with gi | 38,935,095 | <p>For libnotify I use the following code</p>
<pre><code>import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify
</code></pre>
<p>Then <code>flake8</code> complains that: </p>
<pre><code>E402 module level import not at top of file
</code></pre>
<p>On the other hand, one has to specify the ver... | 0 | 2016-08-13T17:06:08Z | 38,935,141 | <p>Put <code># noqa: E402</code> at the top of the file to ignore just this error in this file.</p>
<p>Sometimes, imports that aren't at the top of the file are necessary. For example, to avoid a circular import, to avoid the overheard of initializing a module until a certain function is called, or for configuration a... | 2 | 2016-08-13T17:11:02Z | [
"python",
"python-import",
"pep8"
] |
How do I stack rows in a Pandas data frame to get one âlong rowâ, preserving column types? | 38,935,112 | <p>This is a follow up to <a href="http://stackoverflow.com/questions/38900981/how-do-i-stack-rows-in-a-pandas-data-frame-to-get-one-long-row">How do I stack rows in a Pandas data frame to get one "long row"?</a></p>
<p>The answers there work but dropping the index here loses column types (they all become <e... | -1 | 2016-08-13T17:07:55Z | 38,935,411 | <p>You can <code>pivot</code> your table:</p>
<pre><code># create a unique id for all rows and pivot the table
df['id'] = 0
df1 = df.reset_index().pivot(index = 'id', columns = 'index')
# collapse multi index columns to single index
df1.columns = ['_'.join(['row'] + [str(c) for c in col][::-1]) for col in df1.col... | 1 | 2016-08-13T17:46:14Z | [
"python",
"pandas",
"dataframe"
] |
Center-align text with Python-pptx | 38,935,137 | <p><strong>Question in short:</strong> Is it possible to align text to the center in Python-pptx?</p>
<p>Since I'm using Python-pptx, I have been able to automate quite a lot of things and I really enjoy using it! However, I've run into a problem. I'm trying to center my text horizontally on a slide. If you don't unde... | 0 | 2016-08-13T17:10:21Z | 38,935,342 | <pre><code>from pptx.enum.text import PP_ALIGN
shape.paragraphs[0].alignment = PP_ALIGN.CENTER
</code></pre>
<p>This is taken directly from the <a href="https://python-pptx.readthedocs.io/en/latest/" rel="nofollow">Python pptx Docs</a>. Does this not work for you? You said in your question that you've heard of <code>... | 2 | 2016-08-13T17:36:11Z | [
"python",
"powerpoint",
"python-pptx"
] |
Convert elements of a list into binary | 38,935,169 | <p>Suppose I have a list:</p>
<pre><code>lst = [0, 1, 0, 0]
</code></pre>
<p>How can I make python interpret this list as a binary number 0100 so that <code>2*(0100)</code> gives me <code>01000</code>?</p>
<p>The only way that I can think of is to first make a function that converts the "binary" elements to corresp... | 3 | 2016-08-13T17:15:16Z | 38,935,289 | <p>You can try:</p>
<pre><code>l = [0, 0, 1, 0]
num = int(''.join(str(x) for x in l), base=2)
</code></pre>
| -1 | 2016-08-13T17:28:54Z | [
"python",
"python-3.x",
"binary"
] |
Convert elements of a list into binary | 38,935,169 | <p>Suppose I have a list:</p>
<pre><code>lst = [0, 1, 0, 0]
</code></pre>
<p>How can I make python interpret this list as a binary number 0100 so that <code>2*(0100)</code> gives me <code>01000</code>?</p>
<p>The only way that I can think of is to first make a function that converts the "binary" elements to corresp... | 3 | 2016-08-13T17:15:16Z | 38,935,406 | <p>You can use <a href="https://wiki.python.org/moin/BitwiseOperators" rel="nofollow">bitwise operators</a> like this:</p>
<pre><code>>>> lst = [0, 1, 0, 0]
>>> bin(int(''.join(map(str, lst)), 2) << 1)
'0b1000'
</code></pre>
| 2 | 2016-08-13T17:45:07Z | [
"python",
"python-3.x",
"binary"
] |
Convert elements of a list into binary | 38,935,169 | <p>Suppose I have a list:</p>
<pre><code>lst = [0, 1, 0, 0]
</code></pre>
<p>How can I make python interpret this list as a binary number 0100 so that <code>2*(0100)</code> gives me <code>01000</code>?</p>
<p>The only way that I can think of is to first make a function that converts the "binary" elements to corresp... | 3 | 2016-08-13T17:15:16Z | 38,936,539 | <p>This is not a fancy one-liner, but simple and fast.</p>
<pre><code>lst = [0,1,1,0]
num = 0
for b in lst:
num = 2 * num + b
print(num) # 6
</code></pre>
| -1 | 2016-08-13T20:05:55Z | [
"python",
"python-3.x",
"binary"
] |
Error while importing caffe | 38,935,189 | <p>I am getting this error while importing caffe in ipython.</p>
<pre><code>ImportError Traceback (most recent call last)
<ipython-input-1-1cca3aa1f8c5> in <module>()
----> 1 import caffe
/home/harshita/deep-learning/caffe/python/caffe/__init__.py in <module>()
----&... | 0 | 2016-08-13T17:16:59Z | 38,938,285 | <p>Have you built pycaffe? Run
<code>make pycaffe</code>
in your caffe home folder.</p>
<p>By the way, your PATH is fine, otherwise you would receive an error like: no module named caffe.</p>
| 0 | 2016-08-14T00:58:23Z | [
"python",
"caffe",
"pycaffe"
] |
Adding triple containing blank node to stardog with rdflib | 38,935,244 | <p>I'm using the rdflib python library to manipulate a stardog database. How do I add a blank node? I'm trying <code>g.add((BNode(),FOAF.knows,Literal('amy')))</code>, but i get an exception "SPARQLStore does not support Bnodes!". What is the alternative? </p>
| 0 | 2016-08-13T17:24:31Z | 38,942,940 | <p>This is a restriction of RDFLib's SPARQLStore implementation, which you seem to be using. See the <a href="https://rdflib.readthedocs.io/en/2.4.0/apidocs/rdflib.plugins.stores.html?highlight=sparqlstore#rdflib.plugins.stores.sparqlstore.SPARQLStore" rel="nofollow">docs</a>. </p>
<p>You may be able to accomplish thi... | 2 | 2016-08-14T13:57:32Z | [
"python",
"sparql",
"semantic-web",
"rdflib",
"stardog"
] |
Program for ARP scanning | 38,935,304 | <pre><code>#!/usr/bin/python3
#Fazer arping da conexao
import sys
from datetime import datetime
from scapy.all import *
try:
interface = input ("\n[*] Set interface: ")
ips = input("[*] Set IP RANGE or Network: ")
except KeyboardInterrupt:
print("\n user aborted")
sys.exit()
print("Scanning...")
star... | 1 | 2016-08-13T17:30:30Z | 39,048,478 | <p>About the code:</p>
<pre><code> ans,unans = srp(Ether(dst = "ff:ff:ff:ff:ff:ff")/ARP(pdst = ips), timeout = 2, iface = interface ,inter= 0.1)
</code></pre>
<p>What this code does is fairly simple. You use the srp funtion to send packets and receive answer for them - in this case that packets are constructed by the... | 3 | 2016-08-19T22:26:25Z | [
"python",
"python-3.4"
] |
Program for ARP scanning | 38,935,304 | <pre><code>#!/usr/bin/python3
#Fazer arping da conexao
import sys
from datetime import datetime
from scapy.all import *
try:
interface = input ("\n[*] Set interface: ")
ips = input("[*] Set IP RANGE or Network: ")
except KeyboardInterrupt:
print("\n user aborted")
sys.exit()
print("Scanning...")
star... | 1 | 2016-08-13T17:30:30Z | 39,156,820 | <p><strong>1ãWhy there is a tuple ans,unans ?</strong></p>
<p>A: <code>srp</code> return <code>answered</code> and <code>unanswered</code> packets, so it is a tuple.<a href="https://github.com/secdev/scapy/blob/master/scapy/sendrecv.py" rel="nofollow">srp function</a></p>
<p><strong>2ãWhats is inter= 0.1 ?</stron... | 1 | 2016-08-26T00:48:50Z | [
"python",
"python-3.4"
] |
How to chain multiple arguments in python? add(1)(2)(3) = 6 | 38,935,313 | <p>I'm trying to create a function that chains results from multiple arguments.</p>
<pre><code>def hi(string):
print(string)<p>
return hi
</code></pre>
<p>Calling <code>hi("Hello")("World")</code> works and becomes Hello \n World as expected.</p>
<p>the problem is when I want to append the result as a si... | -1 | 2016-08-13T17:31:21Z | 38,935,360 | <p>You are getting into some deep, Haskell-style, type-theoretical issues by having <code>hi</code> return a reference to itself. Instead, just accept multiple arguments and concatenate them in the function.</p>
<pre><code>def hi(*args):
return "\n".join(args)
</code></pre>
<p>Some example usages:</p>
<pre><code... | 2 | 2016-08-13T17:38:28Z | [
"python"
] |
How to chain multiple arguments in python? add(1)(2)(3) = 6 | 38,935,313 | <p>I'm trying to create a function that chains results from multiple arguments.</p>
<pre><code>def hi(string):
print(string)<p>
return hi
</code></pre>
<p>Calling <code>hi("Hello")("World")</code> works and becomes Hello \n World as expected.</p>
<p>the problem is when I want to append the result as a si... | -1 | 2016-08-13T17:31:21Z | 38,935,526 | <p>You're running into difficulty here because the result of each call to the function must be a function (so you can chain another function call), while at the same time <em>also</em> being a legitimate string (in case you <em>don't</em> chain another function call and just use the return value as-is). </p>
<p>Fortun... | 3 | 2016-08-13T18:01:30Z | [
"python"
] |
simple multithreading example with tornado.web.RequestHandler | 38,935,322 | <p>I have got a <code>mysterious_library</code>, providing a synchronous function <code>query_resource_for_a_long_time</code>.</p>
<p>Then I have the code below that is supposed to fetch the resource asynchronously:</p>
<pre><code>import tornado.ioloop
import tornado.web
import threading
from mysterious_library impo... | 0 | 2016-08-13T17:33:18Z | 38,935,985 | <p>Yes, follow the instructions to use ThreadPoolExecutor:</p>
<p><a href="http://www.tornadoweb.org/en/stable/guide/coroutines.html#calling-blocking-functions" rel="nofollow">http://www.tornadoweb.org/en/stable/guide/coroutines.html#calling-blocking-functions</a></p>
<p>Be aware, when you're testing this, that you c... | 1 | 2016-08-13T18:58:16Z | [
"python",
"asynchronous",
"tornado"
] |
Dynamic Filtering in Django with default Queryset | 38,935,422 | <p>I've read the excellent explanation in this question
<a href="http://stackoverflow.com/questions/25662374/dynamically-filter-listview-cbv-in-django-1-7">Dynamically filter ListView CBV in Django 1.7</a>. </p>
<p>But I wan't to get extra help on the queryset.</p>
<pre><code># urls.py
urlpatterns = patterns('',... | 0 | 2016-08-13T17:47:37Z | 38,935,505 | <p>Just wrap it in an <code>if</code>.</p>
<pre><code> qs = super(ScholarshipDirectoryView, self).get_queryset()
exp = self.kwargs['exp']
if exp:
qs = qs.filter(experience_level__exact=exp)
# return the new or the old queryset.
return qs
</code></pre>
| 0 | 2016-08-13T17:58:01Z | [
"python",
"django",
"listview"
] |
TensorFlow REST Frontend but not TensorFlow Serving | 38,935,428 | <p>I want to deploy a simple TensorFlow model and run it in REST service like Flask.
Did not find so far good example on github or here.</p>
<p>I am not ready to use TF Serving as suggested in other posts, it is perfect solution for Google but it overkill for my tasks with gRPC, bazel, C++ coding, protobuf...</p>
| 11 | 2016-08-13T17:48:09Z | 39,102,115 | <p>This <a href="https://github.com/sugyan/tensorflow-mnist/blob/master/main.py" rel="nofollow">github project</a> shows a working example of restoring a model checkpoint and using Flask.</p>
<pre><code>@app.route('/api/mnist', methods=['POST'])
def mnist():
input = ((255 - np.array(request.json, dtype=np.uint8)) ... | 1 | 2016-08-23T13:06:53Z | [
"python",
"flask",
"tensorflow",
"tensorflow-serving"
] |
TensorFlow REST Frontend but not TensorFlow Serving | 38,935,428 | <p>I want to deploy a simple TensorFlow model and run it in REST service like Flask.
Did not find so far good example on github or here.</p>
<p>I am not ready to use TF Serving as suggested in other posts, it is perfect solution for Google but it overkill for my tasks with gRPC, bazel, C++ coding, protobuf...</p>
| 11 | 2016-08-13T17:48:09Z | 39,104,964 | <p>There are different ways to do this. Purely, using tensorflow is not very flexible, however relatively straightforward. The downside of this approach is that you have to rebuild the graph and initialize variables in the code where you restore the model. There is a way shown in <a href="https://github.com/tensorflow/... | 4 | 2016-08-23T15:14:47Z | [
"python",
"flask",
"tensorflow",
"tensorflow-serving"
] |
TensorFlow REST Frontend but not TensorFlow Serving | 38,935,428 | <p>I want to deploy a simple TensorFlow model and run it in REST service like Flask.
Did not find so far good example on github or here.</p>
<p>I am not ready to use TF Serving as suggested in other posts, it is perfect solution for Google but it overkill for my tasks with gRPC, bazel, C++ coding, protobuf...</p>
| 11 | 2016-08-13T17:48:09Z | 39,222,603 | <p>i don't like to put much code with data\model processing in flask restful file.. Usually have tf model class and so on separately.. i.e. it could be something like this</p>
<pre><code># model init, loading data
cifar10_recognizer = Cifar10_Recognizer()
cifar10_recognizer.load('data/c10_model.ckpt')
@app.route('/tf... | 1 | 2016-08-30T08:37:30Z | [
"python",
"flask",
"tensorflow",
"tensorflow-serving"
] |
Finding Excel cell reference using Python | 38,935,460 | <p><a href="http://i.stack.imgur.com/fwVen.png" rel="nofollow">Here is the Excel file in question:</a></p>
<p>Context: I am writing a program which can pull values from a PDF and put them in the appropriate cell in an Excel file.</p>
<p>Question: I want to write a function which takes a column value (e.g. 2014) and a... | 0 | 2016-08-13T17:53:01Z | 38,947,108 | <p>There are a surprising number of details you need to get right to manipulate Excel files this way with openpyxl. First, it's worth knowing that the xlsx file contains two representations of each cell - the formula, and the current value of the formula. openpyxl can return either, and if you want values you should sp... | 0 | 2016-08-14T22:18:06Z | [
"python",
"excel",
"match",
"cell"
] |
Finding Excel cell reference using Python | 38,935,460 | <p><a href="http://i.stack.imgur.com/fwVen.png" rel="nofollow">Here is the Excel file in question:</a></p>
<p>Context: I am writing a program which can pull values from a PDF and put them in the appropriate cell in an Excel file.</p>
<p>Question: I want to write a function which takes a column value (e.g. 2014) and a... | 0 | 2016-08-13T17:53:01Z | 38,948,460 | <p>Consider a translated VBA solution as the <a href="https://msdn.microsoft.com/en-us/library/office/ff835873.aspx" rel="nofollow">Match</a> function can adequately handle your needs. Python can access the Excel VBA Object Library using a COM interface with the <code>win32com</code> module. Please note this solution a... | 0 | 2016-08-15T02:16:38Z | [
"python",
"excel",
"match",
"cell"
] |
dplyr summarize equivalent in pandas | 38,935,541 | <p>I used to work with R and really love the dplyr package which you can easily group by and summarize. </p>
<p>However, in pandas, I don't see an equivalent of summarize and here is how I achieve it in Python: </p>
<pre><code>import pandas as pd
data = pd.DataFrame(
{'col1':[1,1,1,1,1,2,2,2,2,2],
'col2':[1,2... | 8 | 2016-08-13T18:03:32Z | 38,935,669 | <p>The equivalent in pandas would be something like this:</p>
<pre><code>data.groupby(['col1']).agg({'col2': max, 'col3': min})
Out:
col2 col3
col1
1 5 -5
2 9 -9
</code></pre>
<p>If you don't want col1 as an index, you can add <code>.reset_index()</code> at the end.</p>
<p>In ... | 5 | 2016-08-13T18:18:21Z | [
"python",
"pandas"
] |
Confusion with data after scipy.fftconvolve | 38,935,606 | <p>This question has probably been asked before but I cannot find my specific answer in any one place. So here it is: I am trying to find the time difference (lag) between two audio signals (Gaussian white noise) that have been captured by two USB mics. With no problem I have recorded the audio from two different strea... | 0 | 2016-08-13T18:11:19Z | 38,938,439 | <p>In situations like this, itâs a good idea to make sure your algorithm works on perfect data before trying with real data. It turns out that even if you understand the algorithm, Scipy is stupid in not giving an easy way to obtain the lags corresponding to correlations.</p>
<p>So hereâs my <a href="https://gist.... | 0 | 2016-08-14T01:35:02Z | [
"python",
"scipy",
"signal-processing",
"fft"
] |
How to generate this sequence using python | 38,935,690 | <p>For example if q = 2, then i have to generate all sequence between [1,1] to [2,2].
if q = 3, then generate sequence between [1,1,1] to [3,3,3]. for q = 4, then generate sequence between [1,1,1,1] to [4,4,4,4], etc..</p>
<p>example of sequence .
for q = 3</p>
<pre><code>(1, 1, 1)
(1, 1, 2)
(1, 1, 3)
(1, 2, 1)
(1, 2... | 0 | 2016-08-13T18:21:38Z | 38,935,749 | <p>Use itertools.product with the repeat parameter:</p>
<pre><code>q = 2
list(itertools.product(range(1, q + 1), repeat=q))
Out: [(1, 1), (1, 2), (2, 1), (2, 2)]
q = 3
list(itertools.product(range(1, q + 1), repeat=q))
Out:
[(1, 1, 1),
(1, 1, 2),
(1, 1, 3),
(1, 2, 1),
(1, 2, 2),
...
</code></pre>
| 6 | 2016-08-13T18:28:29Z | [
"python",
"itertools"
] |
How to generate this sequence using python | 38,935,690 | <p>For example if q = 2, then i have to generate all sequence between [1,1] to [2,2].
if q = 3, then generate sequence between [1,1,1] to [3,3,3]. for q = 4, then generate sequence between [1,1,1,1] to [4,4,4,4], etc..</p>
<p>example of sequence .
for q = 3</p>
<pre><code>(1, 1, 1)
(1, 1, 2)
(1, 1, 3)
(1, 2, 1)
(1, 2... | 0 | 2016-08-13T18:21:38Z | 38,935,818 | <p>I think you want <code>itertools.product()</code>, which does all possible combinations of the iterable elements. <code>itertools.permutations()</code> does not repeat elements, and <code>itertools.combinations()</code> or <code>itertools.combinations_with_replacement()</code> only goes in sorted order (e.g. the fir... | 3 | 2016-08-13T18:36:36Z | [
"python",
"itertools"
] |
'int' object is not iterable in class __init__ definition | 38,935,713 | <pre><code>class MenuItem():
def __init__(self, width, height, (posX, posY)=(0,0)):
#self.label = self.render(self.text, 1, self.font_color)
self.width = width
self.height = height
self.posX = posX
self.posY = posY
self.position = posX, posY
def set_position(self, x, y):
self.position = (x,... | -2 | 2016-08-13T18:25:16Z | 38,961,426 | <p>You're trying to iterate an integer. </p>
<pre><code>class RadioFrame(MenuItem):
def __init__(numButtons, buttonWidth, (posX, posY)=(0, 0)):
super(RadioFrame, self).__init__(numButtons * buttonWidth, width)
self.set_position(posX, posY)
self.numButtons = numButtons
self.buttons =... | 0 | 2016-08-15T19:08:58Z | [
"python",
"class",
"pygame"
] |
Get windows 10 build version (release ID) | 38,935,715 | <p>I want to get Windows build <em>version</em>. I have searched everywhere for this, but to no avail.</p>
<p>No, I don't want to know if it's 7, 8, 10, or whatever. I don't want the Windows build number. I want to know the Windows build <strong>version</strong>. I am not sure what the official name of this would be, ... | 3 | 2016-08-13T18:25:28Z | 38,936,122 | <p>I don't know of any libraries that will give you this value directly, but you can parse the command window output when you open a new command window via <code>os.popen()</code>.</p>
<pre><code>print(os.popen('cmd').read())
</code></pre>
<p>The boot screen for the command window has the version/build data on the fi... | 0 | 2016-08-13T19:14:23Z | [
"python",
"windows-10"
] |
Get windows 10 build version (release ID) | 38,935,715 | <p>I want to get Windows build <em>version</em>. I have searched everywhere for this, but to no avail.</p>
<p>No, I don't want to know if it's 7, 8, 10, or whatever. I don't want the Windows build number. I want to know the Windows build <strong>version</strong>. I am not sure what the official name of this would be, ... | 3 | 2016-08-13T18:25:28Z | 38,936,407 | <p>You can use <a href="https://docs.python.org/3.5/library/ctypes.html?highlight=ctypes#module-ctypes" rel="nofollow">ctypes</a> and <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx" rel="nofollow">GetVersionEx</a> from <code>Kernel32.dll</code> to find the build number.</p>
<p... | 2 | 2016-08-13T19:49:43Z | [
"python",
"windows-10"
] |
Get windows 10 build version (release ID) | 38,935,715 | <p>I want to get Windows build <em>version</em>. I have searched everywhere for this, but to no avail.</p>
<p>No, I don't want to know if it's 7, 8, 10, or whatever. I don't want the Windows build number. I want to know the Windows build <strong>version</strong>. I am not sure what the official name of this would be, ... | 3 | 2016-08-13T18:25:28Z | 38,936,997 | <p>It seems you are looking for the <code>ReleaseID</code> which is different from the build number.</p>
<p>You can find it by query the value of <code>ReleaseID</code> in <code>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion</code> registry key. </p>
<p>You can query the value using <a href="https://... | 1 | 2016-08-13T21:03:34Z | [
"python",
"windows-10"
] |
pandas extract list from dataframe | 38,935,735 | <p>Suppose I have a dataframe like below: </p>
<pre><code> FDT_DATE FFLT_LATITUDE FFLT_LONGITUDE FINT_STAT FSTR_ID
51307 1417390467000 31.2899 121.4845 0 112609
51308 1417390428000 31.2910 121.4859 0 112609
51309 1417390608000 31.2944 121.4857 1 112609
51310 1417... | 1 | 2016-08-13T18:26:55Z | 38,936,581 | <p><a href="http://stackoverflow.com/questions/26483254/python-pandas-insert-list-into-a-cell">You can insert</a> <code>list</code> into <code>pandas.DataFrame()</code> only with <code>.set_value()</code> method. And the column type should be <code>object</code>.</p>
<pre><code>df = pd.DataFrame({"FDT_DATE":[141739046... | 1 | 2016-08-13T20:11:18Z | [
"python",
"pandas",
"dataframe",
"preprocessor",
"data-cleaning"
] |
pandas extract list from dataframe | 38,935,735 | <p>Suppose I have a dataframe like below: </p>
<pre><code> FDT_DATE FFLT_LATITUDE FFLT_LONGITUDE FINT_STAT FSTR_ID
51307 1417390467000 31.2899 121.4845 0 112609
51308 1417390428000 31.2910 121.4859 0 112609
51309 1417390608000 31.2944 121.4857 1 112609
51310 1417... | 1 | 2016-08-13T18:26:55Z | 38,937,043 | <pre><code>import pandas as pd
import numpy as np
# Initializing the data
df = pd.DataFrame({'FDT_DATE': {0: 1417390467000, 1: 1417390428000, 2: 1417390608000, 3: 1417390548000,
4: 1417390668000, 5: 1417390717000, 6: 1417390758000, 7: 1417390798000,
8: 14... | 2 | 2016-08-13T21:11:17Z | [
"python",
"pandas",
"dataframe",
"preprocessor",
"data-cleaning"
] |
Using pyCrypto to hash results in a TypeError | 38,935,777 | <p>I'm trying to use pycrypto for python 3.5.1 on win10<br>
using this simple piece of code for has: </p>
<pre><code>from Crypto.Hash import SHA256
SHA256.new('abc').hexdigest()
</code></pre>
<p>resulting this error:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
File... | 0 | 2016-08-13T18:31:05Z | 38,936,070 | <p>Use the <code>.encode()</code> function on your 'abc' string before running the hashing function. </p>
<p>For example, if you wish to use <em>Unicode</em> encoding:</p>
<pre><code>'abc'.encode('utf-8')
</code></pre>
| 0 | 2016-08-13T19:07:18Z | [
"python",
"hash",
"encoding",
"pycrypto"
] |
Using pyCrypto to hash results in a TypeError | 38,935,777 | <p>I'm trying to use pycrypto for python 3.5.1 on win10<br>
using this simple piece of code for has: </p>
<pre><code>from Crypto.Hash import SHA256
SHA256.new('abc').hexdigest()
</code></pre>
<p>resulting this error:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
File... | 0 | 2016-08-13T18:31:05Z | 38,936,506 | <blockquote>
<p>TypeError: Unicode-objects must be encoded before hashing</p>
</blockquote>
<p>means you should do something like this:</p>
<pre><code>from Crypto.Hash import SHA256
print(SHA256.new('abc'.encode('utf-8')).hexdigest())
</code></pre>
| 0 | 2016-08-13T20:02:16Z | [
"python",
"hash",
"encoding",
"pycrypto"
] |
Using Python 3 when Python 2.7 is default, pip install error | 38,935,801 | <p>I originally had both python 2.7 and python 3 installed with python 2.7 as my default in PATH. I needed to run a script using python 3 but could not set it as my default python in PATH for some reason. After just uninstalling python 2.7 I opened 3 and ran the command python get-pip.py install which gave me this erro... | 2 | 2016-08-13T18:34:48Z | 39,140,216 | <p>I assume you use windows, so here is an answer how to install pip on windows:</p>
<p><a href="http://stackoverflow.com/questions/4750806/how-do-i-install-pip-on-windows">how-do-i-install-pip-on-windows</a></p>
<p>On Linux you could just type:</p>
<pre><code>sudo apt install python-pip
</code></pre>
| 0 | 2016-08-25T08:25:37Z | [
"python",
"python-3.x",
"pip"
] |
I am trying to run a program that will tell you how many times a letter is repeated in a string based on raw_input | 38,935,845 | <pre><code>dict = {}
raw_input('Please enter a string :')
letter = raw_input()
for letter in raw_input:
if letter not in dict.keys():
dict[letter] = 1
else:
dict[letter] += 1
print dict
</code></pre>
<p>My error: </p>
<pre><code>line 9, in <module>
TypeError: 'builtin_function_or_method... | 1 | 2016-08-13T18:39:28Z | 38,944,620 | <p>You are receiving this error because you are attempting to iterate through <code>raw_input</code>: <code>for letter in raw_input:</code>. </p>
<p>However, in Python, only objects with an <code>__iter__()</code> method are iterable, and <code>raw_input</code> doesn't have this method (it's also a builtin in Python)... | 1 | 2016-08-14T17:15:01Z | [
"python",
"python-2.7",
"raw-input"
] |
I am trying to run a program that will tell you how many times a letter is repeated in a string based on raw_input | 38,935,845 | <pre><code>dict = {}
raw_input('Please enter a string :')
letter = raw_input()
for letter in raw_input:
if letter not in dict.keys():
dict[letter] = 1
else:
dict[letter] += 1
print dict
</code></pre>
<p>My error: </p>
<pre><code>line 9, in <module>
TypeError: 'builtin_function_or_method... | 1 | 2016-08-13T18:39:28Z | 38,945,736 | <p>worked for me when i changed <code>for letter in raw_input:</code> to <code>for letter in raw_input():</code> and the input was "question" and output was "{'e': 1, 'i': 1, 'o': 1, 'n': 1, 'q': 1, 's': 1, 'u': 1, 't': 1}" , and also i think you can change the part of code inside the for loop to <code>dict[letter] = d... | 1 | 2016-08-14T19:16:07Z | [
"python",
"python-2.7",
"raw-input"
] |
I am trying to run a program that will tell you how many times a letter is repeated in a string based on raw_input | 38,935,845 | <pre><code>dict = {}
raw_input('Please enter a string :')
letter = raw_input()
for letter in raw_input:
if letter not in dict.keys():
dict[letter] = 1
else:
dict[letter] += 1
print dict
</code></pre>
<p>My error: </p>
<pre><code>line 9, in <module>
TypeError: 'builtin_function_or_method... | 1 | 2016-08-13T18:39:28Z | 38,946,684 | <p>By far the easiest way to do this is to use the <code>Counter</code> class in the built-in <code>collections</code> module:</p>
<pre><code>from collections import Counter
print Counter(raw_input('Please enter a string: '))
</code></pre>
<p>A <code>Counter</code> can be accessed just like a dictionary:</p>
<pre><... | 0 | 2016-08-14T21:13:34Z | [
"python",
"python-2.7",
"raw-input"
] |
rmvirtualenv <name> does not remove a env | 38,935,850 | <p>I am a beginner in Python.</p>
<p>I am trying to remove a virtualenv which I have created before by using this command under C:>virtualenvs</p>
<pre><code>rmvirtualenv test
</code></pre>
<p>and then I got the following</p>
<p>virtualenv "test" does not exist.</p>
<p>I still can see the directory listed under vi... | 0 | 2016-08-13T18:40:11Z | 38,936,179 | <p>I have sorted out this issue.</p>
<p>Considering you have already installed virtualenvwrapper-win(if Windows)</p>
<p>The steps are -- </p>
<pre><code>1.Go to directory 'virtualenvs' (where all the envs are listed)
2.Make an env by using this command -- mkvirtualenv test (where test is a env name in my case)
3. Us... | 0 | 2016-08-13T19:19:58Z | [
"python",
"virtualenv",
"virtualenvwrapper"
] |
Convert python pandas rows to columns | 38,935,862 | <pre><code> Decade difference (kg) Version
0 1510 - 1500 -0.346051 v1.0h
1 1510 - 1500 -3.553251 A2011
2 1520 - 1510 -0.356409 v1.0h
3 1520 - 1510 -2.797978 A2011
4 1530 - 1520 -0.358922 v1.0h
</code>... | 0 | 2016-08-13T18:41:10Z | 38,935,934 | <pre><code>In [28]: df.pivot(index='Decade', columns='Version', values='difference (kg)')
Out[28]:
Version A2011 v1.0h
Decade
1510 - 1500 -3.553251 -0.346051
1520 - 1510 -2.797978 -0.356409
1530 - 1520 NaN -0.358922
</code></pre>
<p>or</p>
<pre><code>In [31]: df.pivot(index... | 1 | 2016-08-13T18:52:35Z | [
"python",
"pandas"
] |
Running python code from ruby with variables | 38,935,919 | <p>I am running python scripts from ruby. But I have pass parameters to python script that i cam from ruby. The parameters that should be passed is the some variable i have in that particular instance. Here is my code that illustrate the scenario.</p>
<pre><code> #test.rb
result = `python ml.py '{"a":1, "b":23,... | 0 | 2016-08-13T18:50:56Z | 38,936,005 | <p>Try this:</p>
<pre><code>$ cat d.py
import json
import sys
from collections import OrderedDict
print json.loads(sys.argv[1], object_pairs_hook=OrderedDict)
$ cat a.rb
require 'json'
params = {"a":1, "b":23, "c":2334,"d":2244}.to_json
result = `python d.py '#{params}'`
puts result
$ ruby a.rb
OrderedDict([(u'a', 1),... | 0 | 2016-08-13T18:59:45Z | [
"python",
"json",
"ruby",
"python-3.x"
] |
Why does this passlib hashing script create a new result every time I run the script? | 38,935,992 | <p>I'm using the following <a href="http://pythonhosted.org/passlib/#welcome" rel="nofollow">script from the passlib docs</a> to hash a password:</p>
<pre><code># import the hash algorithm
from passlib.hash import sha256_crypt ... | 0 | 2016-08-13T18:58:58Z | 38,936,197 | <p>Hash result depends on the input and <a href="https://en.wikipedia.org/wiki/Salt_%28cryptography%29" rel="nofollow">salt</a>. Where the salt - it is randomly generated value which is included in the output string together with result of hashing. That is why for each call sha256_crypt.encrypt output string looks rand... | 2 | 2016-08-13T19:21:59Z | [
"python",
"hash",
"passwords",
"salt",
"passlib"
] |
Open multiple files using path = open() feature | 38,936,000 | <p>I have been using path = open(Testfilename) on a few of my beginning python scripts while I was learning about arrays. Now that I am working on dictionaries, I want to see if I can open up multiple files using this feature. </p>
<pre><code>fav_cars = {}
for c in cars: #I have a few separate CSV files with differ... | 0 | 2016-08-13T18:59:25Z | 38,936,073 | <p>You should do it like this:</p>
<pre><code>fav_cars = {}
for c in cars:
with open(c, 'r') as f:
fav_vars[c] = f.readlines()
</code></pre>
<p>builtin <code>open</code> function expects only one file as an argument, second one is the file mode for your opening.</p>
| 0 | 2016-08-13T19:07:45Z | [
"python",
"python-2.7",
"loops",
"dictionary",
"path"
] |
Keras - How are batches and epochs used in fit_generator()? | 38,936,016 | <p>I have a video of 8000 frames, and I'd like to train a Keras model on batches of 200 frames each. I have a frame generator that loops through the video frame-by-frame and accumulates the (3 x 480 x 640) frames into a numpy matrix <code>X</code> of shape <code>(200, 3, 480, 640)</code> -- (batch size, rgb, frame heig... | 3 | 2016-08-13T19:01:09Z | 38,938,237 | <blockquote>
<p>After the first epoch is complete (after the model logs batches 0-24), the generator picks up where it left off</p>
</blockquote>
<p>This is an accurate description of what happens. If you want to reset or rewind the generator, you'll have to do this internally. Note that keras's behavior is quite us... | 1 | 2016-08-14T00:48:19Z | [
"python",
"tensorflow",
"generator",
"keras"
] |
Count lines in file, float numbers in chosen lines, add them and compute average | 38,936,065 | <blockquote>
<p>Write a program that prompts for a file name, then opens that file and
reads through the file, looking for lines of the form:</p>
<p><code>X-DSPAM-Confidence: 0.8475</code></p>
<p>Count these lines and extract the floating point values from each of
the lines and compute the average of... | -1 | 2016-08-13T19:06:58Z | 38,936,176 | <p>You're not doing anything in your code to actually extract the float value from the line. Simply casting the <code>line</code> as a float and trying to add it to total wont work, because <code>line</code> is referring to the entire line from the file. An easy way to extract the float value would be to split the line... | 1 | 2016-08-13T19:19:43Z | [
"python"
] |
Spark Exception: Python in worker has different version 3.4 than that in driver 3.5 | 38,936,150 | <p>I am using Amazon EC2, and I have my master and development servers as one. And I have another instance for a single worker.</p>
<p>I am new to this, but I have managed to make spark work in a standalone mode. Now I am trying cluster. the master and worker are active (I can see the webUI for them and they are funct... | 0 | 2016-08-13T19:16:54Z | 38,936,300 | <p>Since you already use Anaconda you can simply create an environment with the desired Python version:</p>
<pre><code>conda create --name foo python=3.4
source activate foo
python --version
## Python 3.4.5 :: Continuum Analytics, Inc
</code></pre>
<p>and use it as <code>PYSPARK_DRIVER_PYTHON</code>:</p>
<pre><code... | 2 | 2016-08-13T19:33:54Z | [
"python",
"apache-spark",
"version",
"cluster-computing"
] |
Multiple Models on a Single View/Template in Django | 38,936,153 | <p>Trying to incorporate 2 models into my "season" view/template on my django site. Currently, I get the following as a ValueError "The view webapp.views.season didn't return an HttpResponse object. It returned None instead." Not sure what I am doing wrong, but hoping someone can take a look. </p>
<p>views.py</p>
<pr... | 0 | 2016-08-13T19:17:12Z | 38,937,144 | <p>The views:<code>home</code>, <code>player</code> and <code>seasons</code> are <a href="https://docs.djangoproject.com/en/1.10/topics/http/views/" rel="nofollow">Function Based Views</a>, this is the old Django Views style. On the other hand, <code>ListView</code> is a <a href="https://docs.djangoproject.com/en/1.10... | 1 | 2016-08-13T21:26:20Z | [
"python",
"django"
] |
Multiple Models on a Single View/Template in Django | 38,936,153 | <p>Trying to incorporate 2 models into my "season" view/template on my django site. Currently, I get the following as a ValueError "The view webapp.views.season didn't return an HttpResponse object. It returned None instead." Not sure what I am doing wrong, but hoping someone can take a look. </p>
<p>views.py</p>
<pr... | 0 | 2016-08-13T19:17:12Z | 38,937,791 | <p>In the url you need to call the class based view like, views.season.as_view()</p>
| 0 | 2016-08-13T23:19:43Z | [
"python",
"django"
] |
Why is Numpy's LinAlg Norm function named the way it is? | 38,936,171 | <p>I have been following some online tutorials that introduce Linear Algebra through Python and have come across the section that talks about a vector's magnitude and normalization. The linear algebra concept seems to state that:</p>
<p><strong>Magnitude of Vector</strong> = Square all of the elements of a vector, add... | 0 | 2016-08-13T19:18:54Z | 38,936,420 | <p>As you already can see in the docs of <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.norm.html" rel="nofollow">numpy.linalg.norm()</a>, there is a parameter called ord, which is the order of the norm, by default such parameter is None and if you read the docs that means it will be calculat... | 2 | 2016-08-13T19:51:00Z | [
"python",
"numpy",
"linear-algebra"
] |
etree & xpath return entire html instead of text | 38,936,185 | <p>I'm working around since quite a while on this and tried all kind of namespace solutions. However, my current script is not printing the demanded strings but the entire html dump. Does anyone knows how to get around that issue?</p>
<pre class="lang-py prettyprint-override"><code>from lxml.html import parse
from lxm... | 1 | 2016-08-13T19:21:00Z | 38,936,269 | <p>Namespaces are inherited. If a document is XHTML, then all the nodes in the document are in the XHTML namespace by default.</p>
<p>That means you must use that namespace in every step of your XPath expression. Using it on the first step (<code>html</code>) is not enough.</p>
<p><code>nsmap</code> can help you with... | 1 | 2016-08-13T19:30:17Z | [
"python",
"parsing",
"xpath",
"lxml"
] |
Pandas Dataframe to SQLite - AttributeError: 'DataFrame' object has no attribute 'encode' | 38,936,186 | <p>I have a Pandas data frame that I want to export to a SQLite db. The db has a datetime index and I suspect that might be an issue. </p>
<p>When I run this part of the code:</p>
<pre><code>con = sqlite3.connect("pat_rec.db")
dfMid.to_sql(dfMid,con=con, flavor='sqlite', if_exists='replace')
</code></pre>
<p>I get t... | 1 | 2016-08-13T19:21:04Z | 38,936,235 | <p>The first attribute of <code>to_sql</code> is name of the SQL table. You're passing the data frame object again. If you want to use <code>dfMid</code> as the table name, you have to put it in quotes.</p>
<p>Thus, your code would become:</p>
<pre><code>dfMid.to_sql('dfMid',con=con, flavor='sqlite', if_exists='repla... | 0 | 2016-08-13T19:26:29Z | [
"python",
"dataframe",
"sqlite3"
] |
ImportError: No module named fcntl under windows | 38,936,259 | <p>I am trying to test simple script to get WIFI information.i installed python-wifi module to use it but once i run the script i get this message error</p>
<p>File "C:\Users\PC\Anaconda2\lib\site-packages\pythonwifi\iwlibs.py", line 28, in
import fcntl
ImportError: No module named fcntl</p>
<p>any ideas !!
than... | 0 | 2016-08-13T19:29:18Z | 38,936,724 | <p>If you read the description from <a href="https://pypi.python.org/pypi/python-wifi" rel="nofollow">python-wifi on pip</a> you'll see the Operating System it's POSIX & Linux, that's why you're having problems in the first place, they didn't write portable code and just stick to linux. </p>
<p>Therefore, either y... | 0 | 2016-08-13T20:30:10Z | [
"python",
"windows-10"
] |
Returning False to Break out of a loop | 38,936,287 | <p>I am trying to break out of this loop. I have returned False and added a break if the character in the word is not on the hand, which is a dictionary with integer values per letter, based on Scrabble letter scores. This is part of a larger game but this particular function checks to see if the word I've entered is... | 0 | 2016-08-13T19:32:06Z | 38,936,436 | <p>There are several problems in your code, I have refactored it to make it clearer (and fixed it, that was the point :))</p>
<p><em>minor issues</em>:</p>
<ul>
<li>not optimal: first check if word is in word_list (you'd better use a <code>set</code> rather than a list, would be much faster), then test for available ... | 0 | 2016-08-13T19:52:59Z | [
"python",
"loops",
"return"
] |
Python: easy way to modify array in parallel | 38,936,296 | <p>The question might sound easy, but being new to parallelization in Python I am definitely struggling. I dealt with parallelization in OpenMP for C++ and that was a hell of a lot easier.
What I need to do is modify entries of a matrix in parallel. That's it. Thing is, I can't do it using the simple joblib library:</p... | 3 | 2016-08-13T19:33:47Z | 38,937,003 | <p>Generally there are two ways of sharing data</p>
<ul>
<li>Shared Memory</li>
<li>Multiple processes (in your case)</li>
</ul>
<p>if you used the <code>threading</code> backend in Joblib, you wouldn't have any problem with your current code, but in python (Cpython) don't execute in parallel because of the GIL (Glob... | 0 | 2016-08-13T21:04:18Z | [
"python",
"arrays",
"parallel-processing"
] |
Python: easy way to modify array in parallel | 38,936,296 | <p>The question might sound easy, but being new to parallelization in Python I am definitely struggling. I dealt with parallelization in OpenMP for C++ and that was a hell of a lot easier.
What I need to do is modify entries of a matrix in parallel. That's it. Thing is, I can't do it using the simple joblib library:</p... | 3 | 2016-08-13T19:33:47Z | 38,948,653 | <p>Using only the standard library, you could use shared memory, in this case an <code>Array</code> to store and modify your array:</p>
<pre><code>from multiprocessing import Pool, Array, Lock
lock = Lock()
my_array = [Array('i', [1, 2, 3], lock=lock),
Array('i', [4, 5, 6], lock=lock),]
</code></pre>
<p... | 1 | 2016-08-15T02:45:57Z | [
"python",
"arrays",
"parallel-processing"
] |
How to use mask indexing on numpy arrays of classes? | 38,936,349 | <p>When working with numpy <code>array</code> of custom classes like:</p>
<pre><code>class TestClass:
active = False
</code></pre>
<p>How to use the inline masking (boolean index arrays) like described here: <a href="http://docs.scipy.org/doc/numpy/user/basics.indexing.html#boolean-or-mask-index-arrays" rel="nofo... | 0 | 2016-08-13T19:40:19Z | 38,936,480 | <p>So your array is <code>dtype=object</code> (print it) and each element points to an instance of your class:</p>
<pre><code>items = np.array([TestClass() for _ in range(10)])
</code></pre>
<p>Now try:</p>
<pre><code>items.active
</code></pre>
<p><code>items</code> is an array; <code>active</code> is an attribute ... | 2 | 2016-08-13T19:59:02Z | [
"python",
"numpy"
] |
how to install sqlite in a django project | 38,936,355 | <p>i am learning django. It seems when you create a new project, a sqlite3 data base comes with it. In my case, when i look in my project, no data base can be found.</p>
<pre><code> Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 13/08/2016 ... | -1 | 2016-08-13T19:41:15Z | 38,936,448 | <p>To create a database and tables in database You must run the following command:</p>
<pre><code>python manage.py migrate
</code></pre>
<p>Read more about migrations <a href="https://docs.djangoproject.com/en/1.10/ref/django-admin/#django-admin-migrate" rel="nofollow">here</a> and <a class='doc-link' href="http://st... | 1 | 2016-08-13T19:54:19Z | [
"python",
"django",
"sqlite",
"sqlite3"
] |
How to get path of all elements in lxml with attribute | 38,936,531 | <p>I have the following code:</p>
<pre><code>tree = etree.ElementTree(new_xml)
for e in new_xml.iter():
print tree.getpath(e), e.text
</code></pre>
<p>This will give me something like the following:</p>
<pre><code>/Item/Purchases
/Item/Purchases/Purchase[1]
/Item/Purchases/Purchase[1]/URL http://tvgo.xfinity.... | 0 | 2016-08-13T20:05:15Z | 38,937,236 | <p>Not pretty, but it does the job.</p>
<pre><code>replacements = {}
for e in tree.iter():
path = tree.getpath(e)
if re.search('/Purchase\[\d+\]$', path):
new_predicate = '[@Country="' + e.attrib['Country'] + '"]'
new_path = re.sub('\[\d+\]$', new_predicate, path)
replacements[path] =... | 1 | 2016-08-13T21:39:31Z | [
"python",
"xml",
"lxml"
] |
How to find good documentation for Python modules | 38,936,584 | <p>I can't seem to find a good explanation of how to use Python modules. Take for example the <code>urllib</code> module. It has commands such as
<code>req = urllib.request.Request()</code>.</p>
<p>How would I find out what specific commands, like this one, are in certain Python modules?</p>
<p>For all the examples I... | 0 | 2016-08-13T20:12:07Z | 38,937,103 | <p>My flow chart looks something like this:</p>
<ul>
<li>Reading the published documentation (or use <code>help(moduleName)</code> which gives you the same information without an internet connection in a harder to read format). This can be overly verbose if you're only looking for one tidbit of information, in which c... | 1 | 2016-08-13T21:20:26Z | [
"python",
"python-3.x",
"python-module"
] |
VSCode - invoke nosetests for a specific function or class | 38,936,628 | <p>I've setup a task in <code>tasks.json</code> to run <code>nosetests</code> from within VSCode, but, I'd like to invoke specific tests, eg a function or class of tests. Can anyone see a way to do this? In the tasks variable substitution I don't see function or class as variables.</p>
<pre><code>{
"version": "0.... | 0 | 2016-08-13T20:17:07Z | 38,973,685 | <p>@Alex, I'm the author of the extension, the solution is as follows:<br>
(the plan is to make this a seamless experience in the future) </p>
<ol>
<li>Create a file named xyz.py in the root directory </li>
<li>Add the following code </li>
<li>Add a break point in you test method (the test method you wish to debug)... | 1 | 2016-08-16T11:26:28Z | [
"python",
"vscode",
"nose"
] |
Scipy analytically integrate piecewise function | 38,936,703 | <p>Is there a method in scipy for analytic integration of a piecewise function? For example I have:</p>
<pre><code>xrange_one, xrange_two = np.arange(0,4), np.arange(3,7)
part_one = lambda x: x + 3
part_two = lambda x: -2*x + 2
</code></pre>
<p>I'd like to integrate the first moment of this piecewise function:</p>
... | 1 | 2016-08-13T20:27:19Z | 38,936,842 | <p>Scipy will not perform analytical integration for you, since it is made for solving numerical problems. Sympy, on the other hand, can handle simple symbolic problems exactly:</p>
<pre><code>>>> import sympy as sym
>>> x = sym.symbols('x')
>>> f = sym.Piecewise((x*(x+3),x<3), (x*(-2*x+2... | 3 | 2016-08-13T20:43:03Z | [
"python",
"python-2.7",
"scipy",
"integration"
] |
Scipy analytically integrate piecewise function | 38,936,703 | <p>Is there a method in scipy for analytic integration of a piecewise function? For example I have:</p>
<pre><code>xrange_one, xrange_two = np.arange(0,4), np.arange(3,7)
part_one = lambda x: x + 3
part_two = lambda x: -2*x + 2
</code></pre>
<p>I'd like to integrate the first moment of this piecewise function:</p>
... | 1 | 2016-08-13T20:27:19Z | 38,936,993 | <p>After playing with the <code>numpy</code> <code>poly</code> functions, I came up with:</p>
<pre><code>integrate.quad(lambda x:np.piecewise(x, [x < 3, x >= 3],
[lambda x: np.polyval([1,3,0],x),
lambda x: np.polyval([-2,2,0],x)]),
0,6)
</code></pre>
<p>evaluates to:</p>
<pre><code>(-76.5, 1.... | 1 | 2016-08-13T21:02:53Z | [
"python",
"python-2.7",
"scipy",
"integration"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.