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 |
|---|---|---|---|---|---|---|---|---|---|
MacPorts pip install links .so file to wrong python executable on MacOS 10.11 | 37,931,236 | <p>I am using MacOS 10.11 and in addition to the native Python installation I have installed Python and Pip through MacPorts. <code>python</code> and <code>pip</code> are linked against the respective MacPorts versions.</p>
<p>However, when installing a package via</p>
<pre><code>sudo pip install <my-package>
<... | 1 | 2016-06-20T20:24:54Z | 37,951,276 | <p>The short version is: you can't.</p>
<p>It's not a problem with pip. The <code>nupic</code> package relies on the <code>nupic.bindings</code> package, which contains the <code>_math.so</code> you note, and it's currently distributed via PyPI as binary-only:</p>
<p><a href="https://pypi.python.org/pypi/nupic.bindi... | 1 | 2016-06-21T17:51:03Z | [
"python",
"python-2.7",
"pip",
"macports"
] |
Dynamically Updating HTML src with Flask and Jinja2 | 37,931,335 | <p>I have a flask template that has a video like:</p>
<p><code><video id="firstVideo" class="clip-thumbnail" src=""></video></code></p>
<p>and upon an update from a user click, the request's videos content updates the video like:</p>
<p><code>$('#firstVideo').attr("src", response['videos'][0]);</code></p... | 0 | 2016-06-20T20:32:03Z | 37,931,441 | <p>You can't use flask template tags unless you're building a dynamic template on your server, if you're making an ajax request for the video url from the browser you just need to set up your request to return the full video URL and then update the video src exactly as you have it:</p>
<pre><code>$('#firstVideo').attr... | 0 | 2016-06-20T20:39:50Z | [
"javascript",
"python",
"flask"
] |
stuck in realtime plot using matplotlib | 37,931,526 | <p>I am trying to run this in python 2.7.10 with backend 'QTAgg', but it seems that the figure will freeze after the plot is over and I have to force quit the figure. Can anyone give me some advise? Thanks!</p>
<p>Here is the code:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
plt.xlim(0,20)
plt.y... | 1 | 2016-06-20T20:46:25Z | 37,980,527 | <p>It looks like this kind of usage don't have a correct way to exit plotting, which cause an infinite loop I guess. The best way is use matplotlib.animation, which is so powerful.</p>
| 0 | 2016-06-23T00:49:15Z | [
"python",
"matplotlib"
] |
Plotting individual bar graphs for each index of a Pandas dataframe | 37,931,540 | <p>I have a a pandas data frame as follows with the index a;</p>
<pre><code> b c d e f g
a
-2.447948 0.170758 1.246046 -1.452076 1.248984 -0.010419 0.980928
0.038355 0.106015 0.1737... | 1 | 2016-06-20T20:47:20Z | 37,931,662 | <p><strong>UPDATE:</strong></p>
<pre><code>for i in df.T.index:
fig, ax = plt.subplots()
df.T.ix[i].plot.bar(ax=ax)
</code></pre>
<p><strong>OLD answer:</strong></p>
<p>try something like this:</p>
<pre><code>import matplotlib
matplotlib.style.use('ggplot')
df.T.plot.bar(subplots=True)
</code></pre>
<p><a... | 0 | 2016-06-20T20:54:54Z | [
"python",
"pandas",
"dataframe"
] |
Are cell notes and color queryable with gspread? | 37,931,652 | <p>I am trying to learn Python and this Google API thing, and I am wondering if cell notes and colors are queryable in gspread or in another form? If so, could someone please point me in the right direction or documentation?</p>
<p>So far I have found two things that look like they can help, but i don't really underst... | 1 | 2016-06-20T20:54:22Z | 37,939,722 | <p>I think it would be helpful if you first learn how Python works with Google Spreadsheet.
Here's the <a href="https://developers.google.com/sheets/quickstart/python" rel="nofollow">Python Quickstart</a> for Spreadsheets.
Make sure you also have <a href="https://developers.google.com/gdata/articles/python_client_lib"... | 0 | 2016-06-21T08:52:04Z | [
"python",
"google-spreadsheet",
"google-spreadsheet-api",
"gdata",
"gspread"
] |
Obtain string inside curl bracket in python | 37,931,690 | <p>Suppose I have a string like</p>
<pre><code>{"", "b", "c"}, // we are here
</code></pre>
<p>I would like to extract the <code>{"", "b", "c"}</code> and/or <code>"", "b", "c"</code> part of it. Is there any simple prescription for it?</p>
| 0 | 2016-06-20T20:56:22Z | 37,931,750 | <p>You can use regex - <code>re.search</code>:</p>
<pre><code>import re
s = '{"", "b", "c"}, // we are here'
m = re.search(r'{.*}', s)
print(m.group(0))
#'{"", "b", "c"}'
</code></pre>
<p><code>{.*}</code> matches every thing within the curly braces and the braces.</p>
| 0 | 2016-06-20T21:00:59Z | [
"python",
"string",
"python-2.7"
] |
Obtain string inside curl bracket in python | 37,931,690 | <p>Suppose I have a string like</p>
<pre><code>{"", "b", "c"}, // we are here
</code></pre>
<p>I would like to extract the <code>{"", "b", "c"}</code> and/or <code>"", "b", "c"</code> part of it. Is there any simple prescription for it?</p>
| 0 | 2016-06-20T20:56:22Z | 37,931,815 | <p>You can use the following snippet if you prefer to catch the bracket in your match:</p>
<pre><code>import re
s = '{"", "b", "c"}, // we are here '
regex = r'(\(.+?\})'
match = re.findall(regex, s)[0]
</code></pre>
<p>You can also set the regex to <code>'\{(.+?)\}'</code> if you don't want them.</p>
| 0 | 2016-06-20T21:06:16Z | [
"python",
"string",
"python-2.7"
] |
Trouble installing SciPy on windows 7 | 37,931,703 | <p>I am newbie in Python. Before I tried to install this library, I installed NumPy. I don't know why this error occurred error when installing SciPy. Here is the image of the error:</p>
<p><a href="http://i.stack.imgur.com/2G317.png" rel="nofollow"><img src="http://i.stack.imgur.com/2G317.png" alt="enter image descri... | 1 | 2016-06-20T20:57:23Z | 37,931,811 | <p>The easiest way to install SciPy on Windows is using <a href="https://www.continuum.io/downloads" rel="nofollow">Anaconda</a>. This gives you a lot of popular scientific Python packages. All work together. It takes about 2GB on your hard drive because it installs many packages, many of which you won't use, but saves... | 2 | 2016-06-20T21:05:59Z | [
"python",
"python-3.x",
"installation",
"scipy"
] |
Trouble installing SciPy on windows 7 | 37,931,703 | <p>I am newbie in Python. Before I tried to install this library, I installed NumPy. I don't know why this error occurred error when installing SciPy. Here is the image of the error:</p>
<p><a href="http://i.stack.imgur.com/2G317.png" rel="nofollow"><img src="http://i.stack.imgur.com/2G317.png" alt="enter image descri... | 1 | 2016-06-20T20:57:23Z | 37,931,817 | <p>Lets start from the beginning. Try installing SciPy with pip via the Windows command line. The command is:</p>
<pre><code>pip install scipy
</code></pre>
<p>You will need to make sure you have Python set in your system path. Take a look at this tutorial if you are confused about that:
<a href="http://www.computerh... | 1 | 2016-06-20T21:06:19Z | [
"python",
"python-3.x",
"installation",
"scipy"
] |
Assign each value to a range on dataFrame | 37,931,728 | <p>I have an array <code>states</code> like this</p>
<pre><code>[(1,3), (3,5), (5,7), (7,9)]
</code></pre>
<p>and a dataframe <code>df</code> like this</p>
<pre><code> l y
0 a 8
1 b 3
2 c 7
3 d 4
4 e 1
</code></pre>
<p>I need to assign the index of the belonging range on <code>states</code> to get some... | 1 | 2016-06-20T20:58:52Z | 37,931,851 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.cut.html" rel="nofollow">pandas.cut()</a>:</p>
<pre><code>bins=pd.Series([1,3,5,7,9, np.inf])
df['state'] = pd.cut(df.y, bins=bins, labels=bins.index[:-1], include_lowest=True)
</code></pre>
<p>Output:</p>
<pre><code>In [113]: df
Out[113... | 0 | 2016-06-20T21:08:29Z | [
"python",
"pandas",
"dataframe"
] |
Assign each value to a range on dataFrame | 37,931,728 | <p>I have an array <code>states</code> like this</p>
<pre><code>[(1,3), (3,5), (5,7), (7,9)]
</code></pre>
<p>and a dataframe <code>df</code> like this</p>
<pre><code> l y
0 a 8
1 b 3
2 c 7
3 d 4
4 e 1
</code></pre>
<p>I need to assign the index of the belonging range on <code>states</code> to get some... | 1 | 2016-06-20T20:58:52Z | 37,931,892 | <p>To avoid looping over all rows using <code>.apply()</code> and instead assign <code>states</code> in a vectorized way:</p>
<pre><code>df['states'] = 0
for i, state in enumerate(states):
df.loc[(df.y > state[0]) & (df.y <= state[1]), 'states'] = i
</code></pre>
<p>to get:</p>
<pre><code> l y stat... | 0 | 2016-06-20T21:11:04Z | [
"python",
"pandas",
"dataframe"
] |
Package not importing when invoking Python script remotely | 37,931,755 | <p>We have a python 2.7 script that executes LOCALLY perfectly fine. </p>
<p>The problem occurs ONLY when I attempt to invoke the script remotely (SSH):</p>
<pre><code>ssh user@server "python script.py"
*Traceback (most recent call last):
File "script.py", line 18, in <module>
import requests
ImportError: ... | 0 | 2016-06-20T21:01:18Z | 37,931,780 | <p><code>requests</code> is a non-standard Python library. Make sure it is installed on the remote box you are attempting to execute the script on.</p>
<p>On the remote, execute from the shell:</p>
<pre><code>easy_install pip
pip install requests
</code></pre>
| 0 | 2016-06-20T21:03:43Z | [
"python",
"python-2.7"
] |
Package not importing when invoking Python script remotely | 37,931,755 | <p>We have a python 2.7 script that executes LOCALLY perfectly fine. </p>
<p>The problem occurs ONLY when I attempt to invoke the script remotely (SSH):</p>
<pre><code>ssh user@server "python script.py"
*Traceback (most recent call last):
File "script.py", line 18, in <module>
import requests
ImportError: ... | 0 | 2016-06-20T21:01:18Z | 37,931,850 | <p>If I understand correctly, you are trying to run the same script on the same machine, but once from a local shell and once from a remote shell (with <code>ssh</code>).</p>
<p>If this is the case, when you use the remote shell, be sure that you have the environment properly setup.</p>
<p>This may boil down to just ... | 0 | 2016-06-20T21:08:27Z | [
"python",
"python-2.7"
] |
Create a hierarchical index from a .tsv file (pandas) | 37,931,760 | <p>I have a data frame of this shape (not the actual one):</p>
<p>Fruit Banana House-1 15</p>
<p>Fruit Banana House-2 4</p>
<p>Fruit Apple House-2 6</p>
<p>Fruit Apple House-2 8</p>
<p>Vegetable Broccoli House-3 8</p>
<p>Vegetable Lettuce House-4 12</p>
<p>Vegetable Peppers House-5 3</p>
<p>Vegetable Corn House... | 1 | 2016-06-20T21:01:57Z | 37,932,101 | <p>Try this:</p>
<pre><code>In [11]: df
Out[11]:
Type Food Loc Num
0 Fruit Banana House-1 15
1 Fruit Banana House-2 4
2 Fruit Apple House-2 6
3 Fruit Apple House-2 8
4 Vegetable Broccoli House-3 8
5 Vegetable Lettuce House-4 12
6 V... | 0 | 2016-06-20T21:27:54Z | [
"python",
"csv",
"pandas",
"indexing",
"dataframe"
] |
How to redirect submodule calls to parent module in Python | 37,931,771 | <p>My directory structure looks like this:</p>
<pre><code>\Module
|
__init.py__ (from File1 import File1...)
File1.py
File2.py
\Submodule
|
__init.py__ (Empty right now)
</code></pre>
<p>I can do <code>Module.File1.run()</code>.</p>
<p>But I want to do <co... | 2 | 2016-06-20T21:02:50Z | 37,932,262 | <p>If you are on a *nix system, you can simply create a symbolic link. On the CLI, use <code>ln -s</code>:</p>
<pre><code>ln -s ./Module/File1.py ./Module/Submodule/
</code></pre>
<p>That would create a symbolic link named <code>./Module/Submodule/File1.py</code> that points to the original <code>File1.py</code>.</p>... | 1 | 2016-06-20T21:41:47Z | [
"python",
"import"
] |
How to redirect submodule calls to parent module in Python | 37,931,771 | <p>My directory structure looks like this:</p>
<pre><code>\Module
|
__init.py__ (from File1 import File1...)
File1.py
File2.py
\Submodule
|
__init.py__ (Empty right now)
</code></pre>
<p>I can do <code>Module.File1.run()</code>.</p>
<p>But I want to do <co... | 2 | 2016-06-20T21:02:50Z | 37,932,323 | <p>Syntactically, this is how to do this:</p>
<pre><code>\Module
|
__init.py__ (from File1 import File1...)
> import Submodule
File1.py
> def run():
> print "RUNNING"
\Submodule
|
__init.py__
> from Module import... | 1 | 2016-06-20T21:47:06Z | [
"python",
"import"
] |
How to redirect submodule calls to parent module in Python | 37,931,771 | <p>My directory structure looks like this:</p>
<pre><code>\Module
|
__init.py__ (from File1 import File1...)
File1.py
File2.py
\Submodule
|
__init.py__ (Empty right now)
</code></pre>
<p>I can do <code>Module.File1.run()</code>.</p>
<p>But I want to do <co... | 2 | 2016-06-20T21:02:50Z | 37,932,459 | <p>Just set <code>Module.Submodule.File1</code> to <code>Module.File1</code>:</p>
<pre><code>import Module.File1
import Module.Submodule
Module.Submodule.File1 = Module.File1
</code></pre>
<p>Now this works:</p>
<pre><code>Module.Submodule.File1.run()
</code></pre>
| 1 | 2016-06-20T21:56:31Z | [
"python",
"import"
] |
How to distribute ansible modules? | 37,931,803 | <p>If someone develops an ansible role, it can be easily distributed by creating a repo on github that will be available for installation through ansible-galaxy (<a href="https://galaxy.ansible.com/intro#create-role" rel="nofollow">very clear instructions</a>).</p>
<p>What about modules?</p>
<p>Is there a similar "su... | 0 | 2016-06-20T21:05:11Z | 37,932,005 | <p>Currently, the best way to do it is actually via the <code>library</code> directory in a galaxy role. You can still get the roles (and bundled modules) installed and usable via a <a href="http://docs.ansible.com/ansible/galaxy.html#installing-multiple-roles-from-a-file" rel="nofollow">requirements file</a> without a... | 1 | 2016-06-20T21:20:47Z | [
"python",
"module",
"ansible",
"release",
"ansible-galaxy"
] |
How to distribute ansible modules? | 37,931,803 | <p>If someone develops an ansible role, it can be easily distributed by creating a repo on github that will be available for installation through ansible-galaxy (<a href="https://galaxy.ansible.com/intro#create-role" rel="nofollow">very clear instructions</a>).</p>
<p>What about modules?</p>
<p>Is there a similar "su... | 0 | 2016-06-20T21:05:11Z | 37,939,069 | <p>A role can hold modules in the library folder. To activate a module in a playbook, you need to add this role first to your playbook or as a dependency of another role. Otherwise Ansible does not know the contained modules. A role providing a module is not required to have anything else like tasks defined. Simply put... | 1 | 2016-06-21T08:18:43Z | [
"python",
"module",
"ansible",
"release",
"ansible-galaxy"
] |
Possible bug in Cython generated C++ code | 37,931,814 | <p>I'm trying to create a Cython wrapper for the __gnu_parallel::sort in the same way as they do in this thread <a href="http://stackoverflow.com/questions/27551363/parallel-in-place-sort-for-numpy-arrays">Parallel in-place sort for numpy arrays</a>.</p>
<p>This is my simplified code for wrapparallel.pyx:</p>
<pre><c... | 2 | 2016-06-20T21:06:13Z | 37,933,601 | <p>Whoever told you to remove the <code>-1</code> is right. The sort function expects arguments similar to <code>range</code> (eg. <code>range(0, 3) <-> [0, 1, 2]</code>)</p>
<p>So you need to provide the sort algorithm with the first pointer that is not in the array that you wish to sort. Given the following da... | 0 | 2016-06-20T23:57:45Z | [
"python",
"c++",
"cython"
] |
python to pair items from two large lists | 37,931,832 | <p>I have two files:</p>
<ul>
<li>file1 (200mln lines) in format: email:hash1:hash2</li>
<li>file2 (90mln lines) in format: hash:plaintext</li>
</ul>
<p>What I want to do is replace hash(1 or 2) in file1 with plaintext found in file2. I tried to use solution from question I asked previously here <a href="http://stack... | 1 | 2016-06-20T21:07:13Z | 37,931,935 | <p>With that many keys I would highly suggest using some sort of database with Python in order to complete your task. With a SQL database, you would have two tables that looked like this:</p>
<p><strong>emails_and_hashes</strong></p>
<pre><code>column_name | column_type
----------- | ------------
email | VARCHA... | 0 | 2016-06-20T21:14:51Z | [
"python"
] |
python to pair items from two large lists | 37,931,832 | <p>I have two files:</p>
<ul>
<li>file1 (200mln lines) in format: email:hash1:hash2</li>
<li>file2 (90mln lines) in format: hash:plaintext</li>
</ul>
<p>What I want to do is replace hash(1 or 2) in file1 with plaintext found in file2. I tried to use solution from question I asked previously here <a href="http://stack... | 1 | 2016-06-20T21:07:13Z | 37,974,369 | <p>After a day of thinking, I came up with the idea of using a <a href="https://en.wikipedia.org/wiki/Trie" rel="nofollow"><strong><em>Trie</em></strong></a>.</p>
<p>A trie will let you store that repeating hash dictionary at a much more efficient container and lookup at the same cost.</p>
<p>A good implementation of... | 0 | 2016-06-22T17:07:43Z | [
"python"
] |
re.search is not working when the string is read from a tuple | 37,931,871 | <p>output:</p>
<pre><code>[----------] My test environment
[==========] 14 tests from 6 test cases ran
[ PASSED ] 14 tests.\
(f, code, output) = entry
if output.find("My test environment) != -1:
for line in output.split("\n"):
m = re.search("PASSED. *\] (\d+) tests", line)
if m:
total = total + int(m... | 0 | 2016-06-20T21:09:36Z | 37,932,367 | <p>your indentation after for loop seems to be wrong? and you mean m not M . i don't see any M ?</p>
<pre><code>for line in output.split("\n"):
m = re.search("PASSED. *\] (\d+) tests", line)
if m:
total = total + int(m.group(1))
</code></pre>
| 0 | 2016-06-20T21:51:38Z | [
"python",
"regex",
"python-2.7"
] |
re.search is not working when the string is read from a tuple | 37,931,871 | <p>output:</p>
<pre><code>[----------] My test environment
[==========] 14 tests from 6 test cases ran
[ PASSED ] 14 tests.\
(f, code, output) = entry
if output.find("My test environment) != -1:
for line in output.split("\n"):
m = re.search("PASSED. *\] (\d+) tests", line)
if m:
total = total + int(m... | 0 | 2016-06-20T21:09:36Z | 37,955,377 | <p>Do you actually need to iterate through the lines, you can use <code>re.MULTILINE</code>:</p>
<pre><code>m = re.search("PASSED\s+\] (\d+) tests", output, re.MULTILINE)
</code></pre>
| 0 | 2016-06-21T22:06:58Z | [
"python",
"regex",
"python-2.7"
] |
Why is flask's jsonify method slow? | 37,931,927 | <p>I'm writing an API in flask that returns json. Each flask function is of the form</p>
<pre><code>from flask import jsonify
@app.route('/getdata')
def get_data():
data = load_data_as_dict()
return jsonify(data)
</code></pre>
<p>If I return a large amount of data, a call to this function takes around 1.7 se... | 3 | 2016-06-20T21:14:06Z | 37,932,098 | <p>My guess is: it has a lot to do with indentation and making a <code>pretty</code> json dump. Here's the method definition (I stripped the comments to save space, full code can be found <a href="https://github.com/pallets/flask/blob/master/flask/json.py" rel="nofollow">here</a>) :</p>
<pre><code>def jsonify(*args, *... | 2 | 2016-06-20T21:27:47Z | [
"python",
"json",
"performance",
"api",
"flask"
] |
Why is flask's jsonify method slow? | 37,931,927 | <p>I'm writing an API in flask that returns json. Each flask function is of the form</p>
<pre><code>from flask import jsonify
@app.route('/getdata')
def get_data():
data = load_data_as_dict()
return jsonify(data)
</code></pre>
<p>If I return a large amount of data, a call to this function takes around 1.7 se... | 3 | 2016-06-20T21:14:06Z | 37,932,144 | <p>From the <a href="http://flask.pocoo.org/docs/0.11/api/#returning-json" rel="nofollow">documentation</a> it states that: </p>
<blockquote>
<p>This function wraps dumps() to add a few enhancements that make life
easier. It turns the JSON output into a Response object with the
application/json mimetype.</p>
</b... | 0 | 2016-06-20T21:31:25Z | [
"python",
"json",
"performance",
"api",
"flask"
] |
How to extract tuples using findall? | 37,931,944 | <p>I'm trying to extract tuples from an <strong>url</strong> and I've managed to extract <em>string text</em> and <em>tuples</em> using the <code>re.search(pattern_str, text_str)</code>. However, I got stuck when I tried to extract a list of tuples using <code>re.findall(pattern_str, text_str)</code>.</p>
<p>The text ... | 0 | 2016-06-20T21:15:41Z | 37,932,100 | <p>Your regex does not take into account the whitespace (indentation) between <code>\n</code> and <code><span</code>. (And neither the whitespace at the start of the line you want to capture, but that's not as much of a problem.) To fix it, you could add some <code>\s*</code>:</p>
<pre><code>pat_str = '<a href="... | 2 | 2016-06-20T21:27:51Z | [
"python",
"regex",
"findall"
] |
How to extract tuples using findall? | 37,931,944 | <p>I'm trying to extract tuples from an <strong>url</strong> and I've managed to extract <em>string text</em> and <em>tuples</em> using the <code>re.search(pattern_str, text_str)</code>. However, I got stuck when I tried to extract a list of tuples using <code>re.findall(pattern_str, text_str)</code>.</p>
<p>The text ... | 0 | 2016-06-20T21:15:41Z | 37,932,220 | <p>As suggested in the comments, use a html parser like <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">BeautifulSoup</a>:</p>
<pre><code>from bs4 import BeautifulSoup
h = """<li>
<a href="11111">
some text 111
<span class="some-class">
#11111
<... | 1 | 2016-06-20T21:37:57Z | [
"python",
"regex",
"findall"
] |
Django filter manytomany results | 37,931,974 | <p>Say that I have a many to many relationship field in my model, what I'm trying to do is get all the related entities if the field in the entity is equivalent to MAMMAL. I'm currently doing this in a list comprehension but wondering if there's a more elegant solution that django models provide. </p>
<pre><code>[rela... | 0 | 2016-06-20T21:18:17Z | 37,932,039 | <p>A many-to-many field gives you a manager, just like the standard <code>Model.objects()</code> one, and you can filter it in exactly the same way:</p>
<pre><code>related_entity.filter(entity_type__entity_type_label="MAMMAL")
</code></pre>
| 2 | 2016-06-20T21:23:14Z | [
"python",
"django",
"model"
] |
Django filter manytomany results | 37,931,974 | <p>Say that I have a many to many relationship field in my model, what I'm trying to do is get all the related entities if the field in the entity is equivalent to MAMMAL. I'm currently doing this in a list comprehension but wondering if there's a more elegant solution that django models provide. </p>
<pre><code>[rela... | 0 | 2016-06-20T21:18:17Z | 37,932,176 | <p>Based on Django documentation(<a href="https://docs.djangoproject.com/en/1.9/topics/db/examples/many_to_many/" rel="nofollow">https://docs.djangoproject.com/en/1.9/topics/db/examples/many_to_many/</a>), you could use:</p>
<p>entity.objects.filter(related_entity__entity_type__entity_type_label == 'MAMMAL')</p>
| 3 | 2016-06-20T21:34:17Z | [
"python",
"django",
"model"
] |
Python: Color mapping with data frames | 37,931,986 | <p>I have a data frame called summed_data as follows: </p>
<pre><code>altitude 1000 2000 3000 4000
longitude
-159 0 0 0 1
-158 1 2 2 0
</code></pre>
<p>I am trying to create a 2D grid plot, of longitude vs altitude with the third dimension (values insi... | 1 | 2016-06-20T21:19:23Z | 37,932,436 | <p>Try to add to <code>imshow</code> argument <code>aspect='auto'</code>.</p>
<pre><code>...
plt.imshow(summed_data.values, aspect='auto', extent = [-160,-150,0,5000], cmap = 'RdBu')
</code></pre>
<p>The second variant: do not use <code>extent</code> and set x- and y-labels manually with <code>xticks</code> and <code... | 0 | 2016-06-20T21:55:12Z | [
"python",
"matplotlib",
"colors",
"imshow"
] |
Print everything after a few specific characters in a string | 37,932,006 | <p>My intention was use the index method to search for either a colon (:) or a equal sign (=) in the string and print everything after that character but I realized it's not syntactically possible as it's written below with the OR statement. So is there another way to write this piece of code? (I wasn't able to come u... | 0 | 2016-06-20T21:20:51Z | 37,932,084 | <pre><code>import re
l='Name = stack'
print(re.split(':|=', l)[-1])
</code></pre>
<p>Regular expression split on either character, then take the last result.</p>
<p>You didn't mention if there was guaranteed to be one or the other separator and not both, always a separator, not more than one separator... this might ... | 2 | 2016-06-20T21:26:42Z | [
"python",
"python-3.x"
] |
Print everything after a few specific characters in a string | 37,932,006 | <p>My intention was use the index method to search for either a colon (:) or a equal sign (=) in the string and print everything after that character but I realized it's not syntactically possible as it's written below with the OR statement. So is there another way to write this piece of code? (I wasn't able to come u... | 0 | 2016-06-20T21:20:51Z | 37,932,164 | <p>Assuming your example as above, the long way (explanation of each piece below):</p>
<pre><code>pos = max(l.find(':'), l.find('='), 0)
print(l[pos:].strip())
</code></pre>
<p>Here's a way to shorten it to one line, with an explanation of each part in the order it's evaluated in.</p>
<pre><code>print(l[ma... | 2 | 2016-06-20T21:33:05Z | [
"python",
"python-3.x"
] |
Print everything after a few specific characters in a string | 37,932,006 | <p>My intention was use the index method to search for either a colon (:) or a equal sign (=) in the string and print everything after that character but I realized it's not syntactically possible as it's written below with the OR statement. So is there another way to write this piece of code? (I wasn't able to come u... | 0 | 2016-06-20T21:20:51Z | 37,932,173 | <p>You should limit the number of splits to one, using <code>maxsplit</code> in <code>re.split()</code>:</p>
<pre><code>import re
s1 = 'name1 = x1 and noise:noise=noise'
s2 = 'name2: x2 and noise:noise=noise'
print(re.split(':|=', s1, maxsplit=1)[-1].strip())
print(re.split(':|=', s2, maxsplit=1)[-1].strip())
</code>... | 1 | 2016-06-20T21:34:09Z | [
"python",
"python-3.x"
] |
Pandas Sort Multiindex by Group Sum | 37,932,021 | <p>Given the following data frame:</p>
<pre><code>import pandas as pd
df=pd.DataFrame({'County':['A','B','C','D','A','B','C','D','A','B','C','D','A','B','C','D','A','B'],
'Hospital':['a','b','c','d','e','a','b','c','e','a','b','c','d','e','a','b','c','e'],
'Enrollment':[44,55,42,57,95,5... | 0 | 2016-06-20T21:21:56Z | 37,932,404 | <p>You could:</p>
<pre><code>max_col = max(d2.columns.get_level_values(1)) # get column 2013
d2['sum'] = d2.groupby(level='County').transform('sum').loc[:, ('Enrollment', max_col)]
d2 = d2.sort_values(['sum', ('Enrollment', max_col)], ascending=[False, False])
</code></pre>
<p>to get:</p>
<pre><code> ... | 1 | 2016-06-20T21:53:30Z | [
"python",
"sorting",
"pandas",
"dataframe",
"multi-index"
] |
Python scipy DCT on smaller block on image not working | 37,932,024 | <p>I am using the scipy.fftpack.dct and scipy.fftpack.idct to an image array in python. I don't however want to apply it to the entire image, but to individual 8x8 blocks in the image. This is the simple class I wrote to for testing this</p>
<pre><code>from PIL import Image
import numpy as np
from scipy.fftpack import... | 1 | 2016-06-20T21:22:21Z | 37,933,719 | <p>Check the data type of your image array (<code>self.image.dtype</code>). It is probably 8 bit unsigned integers. The DCT will be floating point values, but when you assign the result of the DCT to the 8x8 block <em>in place</em>, the floating point values are cast to 8 bit integers. Then the same thing happens wh... | 1 | 2016-06-21T00:11:55Z | [
"python",
"image",
"numpy",
"scipy",
"dct"
] |
How to exit from QThread if I have infinite loop inside run method | 37,932,073 | <p>Have such run method:</p>
<pre><code>def run(self):
while True:
new_value = self.client.read_holding_registers(self.reg_num, 1, unit=self.slave_id).registers[0]
if new_value != self.value:
self.value = new_value
self.data_changed.emit(
{"id": "{0};{1};{2};... | 1 | 2016-06-20T21:26:14Z | 37,932,293 | <p>Are you familiar with what a <a href="https://pypi.python.org/pypi/daemons" rel="nofollow">daemon</a> is? If you want your thread to always run and exit when your whole application stops then you need to make it a daemon. </p>
| 0 | 2016-06-20T21:44:40Z | [
"python",
"pyqt4",
"qthread"
] |
What happens if I don't close a mysql connection and opens another? | 37,932,138 | <pre><code>cnx = mysql.connector.connect(user="root", password="pass", host="127.0.0.1", database="db")
cursor = cnx.cursor()
return cursor, cnx
</code></pre>
<p>Lets say I open a connection like the above, and make a select query <code>cursor.execute(selectquery)</code> and use <code>cursor.fetchall()</code> to get t... | 0 | 2016-06-20T21:30:42Z | 37,932,289 | <p>Let's assume you are reusing the same variable name, or that it went out of scope (the function that contained it returns) without being explicitly closed. The most common version of python has reference counting, which <em>should</em> detect that there's no longer any way to access your connection object. So eventu... | 1 | 2016-06-20T21:44:11Z | [
"python",
"mysql"
] |
Python way of changing the film gate | 37,932,182 | <p>What is the command for changing the film gate?</p>
<p>However, in my case, there are 2 film gates with the same values in terms of its camera aperture etc. but they are of different names, eg. 35 mm default and 35 mm delivery.</p>
<p>Any idea?</p>
| 0 | 2016-06-20T21:35:03Z | 37,936,255 | <p>not everything is an attribute in the AE (attribute editor)
its a dynamically built part of the ui to allow for custom settings to be made</p>
<p>the film gate is not an attribute just an enum of settings somehwere else</p>
<p>select your camera and run this,
you wont see film gate listed</p>
<pre><code>for i i... | 0 | 2016-06-21T05:29:21Z | [
"python",
"maya"
] |
Python way of changing the film gate | 37,932,182 | <p>What is the command for changing the film gate?</p>
<p>However, in my case, there are 2 film gates with the same values in terms of its camera aperture etc. but they are of different names, eg. 35 mm default and 35 mm delivery.</p>
<p>Any idea?</p>
| 0 | 2016-06-20T21:35:03Z | 37,951,436 | <p>comment was to long so heres another answer </p>
<p>if you look in that file at the bottom you can see </p>
<pre><code>AEcameraFilmbackNew
</code></pre>
<p>thats where it populates the optionMenu</p>
<pre><code>string $filmbackTable[] = globalFilmbackTable();
</code></pre>
<p>whish is at the top of that mel scr... | 1 | 2016-06-21T17:59:38Z | [
"python",
"maya"
] |
Python way of changing the film gate | 37,932,182 | <p>What is the command for changing the film gate?</p>
<p>However, in my case, there are 2 film gates with the same values in terms of its camera aperture etc. but they are of different names, eg. 35 mm default and 35 mm delivery.</p>
<p>Any idea?</p>
| 0 | 2016-06-20T21:35:03Z | 38,022,502 | <p>So I have sort of found a way to do so via python</p>
<pre><code>cmds.optionMenu('filmbackMenu', edit = True, value = "<Name of the filmback>")
</code></pre>
<p>or</p>
<pre><code>cmds.optionMenu('filmbackMenu', edit = True, select = "<Filmback index in the Film Gate drop-down list")
</code></pre>
<p>Do ... | 0 | 2016-06-24T21:41:39Z | [
"python",
"maya"
] |
Confusion with bandwidth on seaborn's kdeplot | 37,932,283 | <p>lineslist, below, represents a set of lines (for some chemical spectrum, let's say), in MHz. I know the linewidth of the laser used to probe these lines to be 5 MHz. So, naively, the kernel density estimate of these lines with a bandwidth of 5 should give me the continuous distribution that would be produced in an... | 1 | 2016-06-20T21:43:40Z | 38,447,133 | <p>One thing to note is that Seaborn doesn't actually handle the bandwidth itself - it passes the setting on more-or-less as-is to either SciPy or the Statsmodels packages, depending on what you have installed. (It prefers Statsmodels, but will fall back to SciPy.) </p>
<p>The documentation for this parameter in the v... | 1 | 2016-07-18T22:51:31Z | [
"python",
"matplotlib",
"visualization",
"seaborn"
] |
Elif error with more than one elif? | 37,932,356 | <p>I put two <code>elif</code> statements when I was coding a text game, but I received a syntax error when I had a second <code>elif</code>. With one <code>elif</code>, it works just fine, but with two it doesn't work.</p>
<pre><code>exit = raw_input("Do you exit the office?")
if exit == "yes":
print("Shocked, fr... | -3 | 2016-06-20T21:50:42Z | 37,932,374 | <p>I think you need a colon after "window"</p>
| 3 | 2016-06-20T21:52:07Z | [
"python",
"syntax"
] |
Elif error with more than one elif? | 37,932,356 | <p>I put two <code>elif</code> statements when I was coding a text game, but I received a syntax error when I had a second <code>elif</code>. With one <code>elif</code>, it works just fine, but with two it doesn't work.</p>
<pre><code>exit = raw_input("Do you exit the office?")
if exit == "yes":
print("Shocked, fr... | -3 | 2016-06-20T21:50:42Z | 37,932,479 | <p>You need a colon after "window" </p>
<pre><code>elif exit == "window":
</code></pre>
| 0 | 2016-06-20T21:58:28Z | [
"python",
"syntax"
] |
Unable to remove legend box [python] | 37,932,363 | <p>So I need to make this plot in python. I wish to remove my legend's border. However, when I tried the different solutions other posters made, they were unable to work with mine. Please help.</p>
<p><strong>This doesn't work:</strong></p>
<pre><code>plt.legend({'z$\sim$0.35', 'z$\sim$0.1','z$\sim$1.55'})
plt.legend... | 3 | 2016-06-20T21:51:05Z | 37,937,491 | <p>It's very strange because the command :</p>
<pre><code>plt.legend(frameon=False)
</code></pre>
<p>Should work very well.
You can also try this command, to compare :</p>
<pre><code>plt.legend(frameon=None)
</code></pre>
<p>You can also read the documentation on this page about <a href="http://matplotlib.org/api/l... | 1 | 2016-06-21T06:58:46Z | [
"python",
"matplotlib",
"plot"
] |
pinax-theme-bootstrap can't load bootstrap | 37,932,381 | <p>I am currently using (or at least attempting to use) django-user-accout with pinax-theme-bootstrap. However when I attempt to use any of the provided templates I get the expected
<code>TemplateSyntaxError: 'bootstrap' is not a registered tag library</code>.
This error is thrown by the following line<code>{% load b... | 0 | 2016-06-20T21:52:26Z | 37,932,449 | <p>In your INSTALLED_APPS in settings.py should be something like:</p>
<pre><code> INSTALLED_APPS = [
'bootstrap3',
'bootstrap',
'bootstrap_toolkit',
....
]
</code></pre>
| 1 | 2016-06-20T21:55:56Z | [
"python",
"django",
"twitter-bootstrap",
"pinax"
] |
Pandas dataframe combine duplicate columns into one- separate data by comma | 37,932,391 | <p>My dataframe has few duplicate column names. If a duplicate column name is found combine duplicate columns into one. I also want to retain duplicate columns data separated by comma. Can anyone please suggest a way to do this.</p>
<p>I have constructed an example below. In my actual dataframe column names are unknow... | 4 | 2016-06-20T21:52:54Z | 37,932,747 | <p>you can do it this way:</p>
<pre><code>df.T.groupby(level=0).agg(','.join).T
</code></pre>
<p>Data:</p>
<pre><code>In [207]: df
Out[207]:
Col1 Col2 Col1 Col2 Col3
Index
A CA1 CA2 CA3 CA5 ZA1
B CB1 CB2 CB3 CB5 ZA2
C CC1 CC2 CC3 CC5 ZA3
D CD1 CD2 CD3 CD5 ZA4
E CE1 CE2... | 4 | 2016-06-20T22:20:25Z | [
"python",
"pandas",
"dataframe"
] |
Pandas dataframe combine duplicate columns into one- separate data by comma | 37,932,391 | <p>My dataframe has few duplicate column names. If a duplicate column name is found combine duplicate columns into one. I also want to retain duplicate columns data separated by comma. Can anyone please suggest a way to do this.</p>
<p>I have constructed an example below. In my actual dataframe column names are unknow... | 4 | 2016-06-20T21:52:54Z | 37,932,756 | <p>You could also:</p>
<pre><code>df.groupby(df.columns, axis=1).agg(lambda x: ','.join(x.values)))
Col1 Col2 Col3
Index
A CA1 CA2,CA5 CA3
B CB1 CB2,CB5 CB3
C CC1 CC2,CC5 CC3
D CD1 CD2,CD5 CD3
E CE1 CE2,CE5 CE3
</code></pre>
<p>In detail: Use <code>.gro... | 4 | 2016-06-20T22:21:24Z | [
"python",
"pandas",
"dataframe"
] |
Pandas dataframe combine duplicate columns into one- separate data by comma | 37,932,391 | <p>My dataframe has few duplicate column names. If a duplicate column name is found combine duplicate columns into one. I also want to retain duplicate columns data separated by comma. Can anyone please suggest a way to do this.</p>
<p>I have constructed an example below. In my actual dataframe column names are unknow... | 4 | 2016-06-20T21:52:54Z | 37,932,757 | <p>I feel ashamed to post this. But it works.</p>
<pre><code>df = pd.DataFrame(np.random.choice(('a', 'b', 'c'), (5, 4)), list('ABCDE'), ['Col1', 'Col2', 'Col3', 'Col2'])
pd.concat([pd.DataFrame(c) for i, c in df.iteritems()], axis=1, keys=range(len(df.columns))).swaplevel(0, 1, 1).sort_index(1).groupby(level=0, axi... | 1 | 2016-06-20T22:21:30Z | [
"python",
"pandas",
"dataframe"
] |
How to check all the characters in for-loop with boolean type? | 37,932,418 | <p>I need to write a function which returns True if and only if the DNA sequence contains no characters other than 'A', 'T', 'C' and 'G')</p>
<p>Here is my code that produces this type of error - 'str' object does not support item assignment</p>
<pre><code>def is_valid_sequence(dna):
i = 0
for dna[i] in dna:
... | 0 | 2016-06-20T21:54:08Z | 37,932,486 | <pre><code>def func(dna):
for i in dna:
if i not in 'ATCG':
return False
return True
</code></pre>
| -3 | 2016-06-20T21:58:44Z | [
"python",
"if-statement",
"for-loop",
"boolean-operations"
] |
How to check all the characters in for-loop with boolean type? | 37,932,418 | <p>I need to write a function which returns True if and only if the DNA sequence contains no characters other than 'A', 'T', 'C' and 'G')</p>
<p>Here is my code that produces this type of error - 'str' object does not support item assignment</p>
<pre><code>def is_valid_sequence(dna):
i = 0
for dna[i] in dna:
... | 0 | 2016-06-20T21:54:08Z | 37,932,489 | <p>There's a very easy pythonic solution to this problem:</p>
<pre><code>def is_valid_sequence(dna):
return all(c in 'ATCG' for c in dna.upper())
</code></pre>
<p>This will check every letter, and does not care about the case of the input.</p>
<p><code>all()</code> takes an iterable and only returns <code>True</... | 1 | 2016-06-20T21:58:50Z | [
"python",
"if-statement",
"for-loop",
"boolean-operations"
] |
How to check all the characters in for-loop with boolean type? | 37,932,418 | <p>I need to write a function which returns True if and only if the DNA sequence contains no characters other than 'A', 'T', 'C' and 'G')</p>
<p>Here is my code that produces this type of error - 'str' object does not support item assignment</p>
<pre><code>def is_valid_sequence(dna):
i = 0
for dna[i] in dna:
... | 0 | 2016-06-20T21:54:08Z | 37,932,653 | <p>The code you provided has some flaws in looping, in general the loop will run on the characters and the iteration happens for the variable you set in the for loop, the increment of <code>i</code> in your second snippet is not being used in your code. Similary instead of <code>dna[i]</code> just <code>for i in dna</c... | 0 | 2016-06-20T22:11:41Z | [
"python",
"if-statement",
"for-loop",
"boolean-operations"
] |
Cython: why is size_t faster than int? | 37,932,600 | <p>Changing certain Cython variables from type <code>int</code> to type <code>size_t</code> can significantly reduce some functions speeds (~30%), but I do not understand why.</p>
<p>For example:</p>
<pre><code>cimport numpy as cnp
import numpy as np
def sum_int(cnp.int64_t[::1] A):
cdef unsigned long s = 0
... | 1 | 2016-06-20T22:07:22Z | 37,932,911 | <p>It depends on the architecture your CPU uses. Cython, being C based, is a platform-dependent programming language, and while the assembly on your CPU allows it to be faster, this isn't always the case.</p>
<p>The reason it's faster is because that's how your compiler and assembler have optimized it to work. I can... | -2 | 2016-06-20T22:36:22Z | [
"python",
"performance",
"types",
"cython"
] |
Cython: why is size_t faster than int? | 37,932,600 | <p>Changing certain Cython variables from type <code>int</code> to type <code>size_t</code> can significantly reduce some functions speeds (~30%), but I do not understand why.</p>
<p>For example:</p>
<pre><code>cimport numpy as cnp
import numpy as np
def sum_int(cnp.int64_t[::1] A):
cdef unsigned long s = 0
... | 1 | 2016-06-20T22:07:22Z | 37,933,120 | <p>You'd likely have to do a line by line profiling to find out exactly, but one thing stands out to me from the produced C file: <code>int</code> version is checked for wraparound to negative numbers, <code>size_t</code> is assumed ok.</p>
<p>In the int loop: (<code>t_3</code> is assigned from <code>k</code>, they're... | 5 | 2016-06-20T22:59:04Z | [
"python",
"performance",
"types",
"cython"
] |
Cython: why is size_t faster than int? | 37,932,600 | <p>Changing certain Cython variables from type <code>int</code> to type <code>size_t</code> can significantly reduce some functions speeds (~30%), but I do not understand why.</p>
<p>For example:</p>
<pre><code>cimport numpy as cnp
import numpy as np
def sum_int(cnp.int64_t[::1] A):
cdef unsigned long s = 0
... | 1 | 2016-06-20T22:07:22Z | 37,933,274 | <p>On a 64 bit system there seem to be two reasons:</p>
<ol>
<li><p>Use an unsigned integer for the loop:</p>
<pre><code>%%cython
cimport numpy as cnp
import numpy as np
def sum_int_unsigned(cnp.int64_t[::1] A):
cdef unsigned long s = 0
cdef unsigned k
for k in xrange(A.shape[0]):
s += A[k]
... | 2 | 2016-06-20T23:19:07Z | [
"python",
"performance",
"types",
"cython"
] |
Python web scraping - Where to begin | 37,932,621 | <p>I am trying to build a web crawler to gather betting data from multiple betting sites. I have some programming experience but I am very lost in the world of web pages, web scraping etc.</p>
<p>I have previously used Selenium to build "bots" and I think I could do something with that, I have also read some tutorials... | 1 | 2016-06-20T22:09:14Z | 37,933,296 | <p>I found <a href="http://rads.stackoverflow.com/amzn/click/1491910291" rel="nofollow"><strong>Web Scraping with Python: Collecting Data from the Modern Web</strong></a> to be a wonderful book which doesn't assume any experience with web scraping and only assumes that you know the basics of python. </p>
<p>The auth... | 1 | 2016-06-20T23:21:30Z | [
"javascript",
"python",
"selenium",
"web-scraping"
] |
Delete 0 in front of numbers like 06, 07, etc | 37,932,639 | <p>The column of pandas DataFrame contains values like:</p>
<pre><code>d = {'Col1' : pd.Series(['07','','10','06']),'Col2' : pd.Series([1., 2., 3.])}
</code></pre>
<p>I want to delete 0 in front of some integers, i.e. 07->7, 06->6, while 10 is ok.
How can I do it (including the processing of empty cels)?</p>
<p>I tr... | 1 | 2016-06-20T22:10:37Z | 37,932,740 | <p>The <code>int()</code> function doesn't work on empty strings, but you can easily fix it by having a fallback in case the value is falsy (and empty strings are indeed falsy):</p>
<pre><code>df['Col1'] = df['Col1'].apply(lambda x: int(x or 0))
</code></pre>
<p><code>int(x)</code> will be called when the value is no... | 4 | 2016-06-20T22:19:50Z | [
"python"
] |
Delete 0 in front of numbers like 06, 07, etc | 37,932,639 | <p>The column of pandas DataFrame contains values like:</p>
<pre><code>d = {'Col1' : pd.Series(['07','','10','06']),'Col2' : pd.Series([1., 2., 3.])}
</code></pre>
<p>I want to delete 0 in front of some integers, i.e. 07->7, 06->6, while 10 is ok.
How can I do it (including the processing of empty cels)?</p>
<p>I tr... | 1 | 2016-06-20T22:10:37Z | 37,932,845 | <p>You can replace the empty string and set astype to int:</p>
<pre><code>df['Col1'] = df['Col1'].replace('', 0).astype(int)
</code></pre>
<p>Which for larger amounts of data would be faster:</p>
| 1 | 2016-06-20T22:29:27Z | [
"python"
] |
Hide post-function calls in with statement | 37,932,713 | <p>I have a function <code>f</code> that returns two parameters. After this function, I use the first parameter. I need the second one to glue things together with another function <code>g</code>. So my code would look like:</p>
<pre><code>a, b = f()
# do stuff with a
g(b)
</code></pre>
<p>This is very repetitive, so... | 0 | 2016-06-20T22:17:32Z | 37,932,829 | <p>For someone else reading your code (or you in 6 months time), a context manager probably will imply the creation/initialisation and closure/deletion of a resource, and I would be very wary of re-purposing the idiom.</p>
<p>You could use composition, rather than a context manager: </p>
<pre><code>def func(a, b):
... | 1 | 2016-06-20T22:28:03Z | [
"python",
"python-3.x",
"with-statement",
"raii"
] |
Hide post-function calls in with statement | 37,932,713 | <p>I have a function <code>f</code> that returns two parameters. After this function, I use the first parameter. I need the second one to glue things together with another function <code>g</code>. So my code would look like:</p>
<pre><code>a, b = f()
# do stuff with a
g(b)
</code></pre>
<p>This is very repetitive, so... | 0 | 2016-06-20T22:17:32Z | 37,932,994 | <p>A slightly more pythonic way of doing it would be to use the <code>contextlib</code> module. You can do away with rolling out your own class with <code>__enter__</code> and <code>__exit__</code> functions.</p>
<pre><code>from contextlib import contextmanager
def g(x):
print "printing g(..):", x
def f():
r... | 1 | 2016-06-20T22:47:06Z | [
"python",
"python-3.x",
"with-statement",
"raii"
] |
how to find dependence between 2 column in df using python | 37,932,858 | <p>I have data</p>
<pre><code>city inc pop
New-York 29343,00 8683,00
Moscow 25896,00 17496,00
Boston 21785,00 15063,00
Berlin 20000,00 70453,00
London 44057,00 57398,00
Rome 24000,00 104831,00
</code></pre>
<p>I need to find how <code>inc</code> dependence from <code>pop</code>.
I try to pl... | 0 | 2016-06-20T22:31:00Z | 37,932,908 | <p>By default, the plot <code>kind</code> parameter is line. For exploratory data analysis, it is often better to start with scatter plots. </p>
<pre><code>df.plot(x='inc', y='pop', kind='scatter')
</code></pre>
| 1 | 2016-06-20T22:35:54Z | [
"python",
"pandas",
"matplotlib"
] |
how to find dependence between 2 column in df using python | 37,932,858 | <p>I have data</p>
<pre><code>city inc pop
New-York 29343,00 8683,00
Moscow 25896,00 17496,00
Boston 21785,00 15063,00
Berlin 20000,00 70453,00
London 44057,00 57398,00
Rome 24000,00 104831,00
</code></pre>
<p>I need to find how <code>inc</code> dependence from <code>pop</code>.
I try to pl... | 0 | 2016-06-20T22:31:00Z | 37,932,955 | <p>You can do various things to make it more readable. I guess with just this line you get a line plot. You can change it to scatter first.</p>
<p>If you're trying to show some correlation, you can overlay a regression line.</p>
<p>If that's too messy, you can play with colours and for example make the points light g... | 0 | 2016-06-20T22:40:58Z | [
"python",
"pandas",
"matplotlib"
] |
how to find dependence between 2 column in df using python | 37,932,858 | <p>I have data</p>
<pre><code>city inc pop
New-York 29343,00 8683,00
Moscow 25896,00 17496,00
Boston 21785,00 15063,00
Berlin 20000,00 70453,00
London 44057,00 57398,00
Rome 24000,00 104831,00
</code></pre>
<p>I need to find how <code>inc</code> dependence from <code>pop</code>.
I try to pl... | 0 | 2016-06-20T22:31:00Z | 37,943,209 | <p>As noted, you get the <code>correlation</code> via:</p>
<pre><code>df['inc'].corr(df['pop'])
-0.0279628856838
</code></pre>
<p>If you want a linear regression, you can use <a href="http://statsmodels.sourceforge.net/devel/generated/statsmodels.regression.linear_model.OLS.html" rel="nofollow">statsmodels.ols</a>:</... | 1 | 2016-06-21T11:29:08Z | [
"python",
"pandas",
"matplotlib"
] |
Decorator to pass pandas Series into one-column DataFrames | 37,932,927 | <p>I want to write a decorator that I can use on functions that are written for Pandas DataFrame, so that when they receive an input that is actually a Series (or maybe even an array) it first transforms that input into a one-column Pandas DataFrame out of generality. That way I can make every function work for both Da... | 0 | 2016-06-20T22:37:50Z | 37,933,626 | <p><strong>@First question: How can I do that?</strong></p>
<pre><code>import pandas as pd
from functools import wraps
def seriescapable(func):
"""Decorator for turning the first argument from a pandas.Series to a pandas.DataFrame."""
@wraps(func)
def wrapper(*args, **kwargs):
if args and isinstan... | 1 | 2016-06-21T00:01:12Z | [
"python",
"pandas",
"python-decorators"
] |
Perform clustering using t-SNE dimensionality reduction | 37,932,928 | <p>The question is a matter of which should come first: a) the clustering or b) the dimensionality reduction algorithm?
In other words, can I apply a pseudo (as it is not really) dimensionality reduction method like t-SNE and then use a clustering algorithm to extract clusters or should the clustering be performed on t... | 0 | 2016-06-20T22:37:51Z | 37,936,978 | <p>It is very common to first reduce the dimensionality, then cluster. Simply because clustering high-dimensional data is <em>hard</em>, and dimensionality reduction makes it quite a bit more "tractable".</p>
<p>As long as you don't forget that clustering is inherently unreliable (so don't trust the results, but <em>s... | 1 | 2016-06-21T06:26:32Z | [
"python",
"algorithm",
"cluster-analysis",
"dimensionality-reduction"
] |
Perform clustering using t-SNE dimensionality reduction | 37,932,928 | <p>The question is a matter of which should come first: a) the clustering or b) the dimensionality reduction algorithm?
In other words, can I apply a pseudo (as it is not really) dimensionality reduction method like t-SNE and then use a clustering algorithm to extract clusters or should the clustering be performed on t... | 0 | 2016-06-20T22:37:51Z | 38,419,495 | <p>It is always better to perform dimensionality reduction and then clustering.</p>
<p>The reason behind this is that distance in <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.23.7409&rep=rep1&type=pdf" rel="nofollow">high dimensional space behave in a strange way</a>. Another interesting p... | 1 | 2016-07-17T08:54:15Z | [
"python",
"algorithm",
"cluster-analysis",
"dimensionality-reduction"
] |
How to do box-whisker plot using matplotlib | 37,932,950 | <p>I have </p>
<pre><code>num city inc pop edu crime cult
1,0 Moscow 29343,00 8683,00 0,00 10,40 0,00
2,0 Paris 25896,00 17496,00 0,00 10,20 1,00
3,0 London 21785,00 15063,00 0,00 14,20 1,00
4,0 Berlin 20000,00 70453,00 1,00 18,00 1,00
</code></pre>
<p>I try to do <c... | 1 | 2016-06-20T22:40:18Z | 37,944,730 | <p>The issue here is that <code>desire_salary.pivot_table('city', 'cult', aggfunc='count')</code> has only one value, <code>cult</code>, selected. The standard behavior of <code>pivot_table</code> is to return a <code>series</code> when the pivot_table has only one value/one column. However, the <code>series</code> obj... | 0 | 2016-06-21T12:40:52Z | [
"python",
"pandas",
"matplotlib"
] |
action callback for libnotify not working | 37,932,966 | <p>I am trying to develop a desktop notification system with python and Libnotify.</p>
<p>I found this <a href="http://www.devdungeon.com/content/desktop-notifications-python-libnotify" rel="nofollow">tutorial</a> and tried the example with an action callback, below is my code modification</p>
<pre><code>#initializat... | 2 | 2016-06-20T22:42:13Z | 37,934,191 | <p>You need to integrate with D BUS to receive events from your notifications. </p>
<p><a href="http://stackoverflow.com/questions/32681532/python-program-with-notification-in-gnome-shell-doesnt-work/32839296#32839296">Here is good explanation use Glib for it</a>.</p>
| 1 | 2016-06-21T01:21:45Z | [
"python",
"ubuntu",
"linuxmint",
"libnotify"
] |
How to call python script in Spark? | 37,933,023 | <p>I have a metrics.py which calculates the graph.</p>
<p>I can call it in terminal command line(python ./metrics.py -i [input] [output]).</p>
<p>I want to write a function in Spark. It calls the metrics.py script to run on the provide file path and collects the values that metrics.py prints out.</p>
<p>How can I do... | 0 | 2016-06-20T22:50:04Z | 37,966,477 | <p>In order to run metrics.py, you essentially ship it to all the executor nodes that run your Spark Job. </p>
<p>To do this, you either pass it via SparkContext - </p>
<pre><code>sc = SparkContext(conf=conf, pyFiles=['path_to_metrics.py'])
</code></pre>
<p>or pass it later using the Spark Context's addPyFile method... | 0 | 2016-06-22T11:18:12Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql",
"spark-streaming"
] |
cx_Oracle LDAP Connection String syntax | 37,933,090 | <p>With JDBC, we can use the following syntax to connect to an Oracle database over an LDAP connection:</p>
<pre><code>jdbc:oracle:thin:@ldap://host:1234/service_name,cn=OracleContext,dc=org,dc=com
</code></pre>
<p>How can I connect over LDAP using cx_oracle?</p>
| 0 | 2016-06-20T22:55:55Z | 37,945,341 | <p>The short answer is that you use an ldap.ora configuration file and specify that it is to be used in your sqlnet.ora configuration file. Although this link talks about creating a database link and not directly connecting, the same principle applies and you can connect using any of the services referenced in your LDA... | 0 | 2016-06-21T13:07:27Z | [
"python",
"python-2.7",
"cx-oracle"
] |
environment with mutliple python interpreter | 37,933,116 | <p>On Mac, if installed multiple Python interpreter (anaconda, Python 2.7 standard, etc.), wondering when running command <code>python</code>, is there a way to specify if I run with anaconda or Python 2.7 or other Python interpreter? Thanks.</p>
<p>regards,
Lin</p>
| 0 | 2016-06-20T22:58:56Z | 37,933,150 | <p>If you only type python, it will take you to the version of python specified by this:</p>
<pre><code>which python
</code></pre>
<p>This command will print out the location of <code>python</code> in your terminal.</p>
<p>To use a version other than the one above, be it Jython or Anaconda or whatever, you can to ru... | 1 | 2016-06-20T23:03:16Z | [
"python",
"osx",
"python-2.7",
"anaconda"
] |
In the Django admin page for a given model, is it possible to create one or more models that have the original given model as a foreign key field? | 37,933,126 | <p>For example, let's say we have Cars and Manufacturers, where the Cars model contains a foreign key to Manufacturers (many cars to one manufacturer). In the Manufacturer admin page, when you are creating a new Manufacturer, you get to input whatever fields a manufacturer might have, such as name or address for exampl... | 0 | 2016-06-20T22:59:48Z | 37,933,228 | <p>As long as your car has foreign key to manufacturer, you should be able to choose in Django Admin</p>
<p>in your models:</p>
<pre><code>from django.db import models
class Manufacturer(models.Model):
name = models.CharacterField(max_length=200,blank=True,null=True)
location = models.CharacterField(max_le... | 0 | 2016-06-20T23:14:25Z | [
"python",
"django",
"django-admin"
] |
python - extracting values from dictionary in order | 37,933,139 | <p>I have a dictionary with some share related data:</p>
<pre><code>share_data = {'2016-06-13':{'open': 2190, 'close':2200}, '2015-09-10':{'open': 2870, 'close':2450} # and so on, circa 1,500 entries
</code></pre>
<p>is there a way of iterating over the dictionary in order, so the oldest date is retrieved first, then... | 3 | 2016-06-20T23:02:01Z | 37,933,177 | <p>Sure, the default lexicographical order of your date strings will map to chronological order. So it is very easy:</p>
<pre><code>for key in sorted(share_data.keys()):
#do something
</code></pre>
<p>This post has some nice examples of custom sorting on dictionaries:
<a href="http://pythoncentral.io/how-to-sort-... | 6 | 2016-06-20T23:06:22Z | [
"python"
] |
Add the value of two different specific csv columns | 37,933,143 | <p>So I currently get a .csv file that looks like this:</p>
<pre class="lang-none prettyprint-override"><code>HostType,Number
Windows_Desktop,84
Linux_Desktop,12
Windows_Desktop,60
Linux_Desktop,7
</code></pre>
<p>I am trying to write a script that performs a function based on the total value. So I have a two global ... | 1 | 2016-06-20T23:02:47Z | 37,933,209 | <p>You need to identify the type of thing you are collecting by analyzing the contents of the first column. Since you are collecting <code>Windows</code> and <code>Linux</code> totals, you can use a dictionary to collect these data.</p>
<p>Try this version:</p>
<pre><code>import csv
from collections import defaultdic... | 3 | 2016-06-20T23:11:12Z | [
"python",
"csv"
] |
Add the value of two different specific csv columns | 37,933,143 | <p>So I currently get a .csv file that looks like this:</p>
<pre class="lang-none prettyprint-override"><code>HostType,Number
Windows_Desktop,84
Linux_Desktop,12
Windows_Desktop,60
Linux_Desktop,7
</code></pre>
<p>I am trying to write a script that performs a function based on the total value. So I have a two global ... | 1 | 2016-06-20T23:02:47Z | 37,933,250 | <p>I would highly recommend using the <a href="http://pandas.pydata.org/" rel="nofollow">Pandas package</a>. It is very useful for working with csv files.</p>
<pre><code>import pandas as pd
df = pd.read_csv("/Users/daddy30000/Dropbox/Stackoverflow/16_06_20_example.csv")
windows = df[df['HostType'] == 'Windows_Deskto... | 1 | 2016-06-20T23:16:15Z | [
"python",
"csv"
] |
Add the value of two different specific csv columns | 37,933,143 | <p>So I currently get a .csv file that looks like this:</p>
<pre class="lang-none prettyprint-override"><code>HostType,Number
Windows_Desktop,84
Linux_Desktop,12
Windows_Desktop,60
Linux_Desktop,7
</code></pre>
<p>I am trying to write a script that performs a function based on the total value. So I have a two global ... | 1 | 2016-06-20T23:02:47Z | 37,933,338 | <p>One way you can do it is like so:</p>
<pre><code>with open("/tmp/foo.txt", 'r') as input_file:
counts = {}
for line in input_file:
split_line = line.split(",")
device = split_line[0]
counts[device] = int(split_line[1]) + (counts.get(device) or 0)
print counts ## prints {'Window... | 1 | 2016-06-20T23:27:10Z | [
"python",
"csv"
] |
Add the value of two different specific csv columns | 37,933,143 | <p>So I currently get a .csv file that looks like this:</p>
<pre class="lang-none prettyprint-override"><code>HostType,Number
Windows_Desktop,84
Linux_Desktop,12
Windows_Desktop,60
Linux_Desktop,7
</code></pre>
<p>I am trying to write a script that performs a function based on the total value. So I have a two global ... | 1 | 2016-06-20T23:02:47Z | 37,933,575 | <p>For such as small dataset, I'd read the whole thing into memory and use indices (slightly different from yours) to directly access the proper rows and columns. I also see no need for using <code>global</code> variables (or why you're using <code>float</code> instead of <code>int</code>):</p>
<pre><code>import csv
... | 1 | 2016-06-20T23:54:27Z | [
"python",
"csv"
] |
Dictionary comprehension on a filter object | 37,933,148 | <p>What's going on with my dictionary comprehension here? </p>
<p>I am parsing a BLAST file and want to create objects for each line in the file. Ideally each object will be stored in a dictionary for use later in the program.
Parsing works fine but I end up with a blank transSwiss dictionary. </p>
<p>Here are a few... | 0 | 2016-06-20T23:03:06Z | 37,933,208 | <p>When you do this:</p>
<pre><code>for blastmap.transcriptId in filtered
</code></pre>
<p>you're trying to assign each element of <code>filtered</code> to <code>blastmap.transcriptId</code> in sequence. <code>blastmap</code> is either a list or an instance of the <code>map</code> type, depending on your Python versi... | 2 | 2016-06-20T23:11:10Z | [
"python",
"dictionary"
] |
checkpointing the model every iteration | 37,933,225 | <p>what is the best practice for checkpointing (i.e. save an snapshot of) the model every Nth iteration in TensorFlow?</p>
<p>obviously, it is possible to do it using custom logic to call <code>tf.train.Saver.save</code> but was wondering if there is an internal mechanism for that?</p>
| 0 | 2016-06-20T23:14:02Z | 37,933,823 | <p>I do something like this based upon how often I want the checkpoint saved:</p>
<pre><code>if (epoch % N) == (N - 1):
saveto=CkptDir+"ckpt/model"+str(N)+".ckpt"
save_path = saverRun.save(session, saveto)
</code></pre>
<p>This will save a checkpoint file ever N epoch's.</p>
| 0 | 2016-06-21T00:25:06Z | [
"python",
"tensorflow"
] |
checkpointing the model every iteration | 37,933,225 | <p>what is the best practice for checkpointing (i.e. save an snapshot of) the model every Nth iteration in TensorFlow?</p>
<p>obviously, it is possible to do it using custom logic to call <code>tf.train.Saver.save</code> but was wondering if there is an internal mechanism for that?</p>
| 0 | 2016-06-20T23:14:02Z | 37,977,571 | <p>Found the solution <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/state_ops.html#Saver" rel="nofollow">here</a>. It is possible to set <code>max_to_keep</code> and <code>keep_checkpoint_every_n_hours</code> to get a desired saving.</p>
| 0 | 2016-06-22T20:21:47Z | [
"python",
"tensorflow"
] |
GAE import errors; sys.path shows wrong path for appengine libraries | 37,933,277 | <p>I'm developing a web app for Google App Engine in Python on Windows 10. Everything was working fine when my main.py was just serving templates. </p>
<pre><code>import os
import urllib
from google.appengine.api import users
import jinja2
import webapp2
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileS... | 1 | 2016-06-20T23:19:24Z | 37,934,810 | <p>Update: the issue was fixed in SDK version 1.9.40.</p>
<p>There is <a href="https://code.google.com/p/googleappengine/issues/detail?id=12963" rel="nofollow">a GAE issue</a> causing exactly this behaviour introduced in SDK version 1.9.37, see <a href="http://stackoverflow.com/questions/37755195/importerror-no-module... | 2 | 2016-06-21T02:51:46Z | [
"python",
"python-2.7",
"google-app-engine",
"google-cloud-storage",
"jinja2"
] |
GAE import errors; sys.path shows wrong path for appengine libraries | 37,933,277 | <p>I'm developing a web app for Google App Engine in Python on Windows 10. Everything was working fine when my main.py was just serving templates. </p>
<pre><code>import os
import urllib
from google.appengine.api import users
import jinja2
import webapp2
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileS... | 1 | 2016-06-20T23:19:24Z | 37,954,968 | <p>Summary:</p>
<p>The webapp2 and jinja2 import errors are caused by sys.path corruption, a result of a GAE defect present in versions 1.9.37 or 1.9.38. It only impacts development; deployed versions should work. It can occur immediately upon upgrading or after attempting to install other items.</p>
<p>Solutions:</p... | 0 | 2016-06-21T21:34:46Z | [
"python",
"python-2.7",
"google-app-engine",
"google-cloud-storage",
"jinja2"
] |
Why is it giving me the error, "the JSON object must be str, not 'bytes'", and how do I fix it? | 37,933,302 | <p>I was following a tutorial about how to use JSON objects (link: <a href="https://www.youtube.com/watch?v=Y5dU2aGHTZg" rel="nofollow">https://www.youtube.com/watch?v=Y5dU2aGHTZg</a>). When they ran the code, they got no errors, but I did. Is it something to do with different Python versions or something?</p>
<pre><c... | 0 | 2016-06-20T23:22:19Z | 37,933,340 | <p>The <a href="https://docs.python.org/3/library/http.client.html#httpresponse-objects" rel="nofollow"><code>HTTPResponse</code> object</a> returned from <a href="https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen" rel="nofollow"><code>urlopen</code></a> reads <code>bytes</code> data (raw bin... | 2 | 2016-06-20T23:27:29Z | [
"python",
"json",
"urllib"
] |
Why is it giving me the error, "the JSON object must be str, not 'bytes'", and how do I fix it? | 37,933,302 | <p>I was following a tutorial about how to use JSON objects (link: <a href="https://www.youtube.com/watch?v=Y5dU2aGHTZg" rel="nofollow">https://www.youtube.com/watch?v=Y5dU2aGHTZg</a>). When they ran the code, they got no errors, but I did. Is it something to do with different Python versions or something?</p>
<pre><c... | 0 | 2016-06-20T23:22:19Z | 37,934,108 | <p>I think they were using a different version of the urllib</p>
<p>Try with urllib3 and do the import like this:</p>
<pre><code>from urllib import urlopen
</code></pre>
<p>Hope this is the fix to your problem</p>
| 0 | 2016-06-21T01:10:56Z | [
"python",
"json",
"urllib"
] |
Receiving python json through sockets with java | 37,933,360 | <p>I've been following multiple tutorials to connect a java code to python through sockets. </p>
<p>Sending from java to python works great, with json array. However, I can't seem to receive things with java. I don't really understand how the listening should be done. Now I just listen in a 15 second while loop (the p... | 2 | 2016-06-20T23:29:54Z | 37,933,503 | <p>This is happening because your java code is blocking. See how B is not printed to your logs? That is because it does't execute since this part is waiting for a flush command: <code>out.println(new JSONArray(test2).toString());</code>. What you need to do is <code>out.flush();</code> so it goes on.</p>
| 2 | 2016-06-20T23:46:08Z | [
"java",
"python",
"json",
"sockets"
] |
Receiving python json through sockets with java | 37,933,360 | <p>I've been following multiple tutorials to connect a java code to python through sockets. </p>
<p>Sending from java to python works great, with json array. However, I can't seem to receive things with java. I don't really understand how the listening should be done. Now I just listen in a 15 second while loop (the p... | 2 | 2016-06-20T23:29:54Z | 37,940,218 | <p>You code has multiple issues.</p>
<p><b>1. Client.py and Server.java both waiting to receive data, which causes deadlock.</b></p>
<p>Client.py is blocked at <em>while True</em>, keeps waiting for new data.<br>
Server.java has sent the <em>JSONArray(test2).toString()</em> whose length is 51. Then keeps waiting at i... | 1 | 2016-06-21T09:15:23Z | [
"java",
"python",
"json",
"sockets"
] |
Error connecting to MS SQL Server using pyODBC, unixODBC and FreeTDS (on a Mac) | 37,933,369 | <p>I am getting an error when trying to connect to a MS SQL server in python, using the pyODBC --> unixODBC --> FreeTDS --> MS SQL stack. Iâve spent a lot of time on this, and there are some great resources if youâve reached this question with more fundamental problems getting a connection to work <a href="http://... | 2 | 2016-06-20T23:31:09Z | 37,934,501 | <p>There are a lot of moving parts in your question. Not only do you have Notebook-on-Python-on-ODBC, but you have iODBC and OS X. Yikes! </p>
<p>The question boils down to this: <em>Where does iODBC look for <code>odbc.ini</code></em>? I don't know of an ODBC function that reports that information. </p>
<p>Bec... | 1 | 2016-06-21T02:10:00Z | [
"python",
"sql-server",
"pyodbc",
"freetds",
"unixodbc"
] |
Error connecting to MS SQL Server using pyODBC, unixODBC and FreeTDS (on a Mac) | 37,933,369 | <p>I am getting an error when trying to connect to a MS SQL server in python, using the pyODBC --> unixODBC --> FreeTDS --> MS SQL stack. Iâve spent a lot of time on this, and there are some great resources if youâve reached this question with more fundamental problems getting a connection to work <a href="http://... | 2 | 2016-06-20T23:31:09Z | 37,977,913 | <p>Here's an example I think would work for you. If you're using FreeTDS 0.95, you can use TDS Version 7.3, if you're using 0.82 or less, use 7.1. I've never bothered with testing <code>osql</code> with this stack, if <code>tsql</code> and <code>isql</code> work, you should be able to get the rest working, but the nuan... | 0 | 2016-06-22T20:43:26Z | [
"python",
"sql-server",
"pyodbc",
"freetds",
"unixodbc"
] |
Error connecting to MS SQL Server using pyODBC, unixODBC and FreeTDS (on a Mac) | 37,933,369 | <p>I am getting an error when trying to connect to a MS SQL server in python, using the pyODBC --> unixODBC --> FreeTDS --> MS SQL stack. Iâve spent a lot of time on this, and there are some great resources if youâve reached this question with more fundamental problems getting a connection to work <a href="http://... | 2 | 2016-06-20T23:31:09Z | 38,106,959 | <p>Well, we solved it -- with the help of a lot of people on this page and over <a href="http://stackoverflow.com/questions/37947482/pyodbc-refuses-to-look-for-unixodbc-instead-looks-for-iodbc">here</a>, chasing down a lot of blind alleys.</p>
<p>As (eventually) suspected, it was the pyodbc link in the connection. I ... | 0 | 2016-06-29T18:00:41Z | [
"python",
"sql-server",
"pyodbc",
"freetds",
"unixodbc"
] |
How to download images from s3 as numpy arrays? | 37,933,398 | <p>I am trying to train a neural network where I pass in a series of images. I want to create a generator which passes each image in as a numpy array</p>
<pre><code>from skimage import io
image_array = io.imread(url)
</code></pre>
<p>I want something like this:</p>
<pre><code>s3 = boto3.resource('s3')
my_bucket = s3... | 1 | 2016-06-20T23:34:40Z | 37,950,047 | <p>Based on the <a href="http://scikit-image.org/docs/dev/api/skimage.io.html#skimage.io.imread" rel="nofollow">docs for imread</a>, it appears that it only supports passing in a filename or a URL. So no file-like objects. So it looks like you have two options: save to a temp file, or <a href="http://boto3.readthedocs.... | 1 | 2016-06-21T16:39:07Z | [
"python",
"amazon-web-services",
"amazon-s3",
"boto",
"boto3"
] |
python beautifulsoup : lxml html.parser | 37,933,399 | <p>I must use beautifulsoup, but i don't know which parser I have to take.
I hesitate between lxml and html.parser, or why not both.
How to know if a web page is lxml compliant ?
How to know if a web page is html parser compliant ?
Many thanks</p>
| 0 | 2016-06-20T23:34:46Z | 37,933,417 | <p>There is no silver bullet. <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#differences-between-parsers" rel="nofollow">Different HTML parsers behave differently</a> and you should pick the one that works for your particular page. Works in this case basically means, that you can get to your desired da... | 3 | 2016-06-20T23:36:50Z | [
"python",
"beautifulsoup",
"lxml",
"html-parser"
] |
How to programmatically share a google drive link on android? | 37,933,413 | <p>I have an android app that saves an image into the Google Drive and shares the weblink to my Google App Engine server (python).</p>
<pre><code> // Create client
mGoogleApiClient = new GoogleApiClient.Builder(mContext)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallba... | 0 | 2016-06-20T23:36:30Z | 38,445,623 | <p>It's not possible with the android API for google drive.</p>
| 0 | 2016-07-18T20:38:45Z | [
"java",
"android",
"python",
"google-drive-sdk",
"google-drive-android-api"
] |
How can I define global options with sub-parsers in python argparse? | 37,933,480 | <p>I'm trying to figure out how to add global option in a sub-parser scenario with pythons arparse library.</p>
<p>Right now my code looks like this:</p>
<pre class="lang-py prettyprint-override"><code>def parseArgs(self):
parent_parser = argparse.ArgumentParser(add_help=False)
parent_parser.add_argument('--d... | 2 | 2016-06-20T23:44:06Z | 37,933,841 | <p><code>main_parser</code> fills in the defaults into <code>namespace</code> (<code>False</code> for <code>debug</code>); if it encounters <code>--debug</code> it changes <code>debug</code> to <code>True</code>. When it sees the <code>agent</code> string, it calls the subparser, passing it the remaining argument stri... | 3 | 2016-06-21T00:28:25Z | [
"python",
"argparse"
] |
Hosting for app with Python 2.7, Tornado, MongoDB | 37,933,532 | <p>I want to publish my web site. Source code is located on GitHub.
My tech: Python 2.7, Tornado, MongoDB, MongoEngine.</p>
<p>I am interested in free hosting. What should I use or should I do?
Thanks in advance. </p>
<p>PS OpenShift is working only with Django I suppose. </p>
| 0 | 2016-06-20T23:48:51Z | 37,933,573 | <p>You can deploy your application on Google App Engine (20 free instances). You can use a Tornado GAE Template (e.g <a href="https://github.com/tornadoweb/tornado/tree/master/demos/appengine" rel="nofollow">https://github.com/tornadoweb/tornado/tree/master/demos/appengine</a>) to set up Python environment, and you can... | 1 | 2016-06-20T23:53:54Z | [
"python",
"mongodb",
"hosting",
"tornado",
"web-hosting"
] |
How to return dictionary for longest list of dicts containing an item belonging to multiple list of dicts? | 37,933,539 | <p>Really hard to phrase this question and I'm also having problems wrapping my head around how to figure this out.
Say I have the following dictionary.</p>
<pre><code>mydict = { u'10441':
[{u'quantity': 1, u'productId': 10441},
{u'quantity': 25, u'productId': 10451},
{u'qua... | 1 | 2016-06-20T23:49:33Z | 37,933,725 | <p>You could do this. The <code>try/except</code> is just there in case <em>none</em> of the id lists contain the given product id (which will cause <code>max</code> to raise a <code>ValueError</code> because of the empty sequence).</p>
<p>The answer is somewhat ambiguous when multiple items in your product dictionar... | 1 | 2016-06-21T00:12:42Z | [
"python",
"list",
"dictionary"
] |
How to return dictionary for longest list of dicts containing an item belonging to multiple list of dicts? | 37,933,539 | <p>Really hard to phrase this question and I'm also having problems wrapping my head around how to figure this out.
Say I have the following dictionary.</p>
<pre><code>mydict = { u'10441':
[{u'quantity': 1, u'productId': 10441},
{u'quantity': 25, u'productId': 10451},
{u'qua... | 1 | 2016-06-20T23:49:33Z | 37,933,835 | <p>Use <code>id2parents</code> to keep track of the parent ids of each product id. For any product id with same number of parents as the number of elements in <code>mydict</code>, it must exist in every directory. Collect such directory id into <code>parent_ids</code>, and sort by its size, and select the first one:</p... | 0 | 2016-06-21T00:26:49Z | [
"python",
"list",
"dictionary"
] |
How to return dictionary for longest list of dicts containing an item belonging to multiple list of dicts? | 37,933,539 | <p>Really hard to phrase this question and I'm also having problems wrapping my head around how to figure this out.
Say I have the following dictionary.</p>
<pre><code>mydict = { u'10441':
[{u'quantity': 1, u'productId': 10441},
{u'quantity': 25, u'productId': 10451},
{u'qua... | 1 | 2016-06-20T23:49:33Z | 37,933,847 | <p>With only two top-level dictionaries in your example, it's hard to see what you are really after. How many top-level dictionaries are we talking about? How many of them must share an Id? Let's see how you do this efficiently with pairwise comparisons, and hopefully you know where to go from there.</p>
<p>First, mak... | 1 | 2016-06-21T00:29:23Z | [
"python",
"list",
"dictionary"
] |
Why does "import ctask as task" fail in pyinvoke? | 37,933,558 | <p>When I try to use ctask as defined in the <a href="http://docs.pyinvoke.org/en/0.12.2/getting_started.html?highlight=ctask" rel="nofollow">getting started guide</a>, it fails with the following error:</p>
<pre><code>>>> from invoke import ctask as task
Traceback (most recent call last):
File "<stdin&g... | 1 | 2016-06-20T23:52:10Z | 37,933,569 | <p>In pyinvoke 0.13.0, <a href="https://github.com/pyinvoke/invoke/issues/114" rel="nofollow">all tasks are now ctasks</a></p>
<p>Change your import to use task instead.</p>
| 1 | 2016-06-20T23:53:27Z | [
"python",
"pyinvoke"
] |
lutorpy for shared memory between python and torch | 37,933,561 | <p>I am trying to install lutorpy to load a network trained in torch and use it in python code. I get the following error: </p>
<pre><code>lutorpy/_lupa.c:299:17: fatal error: lua.h: no such file or directory
</code></pre>
<p>I do have <code>lua.h</code> in <code>torch/install/include</code> folder. </p>
<p>I'm fol... | 1 | 2016-06-20T23:52:23Z | 38,074,805 | <p>Currently, lutorpy only support the standard torch installation, which means install torch in your home folder. So if that's the case for you, you problem mostly likely to be solved by start a new torch installation in your home folder.</p>
<p>In the meantime, you can track <a href="https://github.com/imodpasteur/l... | 0 | 2016-06-28T11:20:05Z | [
"python",
"lua",
"torch"
] |
Find route_table_id by subnet_id using boto3 | 37,933,608 | <p>I'm trying to figure out how to find route_table_id based upon a subnet_id(in a vpc) using boto3. There is api in boto3(v1.3.1), ec2.RouteTableAssociation(id). With correct route_table_association_id, try to access the resource's attribute route_table_id, it gives exception as below:</p>
<pre><code>In [19]: rta.rou... | 0 | 2016-06-20T23:58:54Z | 37,948,190 | <p>figure out to do this way:</p>
<pre><code>response = client.describe_route_tables(
Filters=[
{
'Name': 'association.subnet-id',
'Values': [
source_subnet_id
]
}
]
)
print(response['RouteTables'][0]['Associations'][0]['RouteTableId'])
</co... | 0 | 2016-06-21T15:09:54Z | [
"python",
"amazon-ec2",
"boto3"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.