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 |
|---|---|---|---|---|---|---|---|---|---|
Import Error: Pillow 3.3.1 & Python 2.7 & El Capitan OS | 39,472,379 | <p>I have installed the Pillow package from PIP using <code>pip install Pillow</code> and Pillow 3.3.1 got installed. I am working with Python 2.7 on Mac OS 10.11 (El Capitan).</p>
<p>When I try to import the Image module, I run into <code>ImportError: No module named Pillow</code>. I tried to import the following:</p... | 1 | 2016-09-13T14:21:07Z | 39,472,408 | <p>Reinstall package properly using <code>python -m pip install package_name</code></p>
<p>Then import using <code>from PIL import Image</code>.</p>
| 2 | 2016-09-13T14:22:47Z | [
"python",
"osx",
"python-2.7",
"pillow"
] |
Selenium scrolling internal scroll bar and scrapping results | 39,472,394 | <p>I'm trying to scrape <a href="http://comparefirst.sg/wap/productsListEvent.action?prodGroup=whole&pageAction=prodlisting" rel="nofollow">this website</a> for my project to populate a list of insurance products available.</p>
<p>However, the website has an internal scrolling bar, that only displays the first 10 ... | 1 | 2016-09-13T14:21:59Z | 39,472,512 | <p>Interesting thing is, <em>you don't need to scroll the container at all.</em> All the results are actually loaded, but part of them are just invisible. You can simply find all <code>li</code> elements with <code>result_content</code> class and get the desired data.</p>
<p>Example working code extracting the "prod n... | 2 | 2016-09-13T14:28:06Z | [
"python",
"selenium"
] |
django-tables2 add dynamic columns to table class from hstore | 39,472,441 | <p>My general question is: can I use the data stored in a <strong><a href="https://docs.djangoproject.com/en/1.8/ref/contrib/postgres/fields/#django.contrib.postgres.fields.HStoreField" rel="nofollow">HStoreField</a></strong> (Django 1.8.9) to generate columns dynamically for an existing <strong>Table</strong> class of... | 0 | 2016-09-13T14:24:43Z | 39,494,326 | <p>Managed to figure this out to a certain extent. The code I was running above was <em>slightly</em> wrong, so I updated it to run my code before the superclass <em>init()</em> gets run, and changed where I was adding the columns.</p>
<p>As a result, my <strong>init()</strong> function now looks like this:</p>
<pre>... | 0 | 2016-09-14T15:28:48Z | [
"python",
"django",
"hstore",
"django-tables2"
] |
Authentication With Imgur API | 39,472,518 | <p>So I'm writing a simple-ish script that can automatically download images from Imgur. I've come across the Imgur API but am struggling to get it to work. I registered an app but am not sure how to use it to be able to get information about images or albums. I do not want to be able to log in as a user or anything li... | 1 | 2016-09-13T14:28:17Z | 39,499,615 | <p>In the end I just used the Imgur API helper that is available on Github to do all the work. Just needed to provide the client ID and secret.</p>
<p><a href="https://github.com/Imgur/imgurpython" rel="nofollow">https://github.com/Imgur/imgurpython</a></p>
| 0 | 2016-09-14T21:04:15Z | [
"python",
"api",
"imgur"
] |
Stop embedded Python prompt from C++ | 39,472,584 | <p>I'm running Python embedded in a C++ application. The program consists of a Qt GUI and a work QThread where computations happen. The user can chose to run a Python script from a file or to start a Python prompt. Both run in the QThread. The program exits when the python script is done or when we exit the python prom... | 1 | 2016-09-13T14:31:23Z | 39,628,593 | <p>Can you not set up a slot receiver on your <code>QThread</code> subclass that will call <code>PyErr_SetInterrupt</code> in the proper context for you?</p>
<p>You might achieve cleaner separation-of-concerns if, instead of using QThreads, you run your embedded Python interpreter in a separate process â which you c... | 1 | 2016-09-22T00:49:28Z | [
"python",
"c++",
"python-c-api",
"embedded-language"
] |
Sort index alphabetically on first, second, third characters | 39,472,601 | <p>I have a df which looks like this:</p>
<pre><code>df = pd.DataFrame({'val': [0, 0, 0, 1, 0, 0, 0]},
index=['13th str', '3SAT', 'ARD',
'ARD Dritte', 'AXNAction', 'Animal', 'bb'])
val
13th str 0
3SAT 0
ARD 0
ARD Dritte 1
AXNAction ... | 1 | 2016-09-13T14:32:39Z | 39,487,638 | <p>Your index is sorted correctly as uppercase characters are sorted before lower case which is why your attempts failed, to sort the way you want you can add a temporary column with the lower case index values, sort by this column and then drop it:</p>
<pre><code>In [155]:
df['labels'] = df.index.str.lower()
df = df.... | 2 | 2016-09-14T10:00:14Z | [
"python",
"sorting",
"pandas",
"dataframe"
] |
Sort index alphabetically on first, second, third characters | 39,472,601 | <p>I have a df which looks like this:</p>
<pre><code>df = pd.DataFrame({'val': [0, 0, 0, 1, 0, 0, 0]},
index=['13th str', '3SAT', 'ARD',
'ARD Dritte', 'AXNAction', 'Animal', 'bb'])
val
13th str 0
3SAT 0
ARD 0
ARD Dritte 1
AXNAction ... | 1 | 2016-09-13T14:32:39Z | 39,487,676 | <p>You can sort the index <a href="https://wiki.python.org/moin/HowTo/Sorting" rel="nofollow">using a custom <code>key</code> function</a>:</p>
<pre><code>In [22]: df = pd.DataFrame({'val': [0, 0, 0, 1, 0, 0, 0]},
index=['13th str', '3SAT', 'ARD',
'ARD Dritte', 'AXNAction', 'Animal... | 2 | 2016-09-14T10:02:29Z | [
"python",
"sorting",
"pandas",
"dataframe"
] |
How to concat and update pandas dataframes | 39,472,712 | <p>I'd like to concat the dataframe <strong>df1</strong> and <strong>df2</strong> and result the dataframe <strong>df</strong></p>
<pre><code>df1 = pd.DataFrame([
{"id": 1, "a": 1, "b": 1},
{"id": 2, "a": 2, "b": 2},
])
df2 = pd.DataFrame([
{"id": 1, "a": 5, "b": 5},
{"id": 3, "a": 6, "b": 6}
])
df =... | -1 | 2016-09-13T14:37:44Z | 39,473,303 | <ol>
<li>Concatenate</li>
<li>Remove duplicates</li>
</ol>
<hr>
<pre><code>df1 = pd.DataFrame([
{"id": 1, "a": 1, "b": 1},
{"id": 2, "a": 2, "b": 2},
])
df2 = pd.DataFrame([
{"id": 1, "a": 5, "b": 5},
{"id": 3, "a": 6, "b": 6}
])
print (pd.concat([df1.set_index('id'),
df2.set_index... | 1 | 2016-09-13T15:05:12Z | [
"python",
"pandas"
] |
GoogleAppEngine access app.yaml contents inside the app | 39,472,839 | <p>I have a python GAE app. Inside my <code>webapp2</code> code I would like to access some of the properties defined in the <code>app.yaml</code>.</p>
<p>I know it's possible to export environment variables and access them inside my python app using <code>os.environ</code>, but is there a way to directly access <code... | 1 | 2016-09-13T14:44:25Z | 39,473,218 | <p>You could simply do:</p>
<pre><code>import yaml
with open('app.yaml') as fd:
data = yaml.load(fd)
logging.error('data=%s' % data)
</code></pre>
| 2 | 2016-09-13T15:00:49Z | [
"python",
"google-app-engine"
] |
django-positions - multi-table model inheritance using parent_link | 39,472,867 | <p>Using <a href="https://github.com/jpwatts/django-positions">https://github.com/jpwatts/django-positions</a>,</p>
<p>I have a few models that inherit from a parent one, for example:</p>
<pre><code>class ContentItem(models.Model):
class Meta:
ordering = ['position']
content_group = models.ForeignKe... | 5 | 2016-09-13T14:45:45Z | 39,475,909 | <p><code>class Meta:</code> should come after your field definitions.</p>
| -1 | 2016-09-13T17:35:47Z | [
"python",
"django"
] |
Fast way to get edges crossing two sets of nodes in networkx.Graph | 39,472,910 | <p>What's the fasted way in <code>networkx</code> to get the crossing edges between two disjoint node sets?
Is there some ready-made function to use?</p>
<p>The way I am using now:</p>
<pre><code>import networkx as nx
from itertools import product
A = set(range(50))
B = set(range(50, 100))
g = nx.complete_graph(100)... | 0 | 2016-09-13T14:47:42Z | 39,483,728 | <p>It depends on assumptions about the graph.</p>
<p>If graph is dense than your approach is optimal since set of result edges is almost the same as <code>product(A,B)</code>. Than it is goot to iterate through all possible edges (<code>product(A,B)</code>) and check is it an edge.</p>
<p>If graph is sparse than it w... | 0 | 2016-09-14T06:23:29Z | [
"python",
"graph-theory",
"networkx"
] |
Mac Terminal Encoding Issues | 39,472,917 | <p>I have been dealing with an issue regarding the terminal in my Macbook.
I am passing greek words in a python string e.g. </p>
<pre><code>text = 'ÎαλημÎÏα κÏÏμε'
</code></pre>
<p>and every time I try to perform any simple task to it like splitting in spaces the result I get looks like this:</p>
<pre>... | 1 | 2016-09-13T14:47:52Z | 39,473,176 | <p>This is not an issue with your terminal, but how Python (2) does things.</p>
<p>Even if you don't perform any task on it, <code>repr</code> will escape any non-ASCII (or non-printable (except space)) characters:</p>
<pre><code>>>> text = 'ÎαλημÎÏα κÏÏμε'
>>> text
'\xce\x9a\xce\xb1\xc... | 0 | 2016-09-13T14:58:48Z | [
"python",
"osx",
"encoding",
"utf-8",
"terminal"
] |
Django: Multiple URL parameters | 39,472,953 | <p>I'm making a study app that involves flashcards. It is divided into subjects. Each subject (biology, physics) has a set of decks (unitone, unittwo). Each deck has a set of cards (terms and definitions). I want my URLs to look like
localhost:8000/biology/unitone/ but I have trouble putting two URL parameters in one ... | 0 | 2016-09-13T14:49:26Z | 39,473,147 | <p>You can't have multiple parameters with the same name. You have to give each parameter a unique name, e.g.:</p>
<pre><code>url(r'^subjects/(?P<pk>[0-9]+)/(?P<deck>[0-9]+)/$', views.DeckView.as_view(), name='deck'),
</code></pre>
<p>In the <code>DeckView</code> you can then access them as <code>self.kwa... | 2 | 2016-09-13T14:57:38Z | [
"python",
"django"
] |
Django: Multiple URL parameters | 39,472,953 | <p>I'm making a study app that involves flashcards. It is divided into subjects. Each subject (biology, physics) has a set of decks (unitone, unittwo). Each deck has a set of cards (terms and definitions). I want my URLs to look like
localhost:8000/biology/unitone/ but I have trouble putting two URL parameters in one ... | 0 | 2016-09-13T14:49:26Z | 39,474,244 | <p>there's a way by rewriting the DetailViews </p>
<p>urls.py</p>
<pre><code>url(r'^subjects/(?P<subjects>\w+)/(?P<deck>\w+)/$', views.DeckView.as_view(), name='deck'),
</code></pre>
<p>views.py</p>
<pre><code>class DeckView(DetailView):
model = Deck
# slug_field = "deck" # you don't need it
... | 1 | 2016-09-13T15:52:06Z | [
"python",
"django"
] |
For Loop Append to list from another | 39,472,967 | <p>I'm working on a "pick up all" and "drop all" for a game I'm designing. The player has an inventory (inventory) and each room has it's own to keep track of what is in it. When it is a specific item, I can easily append or remove the item from the respective lists, but when it is for them all, I am not sure how to pr... | 0 | 2016-09-13T14:49:56Z | 39,473,046 | <p>2 mistakes here</p>
<ol>
<li>you convert to uppercase but test against lower!</li>
<li>you should iterate on a copy of <code>ROOMNAMEinventory</code>, modifying list while iterating on it is not recommended: it changes lists to that <code>['string', 'lamp']
and ['coin']</code>: not that you want</li>
</ol>
<p>Fixe... | 0 | 2016-09-13T14:53:33Z | [
"python",
"list"
] |
For Loop Append to list from another | 39,472,967 | <p>I'm working on a "pick up all" and "drop all" for a game I'm designing. The player has an inventory (inventory) and each room has it's own to keep track of what is in it. When it is a specific item, I can easily append or remove the item from the respective lists, but when it is for them all, I am not sure how to pr... | 0 | 2016-09-13T14:49:56Z | 39,473,403 | <p><code>List</code> in Python supports adding one to another:</p>
<pre><code>roomname_inventory = ['lamp', 'coin']
inventory = ['string']
do = raw_input("What would you like to do?").upper()
if (do == 'DROP ALL'):
inventory += roomname_inventory
roomname_inventory = []
print inventory
print roomname_inventory... | 1 | 2016-09-13T15:09:52Z | [
"python",
"list"
] |
Django Python Social Auth only allow certain users to sign in | 39,472,975 | <p>I want only users from a @companyname.net email <em>or</em> from a list of email addresses to be able to sign in with Python Social Auth through google+. How would I accomplish this?</p>
<pre><code>SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS = ['companyname.net']
</code></pre>
<p>is what I currently have in sett... | 1 | 2016-09-13T14:50:23Z | 39,476,208 | <p>One way to solve this is overriding python-social-auth pipeline.</p>
<p>You can override create_user with something like:</p>
<pre><code>def create_user(strategy, details, user=None, *args, **kwargs):
if user:
return {'is_new': False}
allowed_emails = get_list_of_emails()
fields = dict((name,... | 0 | 2016-09-13T17:53:42Z | [
"python",
"django",
"python-social-auth"
] |
Output size of convolutional auto-encoder in Keras | 39,472,986 | <p>I am doing the convolutional autoencoder tutorial written by the author of the Keras library:
<a href="https://blog.keras.io/building-autoencoders-in-keras.html" rel="nofollow">https://blog.keras.io/building-autoencoders-in-keras.html</a></p>
<p>However, when I launch exactly the same code, and analyse the network'... | 2 | 2016-09-13T14:50:57Z | 39,529,745 | <p>Please notice that you are missing a <code>border_mode</code> option in pre-last convolution layer.</p>
<pre><code>from keras.layers import Input, Dense, Convolution2D, MaxPooling2D, UpSampling2D
from keras.models import Model
input_img = Input(shape=(1, 28, 28))
x = Convolution2D(16, 3, 3, activation='relu', bor... | 1 | 2016-09-16T10:53:59Z | [
"python",
"deep-learning",
"keras"
] |
Evaluating mathematical expressions passed in as strings in python | 39,473,066 | <p><p> I wish to make a mathematical function ( <code>f(x,y)</code> in this case ) with multiple variables, only two in this case, <code>x</code> and <code>y</code>, which evaluates a mathematical expression which is in a string format initially.
<p>
For example,<br>
If the string is</p>
<pre><code>s = "2*x + sin(y) +... | 1 | 2016-09-13T14:54:44Z | 39,473,121 | <p>Use the <code>eval</code> function
<code>return eval(s)</code></p>
| -4 | 2016-09-13T14:56:42Z | [
"python",
"python-2.7"
] |
Evaluating mathematical expressions passed in as strings in python | 39,473,066 | <p><p> I wish to make a mathematical function ( <code>f(x,y)</code> in this case ) with multiple variables, only two in this case, <code>x</code> and <code>y</code>, which evaluates a mathematical expression which is in a string format initially.
<p>
For example,<br>
If the string is</p>
<pre><code>s = "2*x + sin(y) +... | 1 | 2016-09-13T14:54:44Z | 39,473,779 | <p>I'd recommend you stay away of <a href="http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html" rel="nofollow">eval</a> and using a proper library to do the mathematical job at hands, one of the favourite candidates is sympy, which is described as:</p>
<blockquote>
<p>SymPy is a Python library for sym... | 2 | 2016-09-13T15:27:30Z | [
"python",
"python-2.7"
] |
Evaluating mathematical expressions passed in as strings in python | 39,473,066 | <p><p> I wish to make a mathematical function ( <code>f(x,y)</code> in this case ) with multiple variables, only two in this case, <code>x</code> and <code>y</code>, which evaluates a mathematical expression which is in a string format initially.
<p>
For example,<br>
If the string is</p>
<pre><code>s = "2*x + sin(y) +... | 1 | 2016-09-13T14:54:44Z | 39,473,866 | <p>Without using SymPy you should create your own parser, for example by <a href="http://stackoverflow.com/questions/11708195/infix-to-postfix-with-function-support">converting the infix expression to a postfix expression</a>, which are very easy to evaluate once in this notation. Mathematical functions are just unary ... | 1 | 2016-09-13T15:32:20Z | [
"python",
"python-2.7"
] |
Serialdata import python "every other data point" | 39,473,118 | <p>I'm trying to read serial data of an arduino which has been somewhat successful. The values that will be read from the arduino is voltage and current. I'm now trying to differentiate the different variables but i have no clue how. The arduino is sending the values in the following order with 1 sec delay. Voltage, AM... | 0 | 2016-09-13T14:56:40Z | 39,473,263 | <p>First of all, you shouldn't need the <code>sleep</code>s on the raspberry Pi - <code>readline</code> will block until the output comes along.</p>
<p>You should structure your code to read the voltage and current separately:</p>
<pre><code>while True:
voltage = serialVoltage.readline()
current = serialVolta... | 0 | 2016-09-13T15:02:56Z | [
"python",
"arduino",
"serial-port",
"raspberry-pi3"
] |
How to append even and odd chars python | 39,473,259 | <p>I want to convert all the even letters using one function and all the odd numbers using another function. So, each letter represents 0-25 correspsonding with a-z, so a,c,e,g,i,k,m,o,q,s,u,w,y are even characters.</p>
<p>However, only my even letters are converting correctly. </p>
<pre><code>def encrypt(plain):
... | 0 | 2016-09-13T15:02:45Z | 39,473,300 | <p>You never change <code>charCount</code> in your loop -- So it starts at <code>0</code> and stays at <code>0</code> which means that each <code>ch</code> will be treated as "even".</p>
<p>Based on your update, you actually want to check if the character is odd or even based on it's "index" in the english alphabet. ... | 4 | 2016-09-13T15:04:57Z | [
"python"
] |
How to append even and odd chars python | 39,473,259 | <p>I want to convert all the even letters using one function and all the odd numbers using another function. So, each letter represents 0-25 correspsonding with a-z, so a,c,e,g,i,k,m,o,q,s,u,w,y are even characters.</p>
<p>However, only my even letters are converting correctly. </p>
<pre><code>def encrypt(plain):
... | 0 | 2016-09-13T15:02:45Z | 39,473,519 | <p>Since your notion of <em>even letter</em> is based on the position of a character in the alphabet, you could use <a href="https://docs.python.org/3/library/functions.html?highlight=ord#ord" rel="nofollow"><code>ord()</code></a>, like this:</p>
<pre><code> if ord(ch)%2==0:
</code></pre>
<p>Note that <code>ord('a')<... | 0 | 2016-09-13T15:15:02Z | [
"python"
] |
How to append even and odd chars python | 39,473,259 | <p>I want to convert all the even letters using one function and all the odd numbers using another function. So, each letter represents 0-25 correspsonding with a-z, so a,c,e,g,i,k,m,o,q,s,u,w,y are even characters.</p>
<p>However, only my even letters are converting correctly. </p>
<pre><code>def encrypt(plain):
... | 0 | 2016-09-13T15:02:45Z | 39,473,611 | <p>This are my two cents on that. What @mgilson is proposing also works of course but not in the way you specified (in the comments). Try to debug your code in your head after writing it.. Go through the for loop and perform 1-2 iterations to see whether the variables take the values you intended them to. <code>charCou... | 0 | 2016-09-13T15:19:09Z | [
"python"
] |
How to append even and odd chars python | 39,473,259 | <p>I want to convert all the even letters using one function and all the odd numbers using another function. So, each letter represents 0-25 correspsonding with a-z, so a,c,e,g,i,k,m,o,q,s,u,w,y are even characters.</p>
<p>However, only my even letters are converting correctly. </p>
<pre><code>def encrypt(plain):
... | 0 | 2016-09-13T15:02:45Z | 39,473,735 | <p>Your basic approach is to re-encrypt a letter each time you see it. With only 26 possible characters to encrypt, it is probably worth pre-encrypting them, then just performing a lookup for each character in the plain text. While doing that, you don't need to compute the position of each character, because you know y... | 1 | 2016-09-13T15:25:13Z | [
"python"
] |
How to install module and package in python | 39,473,266 | <p>I'm trying to start with OpenCV with python. I have experience c# and I have knowledge of c++. However, I feel more comfortable with python instead of c++. I installed OpenCV then python 3.4 in visual studio 2015. At the beginning I've received an error numpy, "Module couldn't be found", thankfully, I resolved it. T... | 0 | 2016-09-13T15:03:03Z | 39,473,366 | <p>You can install matplotlib using pip (which is already installed on your machine - mentioned in your previous quesiton):</p>
<pre><code>pip install matplotlib
</code></pre>
<p>more info:
<a href="http://matplotlib.org/faq/installing_faq.html" rel="nofollow">http://matplotlib.org/faq/installing_faq.html</a></p>
| 1 | 2016-09-13T15:08:21Z | [
"python",
"windows",
"python-3.x",
"opencv",
"visual-studio-2015"
] |
How to install module and package in python | 39,473,266 | <p>I'm trying to start with OpenCV with python. I have experience c# and I have knowledge of c++. However, I feel more comfortable with python instead of c++. I installed OpenCV then python 3.4 in visual studio 2015. At the beginning I've received an error numpy, "Module couldn't be found", thankfully, I resolved it. T... | 0 | 2016-09-13T15:03:03Z | 39,473,504 | <p>It's very common to install Python packages through <code>pip</code> today (recursive acronym for <em>pip installs packages</em>). However, this is not that trivial under Windows.</p>
<p><strong>How to install <code>matplotlib</code>:</strong></p>
<p>Try to open a commandline and type in <code>pip install matplotl... | 1 | 2016-09-13T15:14:22Z | [
"python",
"windows",
"python-3.x",
"opencv",
"visual-studio-2015"
] |
How to install module and package in python | 39,473,266 | <p>I'm trying to start with OpenCV with python. I have experience c# and I have knowledge of c++. However, I feel more comfortable with python instead of c++. I installed OpenCV then python 3.4 in visual studio 2015. At the beginning I've received an error numpy, "Module couldn't be found", thankfully, I resolved it. T... | 0 | 2016-09-13T15:03:03Z | 39,473,508 | <p>You may be better off using an package such as pythonxy as a start, e.g. from <a href="https://python-xy.github.io/" rel="nofollow">https://python-xy.github.io/</a> , instead of installing each single package manually.</p>
| 1 | 2016-09-13T15:14:41Z | [
"python",
"windows",
"python-3.x",
"opencv",
"visual-studio-2015"
] |
How to pass QLineEdit value to another function? | 39,473,288 | <p>I'm using Python 2.7 and PyQT4, I'm making a simple calculator, I have two <code>QLineEdit</code> and I have a function that prints the result of adding.</p>
<pre><code>class Window(QtGui.QMainWindow):
global number_1_text
global number_2_text
def __init__(self):
super(Window, self).__init__()
... | 0 | 2016-09-13T15:04:25Z | 39,474,586 | <p>You should make your child widgets attributes of the main window. That way, you can easily access them later:</p>
<pre><code>class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
...
self.number_1 = QtGui.QLineEdit(self)
self.number_1.move(20, 50)
... | 0 | 2016-09-13T16:10:08Z | [
"python",
"pyqt",
"pyqt4"
] |
Restrict python exec acess to one directory | 39,473,445 | <p>I have a python script which executes a string of code with the <em>exec</em> function. I need a way to restrict the read/write access of the script to the current directory. How can I achieve this?</p>
<p>Or, is there a way to restrict the python script's environment directly through the command line so that when ... | -1 | 2016-09-13T15:11:42Z | 39,473,520 | <p>Execute the code as a user that only owns that specific directory and has no permissions anywhere else?</p>
<p>However- if you do not completely trust the source of code, you should simply not be using <code>exec</code> under any circumstances. Remember, say you came up with a python solution... the exec code coul... | 1 | 2016-09-13T15:15:03Z | [
"python",
"python-2.7",
"python-exec"
] |
Restrict python exec acess to one directory | 39,473,445 | <p>I have a python script which executes a string of code with the <em>exec</em> function. I need a way to restrict the read/write access of the script to the current directory. How can I achieve this?</p>
<p>Or, is there a way to restrict the python script's environment directly through the command line so that when ... | -1 | 2016-09-13T15:11:42Z | 39,474,240 | <p>The question boils down to: How can I safely execute the code I don't trust.<br>
You can't.<br>
Either you know what the code does or you don't execute it.<br>
You can have an isolated environment for your process, for example with docker. But the use cases are far away from executing unsafe code.</p>
| 1 | 2016-09-13T15:51:51Z | [
"python",
"python-2.7",
"python-exec"
] |
64-bit cx_Oracle: DLL load failed | 39,473,503 | <p>Using Windows 2008 R2 Server. Server was completely clean. Installed 64-bit Python 3.5, 64-bit Oracle Instant Client 12c. pip installed cx_Oracle successfully. When I try to run a python script that imports cx_Oracle however, I get:</p>
<pre><code>ImportError: DLL load failed: The specified module could not be ... | 1 | 2016-09-13T15:14:16Z | 39,503,078 | <p>First, the environment variable ORACLE_HOME should not be set when an instant client is used. Setting it can have unintended side effects!</p>
<p>Second, if you used pip to install cx_Oracle that suggests you have a compiler and it succeeded in compiling the module. Check to make sure that it used the correct libra... | 0 | 2016-09-15T04:23:18Z | [
"python",
"cx-oracle"
] |
Apply numpy.where on condition with either list or numpy.array | 39,473,548 | <p>I discovered that <code>numpy.where</code> behaves differently when applied on a condition such as <code>foo==2</code> when <code>foo</code> is a list or <code>foo</code> is a <code>numpy.array</code></p>
<pre><code>foo = ["a","b","c"]
bar = numpy.array(["a","b","c"])
numpy.where(foo == "a") # Returns array([])
num... | 0 | 2016-09-13T15:16:38Z | 39,474,270 | <p>To me your solution is already the best:</p>
<pre><code>numpy.where(numpy.array(foo, copy=False) == "a")
</code></pre>
<p>It is concise, very clear and totaly efficient thanks to <code>copy=False</code>.</p>
| 2 | 2016-09-13T15:53:17Z | [
"python",
"arrays",
"numpy"
] |
Apply numpy.where on condition with either list or numpy.array | 39,473,548 | <p>I discovered that <code>numpy.where</code> behaves differently when applied on a condition such as <code>foo==2</code> when <code>foo</code> is a list or <code>foo</code> is a <code>numpy.array</code></p>
<pre><code>foo = ["a","b","c"]
bar = numpy.array(["a","b","c"])
numpy.where(foo == "a") # Returns array([])
num... | 0 | 2016-09-13T15:16:38Z | 39,483,596 | <p>If you are really looking for the most <code>numpy</code>-esque solution, use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html" rel="nofollow"><code>np.asarray</code></a>:</p>
<pre><code>numpy.where(numpy.asarray(foo) == "a")
</code></pre>
<p>And if you also want your code to work wi... | 1 | 2016-09-14T06:13:53Z | [
"python",
"arrays",
"numpy"
] |
Setting class variable based on another class' variable | 39,473,653 | <p>I was trying to remind myself of OO programming by creating some kind of chess clone in python and found myself with the current issue.</p>
<p>I'd like to give each piece on the board an 'identifier' variable so that it can be displayed on screen e.g : bR would indicate a black rook. However I'm not sre how I can e... | 1 | 2016-09-13T15:21:30Z | 39,473,724 | <p>I'm not sure what issue you had with using <code>__str__</code>, but that is absolutely the right way to go about it.</p>
<pre><code>class Piece(object):
identifier = ' '
def __init__(self, colour):
self.colour = colour
def __str__(self):
return "{}{}".format(self.colour, self.identif... | 1 | 2016-09-13T15:24:48Z | [
"python",
"python-3.x"
] |
Setting class variable based on another class' variable | 39,473,653 | <p>I was trying to remind myself of OO programming by creating some kind of chess clone in python and found myself with the current issue.</p>
<p>I'd like to give each piece on the board an 'identifier' variable so that it can be displayed on screen e.g : bR would indicate a black rook. However I'm not sre how I can e... | 1 | 2016-09-13T15:21:30Z | 39,473,729 | <p>There's no issue trying to get the value you need by defining <code>__str__</code>, define it on <code>piece</code> and return <code>self.colour + self.identifier</code>:</p>
<pre><code>def __str__(self):
return self.colour + self.identifier
</code></pre>
<p>Now when you print an instance of <code>rook</code>,... | 1 | 2016-09-13T15:25:05Z | [
"python",
"python-3.x"
] |
Reading mashabe API using urllib | 39,473,685 | <p>I have this code to read Mashape.com API in python 2. how can i read it in python 3?</p>
<p><strong>code</strong></p>
<pre><code>import urllib, urllib2, json
from pprint import pprint
URL = "https://getsentiment.p.mashape.com/"
text = "The food was great, but the service was slow."
params = {'text': text, 'domain... | 2 | 2016-09-13T15:22:52Z | 39,474,094 | <p>In this line:</p>
<pre><code>request = urllib.request.Request(URL, urllib.parse.urlencode(params), headers)
</code></pre>
<p>Try to replace to </p>
<pre><code>data = urllib.parse.urlencode(params).encode('utf-8')
request = urllib.request.Request(URL, data, headers)
</code></pre>
| 1 | 2016-09-13T15:43:48Z | [
"python",
"python-3.x",
"mashape"
] |
Theano ValueError: dimension mismatch in args to gemm; 2d array dimension is interpreted as 1d | 39,473,692 | <p>I am trying implementing a simple xnor neural network function using Theano, I am getting the type mismatch</p>
<blockquote>
<p>ValueError: dimension mismatch in args to gemm (8,1)x(2,1)->(8,1)</p>
</blockquote>
<p>despite the fact that the inputs are in dimension (4X2) and the outputs are (4X1), I don't know wh... | 0 | 2016-09-13T15:23:16Z | 39,597,879 | <p>The shared variables w1,w2,w3 are created as a matrices while casting, they should be vectors, the casting should be done as the following:</p>
<p>These lines: </p>
<pre><code>w1 = shared(np.array([rng.random(1).astype(theano.config.floatX), rng.random(1).astype(theano.config.floatX)]))
w2 = shared(np.array([rng.r... | 0 | 2016-09-20T15:18:40Z | [
"python",
"numpy",
"neural-network",
"gpu",
"theano"
] |
Linux - reasons for SIGSTOP and how to deal with it? | 39,473,817 | <p>I have a Python script which is running bash scripts. I need to be able to kill the bash script if it seems to be infinite and it also has to be run in chroot jail because the script might be dangerous. I run it with <code>psutil.Popen()</code> and leave it running for two seconds. If it does not end naturally, I se... | 0 | 2016-09-13T15:29:45Z | 39,474,718 | <p>I'm pretty sure you're running this on Mac OS and not Linux. Why? You're sending signal <code>17</code> to your main python process instead of using:</p>
<pre><code>import signal
signal.SIGCHLD
</code></pre>
<p>I believe you have a handler for signal <code>17</code> which is supposed to respawn the jailed process ... | 1 | 2016-09-13T16:18:52Z | [
"python",
"linux",
"bash",
"shell"
] |
Linux - reasons for SIGSTOP and how to deal with it? | 39,473,817 | <p>I have a Python script which is running bash scripts. I need to be able to kill the bash script if it seems to be infinite and it also has to be run in chroot jail because the script might be dangerous. I run it with <code>psutil.Popen()</code> and leave it running for two seconds. If it does not end naturally, I se... | 0 | 2016-09-13T15:29:45Z | 39,487,438 | <p>Ok, I finally found the solution. The problem really was on the chroot line in the bash script:</p>
<pre><code>echo './prepare.sh' | chroot "$2"
</code></pre>
<p>This appears to be incorrect for some reason. The correct way to run a command in chroot is:</p>
<pre><code>chroot chroot_path shell -c command
</code><... | 1 | 2016-09-14T09:51:16Z | [
"python",
"linux",
"bash",
"shell"
] |
Stop Word Removal with NLTK | 39,473,824 | <p>I've been working with NLTK and Database Classification. I'm having a problem with stop word removal. When I print the list of stop words all of the words are listed with "u'" before them. For example:
[u'all', u'just', u'being', u'over', u'both', u'through']
I'm not sure if this is normal or part of the issue.</p>
... | 0 | 2016-09-13T15:29:58Z | 39,478,210 | <p>After executing these three lines,</p>
<pre><code>stopset = list(set(stopwords.words('english')))
morewords = 'delivery', 'shipment', 'only', 'copy', 'attach', 'material'
stopset.append(morewords)
</code></pre>
<p>have a look at <code>stopset</code> (output shortened):</p>
<pre><code>>>> stopset
[u'all',... | 0 | 2016-09-13T20:08:32Z | [
"python",
"python-3.x",
"unicode",
"nltk",
"stop-words"
] |
Git Blog - the pelican template disappears in the new deployed blog but exists in localhost | 39,473,867 | <p>Sorry if I didn't express the question correctly - I am trying to set up a blog on Git using pelican, but I am new to both of it. </p>
<p>So I followed some websites and tried to release one page, however when I did <code>make serve</code> on my local drive the blog looks ok on <code>localhost:/8000</code></p>
<p>... | 1 | 2016-09-13T15:32:23Z | 39,476,013 | <p>From your Question, what I understood is you are having problem publishing pelican site on git hub. As per my knowledege below is the way to publish it.I don't know why you got 404 Error though.</p>
<p><strong>Step1</strong>:
First you need to create repository in github.To create it follow the below ... | 0 | 2016-09-13T17:41:55Z | [
"python",
"git",
"markdown",
"blogs",
"pelican"
] |
How to square only the positive numbers in a list? | 39,473,895 | <p>I am trying to only square the positive numbers in a list. But when I try the code it squares all of them</p>
<pre><code>def squarethis(numbers):
for n in numbers:
if n > 0:
return[n ** 2 for n in numbers]
print(squarethis([1, 3, 5, -81]))
</code></pre>
<p>Why does it square all numbers? The if-sta... | 0 | 2016-09-13T15:33:35Z | 39,473,965 | <p>Just use a single list comprehension:</p>
<pre><code>def squarethis(numbers):
return [n ** 2 for n in numbers if n > 0]
</code></pre>
<p>What you are doing in the code your provided is checking if the first value in <code>numbers</code> is <code>> 0</code>, and if it is, returning your list comprehension... | 7 | 2016-09-13T15:37:21Z | [
"python",
"list",
"math",
"int",
"square"
] |
How to square only the positive numbers in a list? | 39,473,895 | <p>I am trying to only square the positive numbers in a list. But when I try the code it squares all of them</p>
<pre><code>def squarethis(numbers):
for n in numbers:
if n > 0:
return[n ** 2 for n in numbers]
print(squarethis([1, 3, 5, -81]))
</code></pre>
<p>Why does it square all numbers? The if-sta... | 0 | 2016-09-13T15:33:35Z | 39,474,305 | <p>A purely functional alternative -></p>
<pre><code>>>> map(lambda x: x**2, filter(lambda x: x > 0, [1, 2, 3, -1, -2, -3]))
[1, 4, 9]
</code></pre>
| 1 | 2016-09-13T15:54:57Z | [
"python",
"list",
"math",
"int",
"square"
] |
What is the significance of scikit-learn GridSearchCV best_score_ | 39,473,916 | <p>I can see the answer at <a href="http://stackoverflow.com/questions/24096146/how-is-scikit-learn-gridsearchcv-best-score-calculated">How is scikit-learn GridSearchCV best_score_ calculated?</a> for the what this score means.</p>
<p>I am working with scikit learn example for decision tree and trying various values f... | 0 | 2016-09-13T15:34:44Z | 39,474,373 | <p>The best_score_ value is different every time because you have not passed a fixed value for random_state in your DecisionTreeClassifier. You can do the following in order to get the same value every time you run your code on any machine.</p>
<pre><code>random_seed = 77 ##It can be any value of your choice
pipelin... | 0 | 2016-09-13T15:58:51Z | [
"python",
"pandas",
"scikit-learn",
"grid-search"
] |
Initilize multiple dataframe columns with categorical labels | 39,473,952 | <p>Problem statement:</p>
<p>I need to load 1000's csv files into a data frame. All files have the same columns. The values in each of the columns belong to a <strong>limited</strong> set of possible values in all cases (different per column). The length of the values lies in the 100's of chars. I do not know beforeh... | 1 | 2016-09-13T15:36:44Z | 39,600,440 | <p>This is resolved in pandas v0.19.0, see <a href="https://github.com/pydata/pandas/issues/12699" rel="nofollow">issue in gihub</a> and <a href="http://pandas-docs.github.io/pandas-docs-travis/whatsnew.html#categorical-concatenation" rel="nofollow">in pandas docs v.1.19 dev</a>.</p>
<p>However, there is another post... | 0 | 2016-09-20T17:35:23Z | [
"python",
"pandas",
"dataframe"
] |
ValueError: 'object too deep for desired array' | 39,474,056 | <p>I have a ValueError: 'object too deep for desired array' in a Python program.
I have this error while using numpy.digitize.<br>
I think it's how I use Pandas DataFrames:<br>
To keep it simple (because this is done through an external library), I have a list in my program but the library needs a DataFrame so I do som... | 0 | 2016-09-13T15:42:04Z | 39,474,209 | <p>Try this:</p>
<pre><code>numpy.digitize(df.iloc[:, 0], bins)
</code></pre>
<p>You are trying to get the values from a whole DataFrame. That is why you get the 2D array. Each row in the array is a row of the DataFrame.</p>
| 1 | 2016-09-13T15:49:48Z | [
"python",
"pandas",
"numpy",
"dataframe"
] |
Recording audio for specific amount of time with PyAudio? | 39,474,111 | <p>I am trying to learn about audio capture/recording using Python and in this case PyAudio. I am taking a look at a few examples and came across this one:</p>
<pre><code>import pyaudio
import wave
CHUNK = 2
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 3
WAVE_OUTPUT_FILENAME = "output.wav"
p =... | 0 | 2016-09-13T15:44:41Z | 39,477,855 | <p><code>CHUNK</code> is the number of samples in a block of data. I would call this "block size". Sound cards and sound drivers typically don't process one sample after the other but they use, well, chunks. The block size of those is typically a few hundred samples, e.g. 512 or 1024 samples. Only if you need very low ... | 0 | 2016-09-13T19:44:02Z | [
"python",
"for-loop",
"audio",
"pyaudio"
] |
Odoo qweb call python method | 39,474,140 | <p>I want to modify the RFQ report and in that I wanted to call a python method from the Qweb report, </p>
<p>here is some sample code,</p>
<pre><code><span t-field ="o.my_custom_fuction()" />
</code></pre>
<p>and my python function is like</p>
<pre><code>@api.model
def my_custom_function(self):
return "s... | 1 | 2016-09-13T15:46:03Z | 39,474,355 | <blockquote>
<blockquote>
<p>The t-field directive can only be used when performing field access (a.b) on a "smart" record (result of the browse method). </p>
</blockquote>
</blockquote>
<p>To call that function You will need to use <code>t-esc</code> (takes an expression, evaluates it and prints the content):... | 2 | 2016-09-13T15:57:40Z | [
"python",
"openerp",
"odoo-8",
"odoo-9"
] |
with salt how to access reclass vs pillar data? | 39,474,148 | <p>Im looking at the readme on the salt-swift <a href="https://github.com/openstack/salt-formula-swift" rel="nofollow">formula</a>, and this has me wondering:</p>
<pre><code> rings:
- name: default
partition_power: 9
replicas: 3
hours: 1
region: 1
devices:
- address: ${_para... | 0 | 2016-09-13T15:46:26Z | 39,480,408 | <p>You could definitely just put the addresses right there. You could also define pillar data in the regular manner and access it from there.</p>
| 1 | 2016-09-13T23:28:44Z | [
"python",
"yaml",
"salt-stack",
"configuration-management"
] |
Cardano's formula not working with numpy? | 39,474,254 | <p>--- using python 3 ---</p>
<p>Following the equations <a href="https://proofwiki.org/wiki/Cardano's_Formula" rel="nofollow">here</a>, I tried to find all real roots of an arbitrary third-order-polynomial. Unfortunatelly, my implementation does not yield the correct result and I cannot find the error. Maybe you ... | 2 | 2016-09-13T15:52:38Z | 39,477,903 | <p>Here is my stab at the solution. Your code fails for the case where <code>R + np.sqrt(D)</code> or <code>R - np.sqrt(D)</code> is negative. The reason is in <a href="http://stackoverflow.com/questions/31231115/raise-to-1-3-gives-complex-number">this post</a>. Basically if you do <code>a**(1/3)</code> where <code>a</... | 1 | 2016-09-13T19:46:51Z | [
"python",
"numpy",
"calculus"
] |
how twisted server detects an incomplete message | 39,474,266 | <p>I am right now implementing a twisted client and twisted server.
The question is how does the server detect if a message that is sent by client is completed?</p>
<p>For example, there are 2 clients sending messages to server, the message is a python list which has only several elements, respectively. The 2nd clien... | 0 | 2016-09-13T15:53:07Z | 39,475,446 | <p>You want to implement some sort of <em>protocol</em> (not to be confused with <code>twisted.internet.protocol</code>) which has some sort of delimiter signifying the beginning and end of a message and how long your message will be. For example, let's define a protocol which implements the following rules:</p>
<ol>
... | 1 | 2016-09-13T17:05:31Z | [
"python",
"twisted"
] |
passing function to a class using @property.setter decorator | 39,474,333 | <p>I am making a class that i want to declare a variable which hold a function in it and i want to call them after i do some processing on some information.but i don't know how to use property decorator in this situation.
i already have this code:</p>
<pre><code>class MyClass:
def __init__(self):
self.cal... | 0 | 2016-09-13T15:56:20Z | 39,474,537 | <p>I based on this code don't see a need for <code>properties</code> but here it is anyway.</p>
<pre><code>class MyClass:
def __init__(self):
self.__callback = None
@property
def cb(self):
return self.__callback
@cb.setter
def cb(self, new_cb):
self.__callback = new_cb
</c... | 0 | 2016-09-13T16:07:44Z | [
"python",
"python-3.x",
"callback",
"python-3.5"
] |
Building a tuple containing colons to be used to index a numpy array | 39,474,396 | <p>I've created a class for dealing with multidimensional data of a specific type. This class has three attributes: A list containing the names of the axes (<strong>self.axisNames</strong>); a dictionary containing the parameter values along each axis (<strong>self.axes</strong>; keyd using the entries in axisNames); a... | 2 | 2016-09-13T16:00:01Z | 39,482,568 | <p>Inside indexing <code>[]</code>, a <code>:</code> is translated to a <code>slice</code>, and the whole thing is passed to <code>__getitem__</code> as a tuple</p>
<pre><code>indexList = []
for axis in self.axisNames:
if axis in indexSpec:
indexList.append(indexSpec[axis])
else:
indexList.appe... | 2 | 2016-09-14T04:38:13Z | [
"python",
"arrays",
"numpy"
] |
Building a tuple containing colons to be used to index a numpy array | 39,474,396 | <p>I've created a class for dealing with multidimensional data of a specific type. This class has three attributes: A list containing the names of the axes (<strong>self.axisNames</strong>); a dictionary containing the parameter values along each axis (<strong>self.axes</strong>; keyd using the entries in axisNames); a... | 2 | 2016-09-13T16:00:01Z | 39,483,091 | <p>To add to hpaulj's answer, you can very simply extend your setup to make it even more generic by using <code>np.s_</code>. The advantage of using this over <code>slice</code> is that you can use <code>numpy</code>'s slice syntax more easily and transparently. For example:</p>
<pre><code>mySpec = {'axis1': np.s_[10:... | 0 | 2016-09-14T05:32:54Z | [
"python",
"arrays",
"numpy"
] |
Get Accession Numbers from NCBI from corresponding GI Numbers in fasta headers in python | 39,474,446 | <p>I keep seeing warnings on Genbank that they are phasing out GI numbers and have a number of fasta files saved where I've edited the headers in the following format:</p>
<pre><code>>SomeText_ginumber
</code></pre>
<p>I've no idea where to even begin with this but is there a way, ideally with python, that I could... | 0 | 2016-09-13T16:02:30Z | 39,487,976 | <p>Try using <a href="https://github.com/biopython/biopython.github.io/" rel="nofollow">BioPython</a>.</p>
<p>The following snippet should get you started. First get the GI from the header (the part of the header after the underscore), get the data from GenBank, print the old header but with the accession number and t... | 1 | 2016-09-14T10:19:05Z | [
"python",
"fasta",
"ncbi",
"genbank"
] |
Save/read data to/from textfile | 39,474,469 | <p>I have the following two series:</p>
<pre><code>self.MW_x = ..
self.MW_x = .. (from previous calculations)
</code></pre>
<p>and I zip them together like this:</p>
<pre><code>self.MW_final = list(zip(self.MW_x, self.MW_y))
</code></pre>
<p>and try to save them with <code>numpy.savetxt</code></p>
<pre><code>np.sa... | 0 | 2016-09-13T16:03:41Z | 39,478,325 | <p>Are you tied to exporting it via numpy with the semicolon delimiter? If not, it would be a lot easier to simply export via Pandas as well. i.e.)</p>
<pre><code>df = pd.DataFrame({"x_value":self.MW_x, "y_value": self.MW_y})
df.to_csv("testfile.txt")
df_again = pd.read_csv("testfile.txt")
</code></pre>
<p>Also, in ... | 0 | 2016-09-13T20:16:29Z | [
"python",
"numpy",
"save",
"text-files"
] |
Save/read data to/from textfile | 39,474,469 | <p>I have the following two series:</p>
<pre><code>self.MW_x = ..
self.MW_x = .. (from previous calculations)
</code></pre>
<p>and I zip them together like this:</p>
<pre><code>self.MW_final = list(zip(self.MW_x, self.MW_y))
</code></pre>
<p>and try to save them with <code>numpy.savetxt</code></p>
<pre><code>np.sa... | 0 | 2016-09-13T16:03:41Z | 39,478,486 | <p>Have you tried looking at the first 5 rows of the data at every step (first 5 rows of self.MW_x, self.MW_final, /Users/sping/Desktop/testfile.txt, df, x_val, and y_val) to figure out where the data is changing?</p>
<p>I think you have a problem with how you're using ix</p>
<pre><code>x_val = df.ix[0:]
y_val = df.i... | 0 | 2016-09-13T20:29:02Z | [
"python",
"numpy",
"save",
"text-files"
] |
Validate and get django form's unkown number of multipleselect checkbox fields | 39,474,515 | <p>I am trying to get all selected checkboxes values as a list however not able to validate the form due to choices option</p>
<p>forms.py:</p>
<pre><code>class MarkAccountsForm(forms.Form):
accounts = forms.MultipleChoiceField(
widget = forms.CheckboxSelectMultiple,
required = False
)
</code>... | 0 | 2016-09-13T16:06:25Z | 39,475,486 | <p>If you don't care about validation, why are you calling <code>is_valid</code>? In fact, why are you using a Form class at all? You're not using it to display the form, so you might as well leave it out altogether and just get the data from <code>request.POST.getlist('accounts')</code>.</p>
| 1 | 2016-09-13T17:08:51Z | [
"python",
"django",
"forms",
"django-forms",
"checkboxlist"
] |
How to convert a Python Cairo matrix into Android Canvas Matrix? | 39,474,636 | <p>Matrix in cairo graphics module in python is described as </p>
<pre><code>cairo.Matrix(xx = 1.0, yx = 0.0, xy = 0.0, yy = 1.0, x0 = 0.0, y0 = 0.0)
</code></pre>
<p>In Andorid's Canvas, Matrix is defined as,</p>
<blockquote>
<p>The Matrix class holds a 3x3 matrix for transforming coordinates.</p>
</blockquote>
... | 0 | 2016-09-13T16:13:12Z | 39,957,046 | <p>6 valued PyCairo Matrix can be mapped into 9 valued Android Matrix as followed,</p>
<pre><code>android.graphics.Matrix() matrix = new android.graphics.Matrix();
matrix.setValues(new float[] {xx, xy, x0, yx, yy, y0, 0F, 0F, 1F});
</code></pre>
<p>In terms of Matrix mathematics, the mapping is actually looked like t... | 0 | 2016-10-10T11:18:24Z | [
"android",
"python",
"matrix",
"transformation",
"cairo"
] |
Pandas DataFrame - Transpose few elements of a row into columns and fill missing data | 39,474,667 | <p>I want to reformat a dataframe by transposing some elements of rows into columns.
To provide an example of what I meant.</p>
<p>In the below dataframe, I want all the elements in the code column to be individual columns. And the missing rows like 'JFK 10/06 XX' should be populated as 0 or nan.</p>
<p>Origina... | 0 | 2016-09-13T16:15:46Z | 39,474,807 | <p>You are trying to reshape your data to wide format without a value column. One option is to use <code>pivot_table</code> and specify the <code>size</code> as the aggregate function, which will count the combinations of index and columns and fill as values. Missing values can be replaced with the <code>fill_value</co... | 2 | 2016-09-13T16:24:32Z | [
"python",
"pandas",
"numpy",
"dataframe"
] |
Pandas DataFrame - Transpose few elements of a row into columns and fill missing data | 39,474,667 | <p>I want to reformat a dataframe by transposing some elements of rows into columns.
To provide an example of what I meant.</p>
<p>In the below dataframe, I want all the elements in the code column to be individual columns. And the missing rows like 'JFK 10/06 XX' should be populated as 0 or nan.</p>
<p>Origina... | 0 | 2016-09-13T16:15:46Z | 39,474,889 | <ol>
<li><code>stack</code> the dataframe</li>
<li>reset index</li>
<li>create pivot table of counts</li>
</ol>
<hr>
<pre><code>new_df = (df.set_index(keys=['loc','date'])
.stack()
.reset_index()
.pivot_table(index=['loc','date'], columns=0, fill_value=0, aggfunc='size'))
</code></pre>
... | 0 | 2016-09-13T16:29:40Z | [
"python",
"pandas",
"numpy",
"dataframe"
] |
Pandas DataFrame - Transpose few elements of a row into columns and fill missing data | 39,474,667 | <p>I want to reformat a dataframe by transposing some elements of rows into columns.
To provide an example of what I meant.</p>
<p>In the below dataframe, I want all the elements in the code column to be individual columns. And the missing rows like 'JFK 10/06 XX' should be populated as 0 or nan.</p>
<p>Origina... | 0 | 2016-09-13T16:15:46Z | 39,475,170 | <p>Another solution using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.crosstab.html" rel="nofollow"><code>crosstab</code></a> which computes the frequency of occurence of the values present in the <code>columns</code> argument:</p>
<pre><code>pd.crosstab(index=[df['loc'], df['date']], columns... | 1 | 2016-09-13T16:47:20Z | [
"python",
"pandas",
"numpy",
"dataframe"
] |
Load CSV Strings With Different Types into Pandas Dataframe, Split Columns, Parse Date | 39,474,717 | <p>I have two questions concerning a large csv file which contains data in the following way formatted as strings:</p>
<pre><code> "XAU=,XAU=,XAG=,XAG="
"25/08/2014 6:00:05,1200.343,25/08/2014 6:00:03,19.44,"
"25/08/2014 6:00:05,1200,,,"
</code></pre>
<p>Is there a way to efficiently load this into a ... | 1 | 2016-09-13T16:18:50Z | 39,478,472 | <p>You can preprocess everything inside the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a> as shown:</p>
<pre><code>import csv
data = StringIO(
'''
"XAU=,XAU=,XAG=,XAG="
"25/08/2014 6:00:05,1200.343,25/08/2014 6:00:03,19.44," ... | 0 | 2016-09-13T20:28:04Z | [
"python",
"csv",
"datetime",
"pandas",
"time-series"
] |
How are regex quantifiers applied? | 39,474,794 | <p>I have the following regex:</p>
<pre><code>res = re.finditer(r'(?:\w+[ \t,]+){0,4}my car',txt,re.IGNORECASE|re.MULTILINE)
for item in res:
print(item.group())
</code></pre>
<p>When I use this regex with the following string:</p>
<blockquote>
<p>"my house is painted white, my car is red.
A horse is gallopi... | 0 | 2016-09-13T16:23:38Z | 39,474,906 | <p>So, here's what's happening. You're using ?: to make a non capture group, which collects 1 or more "words", followed by a [ \t,] (a space, tab char, or comma), match one or more of the preceeding. {0,4} matches between 0-4 of the non-capturing group. So it looks at the word "my car" and captures the 4 words befo... | 1 | 2016-09-13T16:30:28Z | [
"python",
"regex",
"python-3.x"
] |
OperationalError: Can't connect to local MySQL server through socket | 39,474,896 | <p>I'm trying to run a server in python/django and I'm getting the following error:</p>
<blockquote>
<p>django.db.uils.OperationslError: (200, "Can't connect to local MySQL
server through socket '/tmp/mysql.sock' (2)").</p>
</blockquote>
<p>I have <code>MySQL-python</code> installed (1.2.5 version) and mysql inst... | 0 | 2016-09-13T16:29:51Z | 39,475,119 | <p>You can't install mysql through pip; it's a database, not a Python library (and it's currently in version 5.7). You need to install the binary package for your operating system.</p>
| 1 | 2016-09-13T16:43:20Z | [
"python",
"mysql",
"django"
] |
gooey module not installing correctly | 39,474,930 | <pre><code>C:\Python34\Scripts>pip install Gooey
Collecting Gooey
Using cached Gooey-0.9.2.3.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Haeshan\AppData\Local\Temp\pip-build- 5waer38m\Gooey\set... | 0 | 2016-09-13T16:32:26Z | 39,475,414 | <p>Looks like you're using Python 3.4 but Gooey only supports Python 2:</p>
<p><a href="https://github.com/chriskiehl/Gooey/issues/65" rel="nofollow">https://github.com/chriskiehl/Gooey/issues/65</a></p>
<p><a href="http://python3porting.com/differences.html#except" rel="nofollow">http://python3porting.com/difference... | 0 | 2016-09-13T17:03:06Z | [
"python",
"windows",
"pip"
] |
How to convert the data as following in python? | 39,474,936 | <p>I have some data in the following format in a csv file.</p>
<pre><code> Id Category
1 A
2 B
3 C
4 B
5 C
6 d
</code></pre>
<p>I'd like to convert it into the below format and save it another csv file</p>
<pre><code>Id A B C D E
1 1 0 0 0 0
2 0 1 0 ... | 0 | 2016-09-13T16:32:44Z | 39,475,023 | <p>Try with <code>pd.get_dummies()</code></p>
<pre><code>>> df = pd.read_csv(<path_to_file>, sep=',', encoding='utf-8', header=0)
>> df
Id Category
0 1 A
1 2 B
2 3 C
3 4 B
4 5 C
5 6 d
>> pd.get_dummies(df.Category)
</code>... | 2 | 2016-09-13T16:38:04Z | [
"python",
"python-3.x",
"pandas",
"text-processing",
"spyder"
] |
How to convert the data as following in python? | 39,474,936 | <p>I have some data in the following format in a csv file.</p>
<pre><code> Id Category
1 A
2 B
3 C
4 B
5 C
6 d
</code></pre>
<p>I'd like to convert it into the below format and save it another csv file</p>
<pre><code>Id A B C D E
1 1 0 0 0 0
2 0 1 0 ... | 0 | 2016-09-13T16:32:44Z | 39,475,197 | <p>Use a pivot table (updated to include .csv read/write functionality):</p>
<pre><code>import pandas as pd
path = 'the path to your file'
df = pd.read_csv(path)
# your original dataframe
# Category Id
# 0 A 1
# 1 B 2
# 2 C 3
# 3 B 4
# 4 C 5
# 5 D 6
# pivot tabl... | 1 | 2016-09-13T16:49:07Z | [
"python",
"python-3.x",
"pandas",
"text-processing",
"spyder"
] |
JSON TypeError: list indices must be integers, not str | 39,474,985 | <p>I want to extract some data from JSON, but I don't know what happenend. It response "TypeError: list indices must be integers, not str".
Here is my code, thanks:</p>
<pre><code>import urllib
import json
url = 'http://python-data.dr-chuck.net/comments_304658.json'
data = urllib.urlopen(url).read()
info = json.loads... | -1 | 2016-09-13T16:35:52Z | 39,475,060 | <p>You seem to be confused by the structure of the returned data. Your code assumes the structure is a list of two-level dictionaries. If this were the case, then you could find an individual <code>count</code> like so:</p>
<pre><code>info[7]['comments']['count']
</code></pre>
<p>It is actually a dictionary, one item... | 1 | 2016-09-13T16:39:53Z | [
"python",
"json"
] |
understanding pyresample to regrid irregular grid data to a regular grid | 39,475,003 | <p>I need to regrid data on a irregular grid (lambert conical) to a regular grid. I think pyresample is my best bet. Infact my original lat,lon are not 1D (which seems to be needed to use basemap.interp or scipy.interpolate.griddata).</p>
<p>I found <a href="http://stackoverflow.com/questions/35734070/interpolating-da... | 0 | 2016-09-13T16:37:00Z | 39,476,457 | <p>The problem is that XI and XI are integers, not floats. You can fix this by simply doing</p>
<pre><code>XI = np.arange(148,360.)
YI = np.arange(0,87.)
XI, YI = np.meshgrid(XI,YI)
</code></pre>
<p>The inability to handle integer datatypes is an undocumented, unintuitive, and possibly buggy behavior from pyresample.... | 2 | 2016-09-13T18:09:14Z | [
"python",
"netcdf",
"netcdf4"
] |
Read data from binary file python | 39,475,010 | <p>I have a binary file with this format:</p>
<p><a href="http://i.stack.imgur.com/qHVBs.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/qHVBs.jpg" alt="enter image description here"></a></p>
<p>and i use this code to open it:</p>
<pre><code>import numpy as np
f = open("author_1", "r")
dt = np.dtype({'names... | 1 | 2016-09-13T16:37:26Z | 39,477,733 | <p>The data structure stored in this file is hierarchical, rather than "flat": child arrays of different length are stored within each parent element. It is not possible to represent such a data structure using numpy arrays (even recarrays), and therefore it is not possible to read the file with <code>np.fromfile()</co... | 0 | 2016-09-13T19:36:18Z | [
"python",
"binaryfiles",
"binary-data"
] |
Read data from binary file python | 39,475,010 | <p>I have a binary file with this format:</p>
<p><a href="http://i.stack.imgur.com/qHVBs.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/qHVBs.jpg" alt="enter image description here"></a></p>
<p>and i use this code to open it:</p>
<pre><code>import numpy as np
f = open("author_1", "r")
dt = np.dtype({'names... | 1 | 2016-09-13T16:37:26Z | 39,479,003 | <p>I agree with Ryan: parsing the data is straightforward, but not trivial, and really tedious. Whatever disk space saving you gain by packing the data in this way, you pay it dearly at the hour of unpacking.</p>
<p>Anyway, the file is made of variable length records and fields. Each record is made of variable number ... | 0 | 2016-09-13T21:07:24Z | [
"python",
"binaryfiles",
"binary-data"
] |
compatibility issue with contourArea in openCV 3 | 39,475,125 | <p>I am trying to do a simple area calculation of contours I get from findContours.
My openCv version is 3.1.0</p>
<p>My code is:</p>
<pre><code>cc = cv2.findContours(im_bw.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.contourArea(cc[0])
error: 'C:\\builds\\master_PackSlaveAddon-win32-vc12-static\\opencv\\modu... | 0 | 2016-09-13T16:44:01Z | 39,475,245 | <p>In Opencv 3 API version the <code>cv2.findContours()</code> returns 3 <a href="http://docs.opencv.org/3.1.0/d4/d73/tutorial_py_contours_begin.html" rel="nofollow">objects</a></p>
<ul>
<li>image </li>
<li>contours</li>
<li>hierarchy</li>
</ul>
<p>So you need to rewrite your statement as:</p>
<pre><code>image, cont... | 1 | 2016-09-13T16:52:32Z | [
"python",
"opencv",
"opencv3.0"
] |
From scatter plot to 2D array | 39,475,146 | <p>My mind has gone completely blank on this one.</p>
<p>I want to do what I think is very simple.</p>
<p>Suppose I have some test data:</p>
<pre><code>import pandas as pd
import numpy as np
k=10
df = pd.DataFrame(np.array([range(k),
[x + 1 for x in range(k)],
[... | 1 | 2016-09-13T16:45:11Z | 39,477,098 | <p>I don't use pandas, so I cannot really follow what your function does. But from the description of your array M and what you want, I think the funktion np.histogram2d is what you want. It bins the range of your independent values in equidistant steps and sums all the occurrences. You can apply weighting with your 3r... | 1 | 2016-09-13T18:53:03Z | [
"python",
"arrays",
"numpy",
"matplotlib"
] |
From scatter plot to 2D array | 39,475,146 | <p>My mind has gone completely blank on this one.</p>
<p>I want to do what I think is very simple.</p>
<p>Suppose I have some test data:</p>
<pre><code>import pandas as pd
import numpy as np
k=10
df = pd.DataFrame(np.array([range(k),
[x + 1 for x in range(k)],
[... | 1 | 2016-09-13T16:45:11Z | 39,478,996 | <p>You can convert the values in M[:,1] and M[:,2] to integers and use them as indices to a 2D numpy array. Here's an example using the value for M you defined. </p>
<pre><code>out = np.empty((20,10))
out[:] = np.NAN
N = M[:,[0,1]].astype(int)
out[N[:,1], N[:,0]] = M[:,2]
plt.scatter(M[:,0],M[:,1],15,M[:,2])
plt.scatt... | 2 | 2016-09-13T21:07:00Z | [
"python",
"arrays",
"numpy",
"matplotlib"
] |
How to access environment variables set in a script later in a batch file run from same script? | 39,475,162 | <p>My code:</p>
<pre><code>file = open("crash_reports_envs.txt")
envVariables=file.read()
print(envVariables)
file.close()
os.environ['linuxwdir'] = (re.search("linuxwdir:(\S+)",envVariables).group(1))
os.environ['invertwdir']= (re.search("wdir:(\S+.*)\\n",envVariables).group(1))
</code></pre>
<p>I am setting these ... | 0 | 2016-09-13T16:46:44Z | 39,477,852 | <p>The way you use environment variables in .bat files is to surround them with %, for example %linuxwdir%. If I understand your <code>.bat</code> file correctly, you need something like this (untested):</p>
<pre><code>cd "C:\Program Files (x86)\PuTTY"
pscp.exe -pw "pswd" "%invertwdir%/file2" uname@execServer:%linux... | 0 | 2016-09-13T19:43:57Z | [
"python",
"windows",
"batch-file"
] |
How to speed LabelEncoder up recoding a categorical variable into integers | 39,475,187 | <p>I have a large csv with two strings per row in this form:</p>
<pre><code>g,k
a,h
c,i
j,e
d,i
i,h
b,b
d,d
i,a
d,h
</code></pre>
<p>I read in the first two columns and recode the strings to integers as follows:</p>
<pre><code>import pandas as pd
df = pd.read_csv("test.csv", usecols=[0,1], prefix="ID_", header=None... | 5 | 2016-09-13T16:48:29Z | 39,503,973 | <p>It looks like it will be much faster to use the pandas <code>category</code> datatype; internally this uses a hash table rather whereas LabelEncoder uses a sorted search:</p>
<pre><code>In [87]: df = pd.DataFrame({'ID_0':np.random.randint(0,1000,1000000),
'ID_1':np.random.randint(0,1000... | 4 | 2016-09-15T05:55:07Z | [
"python",
"pandas",
"scikit-learn"
] |
How to speed LabelEncoder up recoding a categorical variable into integers | 39,475,187 | <p>I have a large csv with two strings per row in this form:</p>
<pre><code>g,k
a,h
c,i
j,e
d,i
i,h
b,b
d,d
i,a
d,h
</code></pre>
<p>I read in the first two columns and recode the strings to integers as follows:</p>
<pre><code>import pandas as pd
df = pd.read_csv("test.csv", usecols=[0,1], prefix="ID_", header=None... | 5 | 2016-09-13T16:48:29Z | 39,521,228 | <p>I tried this with the DataFrame:</p>
<pre><code>In [xxx]: import string
In [xxx]: letters = np.array([c for c in string.ascii_lowercase])
In [249]: df = pd.DataFrame({'ID_0': np.random.choice(letters, 10000000), 'ID_1':np.random.choice(letters, 10000000)})
</code></pre>
<p>It looks like this:</p>
<pre><code>In [2... | 3 | 2016-09-15T22:26:22Z | [
"python",
"pandas",
"scikit-learn"
] |
Summing part of 2D array in python | 39,475,275 | <p>I have a 2D array. After manipulating the x column of the array, I created a new 2D array (data2) with the new changes to the x column (and the y column remained the same). I now want to append the array of y values in data2 to a new array only if its x value is greater than 3 or less than 5. For example, if the 2D ... | 0 | 2016-09-13T16:54:24Z | 39,475,494 | <p>Here is a one-liner solution broken in several steps for clarity.</p>
<p>Given an array</p>
<pre><code>>>> a
array([[ 2. , 3. ],
[ 4. , 5. ],
[ 3.5, 6. ],
[ 9. , 7. ]])
</code></pre>
<p>You can find the <em>index</em> of the elements where the <code>x</code> value is more than 3 ... | 1 | 2016-09-13T17:09:17Z | [
"python",
"arrays",
"function",
"numpy",
"append"
] |
Summing part of 2D array in python | 39,475,275 | <p>I have a 2D array. After manipulating the x column of the array, I created a new 2D array (data2) with the new changes to the x column (and the y column remained the same). I now want to append the array of y values in data2 to a new array only if its x value is greater than 3 or less than 5. For example, if the 2D ... | 0 | 2016-09-13T16:54:24Z | 39,475,630 | <p>You can use this function to flatten the list and then append the values according. </p>
<pre><code>def flatten_list(a, result=None):
""" Flattens a nested list. """
if result is None:
result = []
for x in a:
if isinstance(x, list):
flatten_list(x, result)
else:
... | 0 | 2016-09-13T17:16:32Z | [
"python",
"arrays",
"function",
"numpy",
"append"
] |
How to find the source of global(ish) variable? | 39,475,290 | <p>I inherited some large and unwieldy python code. In one file its using a list of commands imported from another file. Looking at it with pdb this commands variable ends up in the global namespace. However there's another file that doesn't look like its even being used that also has a commands variable in it and f... | 0 | 2016-09-13T16:55:41Z | 39,475,532 | <p>To get the module of the <code>commands</code> object, you could try:</p>
<pre><code>import inspect
inspect.getmodule(commands)
</code></pre>
| 0 | 2016-09-13T17:11:03Z | [
"python",
"pdb"
] |
How to handle unknow encoding | 39,475,359 | <p>I'm having some issues with a Python script that needs to open files with different encoding.</p>
<p><strong>I'm usually using this:</strong></p>
<pre><code>with open(path_to_file, 'r') as f:
first_line = f.readline()
</code></pre>
<p>And that works great when the file is properly encode.</p>
<p><strong>But ... | 1 | 2016-09-13T17:00:23Z | 39,475,568 | <p>It looks like you need to detect the encoding in the input file. The <code>chardet</code> library mentioned in the answer to <a href="http://stackoverflow.com/questions/436220/python-is-there-a-way-to-determine-the-encoding-of-text-file">this question</a> might help (though note the proviso that complete encoding de... | 4 | 2016-09-13T17:13:24Z | [
"python",
"python-2.7",
"encoding"
] |
How to handle unknow encoding | 39,475,359 | <p>I'm having some issues with a Python script that needs to open files with different encoding.</p>
<p><strong>I'm usually using this:</strong></p>
<pre><code>with open(path_to_file, 'r') as f:
first_line = f.readline()
</code></pre>
<p>And that works great when the file is properly encode.</p>
<p><strong>But ... | 1 | 2016-09-13T17:00:23Z | 39,475,719 | <p>it looks like this is utf-16-le (utf-16 little endian ...) but you are missing a final <code>\x00</code></p>
<pre><code>>>> s = '\xff\xfeT\x00e\x00s\x00t\x00 \x00f\x00o\x00r\x00 \x00S\x00t\x00a\x00c\x
00k\x00O\x00v\x00e\x00r\x00l\x00o\x00w\x00\r\x00\n'
>>> s.decode('utf-16-le') # creates error
Tra... | 4 | 2016-09-13T17:22:49Z | [
"python",
"python-2.7",
"encoding"
] |
Openerp , how to save and re-direct in to another form by clicking on save button | 39,475,431 | <p>I am working in <strong>hr</strong> module in Openerp and there is that requirement arises that once you click on the save button
1. Save the data in to the DB (already happening)
2. Redirect in to leave allocation form.</p>
<p>Please help me with completing second requirement which I have no idea .</p>
<p><stron... | 0 | 2016-09-13T17:04:46Z | 39,475,504 | <p>You can override the create or write function and have it return an action to bring up the other view.</p>
<p>I used super(Partner,self) you may need to replace this with something else. The pitfall with this method is that it will not work using xmlrpc. </p>
<pre><code>@api.model
def create(self, vals):
super... | 1 | 2016-09-13T17:09:51Z | [
"python",
"xml",
"python-2.7",
"openerp",
"openerp-7"
] |
Get name of users(persons, not applications) in linux system using psutil library | 39,475,435 | <p>I am trying to use psutil library to get users logged in to linux system.</p>
<p>For that i used function psutil.users()</p>
<pre><code>>>> import psutil
>>> psutil.users()
[suser(name='vibhcool', terminal='tty2',host='localhost',started=1473815296.0)]
</code></pre>
<p>I want to extract the user... | 0 | 2016-09-13T17:05:05Z | 39,475,513 | <p>I got the answer, (sorry i am bad at googling)</p>
<p>psutil.users() outputs a list, so it can be traversed using for loop</p>
<pre><code>users = psutil.users()
for user in users:
print(user.name)
</code></pre>
<p>reference: <a href="http://www.programcreek.com/python/example/53877/psutil.users" rel="... | -1 | 2016-09-13T17:10:08Z | [
"python",
"linux",
"psutil"
] |
Get name of users(persons, not applications) in linux system using psutil library | 39,475,435 | <p>I am trying to use psutil library to get users logged in to linux system.</p>
<p>For that i used function psutil.users()</p>
<pre><code>>>> import psutil
>>> psutil.users()
[suser(name='vibhcool', terminal='tty2',host='localhost',started=1473815296.0)]
</code></pre>
<p>I want to extract the user... | 0 | 2016-09-13T17:05:05Z | 39,475,528 | <p>I don't know why they choose the name <code>suser</code>, but it's actually a namedtuple.</p>
<p>That shouldn't matter, you get the name of a user like so:</p>
<pre><code>>>> import psutil
>>> users = psutil.users()
>>> first_user = users[0]
>>> name = first_user.name
>>&g... | 0 | 2016-09-13T17:10:39Z | [
"python",
"linux",
"psutil"
] |
Concurrency error while executing DocumentDB stored procedure on multiple Docker containers | 39,475,503 | <p>I am currently building a python Tornado web application using Azure Storage to store images, and DocumentDB to store metadata on the images. Whenever an image is uploaded, it can use any 1 of 2 possible Docker containers running the Tornado Web App to execute the POST method asynchronously. The error I'm having is ... | 0 | 2016-09-13T17:09:44Z | 39,476,273 | <p>The typical NoSQL solution to this common problem is to use GUIDs rather than sequential IDs. </p>
<p>However, since DocumentDB sprocs provide you with ACID constraints, it should be possible to do what you want using an optimistic concurrency approach with retry. </p>
<p>So, if you run this sproc twice from two d... | 0 | 2016-09-13T17:58:18Z | [
"python",
"azure",
"stored-procedures",
"docker",
"azure-documentdb"
] |
python pandas: filter out records with null or empty string for a given field | 39,475,566 | <p>I am trying to filter out records whose field_A is null or empty string in the data frame like below:</p>
<pre><code>my_df[my_df.editions is not None]
my_df.shape
</code></pre>
<p>This gives me error:</p>
<pre><code>---------------------------------------------------------------------------
KeyError ... | 0 | 2016-09-13T17:13:13Z | 39,476,074 | <p>Can you create a new dataframe from the filtering?</p>
<p>Dataframe before:</p>
<pre><code>a b
1 9
2 10
3 11
4 12
5 13
6 14
7 15
8 null
</code></pre>
<p>Example: </p>
<pre><code>import pandas
my_df = pandas.DataFrame({"a":[1,2,3,4,5,6,7,8],"b":[9,10,11,12,13,14,15,"null"]})
my_df2=... | 1 | 2016-09-13T17:45:14Z | [
"python",
"pandas",
"dataframe"
] |
Django ImportError cannot import name request | 39,475,651 | <p>I'm learning Django using book Django-By-Example by Antonio Mele. For now I reached chapter 5 and now I'm trying to create image sharing app. But despite following all instructions in that chapter I'm getting ImportError when I try to add the image from external URL in django development server.</p>
<pre><code> ... | 0 | 2016-09-13T17:18:50Z | 39,475,826 | <p>This is due to discrepancy in Python version.</p>
<p>In Python 2.7, you might have to replace:</p>
<pre><code>from urllib import request
</code></pre>
<p>in your <code>forms.py</code> with</p>
<pre><code>import urllib2
</code></pre>
<p>Again the <code>urllib2 > Request</code> module does not have the <code>u... | 1 | 2016-09-13T17:29:23Z | [
"python",
"django",
"importerror"
] |
Import error for urllib3 | 39,475,652 | <p>I'm using Python 2.7 and am trying pull data from an API using a python script and urllib3. I've installed urllib3 by copying the source code but from GitHub. But, I'm still getting the following error when running the script: </p>
<pre><code>ImportError: No module named urllib3
</code></pre>
<p>The script starts ... | -1 | 2016-09-13T17:18:55Z | 39,475,703 | <p>you need to copy that module directory (<strong>urllib3/urllib3/</strong>). you'll find __init__py file on that directory to that script's directory. </p>
<p>Another way:</p>
<pre><code>$ pip search urllib3
opbeat_python_urllib3 (1.1) - An urllib3 transport for Opbeat
apiclient (1.0.3) - Framework for ... | 1 | 2016-09-13T17:21:30Z | [
"python",
"python-2.7",
"urllib3"
] |
Import error for urllib3 | 39,475,652 | <p>I'm using Python 2.7 and am trying pull data from an API using a python script and urllib3. I've installed urllib3 by copying the source code but from GitHub. But, I'm still getting the following error when running the script: </p>
<pre><code>ImportError: No module named urllib3
</code></pre>
<p>The script starts ... | -1 | 2016-09-13T17:18:55Z | 39,475,712 | <blockquote>
<p>I've installed urllib3 by copying the source code but from GitHub. </p>
</blockquote>
<p>Bad way to "install" <code>urllib3</code>. Use this instead</p>
<pre><code>pip install urllib3
</code></pre>
| 2 | 2016-09-13T17:22:32Z | [
"python",
"python-2.7",
"urllib3"
] |
Stacked bar graph with variable width elements? | 39,475,683 | <p>In Tableau I'm used to making graphs like the one below. It has for each day (or some other discrete variable), a stacked bar of categories of different colours, heights and widths.</p>
<p>You can imagine the categories to be different advertisements that I show to people. The heights correspond to the percentage o... | 3 | 2016-09-13T17:20:33Z | 39,476,288 | <p>Unfortunately, this is not so trivial to achieve with <code>ggplot2</code> (I think), because <code>geom_bar</code> does not really support changing widths for the same x position. But with a bit of effort, we can achieve the same result:</p>
<h3>Create some fake data</h3>
<pre><code>set.seed(1234)
d <- as.data... | 7 | 2016-09-13T17:59:03Z | [
"python",
"graph",
"ggplot2",
"data-visualization"
] |
Stacked bar graph with variable width elements? | 39,475,683 | <p>In Tableau I'm used to making graphs like the one below. It has for each day (or some other discrete variable), a stacked bar of categories of different colours, heights and widths.</p>
<p>You can imagine the categories to be different advertisements that I show to people. The heights correspond to the percentage o... | 3 | 2016-09-13T17:20:33Z | 39,476,491 | <pre><code>set.seed(1)
days <- 5
cats <- 8
dat <- prop.table(matrix(rpois(days * cats, days), cats), 2)
bp1 <- barplot(dat, col = seq(cats))
</code></pre>
<p><a href="http://i.stack.imgur.com/pvEFA.png" rel="nofollow"><img src="http://i.stack.imgur.com/pvEFA.png" alt="enter image description here"></a></p... | 7 | 2016-09-13T18:12:03Z | [
"python",
"graph",
"ggplot2",
"data-visualization"
] |
Conditional row select with Pandas | 39,475,788 | <p>I want to select a sub-set of a pandas dataframe <code>df</code> where the column <code>text</code> has the value <code>'0.0, 0.0'</code>. I thought the command for this would be <code>df.ix[df['text'] == "0.0, 0.0"]</code> but this returns</p>
<pre><code><console>:1: error: identifier expected but symbol lit... | 1 | 2016-09-13T17:26:52Z | 39,476,085 | <p>As <a href="http://stackoverflow.com/users/487339/dsm">DSM</a> pointed out, the error appears to be an error from the Scala programming language. This is because I was using a Zeppelin Notebook, and had failed to specify that the code should be interpreted with the pyspark interpreter. After specifying the interpret... | 1 | 2016-09-13T17:45:47Z | [
"python",
"pandas"
] |
How to get pytest fixture data dynamically | 39,475,849 | <p>I'm trying to define init data for several tests scenarios that test a single api endpoint. I want to do this so that I don't have to produce boiler plate code for multiple iterations of a test where just the data differs. I can't seem to wrap my head around how to do this using the built-in pytest fixtures. Here'... | 0 | 2016-09-13T17:30:47Z | 39,565,326 | <p>You can import from your conftest.py like so:</p>
<pre><code>from conftest import data_for_a, data_for_b
</code></pre>
<p>or</p>
<pre><code>from conftest import *
</code></pre>
<p>which will allow you to reference that function without passing it as an parameter to a test function.</p>
<p><strong>Edit:</strong>... | 1 | 2016-09-19T04:23:10Z | [
"python",
"py.test",
"python-3.5",
"fixtures"
] |
Searching to End of String in Regex | 39,475,890 | <p>I am trying to extract all sequences of '1's from a string of binary digits (0 and 1) and get them into a <code>list</code>. <br/>For example the string may be of the form <code>001111000110000111111</code>. And I am looking for a list that looks like this <code>["1111", "11", "111111"]</code>. </p>
<p>I am using t... | 1 | 2016-09-13T17:33:23Z | 39,476,024 | <p>I think the regex you're looking for is:</p>
<pre><code>1+(?!\0)
</code></pre>
<p>i.e. match one or more 1s which aren't followed by a 0.</p>
<p>The one you have is specifically looking for ones that are followed by 0s.</p>
<p>you can play around with regexs on various jsfiddle like sites, with interactive expla... | 0 | 2016-09-13T17:42:26Z | [
"python",
"regex"
] |
Searching to End of String in Regex | 39,475,890 | <p>I am trying to extract all sequences of '1's from a string of binary digits (0 and 1) and get them into a <code>list</code>. <br/>For example the string may be of the form <code>001111000110000111111</code>. And I am looking for a list that looks like this <code>["1111", "11", "111111"]</code>. </p>
<p>I am using t... | 1 | 2016-09-13T17:33:23Z | 39,476,033 | <p>What you are trying:</p>
<pre><code>([1]+?)0
</code></pre>
<p><img src="https://www.debuggex.com/i/bHmtnovezOT8omWZ.png" alt="Regular expression visualization"></p>
<p><a href="https://regex101.com/r/fJ7lN1/1" rel="nofollow">Regex101 Demo</a></p>
<pre><code>([1]+?)0|$
</code></pre>
<p><img src="https://www.debu... | 1 | 2016-09-13T17:42:58Z | [
"python",
"regex"
] |
Searching to End of String in Regex | 39,475,890 | <p>I am trying to extract all sequences of '1's from a string of binary digits (0 and 1) and get them into a <code>list</code>. <br/>For example the string may be of the form <code>001111000110000111111</code>. And I am looking for a list that looks like this <code>["1111", "11", "111111"]</code>. </p>
<p>I am using t... | 1 | 2016-09-13T17:33:23Z | 39,476,211 | <p><strong>Matching</strong>: To match one or more <code>1</code>s, use <code>1+</code> regex.</p>
<p><strong>Splitting</strong>: You may split with 1 or more <code>0</code>s and remove empty elements.</p>
<p>See <a href="http://ideone.com/sH8MX3" rel="nofollow">Python demo</a>:</p>
<pre><code>import re
s = '0011110... | 0 | 2016-09-13T17:53:56Z | [
"python",
"regex"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.