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
Django JSON not sending proper data
39,133,537
<p>I am developing a django python web application. In my webpage, I am sending a request to my API by sending a 'term' and my API is supposed to return the 'content' field of the search.</p> <p>My content contains 'xxx is good' in my database.</p> <p>Here is my code in views.py</p> <pre><code>def get_RuleStatement(...
0
2016-08-24T21:47:25Z
39,134,328
<p>The only reason possible for it is <code>is_ajax()</code> is return False. That means your are not making the <code>AJAX</code> request. I believe you are making normal HTTP call to your endpoint.</p>
0
2016-08-24T23:06:47Z
[ "python", "json", "django" ]
Django JSON not sending proper data
39,133,537
<p>I am developing a django python web application. In my webpage, I am sending a request to my API by sending a 'term' and my API is supposed to return the 'content' field of the search.</p> <p>My content contains 'xxx is good' in my database.</p> <p>Here is my code in views.py</p> <pre><code>def get_RuleStatement(...
0
2016-08-24T21:47:25Z
39,134,355
<p>See the <a href="https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.is_ajax" rel="nofollow">django documentation</a> and check that your HTTP request has the HTTP header <code>HTTP_X_REQUESTED_WITH</code> set with the string 'XMLHttpRequest'. Then <code>request.is_ajax()</code> wil...
0
2016-08-24T23:11:41Z
[ "python", "json", "django" ]
Automatic db router for migrations in django
39,133,559
<p>I am building a Django powered site and I want to have separate databases for some of the apps, I build a flexible router that routes each app to predefined database, this works fine. The problem is that when I am migrating my models I have to set the <code>--database</code> parameter every time and I find this anno...
1
2016-08-24T21:49:32Z
39,134,659
<p>I don't know of any way to do that automatically. However, a simple approach might be to <a href="https://docs.djangoproject.com/en/dev/howto/custom-management-commands/" rel="nofollow">write your own version</a> of the <code>migrate</code> command that calls the Django <code>migrate</code> command multiple times wi...
1
2016-08-24T23:51:53Z
[ "python", "django", "django-migrations" ]
Automatic db router for migrations in django
39,133,559
<p>I am building a Django powered site and I want to have separate databases for some of the apps, I build a flexible router that routes each app to predefined database, this works fine. The problem is that when I am migrating my models I have to set the <code>--database</code> parameter every time and I find this anno...
1
2016-08-24T21:49:32Z
39,152,567
<p>For anyone facing the issue I was having, here is what I finally settled on:</p> <p>routers.py:</p> <pre><code>from django.conf import settings class DatabaseAppsRouter(object): def db_for_read(self, model, **hints): # your db routing def db_for_write(self, model, **hints): # your db ro...
0
2016-08-25T18:39:38Z
[ "python", "django", "django-migrations" ]
Fastest way to expose C strings to numpy?
39,133,578
<p>I'm working on converting some old text logs to a usable format in Python. The files are huge, so I'm writing my own C extensions to run through the files as quickly as possible and parse out the relevant fields with regular expressions. My ultimate goal is to export these fields into numpy arrays of strings.</p> <...
3
2016-08-24T21:50:54Z
39,134,223
<p>To give a sense of how an array of strings is stored, I'll make one, and view it in several ways:</p> <pre><code>In [654]: np.array(['one','two','three','four'],dtype='S5') Out[654]: array([b'one', b'two', b'three', b'four'], dtype='|S5') In [655]: x=np.array(['one','two','three','four'],dtype='S5') In [656...
3
2016-08-24T22:55:43Z
[ "python", "c", "arrays", "numpy", "cython" ]
movie imdb get the id of the actor
39,133,599
<p>I have an actor object, and it has both name and id, i could take the name, but it couldn't take the id</p> <p>look please</p> <pre><code>&gt;&gt;&gt; actor &lt;Person id:0000199[http] name:_Pacino, Al_&gt; &gt;&gt;&gt; actor["name"] u'Al Pacino' &gt;&gt;&gt; actor["id"] Traceback (most recent call last): File "...
1
2016-08-24T21:52:31Z
39,133,618
<p>Use the <code>.personID</code> property of a <code>Person</code> object:</p> <pre><code>actor.personID </code></pre>
3
2016-08-24T21:53:56Z
[ "python", "imdb", "imdbpy" ]
Add child of child to python xml
39,133,613
<p>I create a code which writes the data to xml file.But it is not working properly. It gives a error called "TypeError: must be Element, not None "</p> <p>Here is my code:</p> <pre><code>import xml.etree.cElementTree as ET import lxml.etree import lxml.builder class create_xml: def __init__(self): pass de...
0
2016-08-24T21:53:36Z
39,133,655
<p>The problem is that <code>doc</code> becomes <code>None</code> since it equals to the result of <code>set()</code> call. Instead, you meant to have <code>doc</code> pointing to the <code>SubElement</code> instance: </p> <pre><code>doc = ET.SubElement(root, 'frame') doc.set('name', image) </code></pre>
1
2016-08-24T21:57:18Z
[ "python", "xml" ]
Python 2.7, Requests library, can't get unicode
39,133,669
<p>Documentation for Request library says that requests.get() method returns unicode always. But when I try to know what an encoding was returned, I see "windows-1251". That's a problem. When I try to get requests.get(url).text, there's an error, because current url's content has a Cyrillic symbols.</p> <pre><code>imp...
-1
2016-08-24T21:59:04Z
39,133,988
<p>From the <a href="http://docs.python-requests.org/en/master/user/quickstart/#response-content" rel="nofollow">docs</a>:</p> <blockquote> <p>Requests will automatically decode content from the server. Most unicode charsets are seamlessly decoded.</p> <p>When you make a request, Requests makes educated guess...
1
2016-08-24T22:30:53Z
[ "python", "parsing", "unicode", "python-requests" ]
How to Import multiple CSV files then make a Master Table?
39,133,678
<p>I am a research chemist and have carried out a measurement where I record 'signal intensity' vs 'mass-to-charge (<em>m/z</em>)' . I have repeated this experiment 15x, by changing a specific parameter (Collision Energy). As a result, I have 15 CSV files and would like to align/join them within the same range of <em>m...
0
2016-08-24T22:00:21Z
39,134,006
<p>I don't know or use matlab so my answer is pure python based. I think python and matlab should be equally well suited to read csv files and generate a master table.</p> <p>Please consider this answer more as pointer to how to address the problem in python.</p> <p>In python one would typically address this problem ...
0
2016-08-24T22:33:45Z
[ "python", "matlab" ]
How to Import multiple CSV files then make a Master Table?
39,133,678
<p>I am a research chemist and have carried out a measurement where I record 'signal intensity' vs 'mass-to-charge (<em>m/z</em>)' . I have repeated this experiment 15x, by changing a specific parameter (Collision Energy). As a result, I have 15 CSV files and would like to align/join them within the same range of <em>m...
0
2016-08-24T22:00:21Z
39,196,660
<p>The counts from the different analyses should be named differently, i.e., YCounts_1, YCounts_2, and YCounts_3 from analyses 1, 2, and 3, respectively, in the different datasets before joining them. However, the M/Z name (i.e., XThompson) should be the same since this is the key that will be used to join the datasets...
0
2016-08-28T23:19:32Z
[ "python", "matlab" ]
How to Import multiple CSV files then make a Master Table?
39,133,678
<p>I am a research chemist and have carried out a measurement where I record 'signal intensity' vs 'mass-to-charge (<em>m/z</em>)' . I have repeated this experiment 15x, by changing a specific parameter (Collision Energy). As a result, I have 15 CSV files and would like to align/join them within the same range of <em>m...
0
2016-08-24T22:00:21Z
39,277,031
<p>I managed to create a solution to my problem based on learning through everyone's input and taking an online matlab courses. I am not a natural coder so my script is not as elegant as the geniuses here, but hopefully it is clear enough for other non-programming scientists to use.</p> <p>Here's the result that works...
0
2016-09-01T16:55:10Z
[ "python", "matlab" ]
numpy convert array of strings to integers or boolean (for masking)
39,133,682
<p>I'm new to Python and I'm challenged with converting an array of strings to numbers. My data was extracted from a larger data set of numbers and strings. It looks like:</p> <pre><code>array([b'Single', b'', b'', b'', b'', b'Single', b'Single', b'', b'Single', ...]) </code></pre> <p>I would like to use this data t...
1
2016-08-24T22:00:37Z
39,134,509
<p>You could use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html" rel="nofollow">numpy.vectorize</a></p> <pre><code>import numpy as np def f(x): return not x == b'Single' vfunc = np.vectorize(f) x = np.array([b'Single', b'', b'', b'', b'', b'Single']) result = vfunc(x) </code><...
0
2016-08-24T23:31:54Z
[ "python", "arrays", "string", "numpy" ]
PyQt: QLineEdit with attached label
39,133,740
<p>This is probably a very silly question, but anyway I am struck by it :-(</p> <p>I have a window with two side-by-side lists and a line edit control with a label below them (see the attached image). What I want is to have the line edit field placed just after the corresponding label and not below the second list.</p...
0
2016-08-24T22:06:11Z
39,133,834
<p>What you need here is:</p> <ul> <li>Set the widget up in a vertical layout, not grid layout</li> <li>In that vertical layout, add two horizontal layouts</li> <li>Add the two tree widgets to the first horizontal layout</li> <li>Add your label and lineedit to the second horizontal layout</li> </ul>
1
2016-08-24T22:15:20Z
[ "python", "pyqt" ]
PyQt: QLineEdit with attached label
39,133,740
<p>This is probably a very silly question, but anyway I am struck by it :-(</p> <p>I have a window with two side-by-side lists and a line edit control with a label below them (see the attached image). What I want is to have the line edit field placed just after the corresponding label and not below the second list.</p...
0
2016-08-24T22:06:11Z
39,134,248
<p>Here is the answer to my question, based on the suggestion by ypnos:</p> <pre><code>import sys from PyQt4 import Qt, QtCore, QtGui class MainWindow(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) verticalLayout = QtGui.QVBoxLayout() verticalLayout.setSpacing(2) ...
1
2016-08-24T22:58:06Z
[ "python", "pyqt" ]
How to attach a component in a specific line of GtkBox?
39,133,741
<p>I created a <code>GtkBox</code> with Glade, I added some components at the beginning and end of the <code>GtkBox</code> and left a empty line in the middle. Now, how do I add a new component in the empty line through code? E.g:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- Generated with glade...
0
2016-08-24T22:06:12Z
39,158,925
<p>There are multiple solutions to your problem:</p> <ol> <li>Containers store their children's packing properties (stuff like <code>expand</code> and <code>fill</code> and, you guessed it, <code>position</code>). You can use <code>container_widget.child_set_property(child_widget, 'position', index)</code> to change t...
3
2016-08-26T05:33:43Z
[ "python", "python-3.x", "gtk", "gtk3" ]
Operations on Large Python Sets
39,133,758
<p><strong>UPDATE 1</strong></p> <p>Both sets contain strings of maximum length 20 and can only take values from 'abcdefghijklmnopqrstuvwxyz'</p> <p><strong>UPDATE 2</strong></p> <p>I constructed the sets by reading 2 files from disk using a library called ujson (similar to simplejson) and then converting the retur...
2
2016-08-24T22:08:34Z
39,133,943
<p>When talking about 100 million element sets, I'd worry about data being evicted from RAM (going to swap/pagefile). A 100M element <code>set</code> on Python 3.5 built for a 64 bit processor (which you're using, because you couldn't even create such a <code>set</code> in a 32 bit build of Python) uses 4 GB of memory ...
9
2016-08-24T22:27:39Z
[ "python", "set" ]
Operations on Large Python Sets
39,133,758
<p><strong>UPDATE 1</strong></p> <p>Both sets contain strings of maximum length 20 and can only take values from 'abcdefghijklmnopqrstuvwxyz'</p> <p><strong>UPDATE 2</strong></p> <p>I constructed the sets by reading 2 files from disk using a library called ujson (similar to simplejson) and then converting the retur...
2
2016-08-24T22:08:34Z
39,134,693
<p>Checking if an element is in a set does appear to be O(1), see below code. A set must be internally made with a hash function. The rate of success of hash tables depends on the key's you use, and the way Python guesses what you did. using a <code>range(n)</code> for a set is then sort of ideal. </p> <pre><code>imp...
-1
2016-08-24T23:56:17Z
[ "python", "set" ]
How to pass 'self' parameter of one class to another class
39,133,820
<p>I am trying to incorporate matplotlib into tkinter by having multiple frames. I need to pass the entry inputs from <code>StartPage</code> frame to update the plot in <code>GraphPage</code> once the button in <code>StartPage</code> is clicked. Therefore, I'm trying to bind the update function of <code>GraphPage</code...
0
2016-08-24T22:13:23Z
39,133,968
<p>This is the problem:</p> <pre><code>GraphPage.update(graphPage) </code></pre> <p>You call the method on the class itself. You need to create an instance of that class and then call the <code>update</code> method with a parent and a controller, for example:</p> <pre><code>self.grpage = GraphPage(parent, controller...
3
2016-08-24T22:29:42Z
[ "python", "python-3.x", "matplotlib", "tkinter" ]
Smart-on-FHIR Python Client with Bundles
39,133,855
<p>So I have a FHIR patient bundle json from the "$everything" operation: <a href="https://www.hl7.org/fhir/operation-patient-everything.html" rel="nofollow">https://www.hl7.org/fhir/operation-patient-everything.html</a></p> <p>I am now interested in using the Smart on FHIR Python Client Models to make working with th...
2
2016-08-24T22:18:05Z
39,137,796
<p>Yes, you can instantiate a <code>Bundle</code> like you can instantiate any other model, either manually from JSON or by a <code>read</code> from the server. Every <code>search</code> returns a Bundle as well. Then you can just iterate over the bundle's entries and work with them, like put them in an array:</p> <pr...
1
2016-08-25T06:06:41Z
[ "python", "json", "hl7-fhir" ]
docker + django : loop + break using forms
39,133,927
<p>I am using django in a docker container. I have a page with two buttons: 'Run' and 'Stop'. When someone presses 'Run' it should start an optimisation process, when you press 'Stop', it should stop.</p> <p><strong>views.py</strong></p> <pre><code>def runGA(request): #read from database and initate form rundat...
0
2016-08-24T22:25:46Z
39,259,636
<p>Found the solution ! Number of threads in the uwsgi.ini was only 1. Increasing this solved the problem.</p> <p><strong>uwsgi.ini</strong></p> <pre><code>[uwsgi] master = true processes = 4 threads = 4 socket = :3031 chdir = /code/ post-buffering = true log-date = true max-requests = 5000 wsgi-file = neuropowerto...
0
2016-08-31T21:57:24Z
[ "python", "django", "loops", "docker", "interrupt" ]
Multiple Python Scripts in Docker
39,133,956
<p>This is quite a basic question but I haven't been able to get an answer from researching on Google, although I think its more due to my lack of understanding, than the answer not being out there.</p> <p>I am getting to grips with Docker and have a python Flask Admin script and a postgres db both in two separate con...
0
2016-08-24T22:28:14Z
39,134,645
<p>Exactly what to write depends on your directory configuration, but you basically want</p> <pre><code>version: '2' services: db: image: postgres environment: - PG_PASSWORD=XXXXX dev: build: &lt;path-to-dev&gt; volumes: - ./app:/code/app - ./run.sh:/code/run.sh ports: -...
1
2016-08-24T23:50:01Z
[ "python", "docker" ]
Generator expression makes binary string generator freeze forever
39,134,067
<p>I have written a function to generate binary strings starting from a given list <code>s</code> (all binary strings that end in one of <code>s</code> items):</p> <pre><code>def binary_strings(s): yield from s while True: s = [b + x for x in s for b in "01"] yield from s </code></pre> <p>It w...
3
2016-08-24T22:39:30Z
39,134,115
<p>I found the answer, the line <code>yield from s</code> was exhausting the generator so the line <code>yield from s</code> yielded from an empty generator (the comprehension before yields empty as <code>s</code> is empty) hence freezeing forever.</p> <p>A list instead can be iterated arbitrarly many times so this pr...
1
2016-08-24T22:45:00Z
[ "python", "python-3.x", "generator", "generator-expression" ]
Copy HTML, save all images on that page and redirect the images in the html
39,134,172
<p>Here's what I want to do:</p> <p>Hit a url, save all of the html to a .html file save all of the images create a copy of that .html where all of the images are redirected to the local copy.</p> <p>At this point, I can now open the second file while my computer is disconnected from the internet.</p> <p>Here's what...
0
2016-08-24T22:51:29Z
39,135,091
<p>Doesn't need to be Python? Great. Try downloading <a href="http://gnuwin32.sourceforge.net/packages/wget.htm" rel="nofollow">Wget for Windows</a> and doing</p> <p><code>wget -p -k http://the-site-you-want.com/fileName.html</code></p>
0
2016-08-25T00:52:58Z
[ "python", "html" ]
Python Dictionary convert to HTML in flask
39,134,183
<p>I have python dictionary that have a list of dictionaries inside. I am trying to convert this to an HTML table that I can give to Flask render_template</p> <p>My dictionary format is:</p> <pre><code>{'sentiment_analysis_result': [{'article_title': u'These Digital Locks Help Keep Tabs on Tenants', 'score': u'0.1396...
0
2016-08-24T22:52:22Z
39,134,339
<p>Not the most efficient but gets the job done if you want to just pass the table already rendered as html as a variable to the view. A better way would be to pass just the data then have the template use template logic to loop over and output variables in the places you want.</p> <pre><code>data = {'sentiment_analys...
0
2016-08-24T23:08:38Z
[ "python", "html", "dictionary", "flask" ]
Python Dictionary convert to HTML in flask
39,134,183
<p>I have python dictionary that have a list of dictionaries inside. I am trying to convert this to an HTML table that I can give to Flask render_template</p> <p>My dictionary format is:</p> <pre><code>{'sentiment_analysis_result': [{'article_title': u'These Digital Locks Help Keep Tabs on Tenants', 'score': u'0.1396...
0
2016-08-24T22:52:22Z
39,134,353
<p>Just pass the dictionary from controller to template and loop it twice. First one for recovering each element of dictionary (key and value respectly), and the second one for recovering each element of each list (value recovered before), paint them using html (table tag, div formatted as a table would be the proper w...
1
2016-08-24T23:11:31Z
[ "python", "html", "dictionary", "flask" ]
Jet API bulk JSON upload: The magic number in GZip header is not correct
39,134,305
<p>I attempted to contact Jet directly and was told to “try using 7zip to gzip the file” and then received no further responses (despite further questions).</p> <p>Here's the error code:</p> <pre><code>"error_excerpt": [ "Error parsing file: The magic number in GZip header is not correct. Make sure you are pa...
0
2016-08-24T23:03:58Z
39,137,065
<p>Figured out the answer. Must make sure to ONLY put the binary data (not a dictionary, like for files) inside the data parameter in requests. </p> <p>making it:</p> <pre><code>def file_upload_url(self, url, filename, data): headers = {"x-ms-blob-type": "blockblob"} with open(filename, 'rb') as f: fi...
1
2016-08-25T05:07:37Z
[ "python", "python-requests", "jet.com-apis" ]
how to install PIL on python shell on OS X 10.9.5
39,134,324
<p>I am new to Python. I try to install PIL using Python 3.5.2 shell. I input <code>pip install PIL</code> into python interpreter first. It didn't work and showed me this: <code>SyntaxError: invalid syntax</code>.</p> <p>Then I searched online and tried this: <code>pip install --no-index -f http://dist.plone.org/thi...
0
2016-08-24T23:05:43Z
39,134,481
<p>You should run the <code>pip</code> command from a system terminal (BASH prompt), not from inside Python. Normally you would open /Applications/Utilities/Terminal.app, and then type <code>pip install PIL</code>. If that installs packages for Python 2.7 instead of 3.5, you could try this instead: <code>python3 $(whic...
1
2016-08-24T23:27:33Z
[ "python", "osx", "shell" ]
how to install PIL on python shell on OS X 10.9.5
39,134,324
<p>I am new to Python. I try to install PIL using Python 3.5.2 shell. I input <code>pip install PIL</code> into python interpreter first. It didn't work and showed me this: <code>SyntaxError: invalid syntax</code>.</p> <p>Then I searched online and tried this: <code>pip install --no-index -f http://dist.plone.org/thi...
0
2016-08-24T23:05:43Z
39,154,914
<pre><code>pip install pillow </code></pre> <p><code>pillow</code> is a wrapper to an old <code>PIL</code> package and it works like a charm.</p>
0
2016-08-25T21:22:11Z
[ "python", "osx", "shell" ]
Use Regex to parse out some part of URL using python
39,134,347
<p>Suppose I am having some like as the following,</p> <pre><code>URL http://hostname.com/as/ck$st=fa+gw+hw+ek+ei/ http://hostname.com/wqs/ck$st=fasd+/ http://hostname.com/as/ck$st=fa+gq+hf+kg+is&amp;sadfnlslkdfn&amp;gl+jh+ke+oj+kp sfav </code></pre> <p>I want to check for first + symbol in the url and move backward ...
0
2016-08-24T23:10:35Z
39,134,454
<p>If you change <code>[^\w\+ ]([\w\+ ]+\+[\w\+ ]+)(?:[^\w\+ ]|$)</code> to <code>[^\w\+ ]([\w\+ ]+\+[\w\+ ]*)(?:[^\w\+ ]|$)</code> it will match the second URL as well.</p> <p>It will include the trailing '+', which isn't included in your desired output but does seem to meet the criteria you had mentioned, so this ma...
0
2016-08-24T23:23:24Z
[ "python", "regex", "python-2.7", "python-3.x" ]
Use Regex to parse out some part of URL using python
39,134,347
<p>Suppose I am having some like as the following,</p> <pre><code>URL http://hostname.com/as/ck$st=fa+gw+hw+ek+ei/ http://hostname.com/wqs/ck$st=fasd+/ http://hostname.com/as/ck$st=fa+gq+hf+kg+is&amp;sadfnlslkdfn&amp;gl+jh+ke+oj+kp sfav </code></pre> <p>I want to check for first + symbol in the url and move backward ...
0
2016-08-24T23:10:35Z
39,134,492
<p>I used regexr to come up with this (<a href="http://regexr.com/3e3go" rel="nofollow">regexr link</a>):</p> <p><code>([\w\+]*\+[\w\+]*)(?:[^\w\+]|$)</code></p> <p>Matches:</p> <p><code>fa+gw+hw+ek+ei fasd+ fa+gq+hf+kg+is gl+jh+ke+oj+kp </code></p> <p>EDIT: Instead of using re.search, try using re.findall instead:...
2
2016-08-24T23:28:58Z
[ "python", "regex", "python-2.7", "python-3.x" ]
Use Regex to parse out some part of URL using python
39,134,347
<p>Suppose I am having some like as the following,</p> <pre><code>URL http://hostname.com/as/ck$st=fa+gw+hw+ek+ei/ http://hostname.com/wqs/ck$st=fasd+/ http://hostname.com/as/ck$st=fa+gq+hf+kg+is&amp;sadfnlslkdfn&amp;gl+jh+ke+oj+kp sfav </code></pre> <p>I want to check for first + symbol in the url and move backward ...
0
2016-08-24T23:10:35Z
39,134,555
<p>After trying to use unsuccesfully <a href="https://docs.python.org/2/library/urlparse.html" rel="nofollow">urlparse</a> it seems the best way to get the info you want is using regular expressions:</p> <pre><code>import urlparse import re urls = [ "http://hostname.com/as/ck$st=fa+gw+hw+ek+ei/", "http://host...
0
2016-08-24T23:37:29Z
[ "python", "regex", "python-2.7", "python-3.x" ]
Pythonic way to add values to a set within a dictionary
39,134,400
<p>Lets say i have a dictionary of sets:</p> <pre><code>d = {"foo":{1,2,3}, "bar":{3,4,5}} </code></pre> <p>Now lets say I want to add the value <code>7</code> to the set found within the key <code>foo</code>. This would be easy:</p> <pre><code>d["foo"].add(7) </code></pre> <p>but what if we were unsure of...
1
2016-08-24T23:16:52Z
39,134,412
<p>Use <code>defaultdict</code></p> <pre><code>&gt;&gt;&gt; from collections import defaultdict &gt;&gt;&gt; d = defaultdict(set) &gt;&gt;&gt; d defaultdict(&lt;class 'set'&gt;, {}) &gt;&gt;&gt; d['foo'].add(1) &gt;&gt;&gt; d['foo'].add(2) &gt;&gt;&gt; d defaultdict(&lt;class 'set'&gt;, {'foo': {1, 2}}) &gt;&gt;&gt; d...
8
2016-08-24T23:18:48Z
[ "python", "dictionary" ]
Pythonic way to add values to a set within a dictionary
39,134,400
<p>Lets say i have a dictionary of sets:</p> <pre><code>d = {"foo":{1,2,3}, "bar":{3,4,5}} </code></pre> <p>Now lets say I want to add the value <code>7</code> to the set found within the key <code>foo</code>. This would be easy:</p> <pre><code>d["foo"].add(7) </code></pre> <p>but what if we were unsure of...
1
2016-08-24T23:16:52Z
39,134,464
<p>trying to keep this simple, how about this</p> <pre><code>dict['baz'] = dict.get('baz', set()) dict['baz'].add(7) </code></pre>
1
2016-08-24T23:25:05Z
[ "python", "dictionary" ]
plot sensor boolean data matplotlib
39,134,407
<p>I have data from two sensors that I want to visualize. Both sensors take only 0/1 values. How can I change the xaxis labels to show the time series and y axis should have 2 labels 0 and 1 representing the value of sensors along the time series.</p> <pre><code>import pandas as pd import matplotlib.pyplot as plt de...
0
2016-08-24T23:18:11Z
39,136,103
<p>You should have explained what you tried before asking a question for this to be meaningful. Anyway, below is the example.</p> <pre><code>%matplotlib inline import pandas as pd import numpy as np import matplotlib.pyplot as plt trange = pd.date_range("11:00", "21:30", freq="30min") df = pd.DataFrame({'time':trange...
1
2016-08-25T03:09:39Z
[ "python", "pandas", "matplotlib", "time-series" ]
Selenium webdriver python find element by xpath - Could not find element
39,134,440
<p>I m trying to write a script with selenium webdriver python. When I try to do a </p> <pre><code>find_element_by_xpath("//*[@id='posted_1']/div[3]") </code></pre> <p>it says </p> <blockquote> <p>NoElementFoundException.</p> </blockquote> <p>Can someone please help me here?</p> <p>Regards Bala</p>
1
2016-08-24T23:21:57Z
39,134,498
<p>that exception, unsurprisingly, means that that element wasn't available on the DOM. There are a couple of options here:</p> <pre><code>driver.implicitly_wait(10) </code></pre> <p>will tell the driver to wait 10 seconds (or any amount of time) after an element is not found/not clickable etc., and tries again afte...
0
2016-08-24T23:30:08Z
[ "python", "selenium", "selenium-webdriver" ]
Selenium webdriver python find element by xpath - Could not find element
39,134,440
<p>I m trying to write a script with selenium webdriver python. When I try to do a </p> <pre><code>find_element_by_xpath("//*[@id='posted_1']/div[3]") </code></pre> <p>it says </p> <blockquote> <p>NoElementFoundException.</p> </blockquote> <p>Can someone please help me here?</p> <p>Regards Bala</p>
1
2016-08-24T23:21:57Z
39,134,540
<p>If you are getting <code>NoSuchElementException</code> as your provided exception, There may be following reasons :-</p> <ul> <li><p>May be you are locating with incorrect locator, So you need to share HTML for better locator solution. </p></li> <li><p>May be when you are going to find element, it would not be pres...
0
2016-08-24T23:35:39Z
[ "python", "selenium", "selenium-webdriver" ]
using Python, How to group a column in Dataframe by the hour?
39,134,523
<p>I have a python dataframe (<code>df1</code>) which has a column time. I converted the column into a datetime series using <code>pd.to_datetime(df1['time'])</code>. Now I get a column like this:</p> <pre><code>2016-08-24 00:00:00 2016-08-13 00:00:00 2016-08-24 00:00:00 2016-08-13 00:00:00 2016-08-24 00...
3
2016-08-24T23:33:50Z
39,135,260
<p>You can use <code>pandas.DatetimeIndex</code> as follows.</p> <pre><code>import numpy as np import pandas as pd # An example of time period drange = pd.date_range('2016-08-01 00:00:00', '2016-09-01 00:00:00', freq='10min') N = len(drange) # The number of columns without 'time' is three. df...
1
2016-08-25T01:15:12Z
[ "python", "datetime", "pandas", "dataframe", "group-by" ]
using Python, How to group a column in Dataframe by the hour?
39,134,523
<p>I have a python dataframe (<code>df1</code>) which has a column time. I converted the column into a datetime series using <code>pd.to_datetime(df1['time'])</code>. Now I get a column like this:</p> <pre><code>2016-08-24 00:00:00 2016-08-13 00:00:00 2016-08-24 00:00:00 2016-08-13 00:00:00 2016-08-24 00...
3
2016-08-24T23:33:50Z
39,137,005
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.resample.html" rel="nofollow"><code>resample</code></a>:</p> <pre><code>#pandas version 0.18.0 and higher df = df.resample('H').size() #pandas version below 0.18.0 #df = df.resample('H', 'size') print (df) 2016-08-24 00:00:00 1...
2
2016-08-25T05:01:59Z
[ "python", "datetime", "pandas", "dataframe", "group-by" ]
using Python, How to group a column in Dataframe by the hour?
39,134,523
<p>I have a python dataframe (<code>df1</code>) which has a column time. I converted the column into a datetime series using <code>pd.to_datetime(df1['time'])</code>. Now I get a column like this:</p> <pre><code>2016-08-24 00:00:00 2016-08-13 00:00:00 2016-08-24 00:00:00 2016-08-13 00:00:00 2016-08-24 00...
3
2016-08-24T23:33:50Z
39,137,189
<p>Using @jezrael setup. </p> <pre><code>df.resample(rule='H', how='count').rename(columns = {'time':'count'}) count 2016-08-24 00:00:00 1 2016-08-24 01:00:00 3 2016-08-24 02:00:00 1 </code></pre>
3
2016-08-25T05:17:50Z
[ "python", "datetime", "pandas", "dataframe", "group-by" ]
custom iterator or generator to execute closeout after break
39,134,524
<p>I'm implementing customized loop behavior, where I need things to happen on entering the loop, at every loop start, at every loop end, and on exiting the loop area. So far this is beautifully simple in Python (2.7):</p> <pre><code>def my_for(loop_iterable): enter_loop() for i in loop_iterable: loop...
0
2016-08-24T23:34:17Z
39,134,601
<p>You may use <code>__enter__</code> and <code>__exit__</code> magic function by defining it in class. To make a call, you may use it with <code>with</code>. <code>__enter__</code> method will be called before executing the code within <code>with</code> block and and when the <code>with</code> block will be exited, <c...
0
2016-08-24T23:44:21Z
[ "python", "loops", "iterator", "generator", "break" ]
custom iterator or generator to execute closeout after break
39,134,524
<p>I'm implementing customized loop behavior, where I need things to happen on entering the loop, at every loop start, at every loop end, and on exiting the loop area. So far this is beautifully simple in Python (2.7):</p> <pre><code>def my_for(loop_iterable): enter_loop() for i in loop_iterable: loop...
0
2016-08-24T23:34:17Z
39,134,622
<p>You could use a <a href="https://docs.python.org/2/reference/datamodel.html#context-managers" rel="nofollow">context manager</a>:</p> <pre><code>class Looper(object): def __init__(self, iterable): self.iterable = iterable self.need_to_end = False def __enter__(self): return self ...
0
2016-08-24T23:47:16Z
[ "python", "loops", "iterator", "generator", "break" ]
Network model of document similarity
39,134,571
<p>Thanks in advance for your help. Briefly, I have been asked to help my organization in an accreditation process that repeats every 5 years. The document we need to compile is roughly 50 pages long (150 or so questions, total), so we would like to reuse as much of the content we produced in our last round as possible...
0
2016-08-24T23:40:09Z
39,135,049
<p>Bit of an outline, but the overall steps for a quick solution are: 1. Convert your words to a format more suitable for machine processing with a tool like <a href="http://www.nltk.org/api/nltk.stem.html" rel="nofollow">http://www.nltk.org/api/nltk.stem.html</a> 2. Follow the steps outlined here to calculate the tf...
0
2016-08-25T00:45:55Z
[ "python", "nlp", "graph-theory", "bipartite" ]
Network model of document similarity
39,134,571
<p>Thanks in advance for your help. Briefly, I have been asked to help my organization in an accreditation process that repeats every 5 years. The document we need to compile is roughly 50 pages long (150 or so questions, total), so we would like to reuse as much of the content we produced in our last round as possible...
0
2016-08-24T23:40:09Z
39,155,334
<p>First thought on my mind: For 50 pages of work, you might save more time by just doing it with a human.</p> <p>But, if you have a good data scientist in your team, you can try gensim. The most recent technology of comparing two different phrases is word embedding. You can think of it as converting words to high-dim...
1
2016-08-25T21:54:58Z
[ "python", "nlp", "graph-theory", "bipartite" ]
How do I set the DJANGO_SETTINGS_MODULE env variable?
39,134,580
<p>I'm trying to fix a bug I'm seeing in a django application where it isn't sending mail. Please note that the application works great, it's only the mail function that is failing. I've tried to collect error logs, but I can't come up with any errors related to sending the mail. So, I made a example to try and force t...
1
2016-08-24T23:40:58Z
39,134,595
<p>Are you on Mac or Linux? Then simply <code>export DJANGO_SETTINGS_MODULE="project_name.settings.your_settings_file"</code> Make sure that if your settings file is in a folder, that there is also an <code>__init__.py</code> file in there.</p> <p>On windows, I believe the equivalent is <code>SET DJANGO_SETTINGS_MODUL...
0
2016-08-24T23:42:59Z
[ "python", "django", "python-2.7", "email" ]
How do I set the DJANGO_SETTINGS_MODULE env variable?
39,134,580
<p>I'm trying to fix a bug I'm seeing in a django application where it isn't sending mail. Please note that the application works great, it's only the mail function that is failing. I've tried to collect error logs, but I can't come up with any errors related to sending the mail. So, I made a example to try and force t...
1
2016-08-24T23:40:58Z
39,134,636
<p>Do not set it from outside the application. Make a entry for <code>DJANGO_SETTINGS_MODULE</code> variable within your <code>wsgi</code> file. Everytime your server will be started, this variable will be set automatically.</p> <p>For example:</p> <pre><code>import os os.environ['DJANGO_SETTINGS_MODULE'] = '&lt;proj...
2
2016-08-24T23:48:51Z
[ "python", "django", "python-2.7", "email" ]
random colours in the spectrum
39,134,696
<p>Hi I am new to programming and I am writing a program that will ask the user to type in a colour. The program will then tell the user if that colour is a primary colour for paint, light, both or neither. </p> <p>primary colours are red, blue and yellow</p> <p>primary colours for light are red, blue and green.</p> ...
0
2016-08-24T23:56:32Z
39,134,730
<p>Try this:</p> <pre><code>a = input("Enter Colour: ").lower() if 'yellow' in a: print('Yellow is a primary coulour for paint.') elif 'green' in a: print('Green is a primary colour for light.') elif 'blue' in a: print('blue is a primary colour for light and paint.') elif 'red' in a: print('red is a primary colour...
2
2016-08-24T23:59:30Z
[ "python" ]
random colours in the spectrum
39,134,696
<p>Hi I am new to programming and I am writing a program that will ask the user to type in a colour. The program will then tell the user if that colour is a primary colour for paint, light, both or neither. </p> <p>primary colours are red, blue and yellow</p> <p>primary colours for light are red, blue and green.</p> ...
0
2016-08-24T23:56:32Z
39,135,042
<p>Try:</p> <pre><code>a = input("Enter Colour: ").strip() color = a.lower() if color in ["red", "blue"]: print(color, "is a primary colour for light and paint.") elif color in ["yellow"]: print("Yellow is a primary colour for paint.") elif color in ["green"]: print("Green is a primary colour for light.")...
1
2016-08-25T00:45:07Z
[ "python" ]
how to add a package to sys path for testing
39,134,718
<p>This question is occasioned by instructions in the <a href="http://docs.python-guide.org/en/latest/writing/structure/" rel="nofollow">python guide</a> for adding a project to sys path to use in tests, which do not seem to work unless I am misunderstanding the instructions</p> <p>I have a directory structure for a p...
0
2016-08-24T23:58:30Z
39,134,755
<p>Try adding an empty <code>__init__.py</code> to <code>tests/</code>: <code>touch tests/__init__.py</code> should do it.</p>
2
2016-08-25T00:03:12Z
[ "python" ]
how to add a package to sys path for testing
39,134,718
<p>This question is occasioned by instructions in the <a href="http://docs.python-guide.org/en/latest/writing/structure/" rel="nofollow">python guide</a> for adding a project to sys path to use in tests, which do not seem to work unless I am misunderstanding the instructions</p> <p>I have a directory structure for a p...
0
2016-08-24T23:58:30Z
39,134,904
<blockquote> <p>Question: How can I add my sample package to the sys path correctly? </p> </blockquote> <p>You're doing it the right way, but you missed declaring your folder to be a package. Try solution of Christian, it should work.</p> <p>Your path is stored in <code>sys.path</code>. By doing this:</p> <pre><co...
1
2016-08-25T00:23:13Z
[ "python" ]
Missing u-strings on Python 3.2?
39,134,742
<p>I have a litany of unit tests that are run on Travis CI and <em>only</em> on PY3.2 it goes belly up. How can I solve this without using six.u()?</p> <pre><code>def test_parse_utf8(self): s = String("foo", 12, encoding="utf8") self.assertEqual(s.parse(b"hello joh\xd4\x83n"), u"hello joh\u0503n") ===========...
1
2016-08-25T00:01:29Z
39,135,072
<p>Could you instead do <code>from __future__ import unicode_literals</code> and not use the <code>u</code> syntax anywhere?</p> <p><code>from __future__ import unicode_literals</code> makes string literals without a preceding <code>u</code> in earlier versions of Python act as in Python 3, that is default to unicode....
0
2016-08-25T00:49:25Z
[ "python", "unicode", "travis-ci", "nose", "six" ]
Missing u-strings on Python 3.2?
39,134,742
<p>I have a litany of unit tests that are run on Travis CI and <em>only</em> on PY3.2 it goes belly up. How can I solve this without using six.u()?</p> <pre><code>def test_parse_utf8(self): s = String("foo", 12, encoding="utf8") self.assertEqual(s.parse(b"hello joh\xd4\x83n"), u"hello joh\u0503n") ===========...
1
2016-08-25T00:01:29Z
39,135,416
<p>I think you're out of luck here.</p> <p>Either use <code>six.u()</code> or drop support for Python 3.2.</p>
1
2016-08-25T01:39:24Z
[ "python", "unicode", "travis-ci", "nose", "six" ]
Missing u-strings on Python 3.2?
39,134,742
<p>I have a litany of unit tests that are run on Travis CI and <em>only</em> on PY3.2 it goes belly up. How can I solve this without using six.u()?</p> <pre><code>def test_parse_utf8(self): s = String("foo", 12, encoding="utf8") self.assertEqual(s.parse(b"hello joh\xd4\x83n"), u"hello joh\u0503n") ===========...
1
2016-08-25T00:01:29Z
39,145,308
<p>I taken the implementation of <code>six.u()</code> and discarded <code>six</code>.</p> <pre><code>import sys PY3 = sys.version_info[0] == 3 def u(s): return s if PY3 else unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") </code></pre>
0
2016-08-25T12:27:08Z
[ "python", "unicode", "travis-ci", "nose", "six" ]
Python matplotlib divide scatterplot into categories based on slope
39,134,747
<p>I have a list of x and a list of y values. I'd like to construct a scatterplot in Matplotlib and divide the dots into five categories based on their x and y coordinates, like in the image below:</p> <p><a href="http://i.stack.imgur.com/unof7.png" rel="nofollow"><img src="http://i.stack.imgur.com/unof7.png" alt="ent...
0
2016-08-25T00:02:05Z
39,134,988
<p>Here's a working example which will give you a little idea to get started:</p> <pre><code>from matplotlib import pyplot as plt from matplotlib.lines import Line2D import math import random fig = plt.figure() ax = fig.add_subplot(1, 1, 1) w, h = 7, 5 a = [[random.random() * w, random.random() * h] for i in range(...
1
2016-08-25T00:36:21Z
[ "python", "matplotlib" ]
PyQt: How to get the item at a specific position in a TreeWidget?
39,134,775
<p>How do I get the item at a specific position (the first, the last, or any given position) of a TreeWidget? I am interested only on items at the parent level, so that I can programmatically select an item at that position.</p> <p>I searched for more than an hour without finding any clear example.</p> <p>Thanks in a...
0
2016-08-25T00:06:03Z
39,134,929
<p>Did you actually looked in <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qtreewidget.html#itemAt" rel="nofollow">docs</a> ?, you can probably look in to itemAt or itemFromIndex</p>
1
2016-08-25T00:28:04Z
[ "python", "pyqt" ]
Inheritance of class attributes?
39,134,847
<p>Can someone provides a detail explanation why this is happening? How does Python compiler create class variables in this case?</p> <pre><code>class A(object): x = 1 y = x + 1 class B(A): x = 10 &gt;&gt;&gt; B.x 10 &gt;&gt;&gt; B.y 2 # ---&gt; I was expecting 11 here, why does this y still uses the A'...
1
2016-08-25T00:15:50Z
39,134,891
<p>It does not do that.</p> <pre><code>&gt;&gt;&gt; class A(object): ... x = 1 ... y = x + 1 ... &gt;&gt;&gt; class B(object): ... x = 10 ... &gt;&gt;&gt; B.x 10 &gt;&gt;&gt; B.y Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; AttributeError: type object 'B' has no attr...
-1
2016-08-25T00:21:12Z
[ "python", "inheritance" ]
Inheritance of class attributes?
39,134,847
<p>Can someone provides a detail explanation why this is happening? How does Python compiler create class variables in this case?</p> <pre><code>class A(object): x = 1 y = x + 1 class B(A): x = 10 &gt;&gt;&gt; B.x 10 &gt;&gt;&gt; B.y 2 # ---&gt; I was expecting 11 here, why does this y still uses the A'...
1
2016-08-25T00:15:50Z
39,134,892
<p>Because class variables are evaluated at the same time the class itself is evaluated. Here the sequence of events is: <code>A</code> is defined and the values in it are set, so <code>x</code> is 1 and <code>y</code> is 2. Then <code>B</code> is defined, and the <code>x</code> entry in <code>B</code> is set to 10. Th...
5
2016-08-25T00:21:23Z
[ "python", "inheritance" ]
Inheritance of class attributes?
39,134,847
<p>Can someone provides a detail explanation why this is happening? How does Python compiler create class variables in this case?</p> <pre><code>class A(object): x = 1 y = x + 1 class B(A): x = 10 &gt;&gt;&gt; B.x 10 &gt;&gt;&gt; B.y 2 # ---&gt; I was expecting 11 here, why does this y still uses the A'...
1
2016-08-25T00:15:50Z
39,134,902
<p>This is because <code>y</code> is a class attribute that belongs to A, so changing the value of x in a class instance of <code>B</code> does not change the value of <code>y</code>. You can read more about that in the documentation: <a href="https://docs.python.org/2/tutorial/classes.html#class-objects" rel="nofollow...
1
2016-08-25T00:22:49Z
[ "python", "inheritance" ]
Finding neighbours for a an element of an array and making sure it has <4 of them
39,134,888
<p>I have an array of atomic coordinates ( a diamond lattice) That looks like this:</p> <pre><code> [[0.0, 0.0, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0], [0.25, 0.25, 0.25], ...
0
2016-08-25T00:20:59Z
39,141,866
<p>I just took some four neighbors:</p> <p><strong>Note:</strong> the interior atoms may have pathological cases where there are no four neighbors by the Voronoi diagram) </p> <p>(I used <a href="http://docs.enthought.com/mayavi/mayavi/auto/example_chemistry.html" rel="nofollow">http://docs.enthought.com/mayavi/mayav...
0
2016-08-25T09:45:49Z
[ "python", "numpy", "scipy", "simulation", "kdtree" ]
urllib2.Request 404 exception
39,134,898
<p>Okay so I'm having an issue with 404, if my request reaches a 404 it throws an exception error.. rather than return 0 &amp; continue with list</p> <p>Code is here <a href="http://pastebin.com/48tspcEc" rel="nofollow">http://pastebin.com/48tspcEc</a></p>
0
2016-08-25T00:22:29Z
39,135,064
<p>I think you indented correctly since python does not acquire a two spaced or four spaced indentation. You should better post the detail of exception error in your question to analyze your problem.</p>
0
2016-08-25T00:48:55Z
[ "python", "request", "http-status-code-404" ]
accuracy of float32
39,134,956
<p>To reduce the filesize, I'm trying to save <code>float64</code> data to file in <code>float32</code>. The data values generally range from 1e-12 to 10. I tested the accuracy loss when converting <code>float64</code> to <code>float32</code>.</p> <pre><code>print np.finfo('float32') </code></pre> <p>shows</p> <pre>...
2
2016-08-25T00:31:55Z
39,135,004
<p>Numbers that low are in the subnormal range. Basically, the exponent doesn't have enough range to get sufficiently low, so you're gradually losing significant bits as values get lower. This is called "gradual underflow".</p> <p><a href="https://en.wikipedia.org/wiki/Denormal_number" rel="nofollow">https://en.wiki...
4
2016-08-25T00:39:55Z
[ "python", "numpy", "floating-point", "floating-accuracy" ]
accuracy of float32
39,134,956
<p>To reduce the filesize, I'm trying to save <code>float64</code> data to file in <code>float32</code>. The data values generally range from 1e-12 to 10. I tested the accuracy loss when converting <code>float64</code> to <code>float32</code>.</p> <pre><code>print np.finfo('float32') </code></pre> <p>shows</p> <pre>...
2
2016-08-25T00:31:55Z
39,155,754
<p>Since machine floating point epsilon is 1.1920929e-07, rounding would get you relative error within half of that for normal floats: 5.9604645e-8. However, when you get smaller than 1.1754944e-38, you have denormalized numbers, which instead have an absolute error of 1.4012985e-45.</p>
1
2016-08-25T22:32:30Z
[ "python", "numpy", "floating-point", "floating-accuracy" ]
Scheduled scripts stopped logging correctly...don't understand cause
39,135,010
<p>I have a few python scripts that I run with Task Scheduler (Windows 10) everyday. When the scripts run I have a few print lines that I like to view in the command prompt to see some information regarding the script as it runs.</p> <p>I actually had the scripts printing out until recently when I changed the director...
0
2016-08-25T00:40:20Z
39,135,018
<p>Probably your log file is in other directories such as the working directory. Maybe try to specify the location of log.txt can solve your problem</p>
0
2016-08-25T00:42:58Z
[ "python", "python-2.7", "logging", "scheduled-tasks", "windows-10" ]
TensorFlow tf.sparse_tensor_dense_matmul
39,135,024
<p>I run a small experiment to benchmark the tf.sparse_tensor_dense_matmul operation. Unfortunately, I am surprised by the result.</p> <p>I am running a sparse matrix, dense vector multiplication, and vary</p> <ul> <li>the number of columns of the sparse matrix (decreasing)</li> <li>the number of rows of the dense ve...
2
2016-08-25T00:43:29Z
39,933,514
<p>I actually think that it is not an issue of TensorFlow but instead the 8MB input of the input vector in the first case does not fit into the L2 memory. In all the other cases the vector is &lt;= 800kb and fits into the L2 memory.</p>
0
2016-10-08T14:23:33Z
[ "python", "c++", "matrix", "tensorflow" ]
ActiveMQ prebvents new subscribers from getting frames, once there are frames
39,135,055
<p>I have tried this with several libs and languages (php5|php7|Stomp extension|ZF1 Stomp| Python2.7 Stomp package).<br> What I found out is that if there is a subscriber to a queue, and it start to get messages (frames) from the queue, any new subscriber during that time will not be getting any of the messages. </p> ...
0
2016-08-25T00:47:09Z
39,135,739
<p>You are most likely running into issues with prefetching where the first client has prefetched all the messages and is churning through them while the second gets none as a result. To tackle this you should configure the clients with a small prefetch value such as 1 using the values given in the <a href="http://act...
0
2016-08-25T02:19:26Z
[ "php", "python", "queue", "activemq", "stomp" ]
Negation Marking with Regular Expressions in Python
39,135,065
<p>I'm struggling to implement negation marking using regex in Python, a la Christopher Potts' <a href="http://sentiment.christopherpotts.net/lingstruc.html#fig:tokenizer_accuracy_neg" rel="nofollow">sentiment analysis tutorial</a>.</p> <p>The definition of a negation, taken from his tutorial is:</p> <pre><code>(?: ...
-1
2016-08-25T00:48:58Z
39,135,217
<p>If you have a sentence as a string, as you imply, then you can't use '^' and '$' in your regexps. Use <code>\b</code> instead. Then this should work:</p> <pre><code>def add_negation_markers(m): return m.group(1) + re.sub(r'(?&lt;=\w)\b', '_NEG', m.group(2)) re.sub('(' + neg_re + ')(.*)(?=' + punct_re + ')', add...
0
2016-08-25T01:10:28Z
[ "python", "regex", "nlp" ]
How to extract username and public key from a website using xpath?
39,135,093
<p>For my thesis work I am gathering data from bitcointalk.org about the users and their bitcoin public keys which they give at the end of each post they write(for donations and tips).</p> <pre><code>&lt;td valign="top" width="16%" rowspan="2" style="overflow: hidden;" class="poster_info"&gt; &...
0
2016-08-25T00:53:16Z
39,183,196
<p>So from what you've described in the comments you want to do is find users in the forum thread got to each of their profiles and if they have a bitcoin address in their profiles scrape the address and their usersname, right? This is the spider that pretty much does that:</p> <pre><code> class BitcointalkSpider(scra...
0
2016-08-27T16:15:30Z
[ "python", "xpath", "scrapy" ]
How to extract username and public key from a website using xpath?
39,135,093
<p>For my thesis work I am gathering data from bitcointalk.org about the users and their bitcoin public keys which they give at the end of each post they write(for donations and tips).</p> <pre><code>&lt;td valign="top" width="16%" rowspan="2" style="overflow: hidden;" class="poster_info"&gt; &...
0
2016-08-25T00:53:16Z
39,217,325
<p>I think you've the idea about getting a common ancestor so that you can match each author to its public key, but I think you're missing the correct selectors, for example try this:</p> <pre><code>posts = response.css('.windowbg, .windowbg2') for post in posts: author = post.css('.poster_info&gt;b&gt;a::text').e...
0
2016-08-30T00:59:08Z
[ "python", "xpath", "scrapy" ]
cassandra no host available:
39,135,096
<p>I tried using the following code but gave an error: </p> <pre><code>File "cassandra/cluster.py", line 1961, in cassandra.cluster.Session.execute (cassandra/cluster.c:34076) File "cassandra/cluster.py", line 3649, in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:69755) cassandra.cluster.NoHo...
-1
2016-08-25T00:53:30Z
39,135,526
<p>It appears that you don't have a keyspace: <code>demo</code></p> <p>If you're referencing a similar example to the one on the <a href="https://docs.datastax.com/en/developer/python-driver/2.7/python-driver/reference/passingParameters2CqlQueries.html" rel="nofollow">DataStax Documentation</a> page, did you already c...
1
2016-08-25T01:52:50Z
[ "python", "cassandra" ]
How to write into influxdb using line Protocol with Python
39,135,119
<p>I am using line protocol and Python to write into InfluxDB. Below is the code that creates DB and working fine.</p> <pre><code> client = InfluxDBClient(host, port, user, password, dbname) print("Creating database: " + dbname) client.create_database(dbname) print("Database created: " + dbname) </code></p...
0
2016-08-25T00:56:47Z
39,138,651
<p>This is how a client.write statement could look like for the sample data you provided. Also see the GitHub readme for more examples: <a href="https://github.com/influxdata/influxdb-python" rel="nofollow">Source</a></p> <pre><code>json_body = [ { "measurement": "interface", "tags": { "path": "address...
1
2016-08-25T06:59:02Z
[ "python", "influxdb" ]
Don't understand cause of exception
39,135,161
<p>Here is my code:</p> <pre><code>import boto3 import json client = boto3.client('elasticbeanstalk') code_pipeline = boto3.client('codepipeline') def put_job_success(job, message): print "Putting job success" print (message) code_pipeline.put_job_success_result(jobId=job) def put_job_failure(job, messa...
-1
2016-08-25T01:02:30Z
39,135,188
<p>Nothing in your <code>try</code> block is guaranteed to run once you hit the <code>except</code> block. This includes the <code>job_id</code> assignment. If you want to get rid of the error, you can try:</p> <pre><code>def lambda_handler(event, context): job_id = None try: # Extract the Job ID ...
5
2016-08-25T01:06:03Z
[ "python" ]
Do Cython files break the Community Edition (Free) PyCharm?
39,135,179
<p>So, the free edition of PyCharm does not support Cython (unlike the paid version). What does this mean? Will it break if I have any *pyx files in my project directory, or refuse to work with those files in any way, or ...?</p>
1
2016-08-25T01:05:22Z
39,135,238
<p>From the <a href="https://www.jetbrains.com/help/pycharm/5.0/cython-support.html" rel="nofollow">docs</a>:</p> <blockquote> <p>Cython support includes:</p> <p>Coding assistance: <br/> Error and syntax highlighting.<br/> Code completion for keywords, fields of structs, and attributes of ex...
3
2016-08-25T01:12:55Z
[ "python", "pycharm", "cython" ]
Do Cython files break the Community Edition (Free) PyCharm?
39,135,179
<p>So, the free edition of PyCharm does not support Cython (unlike the paid version). What does this mean? Will it break if I have any *pyx files in my project directory, or refuse to work with those files in any way, or ...?</p>
1
2016-08-25T01:05:22Z
39,628,692
<p>This can be sorted out rather cleanly, in three small steps, for anyone curious:</p> <ol> <li>Create a sample Cython project (those with writers’ block can <a href="https://github.com/thearn/simple-cython-example" rel="nofollow">start with this</a>)</li> <li>Open this project using PyCharm® Community Edition™<...
0
2016-09-22T01:02:22Z
[ "python", "pycharm", "cython" ]
nginx uwsgi won't accept new connection while request is being processed
39,135,183
<p>I have a <code>Python Flask</code> app being served with <code>nginx</code> and <code>uwsgi</code>. I am serving the app on my local machine for development and when I open it in the browser, everything is fine. I make a POST request and the request comes back fine. So far so good...</p> <p>Now this POST request is...
0
2016-08-25T01:05:48Z
39,135,421
<p>You're only running one worker.</p> <pre><code>spawned uWSGI worker 1 (pid: 11, cores: 1) </code></pre> <p>One thread/process worker can handle one request. Configure more workers in the uWSGI config.</p> <pre><code>workers = 8 </code></pre> <p>Use <a href="http://uwsgi-docs.readthedocs.io/en/latest/Cheaper.htm...
0
2016-08-25T01:40:13Z
[ "python", "nginx", "flask", "uwsgi" ]
Why os.path.dirname returns /usr/local/bin not the python script's path?
39,135,208
<p>For another simple test, I made this code (file name is test3.py) and I put in in /home/ckim/python/test3 directory.</p> <pre><code>import os.path as osp import sys def add_path(path): if path not in sys.path: sys.path.insert(0, path) this_dir = osp.dirname(__file__) lib_path = osp.join(this_dir, 'li...
0
2016-08-25T01:09:32Z
39,135,371
<p>Use <a href="https://docs.python.org/3/library/os.path.html#os.path.realpath" rel="nofollow">os.path.realpath</a> as well to make it work:</p> <pre><code>this_dir = osp.dirname(osp.realpath(__file__)) </code></pre> <p><code>os.getcwd()</code> might also solve your problem.</p>
0
2016-08-25T01:30:59Z
[ "python" ]
Python - Retrieving certain indicies from an array
39,135,210
<p>I have an array of numbers with shape (1220,) called <code>x</code></p> <p>I'm looking at numbers greater than 1.0, </p> <pre><code>mask1 = [i for i in x if i&gt;1.0 ] </code></pre> <p>returning</p> <pre><code>[1.2958354, 1.0839227, 1.1919032] </code></pre> <p>My question now is then how am able to determine t...
0
2016-08-25T01:09:46Z
39,135,252
<p>Try:</p> <pre><code>mask1 = [i for i in range(len(x)) if x[i]&gt;1.0] </code></pre>
1
2016-08-25T01:14:38Z
[ "python", "arrays", "numpy" ]
Python - Retrieving certain indicies from an array
39,135,210
<p>I have an array of numbers with shape (1220,) called <code>x</code></p> <p>I'm looking at numbers greater than 1.0, </p> <pre><code>mask1 = [i for i in x if i&gt;1.0 ] </code></pre> <p>returning</p> <pre><code>[1.2958354, 1.0839227, 1.1919032] </code></pre> <p>My question now is then how am able to determine t...
0
2016-08-25T01:09:46Z
39,135,265
<p>You can use the <code>index</code> function on <code>x</code>, which will return the first index of each value. To get a list of all the indices from <code>mask1</code> try:</p> <pre><code>map(x.index, mask1) </code></pre>
1
2016-08-25T01:15:45Z
[ "python", "arrays", "numpy" ]
Python - Retrieving certain indicies from an array
39,135,210
<p>I have an array of numbers with shape (1220,) called <code>x</code></p> <p>I'm looking at numbers greater than 1.0, </p> <pre><code>mask1 = [i for i in x if i&gt;1.0 ] </code></pre> <p>returning</p> <pre><code>[1.2958354, 1.0839227, 1.1919032] </code></pre> <p>My question now is then how am able to determine t...
0
2016-08-25T01:09:46Z
39,135,268
<p><code>mask_1 = [index for index, value in enumerate(x) if value &gt; 1.0]</code></p>
1
2016-08-25T01:15:58Z
[ "python", "arrays", "numpy" ]
Python - Retrieving certain indicies from an array
39,135,210
<p>I have an array of numbers with shape (1220,) called <code>x</code></p> <p>I'm looking at numbers greater than 1.0, </p> <pre><code>mask1 = [i for i in x if i&gt;1.0 ] </code></pre> <p>returning</p> <pre><code>[1.2958354, 1.0839227, 1.1919032] </code></pre> <p>My question now is then how am able to determine t...
0
2016-08-25T01:09:46Z
39,135,269
<p>Try using <code>enumerate()</code> to get the index and value together:</p> <pre><code>mask1 = [(i,v) for i,v in enumerate(x) if v &gt; 1.0] </code></pre>
1
2016-08-25T01:16:00Z
[ "python", "arrays", "numpy" ]
Python - Retrieving certain indicies from an array
39,135,210
<p>I have an array of numbers with shape (1220,) called <code>x</code></p> <p>I'm looking at numbers greater than 1.0, </p> <pre><code>mask1 = [i for i in x if i&gt;1.0 ] </code></pre> <p>returning</p> <pre><code>[1.2958354, 1.0839227, 1.1919032] </code></pre> <p>My question now is then how am able to determine t...
0
2016-08-25T01:09:46Z
39,135,271
<p>You can use enumerate function, for example:</p> <pre><code>mask1 = [(i, value) for i, value in enumerate(x) if value&gt;1.0 ] print mask1 </code></pre>
1
2016-08-25T01:16:21Z
[ "python", "arrays", "numpy" ]
Python - Retrieving certain indicies from an array
39,135,210
<p>I have an array of numbers with shape (1220,) called <code>x</code></p> <p>I'm looking at numbers greater than 1.0, </p> <pre><code>mask1 = [i for i in x if i&gt;1.0 ] </code></pre> <p>returning</p> <pre><code>[1.2958354, 1.0839227, 1.1919032] </code></pre> <p>My question now is then how am able to determine t...
0
2016-08-25T01:09:46Z
39,135,345
<p>Use enumerate to create tuple pairs of the index and the filtered value, then use zip with the * operator to unpack the variables into separate lists.</p> <pre><code>a = np.array([0, 1, 2, 3]) idx, vals = zip(*[(i, v) for i, v in enumerate(a) if v &gt; 1]) &gt;&gt;&gt; idx (2, 3) &gt;&gt;&gt; vals (2, 3) </code>...
1
2016-08-25T01:26:24Z
[ "python", "arrays", "numpy" ]
Python - Retrieving certain indicies from an array
39,135,210
<p>I have an array of numbers with shape (1220,) called <code>x</code></p> <p>I'm looking at numbers greater than 1.0, </p> <pre><code>mask1 = [i for i in x if i&gt;1.0 ] </code></pre> <p>returning</p> <pre><code>[1.2958354, 1.0839227, 1.1919032] </code></pre> <p>My question now is then how am able to determine t...
0
2016-08-25T01:09:46Z
39,135,382
<p>You've tagged this as <code>numpy</code>, and describe a <code>shape</code> (not <code>len</code>). Which leads me to think you have a numpy array.</p> <pre><code>In [665]: x=np.random.rand(10) In [666]: x Out[666]: array([ 0.6708692 , 0.2856505 , 0.19186508, 0.59411697, 0.1188686 , 0.54921919, 0.774...
4
2016-08-25T01:34:51Z
[ "python", "arrays", "numpy" ]
django rest framework : contenttype unique_together and serialization
39,135,281
<p>I have a little problem with django rest framework about a generic relation which is also used in a unique_together constraint.</p> <p>I have this model :</p> <pre><code>class VPC(models.Model): name = models.SlugField(null=False, max_length=100) deletable = models.BooleanField(null=False, default=True) ...
0
2016-08-25T01:17:45Z
39,138,781
<p>The serializer validation happens in the </p> <pre><code>def create(self, request, *args, **kwargs): </code></pre> <p>method not in "perform_create"</p> <p>you need to override the "create" method and fill 'content_type', 'object_id' to the request data(which will be used to initialize the serializer and validati...
0
2016-08-25T07:06:12Z
[ "python", "django", "django-rest-framework" ]
Float error when writing Celsius-Fahrenheit converter (Zelle)
39,135,297
<p>I'm currently learning Python from Zelle's book, and wrote the following Celsius to Fahrenheit converter. It works without issue:</p> <pre><code>print("This program will convert Celsius to Fahrenheit") c = eval(input("Input the temperature in Celsius: ")) for i in range(10): f = c * (9/5) + 32 print(f) </co...
0
2016-08-25T01:19:39Z
39,135,424
<p>Your code doesn't work because you are trying to do mathematical operations on the entire list 'c'. Python requires you to access the elements before operating on them. You have two options:</p> <p>1) Use a for loop or list comprehension to do elementwise operations on your list. For example:</p> <pre><code>f = [x...
0
2016-08-25T01:40:25Z
[ "python" ]
Encountering problems encoding characters
39,135,303
<p>I'm retrieving long lists of songs <code>ids</code> from <code>API</code>'s, and I'm appending them to a list:</p> <pre><code>track_ids = [spotify:id:1,spotify:id:2 ...] </code></pre> <p>latetr on, song values are being passed to a function, in order to get corresponding song names, in this fashion:</p> <pre><cod...
0
2016-08-25T01:20:35Z
39,135,403
<p>You can encode every element of list. If your file system encoding is <code>utf-8</code>, you can try:</p> <pre><code>results = [value.encode('utf-8') for value in results] print(results) </code></pre>
0
2016-08-25T01:38:08Z
[ "python", "regex", "list", "utf-8" ]
Encountering problems encoding characters
39,135,303
<p>I'm retrieving long lists of songs <code>ids</code> from <code>API</code>'s, and I'm appending them to a list:</p> <pre><code>track_ids = [spotify:id:1,spotify:id:2 ...] </code></pre> <p>latetr on, song values are being passed to a function, in order to get corresponding song names, in this fashion:</p> <pre><cod...
0
2016-08-25T01:20:35Z
39,135,638
<p>The strings in your example are already decoded since they are Unicode strings. You can't decode a Unicode string again, so Python 2 implicitly encodes it back to a byte string using the <code>ascii</code> codec, hence the "Unicode<strong>Encode</strong>Error". The strings you have are correct, you are just seeing...
0
2016-08-25T02:07:28Z
[ "python", "regex", "list", "utf-8" ]
PIL.Image.save followed by PIL.Image.open doesn't work
39,135,330
<p>I'm using</p> <p><code>Python 2.7.11 |Anaconda 4.0.0 (64-bit)</code> and <code>PIL.Image.VERSION = 1.1.7</code></p> <p>I have a saved tiff image that I can correctly open and view it using:</p> <pre><code>tiffIm = PIL.Image.open(tiffFileName) tiffIm.show() </code></pre> <p>Now if I save the file this way:</p> <...
0
2016-08-25T01:24:41Z
39,135,379
<p>Try passing in <code>compression=None</code> rather than <code>compression="None"</code></p>
0
2016-08-25T01:33:15Z
[ "python", "python-imaging-library", "tiff" ]
How do I see mail related errors in Django logs?
39,135,353
<p>I'm trying to figure out why mail isn't being sent from a django application I copied from a perfectly working application where the mail works. I've tried in vain to get django to spit out something related to mail in the logs, but nothing shows up. Here are my settings in settings.py:</p> <pre><code>LOGGING = { ...
0
2016-08-25T01:27:37Z
39,135,563
<p>Neither <code>django.core.mail</code> nor <code>smtplib</code> are using Pythons logging module. There is a simple logging facility in <code>smtplib</code> that write to the console. You have to set run <code>.set_debuglevel(level)</code> on the connection instace, where level is an integer > 0.</p> <p>This <em>sho...
0
2016-08-25T01:56:31Z
[ "python", "django", "email" ]
Find average grade of 10 students, and increment students
39,135,410
<p>I need to ask the final grade of 10 students (<strong>while</strong>) incrementing their values:</p> <p>So something like:</p> <blockquote> <p>Please enter final grade for student 1</p> <p>Please enter final grade for student 2</p> </blockquote> <p>and so on... till 10</p> <p>Then I need to get the grades...
1
2016-08-25T01:38:42Z
39,135,501
<pre><code># list of grades x = [] # count of students n = 10 # fill list with grades from console input # using pythonic generator x = [int(input('Please enter final grade for student {}: '.format(i+1))) for i in range(n)] # count average, # sum is builtin way to sum values in list # float required for python 2.x to...
1
2016-08-25T01:50:06Z
[ "python", "loops", "python-3.x", "for-loop" ]
Find average grade of 10 students, and increment students
39,135,410
<p>I need to ask the final grade of 10 students (<strong>while</strong>) incrementing their values:</p> <p>So something like:</p> <blockquote> <p>Please enter final grade for student 1</p> <p>Please enter final grade for student 2</p> </blockquote> <p>and so on... till 10</p> <p>Then I need to get the grades...
1
2016-08-25T01:38:42Z
39,135,511
<p>First, you need to get the values, as you have already done:</p> <pre><code>x = [] for i in range(10): x.append(int(input('Please enter final grade for student: '))) </code></pre> <p>Now you need to sum the values of <code>x</code>:</p> <pre><code>total_sum = sum(x) </code></pre> <p>Then, you get the average...
1
2016-08-25T01:50:50Z
[ "python", "loops", "python-3.x", "for-loop" ]
Find average grade of 10 students, and increment students
39,135,410
<p>I need to ask the final grade of 10 students (<strong>while</strong>) incrementing their values:</p> <p>So something like:</p> <blockquote> <p>Please enter final grade for student 1</p> <p>Please enter final grade for student 2</p> </blockquote> <p>and so on... till 10</p> <p>Then I need to get the grades...
1
2016-08-25T01:38:42Z
39,135,677
<pre><code> total=sum(x) average=total/10 print(average) </code></pre> <h1>tack this at the bottom and it should work</h1>
0
2016-08-25T02:12:01Z
[ "python", "loops", "python-3.x", "for-loop" ]
why am I not getting a 4 in this list?
39,135,412
<pre><code>my_list = [9,8,7] for k in range (3): my_list.insert(-k,k+1) print(my_list) </code></pre> <p>I am getting: <code>[1,9,8,3,2,7]</code> I have changed the insert and tested it with different numbers and do not understand. I thought -1 would insert at the end of the list.</p>
0
2016-08-25T01:39:00Z
39,135,448
<p><code>-1</code> will insert into the last but one,if you want insert at the end of the list, use <code>your_list.append(val)</code></p>
0
2016-08-25T01:43:19Z
[ "python", "python-3.x" ]
why am I not getting a 4 in this list?
39,135,412
<pre><code>my_list = [9,8,7] for k in range (3): my_list.insert(-k,k+1) print(my_list) </code></pre> <p>I am getting: <code>[1,9,8,3,2,7]</code> I have changed the insert and tested it with different numbers and do not understand. I thought -1 would insert at the end of the list.</p>
0
2016-08-25T01:39:00Z
39,135,464
<p>The <code>insert(i, x)</code> function insert a new item with value x in the list before position i. my_list[-1] is the end element, so my_list.insert(-1, 2) will insert before the end element 7.</p> <pre><code>for k in range (3): my_list.insert(-k,k+1) my_list.insert(0,1) --&gt; my_list = [1, 9, 8, 7] my_list.in...
2
2016-08-25T01:45:12Z
[ "python", "python-3.x" ]
why am I not getting a 4 in this list?
39,135,412
<pre><code>my_list = [9,8,7] for k in range (3): my_list.insert(-k,k+1) print(my_list) </code></pre> <p>I am getting: <code>[1,9,8,3,2,7]</code> I have changed the insert and tested it with different numbers and do not understand. I thought -1 would insert at the end of the list.</p>
0
2016-08-25T01:39:00Z
39,135,466
<p><code>4</code> is not inserted because you are doing <code>(k+1)</code> on <code>insert</code>. And you called <code>range(3)</code>. <code>range(3)</code> returns <code>[0, 1, 2]</code>. </p> <p>So, it never reaches till <code>4</code>. </p> <p>And if you want to insert at the end use <code>my_list.append(k)</cod...
3
2016-08-25T01:45:17Z
[ "python", "python-3.x" ]
How to flatten nested python dictionaries?
39,135,433
<p>I'm trying to flatten the nested dictionary:</p> <pre><code>dict1 = { 'Bob': { 'shepherd': [4, 6, 3], 'collie': [23, 3, 45], 'poodle': [2, 0, 6], }, 'Sarah': { 'shepherd': [1, 2, 3], 'collie': [3, 31, 4], 'poodle': [21, 5, 6], }, 'Ann': { '...
0
2016-08-25T01:41:15Z
39,135,486
<p>You can use a simple recursive function as follows.</p> <pre><code>def flatten(d): res = [] # Result list if isinstance(d, dict): for key, val in d.items(): res.extend(flatten(val)) elif isinstance(d, list): res = d else: raise TypeError("Undefined ty...
2
2016-08-25T01:48:09Z
[ "python", "dictionary" ]
How to flatten nested python dictionaries?
39,135,433
<p>I'm trying to flatten the nested dictionary:</p> <pre><code>dict1 = { 'Bob': { 'shepherd': [4, 6, 3], 'collie': [23, 3, 45], 'poodle': [2, 0, 6], }, 'Sarah': { 'shepherd': [1, 2, 3], 'collie': [3, 31, 4], 'poodle': [21, 5, 6], }, 'Ann': { '...
0
2016-08-25T01:41:15Z
39,135,549
<p>You're trying to use variables that don't exist.</p> <p>Use this</p> <pre><code>dict_flatted = [ i for names in dict1.values() for dog in names.values() for i in dog] </code></pre>
1
2016-08-25T01:55:12Z
[ "python", "dictionary" ]
Add value into tuple (zip() inside for loop ) in Python
39,135,437
<p>I need to format a list of list into a list of tuples, the desired outcome is:</p> <pre><code>&gt;&gt;A = [[1, 2, 3]] &gt;&gt;A.append([1, 2, 3]) &gt;&gt;A.append([1, 2, 3]) &gt;&gt;print A [[1, 2, 3], [1, 2, 3], [1, 2, 3]] </code></pre> <p>And my desired output is:</p> <pre><code>&gt;&gt;zip (A[0],A[1],A[2]) [(1...
1
2016-08-25T01:41:53Z
39,135,462
<p>try <code>zip(*A)</code>, which is exactly <code>zip(A[0],A[1],...)</code></p> <p>(that's true for any function, not just zip). <a href="https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists" rel="nofollow">https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists</a></p>
2
2016-08-25T01:45:02Z
[ "python", "numpy" ]
an if Statement inside an if Statement?
39,135,470
<pre><code>FarmGround=input("Do you want to pat the animal? ") #this is the input if FarmGround==("Yes") or FarmGround==("yes"): #this is if print("You patted the animal") #print statement if you patted the animal it will go onto the next if statement if print=("You patted the animal"): elif FarmGround==("No") or...
-4
2016-08-25T01:45:27Z
39,135,599
<p>You can indent additional statements, including <code>if</code> statements inside your existing <code>if</code> block, just like you're indented the first <code>print</code> statement. It's not clear from your question what exactly you want to do, so I'll fill in some pseudo-code (which you can replace with whatever...
2
2016-08-25T02:01:49Z
[ "python", "variables" ]
an if Statement inside an if Statement?
39,135,470
<pre><code>FarmGround=input("Do you want to pat the animal? ") #this is the input if FarmGround==("Yes") or FarmGround==("yes"): #this is if print("You patted the animal") #print statement if you patted the animal it will go onto the next if statement if print=("You patted the animal"): elif FarmGround==("No") or...
-4
2016-08-25T01:45:27Z
39,135,609
<p>Indentation matters in python. To nest an if statement in another if statement, just indent it below the first with 4 spaces.</p> <pre><code>If ( var1 == 1 ): If ( var2 == 2 ): print "Both statements are true." </code></pre>
1
2016-08-25T02:03:55Z
[ "python", "variables" ]
an if Statement inside an if Statement?
39,135,470
<pre><code>FarmGround=input("Do you want to pat the animal? ") #this is the input if FarmGround==("Yes") or FarmGround==("yes"): #this is if print("You patted the animal") #print statement if you patted the animal it will go onto the next if statement if print=("You patted the animal"): elif FarmGround==("No") or...
-4
2016-08-25T01:45:27Z
39,135,618
<p>Your code is quite clear. What I understand is you want to ask another question if animal is patted. </p> <pre><code>FarmGround=input("Do you want to pat the animal? ") #this is the input if FarmGround=="Yes" or FarmGround=="yes": #this is if print("You patted the animal") holy_field = input("Did you cl...
2
2016-08-25T02:04:48Z
[ "python", "variables" ]
Setting Order of Columns with matplotlib bar chart
39,135,472
<p>I produce a bar graph with the following code: </p> <pre><code>Temp_Counts = Counter(weatherDFConcat['TEMPBIN_CON']) df = pd.DataFrame.from_dict(Temp_Counts, orient = 'index') df.plot(kind = 'bar') </code></pre> <p>It produces the following bar chart: </p> <p><a href="http://i.stack.imgur.com/4sWHw.png" rel="nofo...
2
2016-08-25T01:45:53Z
39,135,625
<p>I would suggest that you split the <code>TEMPBIN_CON</code> in two: <code>LOWER_TEMP</code> and <code>HIGHER_TEMP</code>. Then, you sort the DataFrame by these columns using:</p> <pre><code>sorted = df.sort_values(by=['LOWER_TEMP', 'HIGHER_TEMP']) </code></pre> <p>and then you do the plot as you have already done:...
1
2016-08-25T02:06:19Z
[ "python", "pandas", "numpy", "matplotlib", "bar-chart" ]