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
Python2 - Summing "for" loop output
39,073,840
<p>I'm trying to make a script that takes a balances of multiple addresses from a json file and adds them together to make a final balance.</p> <p>This is the code so far -</p> <pre><code>import json from pprint import pprint with open('hd-wallet-addrs/addresses.json') as data_file: data = json.load(data_fil...
0
2016-08-22T07:42:30Z
39,073,914
<p>Actually add them together...</p> <pre><code>total = 0 for balance in data: total += float(balance['balance']) print total </code></pre> <p>Or using <code>sum</code>:</p> <pre><code>print sum(float(temp_balance['balance']) for temp_balance in data) </code></pre>
2
2016-08-22T07:46:43Z
[ "python", "json", "python-2.7", "for-loop" ]
Python2 - Summing "for" loop output
39,073,840
<p>I'm trying to make a script that takes a balances of multiple addresses from a json file and adds them together to make a final balance.</p> <p>This is the code so far -</p> <pre><code>import json from pprint import pprint with open('hd-wallet-addrs/addresses.json') as data_file: data = json.load(data_fil...
0
2016-08-22T07:42:30Z
39,074,111
<pre><code>balance_prev = 0 balance_sum = 0 for balance in data: balance_sum = float(balance_prev) + float(balance['balance']) balance_prev = balance_sum print balance['balance'] </code></pre> <p>hope this help!!</p>
0
2016-08-22T07:59:09Z
[ "python", "json", "python-2.7", "for-loop" ]
trying to support python code in tcl
39,073,847
<p>I'm new to all of this thing, and so please excuse me if i kinda did something stupid here. Treat me and explain to me as if i'm a total noob would be helpful.</p> <p>I have a simple function written in python, filename <code>a.pyx</code>:-</p> <pre><code>#!/usr/bin/env python import os import sys def get_syspat...
1
2016-08-22T07:42:46Z
39,076,034
<p>The object code needs to be linked to the libraries it depends on when you're building the loadable library. This means adding appropriate <code>-l...</code> options and possibly some <code>-L...</code> options as well. I'm guessing that the option will be something like <code>-lpython27</code> or something like tha...
2
2016-08-22T09:36:21Z
[ "python", "tcl", "cython", "swig" ]
trying to support python code in tcl
39,073,847
<p>I'm new to all of this thing, and so please excuse me if i kinda did something stupid here. Treat me and explain to me as if i'm a total noob would be helpful.</p> <p>I have a simple function written in python, filename <code>a.pyx</code>:-</p> <pre><code>#!/usr/bin/env python import os import sys def get_syspat...
1
2016-08-22T07:42:46Z
39,107,455
<p>Maybe have a look at <a href="http://jfontain.free.fr/tclpython.htm" rel="nofollow" title="tclpython"><code>tclpython</code></a> or <a href="https://github.com/aidanhs/libtclpy" rel="nofollow" title="libtclpy"><code>libtclpy</code></a>.</p> <p>Both allow calling Python code from Tcl.</p> <p>But if you wanted to wr...
1
2016-08-23T17:32:09Z
[ "python", "tcl", "cython", "swig" ]
_BaseServer__is_shut_down while running glass framework
39,073,853
<p>i am new to Glass framework i have installed glass server in in my ubuntu system when i run sample test application its return _BaseServer__is_shut_down error how can i resolve this issue and i already tried different port number but same issue .</p> <p>test.py</p> <pre><code>#!/usr/bin/env python from glass.HTTPS...
3
2016-08-22T07:43:06Z
39,148,518
<p>I was not able to fix that issue, but the framework seems really old. I can reditect you to the simplest HTTP server existant, and easy too:</p> <p>Python 3 (prefered) using <a href="https://docs.python.org/3/library/http.server.html" rel="nofollow">http.server</a>:</p> <pre><code>import http.server import sockets...
0
2016-08-25T14:53:12Z
[ "python" ]
_BaseServer__is_shut_down while running glass framework
39,073,853
<p>i am new to Glass framework i have installed glass server in in my ubuntu system when i run sample test application its return _BaseServer__is_shut_down error how can i resolve this issue and i already tried different port number but same issue .</p> <p>test.py</p> <pre><code>#!/usr/bin/env python from glass.HTTPS...
3
2016-08-22T07:43:06Z
39,223,671
<p>After doing some research inside the framework code I have found the next:</p> <p>The HTTPServer inside the package is a custom one with a <code>__getattr__</code> built-in set that is rising exceptions when an attribute that is not "is_secure" is accessed.</p> <pre><code># Code from HTTPServer.py def __getattr__(...
0
2016-08-30T09:27:09Z
[ "python" ]
Why Python script has to be executed 2 times to get complete output in the CSV file
39,073,877
<p>I have a simple Python script that writes a sub(CSV)file after reading a large CSV file.</p> <pre><code>import csv import os large_file = "D:\Total_data.csv" with open(large_file, 'rb') as csvfile: reader = csv.reader(csvfile, delimiter='|') path = "D:/CSV_Files/" if not os.path.exists(path): ...
2
2016-08-22T07:44:25Z
39,076,047
<p>I was randomly trying many different ways to solve this issue, and interestingly I found that if we define a function for this code, and then call the function, the issue gets resolved.</p> <pre><code>def create_subfile(): """ now same code as in question""" create_subfile(); </code></pre> <p>Does anyone kn...
-1
2016-08-22T09:36:47Z
[ "python", "csv" ]
Template displays foreign key instead of CharField for disabled field
39,073,885
<p>I am using Django 1.97 and have the following models:</p> <pre><code>class Symbol(models.Model): symbol = models.CharField(max_length=15) # more fields class Position(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) symbol = models.ForeignKey(Symbol) # more fields def ge...
0
2016-08-22T07:44:44Z
39,074,267
<p>The problem is that you are using a Textinput widget for a FKey field, which is treated as a lookup field by default. Why not just have it be a disabled dropdown field?</p> <pre><code>self.fields['symbol'].widget.attrs['disabled'] = 'disabled' </code></pre> <p><strong>Edit: Alternative solution</strong></p> <p>Ba...
1
2016-08-22T08:08:33Z
[ "python", "django", "django-forms" ]
How to generate a matrix with circle of ones in numpy/scipy
39,073,973
<p>There are some signal generation helper functions in <a href="http://docs.scipy.org/doc/scipy/reference/signal.html#waveforms" rel="nofollow">python's scipy</a>, but these are only for 1 dimensional signal.</p> <p>I want to generate a 2-D ideal bandpass filter, which is a matrix of all zeros, with a circle of ones ...
3
2016-08-22T07:50:22Z
39,074,620
<p>Here is a pure NumPy alternative that should run significantly faster and looks cleaner, imho. Basically, we vectorise your code by replacing built-in <code>sqrt</code> and <code>abs</code> with their NumPy alternatives and working on matrices of indices. </p> <p><strong>Updated</strong> to replace <code>distance<...
3
2016-08-22T08:27:50Z
[ "python", "numpy", "scipy", "signal-processing", "python-2.x" ]
How to generate a matrix with circle of ones in numpy/scipy
39,073,973
<p>There are some signal generation helper functions in <a href="http://docs.scipy.org/doc/scipy/reference/signal.html#waveforms" rel="nofollow">python's scipy</a>, but these are only for 1 dimensional signal.</p> <p>I want to generate a 2-D ideal bandpass filter, which is a matrix of all zeros, with a circle of ones ...
3
2016-08-22T07:50:22Z
39,082,209
<p>Here's a vectorized approach -</p> <pre><code>def unit_circle_vectorized(r): A = np.arange(-r,r+1)**2 dists = np.sqrt(A[:,None] + A) return (np.abs(dists-r)&lt;0.5).astype(int) </code></pre> <p>Runtime test -</p> <pre><code>In [165]: %timeit unit_circle(100) # Original soln 10 loops, best of 3: 31.1 m...
2
2016-08-22T14:31:22Z
[ "python", "numpy", "scipy", "signal-processing", "python-2.x" ]
Weblogic WSLT in modular python script
39,074,123
<p>I'm creating a script to automate creation of JMS resources in a declarative way using <code>wslt.sh</code>. This way I just need to run <code>wslt.sh create_resources.py planned_resources.properties</code></p> <p>create_resources.py imports another module of mine <code>import include.jms as nmjms</code>. This incl...
0
2016-08-22T07:59:43Z
39,076,103
<p>First, create a module wl.py with the folowing code : </p> <pre><code># Caution: This file is part of the command scripting implementation. # Do not edit or move this file because this may cause commands and scripts to fail. # Do not try to reuse the logic in this file or keep copies of this file because this # ...
1
2016-08-22T09:39:14Z
[ "python", "weblogic", "weblogic-10.x" ]
Django 1.10 Translation
39,074,285
<p>I was trying internationalization/localization in django. I am getting an error while i am trying to make the '.po' files using the command </p> <blockquote> <p>./manage.py makemessages</p> </blockquote> <p>relevant parts from settings.py</p> <pre><code>import os from django.utils.translation import ugettext_l...
2
2016-08-22T08:09:37Z
39,092,078
<p>The error occurred because of the htmlcov folder which was generated while running the coverage script. </p> <p>Removed that folder and executed the following commands to generate the '.po' files.</p> <blockquote> <p>./manage.py makemessages -l fi</p> </blockquote> <p>and the following command to generate the '...
1
2016-08-23T03:54:11Z
[ "python", "django", "translation" ]
When overwriting __init__ will I call __init__ of base class at the beginning or end?
39,074,292
<p>I have the following short example where I inherit a class <code>A</code> from <code>Base</code> and overwrite <code>__init__</code>. In the <code>__init__</code> the <code>Base.__init__</code> is called. </p> <pre><code>class A(Base): def __init__(self): super(A, self).__init__() ... my initialisation .....
0
2016-08-22T08:09:51Z
39,074,333
<p>No, there is no rule as to where to call it, or if you call it at all. Call it wherever it makes sense <em>to your specific situation</em>.</p> <p>Put differently, <code>super(A, self).__init__()</code> is <em>just another method call</em>, albeit one that specifically uses a method looked up from a base class. Tre...
4
2016-08-22T08:11:39Z
[ "python", "oop", "override" ]
Kivy Gallary programm doesn't work when compiled as apk
39,074,335
<p>I wanted to make an kivy app, with a button, that opens the android gallary, when the button is clicked. So I wrote to code, that you can see down there, on qpython, and it worked. But when I wanted to ran it on my PC, I got the error message:</p> <pre><code> Traceback (most recent call last): File "main.py"...
0
2016-08-22T08:11:46Z
39,078,648
<p>Try adding <code>android</code> to your requirements.</p>
0
2016-08-22T11:42:33Z
[ "android", "python", "kivy", "android-gallery", "pyjnius" ]
How can I strip html with BeautifulSoup, keeping newlines like textContent?
39,074,337
<p>This is what I've got:</p> <pre><code>&gt;&gt;&gt; from bs4 import BeautifulSoup &gt;&gt;&gt; BeautifulSoup("&lt;p&gt;Hello&lt;/p&gt;\n\n&lt;p&gt;World&lt;/p&gt;").get_text() u'Hello\nWorld' </code></pre> <p>Whitespace is mostly preserved but, as in the example above, newlines aren't. I'd like to strip HTML withou...
1
2016-08-22T08:11:55Z
39,074,338
<p>Rather than the default parser, <code>html.parser</code>, installing <code>html5lib</code> did the trick:</p> <pre><code>pip install html5lib ... &gt;&gt;&gt; BeautifulSoup("&lt;p&gt;Hello&lt;/p&gt;\n\n&lt;p&gt;World&lt;/p&gt;", "html.parser").get_text() u'Hello\nWorld' &gt;&gt;&gt; BeautifulSoup("&lt;p&gt;Hello&lt...
1
2016-08-22T08:11:55Z
[ "python", "beautifulsoup", "newline", "whitespace" ]
Creating dicts from file in python
39,074,367
<p>For example, I've got file with multilines like</p> <pre><code>&lt;&lt;something&gt;&gt; 1, 5, 8 &lt;&lt;somethingelse&gt;&gt; hello &lt;&lt;somethingelseelse&gt;&gt; 1,5,6 </code></pre> <p>I need to create dict with keys</p> <pre><code>dict = { "something":[1,5,8], "somethingelse": "hello" ...} </code></pre> ...
0
2016-08-22T08:14:01Z
39,074,527
<p>Assuming that your keys will always be single words, you can play with <a href="https://docs.python.org/2/library/stdtypes.html#str.split" rel="nofollow">split(char, maxSplits)</a>. Something like below</p> <pre><code>import sys def finding_path(file_name): f = open(file_name, 'r') my_dict = {} for li...
1
2016-08-22T08:22:30Z
[ "python", "python-2.7", "file", "input" ]
Creating dicts from file in python
39,074,367
<p>For example, I've got file with multilines like</p> <pre><code>&lt;&lt;something&gt;&gt; 1, 5, 8 &lt;&lt;somethingelse&gt;&gt; hello &lt;&lt;somethingelseelse&gt;&gt; 1,5,6 </code></pre> <p>I need to create dict with keys</p> <pre><code>dict = { "something":[1,5,8], "somethingelse": "hello" ...} </code></pre> ...
0
2016-08-22T08:14:01Z
39,074,552
<p>Please check the below code:</p> <ul> <li><p>Used regex to get key and value</p></li> <li><p>If the length of value list is 1, then converting it into string.</p></li> </ul> <pre><code>import re demo_dict = {} with open("val.txt",'r') as f: for line in f: m= re.search(r"&lt;&lt;(.*?)&gt;&gt;(.*)",...
1
2016-08-22T08:23:54Z
[ "python", "python-2.7", "file", "input" ]
Creating dicts from file in python
39,074,367
<p>For example, I've got file with multilines like</p> <pre><code>&lt;&lt;something&gt;&gt; 1, 5, 8 &lt;&lt;somethingelse&gt;&gt; hello &lt;&lt;somethingelseelse&gt;&gt; 1,5,6 </code></pre> <p>I need to create dict with keys</p> <pre><code>dict = { "something":[1,5,8], "somethingelse": "hello" ...} </code></pre> ...
0
2016-08-22T08:14:01Z
39,075,331
<p>My answer is similar to Dinesh's. I've added a function to convert the values in the list to numbers if possible, and some error handling so that if a line doesn't match, a useful warning is given.</p> <pre><code>import re import warnings regexp =re.compile(r'&lt;&lt;(\w+)&gt;&gt;\s+(.*)') lines = ["&lt;&lt;somet...
1
2016-08-22T09:03:47Z
[ "python", "python-2.7", "file", "input" ]
Plot list of lists as bar graph Python Matplotlib
39,074,422
<p>I have a list of lists that looks as follows:</p> <pre><code>[[1,100.1],[2,133.222],[3,198.0]] </code></pre> <p>I'm trying to use this data to draw a bar graph in matplotlib, where the first element in each element of the list is the x-axis (it's always an integer between 1-1000, no repeats) and the second element...
0
2016-08-22T08:16:51Z
39,074,593
<p>You need to separate the x values from the y values. This can be done by <code>zip</code>:</p> <p>First:</p> <pre><code>import numpy as np import matplotlib.pypl as plt </code></pre> <p>Now:</p> <pre><code>In [263]: lst = [[1,100.1],[2,133.222],[3,198.0]] In [264]: xs, ys = [*zip(*lst)] In [265]: xs Out[265]: ...
3
2016-08-22T08:26:12Z
[ "python", "matplotlib", "plot" ]
Plot list of lists as bar graph Python Matplotlib
39,074,422
<p>I have a list of lists that looks as follows:</p> <pre><code>[[1,100.1],[2,133.222],[3,198.0]] </code></pre> <p>I'm trying to use this data to draw a bar graph in matplotlib, where the first element in each element of the list is the x-axis (it's always an integer between 1-1000, no repeats) and the second element...
0
2016-08-22T08:16:51Z
39,074,643
<p>I would go for something like this:</p> <pre><code>import matplotlib.pyplot as plt data = [[1,100.1],[2,133.222],[3,198.0]] x = map(lambda x: x[0], data) y = map(lambda x: x[1], data) plt.bar(x,y) </code></pre>
0
2016-08-22T08:29:02Z
[ "python", "matplotlib", "plot" ]
Accessing entire string in Python using Negative indices
39,074,498
<p>Here is a Python oddity that I discovered while teaching students.</p> <p>If negative indexing should work right, then for a string m='string', I did the following steps.</p> <pre><code>&gt;&gt;&gt; m='string' &gt;&gt;&gt; m[:-1] 'strin' &gt;&gt;&gt; m[:0] '' &gt;&gt;&gt; m[-1] 'g' &gt;&gt;&gt; m[0:] 'string' &gt;...
2
2016-08-22T08:21:15Z
39,074,556
<pre><code>&gt;&gt;&gt; m='string' &gt;&gt;&gt; m[-len(m):] 'string' </code></pre> <p>Just as positive indices count forward from the beginning of a string, negative indices count back from the end. Thus, we have to count back by <code>len(m)</code> to get back to the beginning of <code>m</code>.</p>
7
2016-08-22T08:24:05Z
[ "python", "python-2.7" ]
Accessing entire string in Python using Negative indices
39,074,498
<p>Here is a Python oddity that I discovered while teaching students.</p> <p>If negative indexing should work right, then for a string m='string', I did the following steps.</p> <pre><code>&gt;&gt;&gt; m='string' &gt;&gt;&gt; m[:-1] 'strin' &gt;&gt;&gt; m[:0] '' &gt;&gt;&gt; m[-1] 'g' &gt;&gt;&gt; m[0:] 'string' &gt;...
2
2016-08-22T08:21:15Z
39,078,477
<p>I'm guessing you don't actually mean an answer like suggested by anyone else. What you want to know is why <code>m[:-N]</code> returns all characters in <em>m</em> except for the last <em>N</em>, <strong>unless N is zero</strong>, because -0 is equal to 0, and <code>m[:0]</code> should, of course, return an empty st...
0
2016-08-22T11:34:21Z
[ "python", "python-2.7" ]
Python - Kivy: AttributeError: 'super' object has no attribute '__getattr__' when trying to get self.ids
39,074,550
<p>I wrote a code for a kind of android lock thing, whenever I try to get an specific ClickableImage using the id it raises the following error:</p> <pre><code>AttributeError: 'super' object has no attribute '__getattr__' </code></pre> <p>I've spent hours trying to look for a solution for this problem, I looked other...
2
2016-08-22T08:23:48Z
39,152,510
<p>Let's look at the output:</p> <pre><code>'super' object has no attribute '__getattr__' </code></pre> <p>In kv language <code>id</code> is set in a special way(up to 1.9.2 now), its value is not a string, because it's not a casual variable. You can't access it with <code>&lt;widget&gt;.id</code>.</p> <p>I'd say it...
1
2016-08-25T18:35:45Z
[ "python", "kivy", "kivy-language" ]
python try and exception
39,074,635
<p>I am not a python geek but have tried to solve this problem using information from several answers to similar questions but none seem to really work in my case. Here it is:</p> <p>I am calling a function from a python script: Here is the function:</p> <pre><code>def getsom(X): #some codes try: st =...
-3
2016-08-22T08:28:37Z
39,075,274
<p>As mentioned in the comments you seem like you want to catch the exception <em>in</em> first-level exception handler. You can do it like this:</p> <pre><code>def getsom(X): #some codes try: st = get data from site 1 using X except: print "not available from site 1, getting from site 2" ...
2
2016-08-22T09:01:27Z
[ "python" ]
python try and exception
39,074,635
<p>I am not a python geek but have tried to solve this problem using information from several answers to similar questions but none seem to really work in my case. Here it is:</p> <p>I am calling a function from a python script: Here is the function:</p> <pre><code>def getsom(X): #some codes try: st =...
-3
2016-08-22T08:28:37Z
39,075,464
<p>Why don't you create a separate function for it?</p> <pre class="lang-py prettyprint-override"><code>def getdata(X): for site in [site1, site2]: # possibly more try: return get_data_from_site_using_X() except: print "not available in %s" % site print "couldn't find d...
0
2016-08-22T09:10:20Z
[ "python" ]
Can OpenWhisk trigger Docker actions in my Bluemix registry?
39,074,638
<p>I pushed my Docker image to my Bluemix registry; I ran the container on Bluemix just fine; I have also set up a skeleton OpenWhisk rule which triggers a sample Python action but wish to trigger the image in my Bluemix registry as the action. </p> <p>But, as far as I can see from the OpenWhisk documents, it is on...
1
2016-08-22T08:28:47Z
39,074,811
<p>This is not currently possible. </p> <p>OpenWhisk can only create Actions from Docker images stored in the external Docker Hub registry. </p>
1
2016-08-22T08:38:27Z
[ "python", "ibm-bluemix", "openwhisk" ]
How can I get the radio button in Matplotlib to update 4 subplots together?
39,074,930
<p>I would highly appreciate your help here. I have 3 .csv files with some data in them. Each .csv file creates 4 histograms. I have created 4 subplots for each histogram.</p> <p>I have also created a radio button with the 3 data sets as variables. I would like the subplots to be updated with the data set I click on i...
0
2016-08-22T08:44:31Z
39,077,643
<pre><code>import csv import numpy as np from scipy.stats import norm, lognorm import matplotlib.pyplot as plt import matplotlib.mlab as mlab from matplotlib.widgets import Slider, Button, RadioButtons #####Importing Data from csv file##### dataset1 = np.genfromtxt('dataSet1.csv', dtype = float, delimiter = ',', sk...
0
2016-08-22T10:51:12Z
[ "python", "python-2.7", "python-3.x", "csv", "matplotlib" ]
SettingWithCopyWarning unsual behavior in Pandas
39,074,931
<p>I have a dataframe say <strong>release_dates</strong></p> <p><strong>release_dates</strong></p> <p><a href="http://i.stack.imgur.com/U3tq0.png" rel="nofollow"><img src="http://i.stack.imgur.com/U3tq0.png" alt="enter image description here"></a> </p> <p>I did the filtering using some conditions and called it <str...
1
2016-08-22T08:44:33Z
39,078,218
<p>As Edchum explained it clearly in his comments that you used <strong>.sort()</strong> in the first code which lets python know that user know, it is a copy rather than a view.</p> <p>Whenever we perform slicing or filtering We get either a View or a copy.However, Pandas docs do not specify any rules about what you ...
1
2016-08-22T11:20:43Z
[ "python", "python-3.x", "pandas" ]
How to deal with string format in python pandas?
39,074,991
<p>I have a data frame like following:</p> <pre><code> pop state country num_1 num_2 0 1.8 Ohio China 1 4 1 1.9 Ohio China 1 5 2 3.9 Nevada Britain 1 6 3 2.9 Nevada Germany 1 2 4 2.0 Nevada Japan ...
-4
2016-08-22T08:47:34Z
39,080,571
<p>OK let's start with a random DataFrame:</p> <pre><code>np.random.seed(0) df = pd.DataFrame({'A': np.random.choice(list('ABC'), 10**7), 'B': 1, 'C': np.random.choice(list('xyztq'), 10**7)}) df.info() &lt;class 'pandas.core.frame.DataFrame'&gt; RangeIndex: 10000000 entries, 0 to...
1
2016-08-22T13:13:57Z
[ "python", "pandas" ]
Django rq scheduler can not enqueue same task twice
39,075,059
<p>I am using <a href="https://github.com/ui/rq-scheduler" rel="nofollow">rq scheduler</a>. I want to remind users to verify their email after 2 mins and 10 mins. So I use post_save signal to schedule these tasks. I have set up task like this:</p> <pre><code>from datetime import timedelta import django_rq def send_ver...
0
2016-08-22T08:51:53Z
39,075,324
<p>Run first task with delta 2 minutes and when it executes, it should run another one with delta 8 minutes. Hope that helps.</p>
1
2016-08-22T09:03:28Z
[ "python", "django", "django-rq" ]
Pandas: create a table using groupby
39,075,173
<p>I have dataframe </p> <pre><code>ID subdomain search_engine search_term code category term_code 0120bc30e78ba5582617a9f3d6dfd8ca yandex.ru 0 None 1 поисковая машина 1 0120bc30e78ba5582617a9f3d6dfd8ca my-shop.ru 0 None 5 интернет-магазин 1 0120bc3...
-4
2016-08-22T08:57:28Z
39,075,295
<p>try this:</p> <pre><code>df.groupby('ID')['category'].apply(lambda x: ' -&gt; '.join(list(x))) </code></pre> <p>Demo:</p> <pre><code>In [14]: df.groupby('ID')['category'].apply(lambda x: ' -&gt; '.join(list(x))) Out[14]: ID 0120bc30e78ba5582617a9f3d6dfd8ca поисковая машина -&...
1
2016-08-22T09:02:24Z
[ "python", "pandas" ]
Install Python 2.7.* in Windows 10
39,075,184
<p>I am using Windows 10. Just now, have installed Python 3.5 64 bit successfully. However, when I want to install Python 2.7.*, the following error is shown.</p> <p><a href="http://i.stack.imgur.com/P6L6u.png" rel="nofollow"><img src="http://i.stack.imgur.com/P6L6u.png" alt=""></a></p> <p>I even uninstalled Python 3...
-1
2016-08-22T08:57:52Z
39,202,386
<p>OK. I solved the problem by installing a 32-bit version.</p>
0
2016-08-29T09:07:55Z
[ "python", "windows" ]
How to make it so a list is chosen and then an image will be drawn in that location?
39,075,271
<p>I have these 4 lists:</p> <pre><code>attempt_01 = [['Piece A', 'In box']] attempt_02 = [['Piece B', 'In box']] attempt_03 = [['Piece C', 'In box']] attempt_04 = [['Piece D', 'In box']] </code></pre> <p>and I need to create a function being </p> <pre><code>def attempt(attempt_number): </code></pre> <p>so that...
-2
2016-08-22T09:01:24Z
39,077,051
<p>It seems that you need something like this:</p> <pre><code>def draw_attempt(attempt_number): if 'In box': x = 0, 350 elif 'Top_Right': x = 350, 350 elif 'Bottom_Left': x = -350, -350 goto(x) if 'Piece A': #STARTS DRAWING FOR IMAGE A(PIECE A CODE IS HERE) elif...
0
2016-08-22T10:23:04Z
[ "python", "python-2.7" ]
Why can't I pass the code test in python3?
39,075,309
<p>what I met is a code question below: <a href="https://www.patest.cn/contests/pat-a-practise/1001" rel="nofollow">https://www.patest.cn/contests/pat-a-practise/1001</a></p> <blockquote> <p>Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by com...
1
2016-08-22T09:02:54Z
39,076,525
<p>I can give you a simple that doesn't match answer, when you enter -1000000, 9 as a, b in your input, you'll get -,999,991.which is wrong.</p> <p>To get the right answer, you really should get to know format in python.</p> <p>To solve this question, you can just write your code like this.</p> <p><code>if __name__ ...
3
2016-08-22T09:59:20Z
[ "python", "python-3.x" ]
Why can't I pass the code test in python3?
39,075,309
<p>what I met is a code question below: <a href="https://www.patest.cn/contests/pat-a-practise/1001" rel="nofollow">https://www.patest.cn/contests/pat-a-practise/1001</a></p> <blockquote> <p>Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by com...
1
2016-08-22T09:02:54Z
39,076,548
<p>Notice the behavior of your code when you input -1000 and 1. You need to handle the minus sign, because it is not a digit.</p>
1
2016-08-22T10:00:06Z
[ "python", "python-3.x" ]
Color time-series based on column values in pandas
39,075,325
<p>I have a time-series in a pandas DataFrame (<code>df.data</code> in the example) and want to color the plot based on the values of another column (<code>df.colors</code>in the example; values are 0, 1, and 2 in this case, but it would be good / more portable if it would also work with <code>float</code>s).</p> <pre...
1
2016-08-22T09:03:30Z
39,076,655
<p>One way to achieve this would be to use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html" rel="nofollow"><code>DF.replace</code></a> and create a nested <code>dictionary</code> to specify the color values for the <code>int/float</code> values to be mapped against.</p> <pr...
2
2016-08-22T10:05:09Z
[ "python", "pandas", "matplotlib" ]
Syntaxnet / Parsey McParseface python API
39,075,339
<p>I've installed syntaxnet and am able to run the parser with the provided demo script. Ideally, I would like to run it directly from python. The only code I found was this:</p> <pre><code>import subprocess import os os.chdir(r"../models/syntaxnet") subprocess.call([ "echo 'Bob brought the pizza to Alice.' | synt...
4
2016-08-22T09:04:15Z
39,815,499
<p>All in all it doesn't look like it would be a problem to refactor the two scripts demo.sh runs (<a href="https://github.com/tensorflow/models/blob/master/syntaxnet/syntaxnet/parser_eval.py" rel="nofollow">https://github.com/tensorflow/models/blob/master/syntaxnet/syntaxnet/parser_eval.py</a> and <a href="https://git...
1
2016-10-02T09:08:53Z
[ "python", "nlp", "syntaxnet", "parsey-mcparseface" ]
Python: Scale each row of 2d array to values that sum to 1. Each row contains some negative values
39,075,390
<p>Let's say I have an array:</p> <pre><code>myArray = [[-1.58, -1.09, -0.41, 0.22, -0.95], [-1.16, -1.27, -1.89, -1.01, 1.11], [-0.73, -0.81, -0.47, -0.46, -0.04], [-1.46, -0.82, 0.40, -0.22, -1.82], [-1.12 , -0.97, -0.89, -0.18, 0.06]] </code></pre> <p>I wish to convert e...
0
2016-08-22T09:06:35Z
39,075,479
<p>Is it what you're asking for:</p> <pre><code>myArray = [[-1.58, -1.09, -0.41, 0.22, -0.95], [-1.16, -1.27, -1.89, -1.01, 1.11], [-0.73, -0.81, -0.47, -0.46, -0.04], [-1.46, -0.82, 0.40, -0.22, -1.82], [-1.12 , -0.97, -0.89, -0.18, 0.06]] print [sum(_list) for _list in myArray] </code></pre> <p>?</p> <pre><...
0
2016-08-22T09:10:53Z
[ "python", "multidimensional-array", "probability" ]
Python: Scale each row of 2d array to values that sum to 1. Each row contains some negative values
39,075,390
<p>Let's say I have an array:</p> <pre><code>myArray = [[-1.58, -1.09, -0.41, 0.22, -0.95], [-1.16, -1.27, -1.89, -1.01, 1.11], [-0.73, -0.81, -0.47, -0.46, -0.04], [-1.46, -0.82, 0.40, -0.22, -1.82], [-1.12 , -0.97, -0.89, -0.18, 0.06]] </code></pre> <p>I wish to convert e...
0
2016-08-22T09:06:35Z
39,076,004
<p>First using min-max normalization to transform original data, this could be one approach:</p> <pre><code>myArray = [[-1.58, -1.09, -0.41, 0.22, -0.95], [-1.16, -1.27, -1.89, -1.01, 1.11], [-0.73, -0.81, -0.47, -0.46, -0.04], [-1.46, -0.82, 0.40, -0.22, -1.82], [-1.12 , -0.97, -0.89, -0.18, 0.06]] #Transform da...
1
2016-08-22T09:35:10Z
[ "python", "multidimensional-array", "probability" ]
Python: Scale each row of 2d array to values that sum to 1. Each row contains some negative values
39,075,390
<p>Let's say I have an array:</p> <pre><code>myArray = [[-1.58, -1.09, -0.41, 0.22, -0.95], [-1.16, -1.27, -1.89, -1.01, 1.11], [-0.73, -0.81, -0.47, -0.46, -0.04], [-1.46, -0.82, 0.40, -0.22, -1.82], [-1.12 , -0.97, -0.89, -0.18, 0.06]] </code></pre> <p>I wish to convert e...
0
2016-08-22T09:06:35Z
39,076,167
<p>As I say, I don't think you can achieve exactly what you need (because if you have a mix of positive and negative values, you'll always have a mix of positive and negative values in the ratio of the value to the sum of the row). But this gets close, I think.</p> <pre><code>import numpy as np myArray = [[-1.58, -1....
1
2016-08-22T09:41:59Z
[ "python", "multidimensional-array", "probability" ]
Python: Scale each row of 2d array to values that sum to 1. Each row contains some negative values
39,075,390
<p>Let's say I have an array:</p> <pre><code>myArray = [[-1.58, -1.09, -0.41, 0.22, -0.95], [-1.16, -1.27, -1.89, -1.01, 1.11], [-0.73, -0.81, -0.47, -0.46, -0.04], [-1.46, -0.82, 0.40, -0.22, -1.82], [-1.12 , -0.97, -0.89, -0.18, 0.06]] </code></pre> <p>I wish to convert e...
0
2016-08-22T09:06:35Z
39,076,603
<p>Here's a working example:</p> <pre><code>data = [[-1.58, -1.09, -0.41, 0.22, -0.95], [-1.16, -1.27, -1.89, -1.01, 1.11], [-0.73, -0.81, -0.47, -0.46, -0.04], [-1.46, -0.82, 0.40, -0.22, -1.82], [-1.12, -0.97, -0.89, -0.18, 0.06]] print[[x / sum(data[r]) for x in data[r]] for r in r...
0
2016-08-22T10:02:34Z
[ "python", "multidimensional-array", "probability" ]
Python matplotlib blit and update a text
39,075,454
<p>I know that this topic is often popping out, but after many tries, searches and give-ups, I am bringing it back to you.</p> <p>I have a class, which contains a matplotlib figure. In this figure, I want a text, and when the user hits some key, the text is updated to something, without drawing all the heavy stuff in ...
0
2016-08-22T09:09:46Z
39,076,800
<p>The previous text still stays behind, because you never removed it - you just drew on top of it. To prevent this, you should save the piece of figure where the text will be, then show the text, then, when the text has changed, restore the saved background and reshow the text.</p> <p><a href="http://matplotlib.org/a...
1
2016-08-22T10:11:36Z
[ "python", "matplotlib", "blit" ]
python __delete__ not working
39,075,469
<p>I'm trying this simple python code:</p> <pre><code>class A: def __init__( self ): self.a = { 'k' : 'kk' } def __delete__( self, key ): del self.a[key] </code></pre> <p>This simple class doesn't work.</p> <pre><code>&gt;&gt;&gt; a = A() &gt;&gt;&gt; del a['k'] Traceback (most recent call last): File ...
-3
2016-08-22T09:10:37Z
39,075,586
<p>In order to achieve the behavior of <code>del a['k']</code> (i.e. deleting an item by index) you should implement the <a href="https://docs.python.org/3/reference/datamodel.html#object.__delitem__" rel="nofollow"><code>__delitem__</code></a> magic method:</p> <pre><code>In [1]: class A: ...: def __init__(sel...
3
2016-08-22T09:16:01Z
[ "python", "python-3.x" ]
RadioSelect with image
39,075,520
<p>Is it possible for Pmw.RadioSelect's buttons to have an icon next to the text? Supposing we have a few buttons added in a Frame, each one of them has different icon on left or right side of text.</p>
-2
2016-08-22T09:12:58Z
39,076,027
<p>You can add images to RadioButton widgets by doing this:</p> <pre><code>from tkinter import * root = Tk() radiobtn = Radiobutton(root) # Image location (add "/" not "\") img = PhotoImage(file="C:/path to image/image.png") # Applying image to the Radiobutton radiobtn.config(image=img) # Display Radiobutton rad...
1
2016-08-22T09:36:10Z
[ "python", "tkinter" ]
IndexError: list index out of range python 3.4
39,075,601
<p>Trying to run this code :</p> <pre><code>sorted_by_name = sorted(sort_array,key=lambda x:x[0])) </code></pre> <p>I get: </p> <blockquote> <p>IndexError: list index out of range</p> </blockquote> <p>How do I resolve this?</p> <p>Thanks</p>
1
2016-08-22T09:16:35Z
39,077,609
<p>Well one of element in the <code>sort_array</code> should be either empty or null string. See the below examples</p> <p>Example #1:</p> <pre><code>sort_array = ['abc', 'acd', 'abcd', ''] sort_array ['abc', 'acd', 'abcd', ''] sorted(sort_array, key=lambda student: student[0]) Traceback (most recent call last): Fi...
1
2016-08-22T10:49:14Z
[ "python", "python-3.x", "lambda" ]
IndexError: list index out of range python 3.4
39,075,601
<p>Trying to run this code :</p> <pre><code>sorted_by_name = sorted(sort_array,key=lambda x:x[0])) </code></pre> <p>I get: </p> <blockquote> <p>IndexError: list index out of range</p> </blockquote> <p>How do I resolve this?</p> <p>Thanks</p>
1
2016-08-22T09:16:35Z
39,077,916
<p>That means that at least one thing in your list is empty so doesn't have a first element. The fix is simple, don't pass a key:</p> <pre><code>sorted_by_name = sorted(sort_array) </code></pre> <p>The default implementation of <code>sorted</code> already tries the first item, then the second item, the third item, e...
0
2016-08-22T11:04:32Z
[ "python", "python-3.x", "lambda" ]
gae intermittent import error (SignedSerializer)
39,075,984
<p>I have a Pyramid app that I'm running on GAE. It works great most of the time but sometimes when I deploy (<code>appcfg.py update ...</code>) things just break. I start getting 500s when I try to access the app. Then if I make absolutely no changes to my code and deploy it again it works. I want the deploy to work e...
0
2016-08-22T09:34:17Z
39,099,313
<p>The problem was that I was pushing webob 1.6.1 to appengine while deploying my app. At the same time I had this in my app.yaml:</p> <pre><code>libraries: - name: webob version: latest </code></pre> <p>What ended up working was just removing webob from app.yaml (I tried different versions supported by gae but no di...
0
2016-08-23T10:59:19Z
[ "python", "google-app-engine", "importerror", "intermittent" ]
Asynchronious email sending using celery doesn't work
39,076,025
<p>I'm trying to make Django not to wait until an email is sent. I've decided to use Celery to do that. Unfortunately I can't figure out how to make it work asynchronously. </p> <p>I've created a file <code>tasks.py</code>:</p> <pre><code># -*- coding: utf-8 -*- from __future__ import absolute_import from .notificati...
0
2016-08-22T09:36:04Z
39,077,043
<p>You are not making async call to <code>prereservation_has_been_confirmed()</code> in order to delay function execution use <code>prereservation_has_been_confirmed.delay(...)</code></p> <pre><code>@csrf_exempt def reservation_confirm(request): if request.method == 'POST': reservation_id = request.POST.ge...
1
2016-08-22T10:22:34Z
[ "python", "django", "celery", "django-celery" ]
Asynchronious email sending using celery doesn't work
39,076,025
<p>I'm trying to make Django not to wait until an email is sent. I've decided to use Celery to do that. Unfortunately I can't figure out how to make it work asynchronously. </p> <p>I've created a file <code>tasks.py</code>:</p> <pre><code># -*- coding: utf-8 -*- from __future__ import absolute_import from .notificati...
0
2016-08-22T09:36:04Z
39,077,246
<p>[Following the comments] your task was correctly sent to the broker (to the database in your case) you can probably check that your pending task is there.</p> <p>you don't see anything in the console because you must launch a celery worker that will read all the pending tasks on the broker and will execute them. <a...
2
2016-08-22T10:31:57Z
[ "python", "django", "celery", "django-celery" ]
How do I add the wires.exe directory to the system environment variables
39,076,079
<p>I have a python program that uses the marionette driver for firefox and for it to work the directory of the driver must be added to PATH. I've packaged the driver with the program and I want the python script to automatically add the driver directory to the system PATH. Is it possible to do that in python?</p>
0
2016-08-22T09:38:19Z
39,076,149
<p>Yes, it's possible :) </p> <pre><code>import sys sys.path.insert(0, "C:/path/to/your/driver") </code></pre> <p>This adds to PATH only temporarily. If you want more permanent change, take a look at <a href="http://stackoverflow.com/questions/3402168/permanently-add-a-directory-to-pythonpath">Permanently add a dire...
0
2016-08-22T09:41:13Z
[ "python", "windows", "selenium" ]
returning multiple values in view django
39,076,112
<p>I'm having some difficulty returning multiple values in my view. I can create a model, store the values in the model, and then return it, but this approach is not what I'm looking for because these values will be used once only.</p> <p>Is it possible to return multiple values without storing them in a model?</p> <...
1
2016-08-22T09:39:50Z
39,076,254
<p>I don't understand your sample code here. The third parameter to <code>render</code> is a dictionary, and you can have as many items as you like in it.</p> <pre><code>return render(request, 'blog/draw.html', {'loanAmount': loanAmount, 'repaymentTime': repaymentTime}) </code></pre>
4
2016-08-22T09:46:09Z
[ "python", "django" ]
if statement always takes first condition python
39,076,133
<p>I am working on a basic python programme where I input a recipe I want to make and the quantity I want to make and the programme should calculate how much of each ingredient I need based on an excel file with the quantities per liter and subtracts the amounts I used from another excel file which contains a list of i...
0
2016-08-22T09:40:18Z
39,076,255
<p>Which version of Python do you use?</p> <p>Possibly, you would have to write <code>input()</code> instead of <code>raw_input()</code> (which would result in a non-string variable)? What is the <code>print</code> statement used for?</p>
1
2016-08-22T09:46:10Z
[ "python", "excel", "if-statement", "condition" ]
if statement always takes first condition python
39,076,133
<p>I am working on a basic python programme where I input a recipe I want to make and the quantity I want to make and the programme should calculate how much of each ingredient I need based on an excel file with the quantities per liter and subtracts the amounts I used from another excel file which contains a list of i...
0
2016-08-22T09:40:18Z
39,077,846
<p>I found my mistake: it should be </p> <pre><code>if recipe == 'recipe1' or recipe == 'RECIPE1': wb1 = load_workbook('recipe1.xlsx') elif recipe == 'recipe2' or recipe == 'RECIPE2': wb1 = load_workbook('recipe2.xlsx') </code></pre> <p>thank you all for taking the time to help me!</p>
0
2016-08-22T11:01:37Z
[ "python", "excel", "if-statement", "condition" ]
Python2 + 3 : How to install modules for Python3 installed from sources and offline?
39,076,141
<p>I'm using RedHat Linux 6 and currently I only have 2.6.X version available from internal Linux repository. So I installed <strong>Python2 package(s) from repository</strong> and in parallel I installed <strong>python3 from sources into /opt directory</strong> :</p> <pre><code>$ ll /usr/bin/python3 lrwxrwxrwx. 1 roo...
0
2016-08-22T09:40:50Z
39,076,413
<p>You can use virtualenv to built individual enviroment for different python version, then install thirdparty libraries with offline install package.</p>
0
2016-08-22T09:54:11Z
[ "python", "linux", "install", "offline", "python-module" ]
Python2 + 3 : How to install modules for Python3 installed from sources and offline?
39,076,141
<p>I'm using RedHat Linux 6 and currently I only have 2.6.X version available from internal Linux repository. So I installed <strong>Python2 package(s) from repository</strong> and in parallel I installed <strong>python3 from sources into /opt directory</strong> :</p> <pre><code>$ ll /usr/bin/python3 lrwxrwxrwx. 1 roo...
0
2016-08-22T09:40:50Z
39,076,656
<ol> <li><p>Change your "python.exe" in your python3 install folder into "python3.exe". Make sure you can use "python" to start Python2 and "pyhton3" to start python3.</p></li> <li><p>For Python3, use the command <code>python3 -m pip</code></p></li> </ol>
1
2016-08-22T10:05:13Z
[ "python", "linux", "install", "offline", "python-module" ]
Generating a image with a List in python Pillow doesnt work
39,076,165
<p>I recently started using pillow for some project but I can't manage to generate a image with a list object. Every int in the list has a value between 0 and 255. So this is my relevant code:</p> <pre><code> img = Image.new('L',(width,height)) img.putdata(pixel) img.save('img.png') </code></pre> <p>The output is ...
1
2016-08-22T09:41:56Z
39,076,537
<p>Use like this:</p> <pre><code>from PIL import Image pixel = [] for i in range(300*100): pixel.append((255,0,0)) for i in range(300*100): pixel.append((0,255,0)) for i in range(300*100): pixel.append((0,0,255)) img = Image.new('RGB',(300,300)) img.putdata(pixel) img.show() </code></pre> <p>Then you ge...
1
2016-08-22T09:59:42Z
[ "python", "python-imaging-library", "pillow" ]
Sort list of key value pairs in python dictionary
39,076,314
<p>How can I sort an adjacency list in python that is store as a dictionary?</p> <pre><code>Adjacency List: 0: [(7, 0.16), (4, 0.38), (2, 0.26), (6, 0.58)] 1: [(5, 0.32), (7, 0.19), (2, 0.36), (3, 0.29)] 2: [(3, 0.17), (0, 0.26), (1, 0.36), (7, 0.34), (6, 0.4)] 3: [(2, 0.17), (1, 0.29), (6, 0.52)] 4: [(5, 0.35), (7, 0...
1
2016-08-22T09:49:25Z
39,076,389
<p><a href="https://docs.python.org/3/library/functions.html#sorted" rel="nofollow"><code>sorted</code></a> returns a new sorted list given an iterable. If you want to sort in-place, use <a href="https://docs.python.org/3/library/stdtypes.html?highlight=sort#list.sort" rel="nofollow"><code>list.sort()</code></a>:</p> ...
4
2016-08-22T09:53:08Z
[ "python", "list", "sorting", "dictionary", "adjacency-list" ]
Sort list of key value pairs in python dictionary
39,076,314
<p>How can I sort an adjacency list in python that is store as a dictionary?</p> <pre><code>Adjacency List: 0: [(7, 0.16), (4, 0.38), (2, 0.26), (6, 0.58)] 1: [(5, 0.32), (7, 0.19), (2, 0.36), (3, 0.29)] 2: [(3, 0.17), (0, 0.26), (1, 0.36), (7, 0.34), (6, 0.4)] 3: [(2, 0.17), (1, 0.29), (6, 0.52)] 4: [(5, 0.35), (7, 0...
1
2016-08-22T09:49:25Z
39,076,435
<p>Here's a working example:</p> <pre><code>my_dict = { 0: [(7, 0.16), (4, 0.38), (2, 0.26), (6, 0.58)], 1: [(5, 0.32), (7, 0.19), (2, 0.36), (3, 0.29)], 2: [(3, 0.17), (0, 0.26), (1, 0.36), (7, 0.34), (6, 0.4)], 3: [(2, 0.17), (1, 0.29), (6, 0.52)], 4: [(5, 0.35), (7, 0.37), (0, 0.38), (6, 0.93)],...
1
2016-08-22T09:55:13Z
[ "python", "list", "sorting", "dictionary", "adjacency-list" ]
Sort list of key value pairs in python dictionary
39,076,314
<p>How can I sort an adjacency list in python that is store as a dictionary?</p> <pre><code>Adjacency List: 0: [(7, 0.16), (4, 0.38), (2, 0.26), (6, 0.58)] 1: [(5, 0.32), (7, 0.19), (2, 0.36), (3, 0.29)] 2: [(3, 0.17), (0, 0.26), (1, 0.36), (7, 0.34), (6, 0.4)] 3: [(2, 0.17), (1, 0.29), (6, 0.52)] 4: [(5, 0.35), (7, 0...
1
2016-08-22T09:49:25Z
39,076,523
<p>You can use <a href="https://docs.python.org/3/library/stdtypes.html?highlight=sort#list.sort" rel="nofollow"><code>list.sort()</code></a> with a key function. Since you want to sort by the second element of each tuple, the key function must select the second item (<code>t[1]</code> below) from each tuple, <code>t</...
1
2016-08-22T09:59:15Z
[ "python", "list", "sorting", "dictionary", "adjacency-list" ]
How to get all key combinations after groupby in Python Pandas
39,076,360
<p>I would like to have all combination of keys after a groupby so if <code>a</code> has <code>na</code> unique values and <code>b</code> has <code>nb</code> unique values than the number of output rows should be <code>na*nb</code>. I have tried <code>reindex</code> and <code>reindex_axis</code> but it didn't work:</p>...
0
2016-08-22T09:51:51Z
39,076,442
<p>You can use reindex:</p> <pre><code>idx = pd.MultiIndex.from_product((df['a'].unique(), df['b'].unique())) df.groupby(['a','b']).count().reindex(idx) Out: c 1 1 1.0 2 1.0 3 NaN 4 NaN 2 1 NaN 2 NaN 3 1.0 4 NaN 3 1 NaN 2 NaN 3 NaN 4 1.0 </code></pre>
4
2016-08-22T09:55:45Z
[ "python", "pandas", "group-by" ]
Tensorflow Deep MNIST: Resource exhausted: OOM when allocating tensor with shape[10000,32,28,28]
39,076,388
<p>This is the sample MNIST code I am running:</p> <pre><code>from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets('MNIST_data', one_hot=True) import tensorflow as tf sess = tf.InteractiveSession() x = tf.placeholder(tf.float32, shape=[None, 784]) y_ = tf.placeholder(tf.float3...
0
2016-08-22T09:53:01Z
39,080,568
<p>Here is how I solved this problem: the error means that the GPU runs out of memory during accuracy evaluation. Hence it needs a smaller sized dataset, which can be achieved by using data in batches. So, instead of running the code on the whole test dataset it needs to be run in batches as mentioned in this post: <a ...
0
2016-08-22T13:13:49Z
[ "python", "tensorflow", "gpu", "mnist" ]
Python 2.7.8 for line iteration error
39,076,390
<p>I want to iterate over all lines in a file with the following script</p> <pre><code>import sys infile = open("test.txt") infile.read() for line in infile if line.find("This") != -1 print line infile.close() </code></pre> <p>Unfortunately, I am getting this error message:</p> <pre><code> File "getR...
-3
2016-08-22T09:53:09Z
39,076,411
<p>You need a colon after any line that introduces a block in Python.</p> <pre><code>for line in infile: if line.find("This") != -1: </code></pre>
2
2016-08-22T09:54:07Z
[ "python", "python-2.7" ]
Python 2.7.8 for line iteration error
39,076,390
<p>I want to iterate over all lines in a file with the following script</p> <pre><code>import sys infile = open("test.txt") infile.read() for line in infile if line.find("This") != -1 print line infile.close() </code></pre> <p>Unfortunately, I am getting this error message:</p> <pre><code> File "getR...
-3
2016-08-22T09:53:09Z
39,082,348
<p>There's another mistake in your code, you don't need:</p> <pre><code>infile.read() </code></pre> <p>Because it reads all contens of infile and doesn't save it to any variable. And what is more important it moves you to the end of file, so there's no more lines to read.</p> <p>In addition there's no need to manual...
0
2016-08-22T14:38:27Z
[ "python", "python-2.7" ]
How to configure an external package into Apache Spark?
39,076,553
<p>I am building a python script executed using <strong>spark-submit</strong> command to retrieve data from <strong>MongoDB</strong> collection and process fetched data to generate analytics. I am utilizing MongoDB Spark connector to query a MongoDB collection using <strong>--packages</strong> option.</p> <p>But I nee...
0
2016-08-22T10:00:12Z
39,078,268
<p>From <a href="http://spark.apache.org/docs/latest/submitting-applications.html" rel="nofollow">http://spark.apache.org/docs/latest/submitting-applications.html</a>:</p> <blockquote> <p>For Python, you can use the --py-files argument of spark-submit to add .py, .zip or .egg files to be distributed with your applic...
1
2016-08-22T11:22:37Z
[ "python", "mongodb", "apache-spark", "pyspark" ]
Required and optional arguments in function
39,076,601
<p>I have a problem with using optional and required arguments in a function.</p> <pre><code>def process_data(*stock, currency) </code></pre> <p>With the arguments</p> <pre><code>process_data('IVV', 'QQQ', 'USD') </code></pre> <p>Yields the error "TypeError: process_data() missing 1 required keyword-only argument: ...
-1
2016-08-22T10:02:31Z
39,076,681
<p>You need to tell Python that USD is the currency as it has no other way of knowing how to assign values to your variables:</p> <pre><code>process_data('IVV', 'QQQ', currency='USD') </code></pre>
2
2016-08-22T10:06:08Z
[ "python", "python-3.x" ]
Required and optional arguments in function
39,076,601
<p>I have a problem with using optional and required arguments in a function.</p> <pre><code>def process_data(*stock, currency) </code></pre> <p>With the arguments</p> <pre><code>process_data('IVV', 'QQQ', 'USD') </code></pre> <p>Yields the error "TypeError: process_data() missing 1 required keyword-only argument: ...
-1
2016-08-22T10:02:31Z
39,076,727
<p>Using <code>*params</code> in a function <em>definition</em> groups all positional arguments as a tuple when that function is called. In order to catch any extra arguments you'll need to supply them in keyword form; i.e supply their name:</p> <pre><code>process_data('IVV', 'QQQ', currency='USD') </code></pre> <p>...
0
2016-08-22T10:08:21Z
[ "python", "python-3.x" ]
Error using numpy.polyfit in a cx_freezed program
39,076,682
<p>I'm trying to build a standalone program using <code>cx_freeze</code> in Python 3.4.</p> <p>When I execute my program through Python there is absolutely no problems (0 errors, everything works), but when I open the <code>.exe</code> file created with <code>cx_freeze</code>, my GUI (Qt) just closes when I'm calling ...
0
2016-08-22T10:06:09Z
39,098,331
<p>I solved my problem with :</p> <ul> <li><p>uninstalling all the packages numpy/scipy</p></li> <li><p>reinstall the whl with pip (numpy-1.11.1+mkl-cp34-cp34m-win32.whl and scipy-0.18.0-cp34-cp34m-win32.whl)</p></li> <li><p>install numpy-1.9.2-win32-superpack-python3.4.exe from <a href="https://sourceforge.net/projec...
0
2016-08-23T10:13:39Z
[ "python", "python-3.x", "numpy", "cx-freeze" ]
How do I make the code return the text using xpath?
39,076,965
<pre><code>from lxml import html import requests import time #Gets prices page = requests.get('https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&amp;field-keywords=hi') tree = html.fromstring(page.content) price = tree.xpath('//h2[@data-attribute="Hi Guess the Food - What’s the Food Brand in the Pictur...
-1
2016-08-22T10:18:47Z
39,077,212
<p>One general advice when you're trying to scrap something from some website. Take a look first to the returned content, in this case <code>page.content</code> before trying anything. You're assuming wrongly amazon is allowing you nicely to fetch their data, when they don't.</p>
0
2016-08-22T10:30:41Z
[ "python", "python-3.x", "parsing", "xpath" ]
How do I make the code return the text using xpath?
39,076,965
<pre><code>from lxml import html import requests import time #Gets prices page = requests.get('https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&amp;field-keywords=hi') tree = html.fromstring(page.content) price = tree.xpath('//h2[@data-attribute="Hi Guess the Food - What’s the Food Brand in the Pictur...
-1
2016-08-22T10:18:47Z
39,077,970
<p>I think urllib2 is better, and xpath could be: </p> <pre><code>price = c.xpath('//div[@class="s-item-container"]//h2')[0] print price.text </code></pre> <p>After all, long string may contains strange characters.</p>
0
2016-08-22T11:07:14Z
[ "python", "python-3.x", "parsing", "xpath" ]
Can't Open Word File With Space
39,076,967
<p>I use sikuli to open doc file </p> <pre><code>cmd = r"C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE c:\report\Monthly report 2016.doc" openApp(cmd) </code></pre> <p>It can't be opened but when i renamed no space to Monthly.doc it can be opened</p>
1
2016-08-22T10:18:55Z
39,077,017
<p>try insert '\' before the space..</p>
0
2016-08-22T10:21:33Z
[ "python", "sikuli", "sikuli-script" ]
Can't Open Word File With Space
39,076,967
<p>I use sikuli to open doc file </p> <pre><code>cmd = r"C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE c:\report\Monthly report 2016.doc" openApp(cmd) </code></pre> <p>It can't be opened but when i renamed no space to Monthly.doc it can be opened</p>
1
2016-08-22T10:18:55Z
39,097,697
<p>First, App.open is advised as openApp is deprecated. Regardless though this is a command line type problem. It is all about wrapping the quotes. Both should work:</p> <pre><code>App.open(r'"C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE" "c:\report\Monthly report 2016.doc"') openApp(r'"C:\Program Fil...
1
2016-08-23T09:43:10Z
[ "python", "sikuli", "sikuli-script" ]
How to print upto n elements in a list
39,077,005
<p>I want to print upto 50 elements in a list</p> <p>i.e If there are 100 elements in the list I need first 50 alone. My current code for the above is 'Filter':switcheroo.get(zaxis,["None Selected"])[zaxis]<strong>.unique().tolist()[:50]</strong></p> <p>If there are 25 elements in the list I need 25 alone. I get an ...
-2
2016-08-22T10:20:39Z
39,077,159
<p>first 50 elements of a list:</p> <pre><code> print mylist[:50] </code></pre> <p>as an iterable:</p> <pre><code> print [x for x in mylist[:50]] </code></pre> <p>Test:</p> <pre><code>newlist = [x for x in xrange(10)] newlist2 = [x for x in xrange(100)] print [x for x in newlist[:50]] &gt;[1,2,3,4,5,6,7,8,9]...
2
2016-08-22T10:28:29Z
[ "python" ]
Set a Python indent in Anaconda
39,077,179
<p>So I've got a problem. I installed Anaconda with Python 3.5.2 and when I go for <code>cmd&gt;python</code> then interpreter is on, and then when I try:</p> <pre><code>for i in range(10): print(i) </code></pre> <p>Then a message pops out (when I press TAB):</p> <pre><code>Readline internal error Traceback (mos...
0
2016-08-22T10:29:11Z
39,078,259
<p>I think it's not a problem with Anaconda but with your Windows console.</p>
0
2016-08-22T11:22:24Z
[ "python", "anaconda" ]
Matplotlib animation: how to make some lines not visible
39,077,240
<p>I am reading some sensors values by serial port.<br> I would like to be able to show/hide the respective lines according to key presses.</p> <p>Here is the code: it has been overly simplified (sorry it is long anyway). I would like to make ALL blue lines in the 3 subplots show/hide by pressing <kbd>1</kbd>; all red...
1
2016-08-22T10:31:48Z
39,077,335
<p>You should hide/show the lines:</p> <pre><code>lineVal1.set_visible(showLines1) lineSpeed1.set_visible(showLines1) lineAccel1.set_visible(showLines1) lineVal2.set_visible(showLines2) lineSpeed2.set_visible(showLines2) lineAccel2.set_visible(showLines2) </code></pre>
1
2016-08-22T10:36:32Z
[ "python", "animation", "matplotlib", "keyboard" ]
Why does this variable does not update
39,077,265
<p>I'm working on a card game. The point is that when the user clicks on two cards, they turn face up. If they're not the same, when they click on the third one, the first two disappear (this has not been implemented yet).</p> <p>I'm trying to use to variables: <strong>first_card</strong> and <strong>second_card</stro...
-2
2016-08-22T10:32:50Z
39,077,461
<p>You need to define the global state variable, that code is crashing and probably it isnt updating the first_card value</p> <pre><code>import random state = 0 deck = range(0, 8)* 2 exposed = [False] * len(deck) print exposed w = 50 h = 100 WIDTH = w * 16 + 2 HEIGHT = 102 first_card = 0 second_card = 0 </code></pre>...
0
2016-08-22T10:42:04Z
[ "python", "for-loop", "global-variables" ]
Why does this variable does not update
39,077,265
<p>I'm working on a card game. The point is that when the user clicks on two cards, they turn face up. If they're not the same, when they click on the third one, the first two disappear (this has not been implemented yet).</p> <p>I'm trying to use to variables: <strong>first_card</strong> and <strong>second_card</stro...
-2
2016-08-22T10:32:50Z
39,078,726
<p>First of all, it's not true your statement of <code>it won't work unless you run it in CodeSkulptor</code>, you can find simplegui on pip and everybody can run your code without using CodeSkulptor. I'm wondering what's the reason for getting downvotes, so don't get bothered by them.</p> <p>Now, about your bug... Le...
0
2016-08-22T11:46:46Z
[ "python", "for-loop", "global-variables" ]
Insert paragraph from Python Flask to HTML
39,077,355
<p>I'm new to Flask in Python. I've managed to transfer values from my python code to an HTML page. I'm trying to transfer one value which is actually a long paragraph. I have a loop creating this long text: </p> <pre><code>google_str += num + '. ' + title + '\n' + url + '\n' </code></pre> <p>I want this to eventual...
1
2016-08-22T10:37:28Z
39,077,453
<p>Found what I was looking for.</p> <p>First, I had to use "&lt; br >" instead of '/n'. Second, use this in my HTML:</p> <pre><code>{{google_str|safe}} </code></pre> <p><a href="http://stackoverflow.com/questions/12253259/new-lines-in-flask-within-block-content">This is where I found the answer.</a></p>
0
2016-08-22T10:41:44Z
[ "python", "html", "python-2.7", "flask" ]
Python, take value of a list from an input
39,077,499
<p>Hi guys i'm Learning python, i have this problem, for not create 1000 "if" function i would did that:</p> <pre><code>#Vari flag print "choose flag" print "(1) Syn" print "(2) Ack" print "(3) Push" print "(4) Fin" print "(5) Urg" print "(6) Rst" flag-list = ["--syn","--ack","--push","--fin","--urg","--rst"] flag = ...
-7
2016-08-22T10:43:48Z
39,077,549
<pre><code># Note that variable names cannot contain hyphens flag_list = ["--syn","--ack","--push","--fin","--urg","--rst"] # This clearly has to be in quotes user_input = raw_input("Enter numbers separated by comma:" ) # Split the user input string at the commas, and turn each element into an integer. flag_nums = ma...
1
2016-08-22T10:46:23Z
[ "python" ]
python dataframe to excel
39,077,566
<p>At this moment i'm trying to convert a dataframe into excel file, using <code>df.to_excel</code>. I've already done it with an older project before but now I have a dataframe which contains more than one value in some cases of the table.<br> For example there is a little part on my dataframe; we can see that the 2 l...
2
2016-08-22T10:47:05Z
39,078,510
<p>Have you tried setting merge_cells=True?</p> <p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_excel.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_excel.html</a></p>
0
2016-08-22T11:35:50Z
[ "python", "excel", "pandas", "dataframe" ]
Can a Python inner class be a subclass of its own outer class?
39,077,623
<p>This...</p> <pre><code>class A(object): class B(A): def __init__(self): pass </code></pre> <p>... throws "NameError: name 'A' is not defined".</p> <p>Is there proper syntax to accomplish this, or must I use workarounds, like this?</p> <pre><code>class A(object): pass class _B(A): ...
0
2016-08-22T10:50:01Z
39,077,925
<p>As per OPs request, posting as an answer.</p> <ol> <li><p>That's an inner class, not a subclass.</p></li> <li><p>No, an inner class can't inherit (not extend) its outer class because the outer class is not fully defined while defining the inner class.</p></li> <li><p>Your workaround is not a work around, as it does...
1
2016-08-22T11:04:52Z
[ "python", "python-2.7", "inheritance", "subclass" ]
Can a Python inner class be a subclass of its own outer class?
39,077,623
<p>This...</p> <pre><code>class A(object): class B(A): def __init__(self): pass </code></pre> <p>... throws "NameError: name 'A' is not defined".</p> <p>Is there proper syntax to accomplish this, or must I use workarounds, like this?</p> <pre><code>class A(object): pass class _B(A): ...
0
2016-08-22T10:50:01Z
39,078,040
<p>You can not do this the normal way and probably should not do this.</p> <p>For those who have a valid reason to attempt something similar, there is a workaround by dynamically changing the superclass of <code>A.B</code> after <code>A</code> is fully defined (see <a href="http://stackoverflow.com/a/9639512/5069869">...
1
2016-08-22T11:10:47Z
[ "python", "python-2.7", "inheritance", "subclass" ]
Gzip compression and http post from python to java
39,077,711
<p>I want to http post a gzip compressed data from python to java and I want to store it as a BLOB in database. Then I want to gzip decompress that BLOB in java. So I want to know howto post a BLOB in python and how to read a BLOB in java. I have given my python and java code below. In my code I gzip compress a string ...
0
2016-08-22T10:55:21Z
39,078,035
<p>Have you checked this: <a href="http://stackoverflow.com/questions/8156707/gzip-a-file-in-python">gzip a file in Python</a> ?</p> <p>My guess is that your string </p> <pre><code>m='hello'+'\r\n'+'world' </code></pre> <p>is possibly causing some issues with the whole process...</p> <p>Have you considered replaci...
0
2016-08-22T11:10:27Z
[ "java", "python", "http-post", "gzip", "decompression" ]
Gzip compression and http post from python to java
39,077,711
<p>I want to http post a gzip compressed data from python to java and I want to store it as a BLOB in database. Then I want to gzip decompress that BLOB in java. So I want to know howto post a BLOB in python and how to read a BLOB in java. I have given my python and java code below. In my code I gzip compress a string ...
0
2016-08-22T10:55:21Z
39,091,858
<p>You can't read the compressed data to string directly.What you have done in <code>readCompressedData</code> method is reading the compressed data to literal(which lead to a wrong string) and then get it's bytes(in method main).After you doing this,the <code>contentInBytes</code> is not really the bytes stored in the...
0
2016-08-23T03:27:31Z
[ "java", "python", "http-post", "gzip", "decompression" ]
Sending values from one python script to another to another
39,077,812
<p>so i've got some values coming in from an Arduino to my Raspberry Pi via an RF transceiver (NRF24L01) and i can display the integers when the program runs (Python). Now i want to display those integer values in my GUI that i've written in a seperate python script. I'm having trouble doing so. I've tried importing th...
2
2016-08-22T10:59:49Z
39,079,116
<p>You should try to combine the data-receiving code and data-displaying code with <code>threading</code> library.</p> <p>In the <code>while True</code> loop in the data-receiving script, it should check for new result and notify the GUI thread somehow (eg. store it in a global variable and use the <code>threading.Con...
1
2016-08-22T12:06:07Z
[ "python", "tkinter" ]
Unable to crawl some href in a webpage using python and beautifulsoup
39,077,890
<p>I am currently crawling a web page using Python 3.4 and bs4 in order to collect the match results played by Serbia in Rio2016. So the url <a href="http://rio2016.fivb.com/en/volleyball/women/teams/srb-serbia#wcbody_0_wcgridpadgridpad1_1_wcmenucontent_3_Schedule" rel="nofollow">here</a> contains links to all the matc...
3
2016-08-22T11:03:14Z
39,079,215
<p>The data is created dynamically, if you look at the actual source you can see <a href="https://docs.angularjs.org/tutorial/step_02" rel="nofollow">Angularjs</a> templating.</p> <p>You can still get all the info in json format by mimicking an ajax call, in the source yuuuuou can also see a div like:</p> <pre><code>...
1
2016-08-22T12:11:26Z
[ "python", "html", "beautifulsoup", "tabpage" ]
Unable to crawl some href in a webpage using python and beautifulsoup
39,077,890
<p>I am currently crawling a web page using Python 3.4 and bs4 in order to collect the match results played by Serbia in Rio2016. So the url <a href="http://rio2016.fivb.com/en/volleyball/women/teams/srb-serbia#wcbody_0_wcgridpadgridpad1_1_wcmenucontent_3_Schedule" rel="nofollow">here</a> contains links to all the matc...
3
2016-08-22T11:03:14Z
39,081,222
<p>Thanks for all your help now I can get the correct url. It is a good learning experience for me. Thanks a lot :)</p> <pre><code>from bs4 import BeautifulSoup import requests Countryr = requests.get('http://rio2016.fivb.com/en/volleyball/women/teams/srb-serbia#wcbody_0_wcgridpadgridpad1_1_wcmenucontent_3_Schedule')...
1
2016-08-22T13:44:35Z
[ "python", "html", "beautifulsoup", "tabpage" ]
IPython.display.Audio cannot correctly handle `.ogg` file type?
39,077,987
<p>I was doing some audio analysis stuff with Jupyter and tried to play <code>.ogg</code> files with <code>IPython.display.Audio</code>. Since PyCharm often failed to open big <code>.ipynb</code> files, I mostly used web browser to view my Notebook files at <code>localhost:8888</code>.</p> <p><a href="http://i.stack.i...
2
2016-08-22T11:07:57Z
39,084,114
<p>Since no one gives a hint, I guess I'll have to work alone...</p> <p>First look into the source code of <code>IPython.display.audio</code>: <a href="https://github.com/ipython/ipython/blob/48b01aadcbb6a53d2c77fa250c8a4344931c357c/IPython/lib/display.py" rel="nofollow">ipython/display.py at 48b01aadcbb6a53d2c77fa250...
2
2016-08-22T16:07:36Z
[ "python", "ipython", "mime", "jupyter", "ogg" ]
How to find closest elements in two array?
39,078,043
<p>I have two numpy arrays, like <code>X=[x1,x2,x3,x4], y=[y1,y2,y3,y4]</code>. Three of the elements are close and the fourth of them maybe close or not.</p> <p>Like:</p> <pre><code>X [ 84.04467948 52.42447842 39.13555678 21.99846595] y [ 78.86529444 52.42447842 38.74910101 21.99846595] </code></pre> <p>O...
5
2016-08-22T11:10:53Z
39,078,294
<p>Seems like best approach would be to pre-sort both array (n<em>log(n)) and then perform merge-like traverse through both arrays. It's definitely faster than n</em>n which you indicated in comment.</p>
2
2016-08-22T11:24:11Z
[ "python", "python-2.7" ]
How to find closest elements in two array?
39,078,043
<p>I have two numpy arrays, like <code>X=[x1,x2,x3,x4], y=[y1,y2,y3,y4]</code>. Three of the elements are close and the fourth of them maybe close or not.</p> <p>Like:</p> <pre><code>X [ 84.04467948 52.42447842 39.13555678 21.99846595] y [ 78.86529444 52.42447842 38.74910101 21.99846595] </code></pre> <p>O...
5
2016-08-22T11:10:53Z
39,078,582
<p>Using this answer <a href="http://stackoverflow.com/a/8929827/3627387">http://stackoverflow.com/a/8929827/3627387</a> and <a href="http://stackoverflow.com/a/12141207/3627387">http://stackoverflow.com/a/12141207/3627387</a></p> <p><strong>FIXED</strong></p> <pre><code>def find_closest(alist, target): return mi...
3
2016-08-22T11:39:32Z
[ "python", "python-2.7" ]
How to find closest elements in two array?
39,078,043
<p>I have two numpy arrays, like <code>X=[x1,x2,x3,x4], y=[y1,y2,y3,y4]</code>. Three of the elements are close and the fourth of them maybe close or not.</p> <p>Like:</p> <pre><code>X [ 84.04467948 52.42447842 39.13555678 21.99846595] y [ 78.86529444 52.42447842 38.74910101 21.99846595] </code></pre> <p>O...
5
2016-08-22T11:10:53Z
39,079,552
<p>You can start by precomputing the distance matrix as show in this <a href="http://stackoverflow.com/a/9704775/6614295">answer</a>:</p> <pre><code>import numpy as np X = np.array([84.04467948,60.,52.42447842,39.13555678]) Y = np.array([78.86529444,52.42447842,38.74910101,21.99846595]) dist = np.abs(X[:, np.newaxis...
1
2016-08-22T12:27:10Z
[ "python", "python-2.7" ]
How to find closest elements in two array?
39,078,043
<p>I have two numpy arrays, like <code>X=[x1,x2,x3,x4], y=[y1,y2,y3,y4]</code>. Three of the elements are close and the fourth of them maybe close or not.</p> <p>Like:</p> <pre><code>X [ 84.04467948 52.42447842 39.13555678 21.99846595] y [ 78.86529444 52.42447842 38.74910101 21.99846595] </code></pre> <p>O...
5
2016-08-22T11:10:53Z
39,097,490
<p>The below simply prints the corresponding indexes of the two arrays as you have done in your question as I'm not sure what output you want your function to give.</p> <pre><code>X1 = [84.04467948, 52.42447842, 39.13555678, 21.99846595] Y1 = [78.86529444, 52.42447842, 38.74910101, 21.99846595] X2 = [84.04467948, 60,...
0
2016-08-23T09:32:40Z
[ "python", "python-2.7" ]
Converting a dataframe to dictionary with multiple values
39,078,078
<p>I have a dataframe like</p> <pre><code>Sr.No ID A B C D 1 Tom Earth English BMW 2 Tom Mars Spanish BMW Green 3 Michael Mercury Hindi Audi Yellow 4 John Venus Portugese Mercedes Blue 5 John ...
2
2016-08-22T11:13:00Z
39,078,825
<p>You can use <code>groupby</code> with orient of <a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.DataFrame.to_dict.html" rel="nofollow"><code>to_dict</code></a> as <code>list</code> and convert the resultant series to a <code>dictionary</code>.</p> <pre><code>df.set_index('Sr.No', inpla...
2
2016-08-22T11:51:54Z
[ "python", "pandas", "dictionary", "dataframe" ]
Converting a dataframe to dictionary with multiple values
39,078,078
<p>I have a dataframe like</p> <pre><code>Sr.No ID A B C D 1 Tom Earth English BMW 2 Tom Mars Spanish BMW Green 3 Michael Mercury Hindi Audi Yellow 4 John Venus Portugese Mercedes Blue 5 John ...
2
2016-08-22T11:13:00Z
39,078,846
<p>Grouping by <code>'ID'</code> and apply <code>to_dict</code> to each group with <code>orient='list'</code> comes pretty close:</p> <pre><code>df.groupby('ID').apply(lambda dfg: dfg.to_dict(orient='list')).to_dict() Out[25]: {'John': {'A': ['Venus', nan], 'B': ['Portugese', 'German'], 'C': ['Mercedes', 'Audi'],...
2
2016-08-22T11:52:26Z
[ "python", "pandas", "dictionary", "dataframe" ]
central path for python modules
39,078,177
<p>I am starting to convert a lot of C stuff in python 3.</p> <p>In C I defined a directory called "Toolbox", where i put all my functions i needed in different programs, so called libraries.</p> <p>To use a specific library i had just to add the line</p> <pre><code>#include "/home/User/Toolbox/VectorFunctions.h" </...
1
2016-08-22T11:18:32Z
39,078,449
<p>You can use python path. Writing this code beginning of your program :</p> <pre><code>import sys sys.path.append('/home/User/Python_Toolbox') </code></pre> <p>If you have <code>VectorFunctions.py</code> in this folder you can import it :</p> <pre><code>import VectorFunctions </code></pre>
1
2016-08-22T11:32:54Z
[ "python" ]
central path for python modules
39,078,177
<p>I am starting to convert a lot of C stuff in python 3.</p> <p>In C I defined a directory called "Toolbox", where i put all my functions i needed in different programs, so called libraries.</p> <p>To use a specific library i had just to add the line</p> <pre><code>#include "/home/User/Toolbox/VectorFunctions.h" </...
1
2016-08-22T11:18:32Z
39,078,643
<p>What I would do is to organize these toolbox functions into one installable Python package <code>bruno_toolbox</code>, with its <code>setup.py</code>, and then install it into development mode to system site packages, using <code>python setup.py develop</code>, and then use the <code>bruno_toolbox</code> like any ot...
3
2016-08-22T11:42:25Z
[ "python" ]
How to form clusters from a list of related ordered pairs (lists)? Please read the details
39,078,251
<p>Suppose we have a list of lists, <code>master = [[1,2], [2,5], [3,5], [7,8], [11,8], [11,12]]</code> where each ordered-pair is related, meaning <strong>1,2 are related and so are 2,5</strong> and they follow <em>Transitive</em> <em>property</em>, implies, <code>1,2,5</code> belong to the same cluster. </p> <p>The ...
-3
2016-08-22T11:22:11Z
39,078,341
<p>Scipy has an implementation of connected components that look suitable for this problem, see <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.connected_components.html" rel="nofollow">scipy.sparse.csgraph.connected_components</a>.</p>
0
2016-08-22T11:26:39Z
[ "python", "graph" ]
How to form clusters from a list of related ordered pairs (lists)? Please read the details
39,078,251
<p>Suppose we have a list of lists, <code>master = [[1,2], [2,5], [3,5], [7,8], [11,8], [11,12]]</code> where each ordered-pair is related, meaning <strong>1,2 are related and so are 2,5</strong> and they follow <em>Transitive</em> <em>property</em>, implies, <code>1,2,5</code> belong to the same cluster. </p> <p>The ...
-3
2016-08-22T11:22:11Z
39,080,512
<p>Let regard the master list as a record of points and edges between them. Which means there are 8 points 1, 2, 3, 5, 7, 8, 11, 12, and 6 edges between them. Following code may give you what you want.</p> <pre><code>import networkx from networkx.algorithms.components.connected import connected_components def to_grap...
0
2016-08-22T13:11:35Z
[ "python", "graph" ]
normalizing data by duplication
39,078,282
<p><em>note: this question is indeed a duplicate of <a href="http://stackoverflow.com/questions/12680754/split-pandas-dataframe-string-entry-to-separate-rows">Split pandas dataframe string entry to separate rows</a>, but the answer provided here is more generic and informative, so with all respect due, I chose not to d...
1
2016-08-22T11:23:29Z
39,078,508
<p>try this:</p> <pre><code>In [44]: df Out[44]: id value 0 a 156 1 b,c 457 2 e,g,f,h 346 In [45]: (df['id'].str.split(',', expand=True) ....: .stack() ....: .reset_index(level=0) ....: .set_index('level_0') ....: .rename(columns={0:'id'})...
2
2016-08-22T11:35:38Z
[ "python", "pandas", "split-apply-combine" ]
Python how to get the calling function (not just its name)?
39,078,467
<p>I want to write a function which returns the calling function:</p> <pre class="lang-py prettyprint-override"><code>def foo(): return get_calling_function() #should return 'foo' function object </code></pre> <p>There's numerous examples online how to get the calling function's <em>name</em>, but not how to get ...
2
2016-08-22T11:33:53Z
39,079,070
<p>Calling can happen from any code object (and from an extension module/builtin): from <code>exec</code>, <code>execfile</code>, from module name space (during import), from within a class definition, from within a method / classmethod / staticmethod, from a decorated function/method, from within a nested function, ....
1
2016-08-22T12:03:27Z
[ "python", "function", "python-3.x", "inspect" ]
How to access parent abstract class of model in Django
39,078,490
<p><em>(using dajngo 1.9 and python 2.7)</em></p> <p>So I have an abstract class with a few child classes. It looks like this :</p> <pre><code>class Node(models.Model): [...] class Meta: abstract = True class Individual(Node): [...] class Company(Node): [...] class Media(Node): [......
0
2016-08-22T11:34:48Z
39,078,579
<p>Use <a href="https://docs.python.org/2/library/functions.html#isinstance" rel="nofollow"><code>isinstance</code></a>:</p> <pre><code>assert isinstance(child, Node) assert isinstance(parent, Node) </code></pre>
1
2016-08-22T11:39:20Z
[ "python", "django", "class", "inheritance" ]