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 |
|---|---|---|---|---|---|---|---|---|---|
Does Spark Dataframe have an equivalent option of Panda's merge indicator? | 38,721,194 | <p>The python Pandas library contains the following function :</p>
<pre><code>DataFrame.merge(right, how='inner', on=None, left_on=None, right_on=None, left_index=False,
right_index=False, sort=False, suffixes=('_x', '_y'), copy=True,
indicator=False)
</code></pre>
<p>The indicator fie... | 1 | 2016-08-02T13:01:45Z | 38,844,233 | <p>Altered LostInOverflow 's answer and got this working:</p>
<pre><code>from pyspark.sql import Row
ASchema = StructType([StructField('ida', IntegerType(),nullable=False),
StructField('name', StringType(),nullable=False)])
BSchema = StructType([StructField('idb', IntegerType(),nullable=False),
... | 2 | 2016-08-09T07:06:45Z | [
"python",
"pandas",
"pyspark",
"spark-dataframe"
] |
why does the plot not show the correct range on the x-axis? | 38,721,200 | <p>I have a question about the accepted answer given in this <a href="http://stackoverflow.com/questions/14873203/plotting-of-1-dimensional-gaussian-distribution-function">thread</a>. I have tested the answer and I wonder why the x-axis goes from 0 to 120 and not from -3 to 3?</p>
| 0 | 2016-08-02T13:01:58Z | 38,721,264 | <p><code>mp.plot()</code> is called with only one argument (array of Y-values), which means the corresponding X-values are natural numbers (starting from 0).</p>
<p>[edit]</p>
<p>To have the X-axis from -3 to 3 it is necessary to pass the X values explicitely:</p>
<pre><code>X = np.linspace(-3, 3, 120)
mp.plot(X, ga... | 1 | 2016-08-02T13:05:12Z | [
"python",
"numpy",
"matplotlib"
] |
How to split a list of strings in Python | 38,721,284 | <p>Say I have a list of strings like so:</p>
<pre><code>list = ["Jan 1", "John Smith", "Jan 2", "Bobby Johnson"]
</code></pre>
<p>How can I split them into two separate lists like this? My teacher mentioned something about indexing but didn't do a very good job of explaining it</p>
<pre><code>li1 = ["Jan 1", "John S... | 0 | 2016-08-02T13:06:21Z | 38,721,350 | <p>Well, use <a class='doc-link' href="http://stackoverflow.com/documentation/python/1494/list-slicing-selecting-parts-of-lists#t=201608021310137148216">list slicing</a>:</p>
<pre><code>li1 = my_list[:2]
li2 = my_list[2:]
</code></pre>
<p>BTW, don't use the name <code>list</code> for a variable because you are shadow... | 5 | 2016-08-02T13:09:17Z | [
"python",
"list",
"python-3.x"
] |
How to split a list of strings in Python | 38,721,284 | <p>Say I have a list of strings like so:</p>
<pre><code>list = ["Jan 1", "John Smith", "Jan 2", "Bobby Johnson"]
</code></pre>
<p>How can I split them into two separate lists like this? My teacher mentioned something about indexing but didn't do a very good job of explaining it</p>
<pre><code>li1 = ["Jan 1", "John S... | 0 | 2016-08-02T13:06:21Z | 38,721,375 | <p>If your list is longer than just two entries you could do this:</p>
<pre><code>zip(list[0::2],list[1::2])
</code></pre>
<p>Output:</p>
<pre><code>[('Jan 1', 'John Smith'), ('Jan 2', 'Bobby Johnson')]
</code></pre>
| 1 | 2016-08-02T13:10:16Z | [
"python",
"list",
"python-3.x"
] |
How to split a list of strings in Python | 38,721,284 | <p>Say I have a list of strings like so:</p>
<pre><code>list = ["Jan 1", "John Smith", "Jan 2", "Bobby Johnson"]
</code></pre>
<p>How can I split them into two separate lists like this? My teacher mentioned something about indexing but didn't do a very good job of explaining it</p>
<pre><code>li1 = ["Jan 1", "John S... | 0 | 2016-08-02T13:06:21Z | 38,721,481 | <p>One of ways to do make it work with lists of arbitrary length in a clean and simple manner:</p>
<pre><code>all_lists = (list[x:x+2] for x in range(0, len(list), 2))
</code></pre>
<p>And then you can access new lists by:</p>
<pre><code>li1 = all_lists[0]
li2 = all_lists[1]
</code></pre>
<p>Or just iterate through... | 0 | 2016-08-02T13:15:05Z | [
"python",
"list",
"python-3.x"
] |
How to split a list of strings in Python | 38,721,284 | <p>Say I have a list of strings like so:</p>
<pre><code>list = ["Jan 1", "John Smith", "Jan 2", "Bobby Johnson"]
</code></pre>
<p>How can I split them into two separate lists like this? My teacher mentioned something about indexing but didn't do a very good job of explaining it</p>
<pre><code>li1 = ["Jan 1", "John S... | 0 | 2016-08-02T13:06:21Z | 38,721,769 | <p>If the length of the list isn't always going to be the same, or known from the start you can do this:</p>
<pre><code>original_list = [YOUR ORIGINAL LIST]
A = [:len(original_list)/2]
B = [len(original_list)/2:]
</code></pre>
<p>A will be the first half and B will be the second half.</p>
| 0 | 2016-08-02T13:26:02Z | [
"python",
"list",
"python-3.x"
] |
Django ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine | 38,721,428 | <p>I am using django with postgresql, whenever I try to save or delete anything, this error occurs - </p>
<pre><code>Traceback (most recent call last):
File "c:\program files (x86)\python35-32\Lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "c:\program files (x86)\python35-32\Lib\wsgiref\handler... | 0 | 2016-08-02T13:12:51Z | 38,736,971 | <p>So if anyone gets this error, update your python to the latest version. It was a python bug that has been fixed.</p>
| 0 | 2016-08-03T07:22:20Z | [
"python",
"django",
"postgresql"
] |
How to drop the rows from dataframe that has all column values as boolean false | 38,721,498 | <p>How to drop the rows from dataframe that has all column values as zero using pandas.</p>
<pre><code>df = pd.DataFrame({'a':[1,0,1,0], 'b':[1,0,0,0], 'c':[1,0,1,0], 'd':[1,0,0,0]}, index=['aa','bb','cc','dd'])
df.index.name = 'name'
a b c d
name
aa 1 1 1 1
bb 0 0 0 0
cc 1 0 1 ... | 2 | 2016-08-02T13:15:43Z | 38,721,577 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> with inverted <code>mask</code> camparing all columns from <code>a</code> with <code>0</code>, where all values are <code>True</code> by <a href="http://pandas.pydata.org/... | 1 | 2016-08-02T13:18:35Z | [
"python",
"pandas"
] |
How to drop the rows from dataframe that has all column values as boolean false | 38,721,498 | <p>How to drop the rows from dataframe that has all column values as zero using pandas.</p>
<pre><code>df = pd.DataFrame({'a':[1,0,1,0], 'b':[1,0,0,0], 'c':[1,0,1,0], 'd':[1,0,0,0]}, index=['aa','bb','cc','dd'])
df.index.name = 'name'
a b c d
name
aa 1 1 1 1
bb 0 0 0 0
cc 1 0 1 ... | 2 | 2016-08-02T13:15:43Z | 38,721,871 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.any.html" rel="nofollow"><code>any()</code></a>, which returns <code>True</code> iff there's any <code>True</code> value (i.e. a value different that 0).</p>
<pre><code>df = df[df.any(axis=1)]
</code></pre>
<p>As for your example, ... | 0 | 2016-08-02T13:30:10Z | [
"python",
"pandas"
] |
Can't call the time data in python | 38,721,519 | <p>I have this csv data below:</p>
<pre><code>2015-01-02,02:29:45 PM,Red
2015-01-02,05:16:15 PM,Red
2015-01-02,05:48:46 PM,Blue
2015-01-02,03:18:34 PM,Blue
2015-01-02,05:22:55 PM,Red
2015-01-02,03:25:45 PM,Blue
2015-01-02,04:23:16 PM,Red
</code></pre>
<p>I am trying to plot this data into a graph using matplotlib
whe... | 0 | 2016-08-02T13:17:00Z | 38,721,898 | <pre><code>time = df['Time']
</code></pre>
<p>Use the <code>[]</code> instead of <code>()</code> when accessing columns in a pandas dataframe.</p>
| 0 | 2016-08-02T13:31:01Z | [
"python",
"csv",
"matplotlib"
] |
Spark Python map function: Error in encoding utf-8 | 38,721,566 | <p>I've been trying to process a textfile with Python. My textfile is in the native language of Vietnamese people, which use the UTF-8. After I use the map function, the output seems to be out of format. I've separated the code and output it step by step. I notice that the encoding went wrong after the map word: (word,... | 0 | 2016-08-02T13:18:15Z | 38,721,938 | <p>There is nothing particularly wrong with encoding here. You simply save a wrong thing. If you want to save a proper Unicode representation you should prepare one yourself:</p>
<pre><code>counts.map(lambda x: u"({0}, {1})".format(*x)).saveAsTextFile(...)
</code></pre>
| 1 | 2016-08-02T13:32:26Z | [
"python",
"python-2.7",
"apache-spark",
"encoding",
"utf-8"
] |
Mypy: no signature inference? | 38,721,750 | <p>It looks like Mypy doesn't do anything to infer signatures. Is that correct? For example:</p>
<pre><code># types.py
def same_int(x: int) -> int:
return x
def f(x):
y = same_int(x)
# This would be "Unsupported operand types for + ("int" and "str")"
# y + "hi"
return y
f("hi")
f(1) + "hi"
... | 2 | 2016-08-02T13:25:28Z | 38,775,381 | <p>That's a deliberate design decision -- mypy was designed to allow you to mix together dynamic and typed code, mainly to make it easier to transition large and diverse codebases + allow you to selectively gain the benefits of both.</p>
<p>As a result, functions without type annotations are treated by default as dyna... | 1 | 2016-08-04T19:00:32Z | [
"python",
"type-inference",
"mypy"
] |
Python : generate all combination from values in dict of lists | 38,721,847 | <p>I would like to generate all combinations of values which are in lists indexed in a dict, like so :</p>
<pre><code>{'A':['D','E'],'B':['F','G','H'],'C':['I','J']}
</code></pre>
<p>Each time, one item of each dict entry would be picked and combined to items from other keys, so we can have :</p>
<pre><code>['D','F'... | 1 | 2016-08-02T13:28:56Z | 38,722,093 | <pre><code>import itertools as it
my_dict={'A':['D','E'],'B':['F','G','H'],'C':['I','J']}
allNames = sorted(my_dict)
combinations = it.product(*(my_dict[Name] for Name in allNames))
print(list(combinations))
</code></pre>
<p>which prints</p>
<blockquote>
<p>[('D', 'F', 'I'), ('D', 'F', 'J'), ('D', 'G', 'I'), ('D',... | 3 | 2016-08-02T13:39:30Z | [
"python",
"dictionary",
"combinations"
] |
After calling python script from Node.js, it does not follow the sequence of execution | 38,721,852 | <p>Here is my python code:</p>
<pre><code>import smbus
import sys
import time
x=0
completeData = "";
while x<800:
crgb = ""+x;
print crgb
completeData = completeData + crgb + "@";
time.sleep(.0001)
x = x+1
file = open("sensorData.txt", "w")
file.write(completeData)
file.close()
sys.stdout.flus... | 0 | 2016-08-02T13:29:11Z | 38,721,981 | <p>Put your read code inside of callback. JavaScript is synchronous and you code is not. </p>
<pre><code>var PythonShell = require('python-shell');
PythonShell.run('sensor.py', function (err) {
if (err) throw err;
console.log('finished');
console.log ("Now read data");
});
</code></pre>
<p>Hope this helps.... | 0 | 2016-08-02T13:34:16Z | [
"python",
"node.js"
] |
Find grandparent node using nltk | 38,721,867 | <p>I am using the Tree-package from nltk with python 2.7 and I want to extract every rule from a tree with it's grandparent node.
I have the following tree</p>
<pre><code>t = Tree('S', [Tree('NP', [Tree('D', ['the']), Tree('N', ['dog'])]), Tree('VP', [Tree('V', ['chased']), Tree('NP', [Tree('D', ['the']), Tree('N', [... | 3 | 2016-08-02T13:29:52Z | 38,724,644 | <p>You need to modify / overwrite <strong>productions method</strong>.</p>
<p><strong>Code:</strong> </p>
<pre><code>from nltk.tree import Tree
from nltk.compat import string_types
from nltk.grammar import Production, Nonterminal
from nltk.tree import _child_names
def productions(t, parent):
if not isinstance(t.... | 1 | 2016-08-02T15:26:41Z | [
"python",
"tree",
"nltk"
] |
Is there any function in python which can perform the inverse of numpy.repeat function? | 38,722,073 | <p>For example</p>
<pre><code>x = np.repeat(np.array([[1,2],[3,4]]), 2, axis=1)
</code></pre>
<p>gives you</p>
<pre><code>x = array([[1, 1, 2, 2],
[3, 3, 4, 4]])
</code></pre>
<p>but is there something which can perform</p>
<pre><code> x = np.*inverse_repeat*(np.array([[1, 1, 2, 2],[3, 3, 4, 4]]), axis=1... | 7 | 2016-08-02T13:38:32Z | 38,722,260 | <p>Regular slicing should work. For the axis you want to <em>inverse</em> repeat, use <code>::number_of_repetitions</code></p>
<pre><code>x = np.repeat(np.array([[1,2],[3,4]]), 4, axis=0)
x[::4, :] # axis=0
Out:
array([[1, 2],
[3, 4]])
x = np.repeat(np.array([[1,2],[3,4]]), 3, axis=1)
x[:,::3] # axis=1
Out... | 5 | 2016-08-02T13:46:09Z | [
"python",
"python-2.7",
"numpy"
] |
Is there any function in python which can perform the inverse of numpy.repeat function? | 38,722,073 | <p>For example</p>
<pre><code>x = np.repeat(np.array([[1,2],[3,4]]), 2, axis=1)
</code></pre>
<p>gives you</p>
<pre><code>x = array([[1, 1, 2, 2],
[3, 3, 4, 4]])
</code></pre>
<p>but is there something which can perform</p>
<pre><code> x = np.*inverse_repeat*(np.array([[1, 1, 2, 2],[3, 3, 4, 4]]), axis=1... | 7 | 2016-08-02T13:38:32Z | 38,722,496 | <pre><code>>>> import numpy as np
>>> x = np.repeat(np.array([[1,2],[3,4]]), 2, axis=1)
>>> y=[list(set(c)) for c in x] #This part remove duplicates for each array in tuple. So this will not work for x = np.repeat(np.array([[1,1],[3,3]]), 2, axis=1)=[[1,1,1,1],[3,3,3,3]. Result will be [[1],[... | -1 | 2016-08-02T13:55:54Z | [
"python",
"python-2.7",
"numpy"
] |
Is there any function in python which can perform the inverse of numpy.repeat function? | 38,722,073 | <p>For example</p>
<pre><code>x = np.repeat(np.array([[1,2],[3,4]]), 2, axis=1)
</code></pre>
<p>gives you</p>
<pre><code>x = array([[1, 1, 2, 2],
[3, 3, 4, 4]])
</code></pre>
<p>but is there something which can perform</p>
<pre><code> x = np.*inverse_repeat*(np.array([[1, 1, 2, 2],[3, 3, 4, 4]]), axis=1... | 7 | 2016-08-02T13:38:32Z | 38,722,499 | <p>This should work, and has the exact same signature as np.repeat:</p>
<pre><code>def inverse_repeat(a, repeats, axis):
if isinstance(repeats, int):
indices = np.arange(a.shape[axis] / repeats, dtype=np.int) * repeats
else: # assume array_like of int
indices = np.cumsum(repeats) - 1
retur... | 0 | 2016-08-02T13:55:59Z | [
"python",
"python-2.7",
"numpy"
] |
Is there any function in python which can perform the inverse of numpy.repeat function? | 38,722,073 | <p>For example</p>
<pre><code>x = np.repeat(np.array([[1,2],[3,4]]), 2, axis=1)
</code></pre>
<p>gives you</p>
<pre><code>x = array([[1, 1, 2, 2],
[3, 3, 4, 4]])
</code></pre>
<p>but is there something which can perform</p>
<pre><code> x = np.*inverse_repeat*(np.array([[1, 1, 2, 2],[3, 3, 4, 4]]), axis=1... | 7 | 2016-08-02T13:38:32Z | 38,725,756 | <p>For the case where we know the axis and the repeat - and the repeat is a scalar (same value for all elements) we can construct a slicing index like this:</p>
<pre><code>In [1117]: a=np.array([[1, 1, 2, 2],[3, 3, 4, 4]])
In [1118]: axis=1; repeats=2
In [1119]: ind=[slice(None)]*a.ndim
In [1120]: ind[axis]=slice(Non... | 0 | 2016-08-02T16:20:14Z | [
"python",
"python-2.7",
"numpy"
] |
Format strings vs concatenation | 38,722,105 | <p>I see many people using format strings like this:</p>
<pre><code>root = "sample"
output = "output"
path = "{}/{}".format(root, output)
</code></pre>
<p>Instead of simply concatenating strings like this:</p>
<pre><code>path = root + '/' + output
</code></pre>
<p>Do format strings have better performance or is thi... | 3 | 2016-08-02T13:40:07Z | 38,722,192 | <p>It's just for the looks. You can see at one glance what the format is. Many of us like readability better than micro-optimization.</p>
<p>Let's see what IPython's <code>%timeit</code> says:</p>
<pre class="lang-none prettyprint-override"><code>In [1]: %timeit root = "sample"; output = "output"; path = "{}/{}".form... | 5 | 2016-08-02T13:43:20Z | [
"python",
"string-formatting"
] |
Format strings vs concatenation | 38,722,105 | <p>I see many people using format strings like this:</p>
<pre><code>root = "sample"
output = "output"
path = "{}/{}".format(root, output)
</code></pre>
<p>Instead of simply concatenating strings like this:</p>
<pre><code>path = root + '/' + output
</code></pre>
<p>Do format strings have better performance or is thi... | 3 | 2016-08-02T13:40:07Z | 38,722,264 | <p>As with most things, there will be a performance difference, but ask yourself "Does it really matter if this is ns faster?". The <code>root + '/' output</code> method is quick and easy to type out. But this can get hard to read real quick when you have multiple variables to print out</p>
<pre><code>foo = "X = " +... | 5 | 2016-08-02T13:46:19Z | [
"python",
"string-formatting"
] |
Format strings vs concatenation | 38,722,105 | <p>I see many people using format strings like this:</p>
<pre><code>root = "sample"
output = "output"
path = "{}/{}".format(root, output)
</code></pre>
<p>Instead of simply concatenating strings like this:</p>
<pre><code>path = root + '/' + output
</code></pre>
<p>Do format strings have better performance or is thi... | 3 | 2016-08-02T13:40:07Z | 38,722,342 | <p>String format is free of data type while binding data. While in concatenation we have to type cast or convert the data accordingly.</p>
<p>For example:</p>
<pre><code>a = 10
b = "foo"
c = str(a) + " " + b
print c
> 10 foo
</code></pre>
<p>It could be done via string formatting as:</p>
<pre><code>a = 10
b = "f... | 4 | 2016-08-02T13:49:18Z | [
"python",
"string-formatting"
] |
Format strings vs concatenation | 38,722,105 | <p>I see many people using format strings like this:</p>
<pre><code>root = "sample"
output = "output"
path = "{}/{}".format(root, output)
</code></pre>
<p>Instead of simply concatenating strings like this:</p>
<pre><code>path = root + '/' + output
</code></pre>
<p>Do format strings have better performance or is thi... | 3 | 2016-08-02T13:40:07Z | 38,722,372 | <p>It's for looks and the maintaining of the code. It's really easier to edit your code if you used format. Also when you use + you may miss the details like spaces. Use format for your and possible maintainers' good.</p>
| 1 | 2016-08-02T13:50:37Z | [
"python",
"string-formatting"
] |
Format strings vs concatenation | 38,722,105 | <p>I see many people using format strings like this:</p>
<pre><code>root = "sample"
output = "output"
path = "{}/{}".format(root, output)
</code></pre>
<p>Instead of simply concatenating strings like this:</p>
<pre><code>path = root + '/' + output
</code></pre>
<p>Do format strings have better performance or is thi... | 3 | 2016-08-02T13:40:07Z | 38,730,669 | <p>It's not just for "looks", or for powerful lexical type conversions; it's also a must for internationalisation.</p>
<p>You can swap out the format string depending on what language is selected.</p>
<p>With a long line of string concatenations baked into the source code, this becomes effectively impossible to do pr... | 2 | 2016-08-02T21:21:41Z | [
"python",
"string-formatting"
] |
Two decay rates for one exponential decay graph | 38,722,124 | <p>I hope my title is understandable. I'm doing a university project on how chlorine (for disinfection purposes) decays with time in seawater. It is understood that there is a rapid initial decay and then it slows down, resulting in two decay rates but that stem from the same overall exponential decay. It's sort of bee... | -1 | 2016-08-02T13:40:49Z | 38,723,678 | <p>Your question is not quite clear, but it seems you are trying to find best fit parameters for the double exponential function you quote.</p>
<p>An easy way to do this is to use the <code>scipy.optimize.curve_fit</code> function. First, define the function you want to fit</p>
<pre><code> import numpy as np
i... | 0 | 2016-08-02T14:46:47Z | [
"python",
"exponential",
"decay"
] |
Wagtail, how do I populate the choices in a ChoiceBlock from a different model? | 38,722,155 | <p>This is the model for icons displayed on top of a text, they get a name and the icon.</p>
<pre><code>from django.db import models
from django.utils.translation import ugettext as _
from django.conf import settings
class SomeSortOfIcon(models.Model):
name = models.CharField(max_length=200,
... | 0 | 2016-08-02T13:42:08Z | 38,950,149 | <p>You can do that by inheriting from the ChooserBlock.</p>
<pre><code>class SomeSortOfIconChooserBlock(blocks.ChooserBlock):
target_model = SomeSortOfIcon
widget = forms.Select
class Meta:
icon = "icon"
# Return the key value for the select field
def value_for_form(self, value):
... | 0 | 2016-08-15T06:16:18Z | [
"python",
"django",
"wagtail"
] |
How to read from file in Big or Lower Endian format in Python | 38,722,168 | <p>I am trying to update a script from Matlab to Python and am having trouble with a single section. The code is supposed to read a binary file and translate it into something I can use to make plots.</p>
<p>The MatLab code I am having trouble with is this:</p>
<pre><code>%reopen the data file using the correct HIFIR... | -1 | 2016-08-02T13:42:32Z | 38,790,881 | <p>After a few days of digging around, I found a similar code to do what I wanted and used it as an example. The code can be found <a href="http://qtwork.tudelft.nl/gitdata/users/guen/qtlabanalysis/analysis_modules/general/lecroy.py" rel="nofollow">here</a>.</p>
| 0 | 2016-08-05T13:47:58Z | [
"python",
"matlab",
"io",
"binary",
"endianness"
] |
PyQt4: GUI stuck during long-running loops | 38,722,219 | <p>I have been looking for solutions in the stackoverflow and other pyqt tutorials on how to overcome the GUI freeze problem in pyqt4. There are similar topics that suggest the following methods to rectify it:</p>
<ul>
<li>Move your long-running loop to a secondary thread, drawing the GUI is happening in the main thre... | 1 | 2016-08-02T13:44:37Z | 38,742,262 | <p>As suggested by <a href="http://stackoverflow.com/users/1994235/three-pineapples">three_pinapples</a> , I tried to offload the program to by creating more thread. Further I was calling the <code>thread</code> that performed the whole serial writing and reading in <code>while</code> loop. This caused the problem of c... | 1 | 2016-08-03T11:27:17Z | [
"python",
"multithreading",
"qt",
"user-interface",
"pyqt4"
] |
2d-list calculations | 38,722,301 | <p>I have two 2-dimensional lists. Each <code>list</code> item contains a <code>list</code> with a string ID and an integer. I want to subtract the integers from each other where the string ID matches.</p>
<p>List 1:</p>
<pre><code>list1 = [['ID_001',1000],['ID_002',2000],['ID_003',3000]]
</code></pre>
<p>List 2:</p... | 1 | 2016-08-02T13:47:44Z | 38,722,470 | <pre><code>from collections import defaultdict
diffs = defaultdict(int)
list1 = [['ID_001',1000],['ID_002',2000],['ID_003',3000]]
list2 = [['ID_001',500],['ID_003',1000],['ID_002',1000]]
for pair in list1:
diffs[pair[0]] = pair[1]
for pair in list2:
diffs[pair[0]] -= pair[1]
differences = [[k,abs(v)] for k,v ... | 2 | 2016-08-02T13:54:56Z | [
"python",
"list",
"python-3.x",
"multidimensional-array",
"mapping"
] |
2d-list calculations | 38,722,301 | <p>I have two 2-dimensional lists. Each <code>list</code> item contains a <code>list</code> with a string ID and an integer. I want to subtract the integers from each other where the string ID matches.</p>
<p>List 1:</p>
<pre><code>list1 = [['ID_001',1000],['ID_002',2000],['ID_003',3000]]
</code></pre>
<p>List 2:</p... | 1 | 2016-08-02T13:47:44Z | 38,722,586 | <p>You could achieve this by using a <strong><a class='doc-link' href="http://stackoverflow.com/documentation/python/196/comprehensions/737/list-comprehensions#t=20160802140427691327">list comprehension</a></strong>:</p>
<pre><code>diff = [(i[0], abs(i[1] - j[1])) for i,j in zip(sorted(list1), sorted(list2))]
</code><... | 2 | 2016-08-02T14:00:00Z | [
"python",
"list",
"python-3.x",
"multidimensional-array",
"mapping"
] |
Raspberry pi bluetooth - send data | 38,722,417 | <p>Before posting this I've tried looking for simple program to send any kind of data using BLE with rapsberry pi. But more I got in detail, I knew that there are some BLE library that supports programming using Python on RPi. I'm new to python networking programming and I'm looking for tutorial. Every single tutorial ... | 0 | 2016-08-02T13:52:47Z | 38,729,736 | <p>See this link:</p>
<p><a class='doc-link' href="http://stackoverflow.com/documentation/proposed/changes/71730">http://stackoverflow.com/documentation/proposed/changes/71730</a></p>
<p>I will change it to the approved version, once it has been approved. At the end, you basically have a TCP-like socket, that you can... | 0 | 2016-08-02T20:19:42Z | [
"python",
"bluetooth",
"bluetooth-lowenergy"
] |
Differentiate a list between human names and company names | 38,722,516 | <p>I have a list of companies, but some of these companies are simply names of people. I want to eliminate these people from the list, but I am having trouble finding a way to identify the names of people from the companies. </p>
<p>Through online research I have tried two ways. The first is using the <code>nltk</code... | 1 | 2016-08-02T13:56:33Z | 38,722,712 | <p>As far as I understand, you need to differentiate the company and human names. I guess the companies in your list end with either <strong>LLC</strong>, <strong>INC</strong> or contains a <strong>-</strong> (hyphen), thus I made a set of these words <code>company_set</code> as <code>{'LLC', 'INC', '-'}</code> and the... | 0 | 2016-08-02T14:05:12Z | [
"python",
"nltk"
] |
Differentiate a list between human names and company names | 38,722,516 | <p>I have a list of companies, but some of these companies are simply names of people. I want to eliminate these people from the list, but I am having trouble finding a way to identify the names of people from the companies. </p>
<p>Through online research I have tried two ways. The first is using the <code>nltk</code... | 1 | 2016-08-02T13:56:33Z | 38,722,847 | <p>Test the list elements for indicators of company names. For your list, this is INC, LLC, and the hyphen (which could be part of a person's name). Or parts of company names (lab, pharma, solutions, ..). There may be other criteria (syllables, phonetics).
Otherwise, you'd need a dictionary of names or companys to test... | 0 | 2016-08-02T14:11:00Z | [
"python",
"nltk"
] |
Differentiate a list between human names and company names | 38,722,516 | <p>I have a list of companies, but some of these companies are simply names of people. I want to eliminate these people from the list, but I am having trouble finding a way to identify the names of people from the companies. </p>
<p>Through online research I have tried two ways. The first is using the <code>nltk</code... | 1 | 2016-08-02T13:56:33Z | 38,723,010 | <p>I don't believe you can do this entirely programatically, so some manual operation will be needed. However, you can make things a little easier with <code>itertools.groupby</code></p>
<p>As pointed out in some comments, companies are likely to contain certain keywords, so we can create a list of these to use:</p>
... | 0 | 2016-08-02T14:18:42Z | [
"python",
"nltk"
] |
How do i keep the order of my SQL columns in Python when saving? | 38,722,593 | <p>If you scroll down a bit you can see this code from g.d.d.c <a href="http://stackoverflow.com/questions/3286525/return-sql-table-as-json-in-python">return SQL table as JSON in python</a>:</p>
<pre><code>qry = "Select Id, Name, Artist, Album From MP3s Order By Name, Artist"
# Assumes conn is a database connection.
c... | 0 | 2016-08-02T14:00:22Z | 38,722,716 | <p>Python <code>dict</code> don't save the order of keys, use <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" rel="nofollow">OrderedDict</a> instead.</p>
| 1 | 2016-08-02T14:05:27Z | [
"python",
"sql-server",
"json",
"pyodbc"
] |
How do i keep the order of my SQL columns in Python when saving? | 38,722,593 | <p>If you scroll down a bit you can see this code from g.d.d.c <a href="http://stackoverflow.com/questions/3286525/return-sql-table-as-json-in-python">return SQL table as JSON in python</a>:</p>
<pre><code>qry = "Select Id, Name, Artist, Album From MP3s Order By Name, Artist"
# Assumes conn is a database connection.
c... | 0 | 2016-08-02T14:00:22Z | 38,722,782 | <p>If I understand You want dictionary to have ordered key. It's not possible, because dictionaries are not keeping keys in some order, because keys are used only to access elements. You can always print columns of data using raw column information:</p>
<pre><code>cols = ["column1", "column2", "column3"]
for row in da... | 1 | 2016-08-02T14:08:29Z | [
"python",
"sql-server",
"json",
"pyodbc"
] |
Adding the values of two strings using Python and XML path | 38,722,598 | <p>It generates an output with wallTime and setupwalltime into a dat file, which has the following format:</p>
<pre><code>24000 4 0
81000 17 0
192000 59 0
648000 250 0
1536000 807 0
3000000 2144 0
6591000 5699 0
</code></pre>
<p>I would like to know how to add the two values i.e.(w... | 0 | 2016-08-02T14:00:31Z | 38,723,417 | <p>In java you can add strings and floats. What I understand is that you need to add the values and then display them. That would work (stringing the sum)</p>
<pre><code>write_file.write(str(unknowns) + "\f" + str(float(walltime) + float(setupwalltime)) + "\n")
</code></pre>
| 0 | 2016-08-02T14:34:48Z | [
"python",
"xml",
"xml-parsing"
] |
Adding the values of two strings using Python and XML path | 38,722,598 | <p>It generates an output with wallTime and setupwalltime into a dat file, which has the following format:</p>
<pre><code>24000 4 0
81000 17 0
192000 59 0
648000 250 0
1536000 807 0
3000000 2144 0
6591000 5699 0
</code></pre>
<p>I would like to know how to add the two values i.e.(w... | 0 | 2016-08-02T14:00:31Z | 38,723,744 | <p>You are trying to add a <code>str</code> to a <code>float</code>. That doesn't work. If you want to use string concatenation, first coerce all of the values to <code>str</code>. Try this:</p>
<pre><code>write_file.write(str(unknowns) + "\t" + str(float(walltime) + float(setupwalltime)) + "\n")
</code></pre>
<p>Or... | 0 | 2016-08-02T14:49:19Z | [
"python",
"xml",
"xml-parsing"
] |
Amazon SES - Hide recipient email addresses | 38,722,615 | <p>I am testing Amazon SES through boto3 python library. When i send emails i see all the recipient addresses. How to hide these ToAddresses of multiple email via Amazon SES ?</p>
<p><a href="http://i.stack.imgur.com/OrGnL.png" rel="nofollow"><img src="http://i.stack.imgur.com/OrGnL.png" alt="enter image description h... | 0 | 2016-08-02T14:01:19Z | 38,722,907 | <p>We use the send_raw_email function instead which gives more control over the make up of your message. You could easily add Bcc headers this way.</p>
<p>An example of the code that generates the message and how to send it</p>
<pre><code>from email.mime.multipart import MIMEMultipart
from email.mime.text import MIME... | 0 | 2016-08-02T14:13:57Z | [
"python",
"python-2.7",
"amazon-web-services",
"amazon-ses",
"boto3"
] |
Python Pandas: Get index of multiple rows which column matches certain value | 38,722,675 | <p>Given a <code>DataFrame</code> with the columns <code>xk</code> and <code>yk</code>, we want to find the indexes of the <code>DataFrame</code> in which the values for <code>xk</code> and <code>yk ==0</code>. </p>
<p>I have it working perfectly fine for just the one column but I cant get it working for both</p>
<p... | 1 | 2016-08-02T14:03:31Z | 38,722,705 | <p>I think you can check if all values are <code>True</code> in compared subset <code>['xk', 'yk']</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.all.html" rel="nofollow"><code>all</code></a>:</p>
<pre><code>b = df[(df[['xk', 'yk']] == 0).all(1)].index.tolist()
</code></pre>
... | 2 | 2016-08-02T14:04:53Z | [
"python",
"pandas",
"indexing"
] |
Updating Axis In Matplotlib Based on Dynamic Values | 38,722,679 | <p>I am working on a project in which I read in values from a text file that dynamically updates with two values separated by a space. These values are taken put into a list and then both plotted with each being a point on the y-axis and time being on the x-axis. In the first set of code provided below I am able to tak... | 0 | 2016-08-02T14:03:36Z | 38,768,831 | <p>This question may be more appropriate at <a href="http://codereview.stackexchange.com/">http://codereview.stackexchange.com/</a></p>
<p>Pseudo Code</p>
<pre><code>plotData = []
for (1 to desired size)
plotData[i] = 0
while data
update time
plotData.push(data with time)
plotData.popTop(oldest data)
... | 0 | 2016-08-04T13:33:01Z | [
"python",
"linux",
"matplotlib",
"plot",
"graph"
] |
Unable to subtract specific fields within structured numpy arrays | 38,722,747 | <p>While trying to subtract to fields within a structured numpy array, the following error occurs:</p>
<pre><code>In [8]: print serPos['pos'] - hisPos['pos']
---------------------------------------------------------------------------
TypeError
Traceback (most recent call last) <ipy... | 2 | 2016-08-02T14:06:52Z | 38,725,980 | <p>The <code>dtype</code> for <code>serPos['pos']</code> is compound</p>
<pre><code>dtype([('x', '<f8'), ('y', '<f8'), ('z', '<f8')])
</code></pre>
<p>subtraction (and other such operations) has not been defined for compound dtype. It doesn't work for the <code>raw</code> dtype either. </p>
<p>You could s... | 1 | 2016-08-02T16:33:07Z | [
"python",
"arrays",
"python-2.7",
"numpy"
] |
Checking monotonicity of subsequences in Python | 38,722,790 | <p>I want to be able to find the index of the end of a monotone decreasing subsequence which starts off at the first index of the list and only goes down in consecutive order. So for example, I may have a list that looks like this: </p>
<p><code>x = [89, 88, 88, 88, 88, 87, 88]</code> and I want to be able to return <... | 0 | 2016-08-02T14:08:35Z | 38,722,909 | <p>I'm not sure I completely understood the question, but take a look at this:</p>
<pre><code>def findseries(a):
for i in xrange(len(a) - 1):
if a[i+1] - a[i] not in [-1, 0]:
return i
return len(a) - 1
</code></pre>
<p>You basically iterate through the list. If the next element you check i... | 0 | 2016-08-02T14:13:59Z | [
"python",
"subsequence"
] |
Checking monotonicity of subsequences in Python | 38,722,790 | <p>I want to be able to find the index of the end of a monotone decreasing subsequence which starts off at the first index of the list and only goes down in consecutive order. So for example, I may have a list that looks like this: </p>
<p><code>x = [89, 88, 88, 88, 88, 87, 88]</code> and I want to be able to return <... | 0 | 2016-08-02T14:08:35Z | 38,723,281 | <p>You can use a python <a class='doc-link' href="http://stackoverflow.com/documentation/python/196/comprehensions/739/generator-expressions#t=201608021429353729963">generator expression</a>:</p>
<pre><code>x = [89, 88, 88, 88, 88, 87, 88]
g = (i for i,(v,u) in enumerate(zip(x,x[1:])) if not (u+1==v or u==v))
next(g)
... | 0 | 2016-08-02T14:30:15Z | [
"python",
"subsequence"
] |
Checking monotonicity of subsequences in Python | 38,722,790 | <p>I want to be able to find the index of the end of a monotone decreasing subsequence which starts off at the first index of the list and only goes down in consecutive order. So for example, I may have a list that looks like this: </p>
<p><code>x = [89, 88, 88, 88, 88, 87, 88]</code> and I want to be able to return <... | 0 | 2016-08-02T14:08:35Z | 38,724,181 | <p>If you want to over-complicate the matter, you can first create a function which generates the pairs of consecutive entries in the iterable:</p>
<pre><code>def consecutive_pairs(iterable):
it = iter(iterable)
first = next(it)
for second in it:
yield (first, second)
first = second
</code>... | 0 | 2016-08-02T15:07:18Z | [
"python",
"subsequence"
] |
Checking monotonicity of subsequences in Python | 38,722,790 | <p>I want to be able to find the index of the end of a monotone decreasing subsequence which starts off at the first index of the list and only goes down in consecutive order. So for example, I may have a list that looks like this: </p>
<p><code>x = [89, 88, 88, 88, 88, 87, 88]</code> and I want to be able to return <... | 0 | 2016-08-02T14:08:35Z | 38,726,525 | <p>This works if <code>[88,88,88]</code> produces 2:</p>
<pre><code>def foo(it, n = 0):
#print(it, n)
try:
monotonic = -1 < it[0] - it[1] < 2
if monotonic:
n = foo(it[1:], n + 1)
except IndexError:
pass
return n
</code></pre>
<hr>
<p>Refactored for <code>[88,... | 0 | 2016-08-02T17:03:27Z | [
"python",
"subsequence"
] |
Check if Date is in Daylight Savings Time for Timezone Without pytz | 38,722,792 | <p>For certain reasons, my employer does not want to use pip to install third party packages and wants me to use packages only hosted on trusty. Thus, I now cannot use pytz in my code. How would I go about checking if a certain date in a timezone is in DST? Here's my original code using pytz.</p>
<pre><code> import... | 1 | 2016-08-02T14:08:41Z | 38,724,080 | <p>Install <a href="https://github.com/newvem/pytz" rel="nofollow">pytz</a> without using pip.</p>
<p>DST is arbitrary and chosen by legislation in different regions, you can't really calculate it - look at <a href="https://github.com/newvem/pytz/blob/master/pytz/zoneinfo/US/Eastern.py" rel="nofollow">the pytz source ... | 0 | 2016-08-02T15:03:03Z | [
"python",
"python-3.x",
"datetime"
] |
Check if Date is in Daylight Savings Time for Timezone Without pytz | 38,722,792 | <p>For certain reasons, my employer does not want to use pip to install third party packages and wants me to use packages only hosted on trusty. Thus, I now cannot use pytz in my code. How would I go about checking if a certain date in a timezone is in DST? Here's my original code using pytz.</p>
<pre><code> import... | 1 | 2016-08-02T14:08:41Z | 38,726,465 | <p>In the general case this is a complex problem that is not amenable to a hand-rolled solution. Relying on an external module that is vetted and maintained by someone dedicated to the task, such as <code>pytz</code>, is the only sane option.</p>
<p>However given the constraint that you're only interested in U.S. time... | 0 | 2016-08-02T17:00:24Z | [
"python",
"python-3.x",
"datetime"
] |
equivalent to R's `do.call` in python | 38,722,804 | <p>Is there an equivalent to R's <code>do.call</code> in python?</p>
<pre><code>do.call(what = 'sum', args = list(1:10)) #[1] 55
do.call(what = 'mean', args = list(1:10)) #[1] 5.5
?do.call
# Description
# do.call constructs and executes a function call from a name or a function and a list of arguments to be passed to... | 1 | 2016-08-02T14:09:17Z | 38,722,886 | <p>There is no built-in for this, but it is easy enough to construct an equivalent.</p>
<p>You can look up any object from the built-ins namespace using the <a href="https://docs.python.org/2/library/__builtin__.html" rel="nofollow"><code>__builtin__</code></a> (Python 2) or <a href="https://docs.python.org/3/library/... | 2 | 2016-08-02T14:13:14Z | [
"python",
"python-2.7"
] |
equivalent to R's `do.call` in python | 38,722,804 | <p>Is there an equivalent to R's <code>do.call</code> in python?</p>
<pre><code>do.call(what = 'sum', args = list(1:10)) #[1] 55
do.call(what = 'mean', args = list(1:10)) #[1] 5.5
?do.call
# Description
# do.call constructs and executes a function call from a name or a function and a list of arguments to be passed to... | 1 | 2016-08-02T14:09:17Z | 38,723,054 | <p><code>do.call</code> is pretty much the equivalent of the <a href="http://stackoverflow.com/q/2322355/1968">splat operator</a> in Python:</p>
<pre><code>def mysum(a, b, c):
return sum([a, b, c])
# normal call:
mysum(1, 2, 3)
# with a list of arguments:
mysum(*[1, 2, 3])
</code></pre>
<p>Note that Iâve had ... | 3 | 2016-08-02T14:20:11Z | [
"python",
"python-2.7"
] |
I need to delete spaces within CSV rows, then add commas to specified character locations | 38,722,892 | <pre><code>import csv
import sys
f = open(sys.argv[1], 'rb')
reader = csv.reader(f)
k = []
for i in reader:
j = i.replace(' ','')
k.append(j)
print k
</code></pre>
<p>the raw CSV is this</p>
<pre><code>['1 323 104 564 382']
['2 322 889 564 483']
['3 322 888 564 479']
['4 322 920 564 425']
['5 322 942 56... | 2 | 2016-08-02T14:13:26Z | 38,723,024 | <p>Try this. I might be off with the <a href="http://stackoverflow.com/a/509295/1619432">slicing</a>:</p>
<pre><code>parts= i[0].split()
one=parts[0]
two=parts[1:2+1]
three=parts[3:4+1]
j= ",".join( [one,two,three] )
</code></pre>
| 0 | 2016-08-02T14:19:13Z | [
"python",
"csv"
] |
I need to delete spaces within CSV rows, then add commas to specified character locations | 38,722,892 | <pre><code>import csv
import sys
f = open(sys.argv[1], 'rb')
reader = csv.reader(f)
k = []
for i in reader:
j = i.replace(' ','')
k.append(j)
print k
</code></pre>
<p>the raw CSV is this</p>
<pre><code>['1 323 104 564 382']
['2 322 889 564 483']
['3 322 888 564 479']
['4 322 920 564 425']
['5 322 942 56... | 2 | 2016-08-02T14:13:26Z | 38,723,416 | <pre><code>[[i[0].replace(' ','')] for i in reader]
</code></pre>
<p>and to get to your final goal:</p>
<pre><code>reader=[[i[0].replace(' ',',',1)] for i in reader]
reader=[[i[0].replace(' ','',1)] for i in reader]
reader=[[i[0].replace(' ',',',1)] for i in reader]
reader=[[i[0].replace(' ','',1)] for i in reader]
<... | 0 | 2016-08-02T14:34:48Z | [
"python",
"csv"
] |
Round off numbers in python | 38,723,011 | <p>I have a list of numbers [0,10,20,30,40,50] now this list will be appended by random numbers such as 33 ,43,I have to check the list every time it appends no to the list and i want them to be rounded off to 30 and 40.</p>
| -1 | 2016-08-02T14:18:45Z | 38,723,176 | <p>Use the <a href="https://docs.python.org/2/library/functions.html#round" rel="nofollow"><code>round()</code></a> built-in function. In conjuction with a <em>list comprehension</em>, can give us an expressive one-line function!</p>
<pre><code>def round_list(l):
return [int(round(i, -1)) for i in l]
</code></pre>... | 2 | 2016-08-02T14:25:26Z | [
"python",
"list",
"numbers",
"append",
"rounding"
] |
Round off numbers in python | 38,723,011 | <p>I have a list of numbers [0,10,20,30,40,50] now this list will be appended by random numbers such as 33 ,43,I have to check the list every time it appends no to the list and i want them to be rounded off to 30 and 40.</p>
| -1 | 2016-08-02T14:18:45Z | 38,724,035 | <p>In order to round to the nearest 10 you can:</p>
<ol>
<li>Divide the number by 10</li>
<li>Use <a href="https://docs.python.org/2/library/functions.html#round" rel="nofollow">round()</a> on the new number</li>
<li>Multiply the rounded number by 10</li>
</ol>
<p>The code below should contain what you need:</p>
<pr... | 0 | 2016-08-02T15:01:10Z | [
"python",
"list",
"numbers",
"append",
"rounding"
] |
Errno 10060 A connection attempt failed | 38,723,055 | <pre><code>EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=465
EMAIL_HOST_USER = 'yogi'
EMAIL_HOST_PASSWORD = '###'
DEFAULT_EMAIL_FROM = 'yogi@gmail.com'
</code></pre>
<p>above are the settings for django core mail module. I am using its send_mail to send mails to ... | 1 | 2016-08-02T14:20:13Z | 38,740,249 | <p>As far as I know django does not detect any SMTP proxy settings from anaconda configuration files. You can overcome this by manually building a connection.</p>
<p>Notice that <a href="https://docs.djangoproject.com/en/1.9/_modules/django/core/mail/#send_mail" rel="nofollow">send_mail</a> , has an option parameter ... | 1 | 2016-08-03T09:55:15Z | [
"python",
"django",
"email",
"proxy"
] |
Python Multiple filetype support with glob.glob | 38,723,153 | <p>I'm trying to use glob.glob to provide support for more than one filetype. The code I have is supposed to take files with the extensions '.pdf', '.xls', and '.xlsx' residing in the directory '/mnt/Test' and execute the code below after files matching have been found.</p>
<p>When I replace the existing for loop with... | 0 | 2016-08-02T14:24:17Z | 38,723,433 | <p><code>doc_placeholder</code> includes this snippet, <code>os.path.splitext(filename)</code>. Assuming <code>filename</code> is the list you passed in you've given a list to <code>os.path.splittext</code> when it is expecting a string.</p>
<p>Fix this by iterating over each filename instead of trying to process the... | 0 | 2016-08-02T14:35:45Z | [
"python",
"python-2.7",
"glob"
] |
Tkinter Toplevel : Destroy window when not focused | 38,723,277 | <p>I have a <code>Toplevel</code> widget that I want to destroy whenever the user clicks out of the window. I tried finding solutions on the Internet, but there seems to be no article discussing about this topic.</p>
<p>How can I achieve this. Thanks for any help !</p>
| 0 | 2016-08-02T14:30:04Z | 38,723,529 | <p>You can try something like that :
fen is your toplevel</p>
<pre><code>fen.bind("<FocusOut>", fen.quit)
</code></pre>
| 1 | 2016-08-02T14:40:21Z | [
"python",
"tkinter",
"focus",
"destroy",
"toplevel"
] |
Django/Jinja: "Unused is at end of expression" | 38,723,343 | <p>I'm getting a weird Django error when accessing the following jinja template:</p>
<pre><code>{% if variable is defined %}
value of variable: {{ variable }}
{% else %}
variable is not defined
{% endif %}
</code></pre>
<p>It is very basic and taken from the original <a href="http://jinja.pocoo.org/docs/dev/t... | 0 | 2016-08-02T14:32:06Z | 38,723,688 | <p>My guess it that this is happening because Django isn't fully compatible with Jinja2. This is taken from the <a href="http://jinja.pocoo.org/docs/dev/faq/#how-compatible-is-jinja2-with-django" rel="nofollow">Jinja FAQ</a>:</p>
<blockquote>
<p>The default syntax of Jinja2 matches Django syntax in many ways. Howeve... | 1 | 2016-08-02T14:47:07Z | [
"python",
"django",
"jinja2"
] |
Django/Jinja: "Unused is at end of expression" | 38,723,343 | <p>I'm getting a weird Django error when accessing the following jinja template:</p>
<pre><code>{% if variable is defined %}
value of variable: {{ variable }}
{% else %}
variable is not defined
{% endif %}
</code></pre>
<p>It is very basic and taken from the original <a href="http://jinja.pocoo.org/docs/dev/t... | 0 | 2016-08-02T14:32:06Z | 38,723,991 | <p>The error is because Django is treating your template as Django template language. Your jinja2 templates belong in your app's <code>jinja2</code> directory, e.g. <code>/home/django/mediwiki/medisearch/jinja2/medisearch/response.html</code></p>
| 0 | 2016-08-02T14:59:40Z | [
"python",
"django",
"jinja2"
] |
Outcome of double-recursion in Python | 38,723,546 | <p>I have a question regarding these lines of code. I was trying to figure out what the print statement would show:</p>
<pre><code>def f(s):
if len(s) <= 1:
return s
return f(f(s[1:])) + s[0]
print f("abcd")
</code></pre>
<p>I was expecting it to print: <code>dcba</code> but instead it showed: <cod... | 2 | 2016-08-02T14:41:05Z | 38,723,832 | <p>I haven't ran your code through a debugger so I can't exactly see the <em>stack trace</em>, but it is due to you recursively calling <code>f()</code> twice. This seems over-manipulate the string leading to an unintended transformation. If you want to reverse a string recursively, the code below is fairly popular: </... | 2 | 2016-08-02T14:53:11Z | [
"python",
"recursion"
] |
Outcome of double-recursion in Python | 38,723,546 | <p>I have a question regarding these lines of code. I was trying to figure out what the print statement would show:</p>
<pre><code>def f(s):
if len(s) <= 1:
return s
return f(f(s[1:])) + s[0]
print f("abcd")
</code></pre>
<p>I was expecting it to print: <code>dcba</code> but instead it showed: <cod... | 2 | 2016-08-02T14:41:05Z | 38,723,865 | <p>Let's start from the bottom up.</p>
<p>Calling <code>f</code> on a one-character string just returns that string. Ex. f("a") returns "a".</p>
<p>Calling <code>f</code> on a two-character string returns that string reversed. Ex. f("ab") == f(f("b")) + "a" == f("b") + "a" == "b" + "a" == "ba".</p>
<p>Calling <code>... | 3 | 2016-08-02T14:54:35Z | [
"python",
"recursion"
] |
Outcome of double-recursion in Python | 38,723,546 | <p>I have a question regarding these lines of code. I was trying to figure out what the print statement would show:</p>
<pre><code>def f(s):
if len(s) <= 1:
return s
return f(f(s[1:])) + s[0]
print f("abcd")
</code></pre>
<p>I was expecting it to print: <code>dcba</code> but instead it showed: <cod... | 2 | 2016-08-02T14:41:05Z | 38,724,144 | <p>If you want to follow the calls add some print statements:</p>
<pre><code>>>> def f(s):
... print
... print "recieved", s
... if len(s) <= 1:
... print "returning", s
... return s
... print "returning f(f(%s)) + %s" % (s[1:], s[0])
... return f(f(s[1:])) + s[0]
...
&g... | 2 | 2016-08-02T15:05:39Z | [
"python",
"recursion"
] |
How to git pull rebase using GitPython library? | 38,723,571 | <p>I am using GitPython library (<a href="https://gitpython.readthedocs.io/en/stable/" rel="nofollow">GitPython Documentation</a>)</p>
<p>The following code is working fine for git pull, but how to use <strong>git pull --rebase</strong> ?"</p>
<pre><code>import git
g = git.cmd.Git(git_dir)
g.pull()
</code></pre>
<... | 3 | 2016-08-02T14:42:17Z | 38,724,479 | <p>Have you tried g.pull("--rebase")</p>
| 1 | 2016-08-02T15:20:35Z | [
"python",
"git",
"gitpython"
] |
'tags' parameter at Python Softlayer API call SoftLayer.VSManager.list_instances() not working as expected | 38,723,603 | <p>I am implementing a cloud bursting system with Softlayer instances and Slurm. But I got a problem with Python Softlayer API.</p>
<p>When I try to get a list of some specific instances with the API call SoftLayer.VSManager.list_instances() I use the parameter 'tags', since I tagged the instances to classify them. Bu... | 0 | 2016-08-02T14:44:04Z | 38,724,046 | <p>According the <a href="https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/vs.py#L71" rel="nofollow">documentation</a> of the method that you are using, you need to send a list of tags, so change the string by a list like this:</p>
<pre><code>client = SoftLayer.Client()
mgr = SoftLayer.VSMa... | 0 | 2016-08-02T15:01:42Z | [
"python",
"api",
"softlayer"
] |
Google App Engine - run task on publish | 38,723,681 | <p>I have been looking for a solution for my app that does not seem to be directly discussed anywhere. My goal is to publish an app and have it reach out, automatically, to a server I am working with. This just needs to be a simple Post. I have everything working fine, and am currently solving this problem with a cron ... | 1 | 2016-08-02T14:46:52Z | 38,742,762 | <p>The main question will be how to ensure it only runs once for a particular version. </p>
<p>Here is an outline on how you might approach it.</p>
<p>You create a HasRun module, which you use store each the version of the deployed app and this indicates if the one time code has been run.</p>
<p>Then make sure you i... | 0 | 2016-08-03T11:49:28Z | [
"python",
"google-app-engine"
] |
Google App Engine - run task on publish | 38,723,681 | <p>I have been looking for a solution for my app that does not seem to be directly discussed anywhere. My goal is to publish an app and have it reach out, automatically, to a server I am working with. This just needs to be a simple Post. I have everything working fine, and am currently solving this problem with a cron ... | 1 | 2016-08-02T14:46:52Z | 38,794,445 | <p>Personally, this makes more sense to me as a responsibility of your deploy process, rather than of the app itself. If you have your own deploy script, add the post request there (after a successful deploy). If you use google's command line tools, you could wrap that in a script. If you use a 3rd party tool for somet... | 2 | 2016-08-05T17:03:42Z | [
"python",
"google-app-engine"
] |
Python - Identifying Extraneous Types within a List | 38,723,695 | <p>Suppose I have a 2-Dimensional list representing a matrix of numerical values (No, I am not using numPy for this). The allowed types within this list fall under the category of <a href="https://docs.python.org/2/library/numbers.html" rel="nofollow">numbers.Number</a>. Supposing that I wish to isolate any non-numeric... | 0 | 2016-08-02T14:47:25Z | 38,723,902 | <p>Try this:</p>
<pre><code>print(any(not isinstance(x, Number) for row in matrix for x in row))
</code></pre>
<p>And in the function:</p>
<pre><code>def foo(matrix):
if any(not isinstance(x, Number) for row in matrix for x in row):
raise ValueError('The Input Matrix contains a non-numeric value')
</code... | 2 | 2016-08-02T14:56:16Z | [
"python",
"list",
"matrix",
"elements",
"isinstance"
] |
How to run Python Unit tests with XML output | 38,723,788 | <p>I try to run Python unit tests on our continues integration server (Bamboo, running on Debian Jessie) with XML output so we can either mark build as fail or success according to the test results. I am currently struggling with the fact that I just cannot install <code>xmlrunner</code> module. This is what I have don... | 0 | 2016-08-02T14:51:12Z | 38,828,430 | <p>You should install the runner using <code>pip</code>, and I think the package is just called <code>xmlrunner</code> (but maybe that is python 2.7)</p>
<pre><code>pip install xmlrunner
</code></pre>
<p>Even better would be to everything inside <a href="https://virtualenv.pypa.io/en/stable/" rel="nofollow">virtualen... | 0 | 2016-08-08T11:47:16Z | [
"python",
"linux",
"debian",
"python-module",
"python-unittest"
] |
Updating TKinter (Python) label with StringVar() - Variable not defined error (possible scope issue?) | 38,723,802 | <p>Okay so I am trying to, every time the user updates a value in an entry box, calculate a new value from the input and display it with a label.</p>
<p>I'm having a few issues however, not matter how I do it, by binding a StringVar() variable to the label and updating that via the .set() method. Or by using .config(t... | 0 | 2016-08-02T14:51:49Z | 38,724,400 | <p>The problem is that you are setting up the traces before you've initialized all of your variables. Move the traces toward the bottom of your script:</p>
<pre><code>...
frequency=StringVar()
numSamples=StringVar()
freqTxt=Entry(...)
numSamplesTxt=Entry(...)
...
frequency.trace("w", ...)
numSamples.trace("w", ...)
... | 0 | 2016-08-02T15:17:21Z | [
"python",
"tkinter",
"label"
] |
Get SQL query count in peewee | 38,723,923 | <p>Is it possible to count queries in peewee?
Make it in Django as follows:</p>
<pre><code>from django.db import connection
print len(connection.queries)
</code></pre>
| 0 | 2016-08-02T14:56:57Z | 38,726,445 | <p>You can act just like <a href="http://docs.peewee-orm.com/en/latest/peewee/database.html#adding-a-new-database-driver" rel="nofollow">here</a>: subclass <code>Database</code> setting it up to count queries:</p>
<pre><code>def execute(*args, **kwargs):
self.counter += 1 # or put the query into some list, as yo... | 1 | 2016-08-02T16:59:10Z | [
"python",
"peewee",
"flask-peewee"
] |
python csv writer if row key does not exist | 38,723,955 | <p>The following script is erroring out:</p>
<pre><code>import csv,time,string,os,requests, datetime
test = "\\\\network\\Shared\\test.csv"
fields = ["id", "Expiration Date", "Cost", "Resale" ]
with open(test) as infile, open("c:\\upload\\tested.csv", "wb") as outfile:
r = csv.DictReader(infile)
w = csv.Dic... | 0 | 2016-08-02T14:58:10Z | 38,724,889 | <p>You got a KeyError accessing something not in the dict at <code>x['Expiration Date']</code> so you could say <code>x.get('Expiration Date')</code> or possibly <code>'Expiration Date' in x</code> instead to discover if it exists and conditionally discard that row.</p>
| 0 | 2016-08-02T15:37:40Z | [
"python"
] |
python csv writer if row key does not exist | 38,723,955 | <p>The following script is erroring out:</p>
<pre><code>import csv,time,string,os,requests, datetime
test = "\\\\network\\Shared\\test.csv"
fields = ["id", "Expiration Date", "Cost", "Resale" ]
with open(test) as infile, open("c:\\upload\\tested.csv", "wb") as outfile:
r = csv.DictReader(infile)
w = csv.Dic... | 0 | 2016-08-02T14:58:10Z | 38,725,278 | <p>Actually, the <code>dict</code> produced by the <code>csv.DictReader</code> just puts <code>None</code> into a field it does not find and thus you should not get that error. You are not using the functionality of the <code>DictReader</code> to produce a proper <code>dict</code>! As far as I can tell, you try to do t... | 1 | 2016-08-02T15:55:59Z | [
"python"
] |
How to store the order of a dynamically-variable number of objects (in python)? | 38,724,002 | <p>Let's say I want to ask a <code>User</code> a <code>Question</code>: <em>"Order the following animals from biggest to smallest"</em>. Here's a little simplified django:</p>
<pre><code>class Question(models.Model):
text = models.CharField() #eg "Order the following animals..."
class Image(models.Model):... | 1 | 2016-08-02T15:00:02Z | 38,724,119 | <p>I am generally strongly opposed to storing comma separated data in a column. However this seems like an exception to the rule! May I propose <a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#commaseparatedintegerfield" rel="nofollow">CommaSeparatedIntegerField</a>? </p>
<blockquote>
<p>class Comma... | 1 | 2016-08-02T15:04:31Z | [
"python",
"django",
"postgresql",
"data-structures",
"django-models"
] |
Django crispy forms - Set label text for multiple fields | 38,724,012 | <p><a href="http://i.stack.imgur.com/JeRno.png" rel="nofollow"><img src="http://i.stack.imgur.com/JeRno.png" alt="enter image description here"></a></p>
<p>I'm working through <a href="https://bixly.com/blog/awesome-forms-django-crispy-forms/" rel="nofollow">https://bixly.com/blog/awesome-forms-django-crispy-forms/</a... | 0 | 2016-08-02T15:00:14Z | 38,724,201 | <p>Try to use the <code>labels</code> meta-field</p>
<p>Like:</p>
<pre><code>class UserForm(forms.ModelForm):
class Meta:
model = User # Your User model
fields = ['contact_name', 'contact_address', 'contact_email', 'contact_phone']
labels = {
'contact_name': 'What is your name'... | 1 | 2016-08-02T15:08:24Z | [
"python",
"django",
"django-crispy-forms"
] |
Modify user password without knowing the existing one | 38,724,085 | <p>I want to create a script for changing user password but without knowing the existing password, so it's like the reseting the password to new one.</p>
<p>Here is my script using python with ldap3</p>
<pre><code>from ldap3 import *
server = Server('myldapserver.com', get_info=ALL)
the_user = 'cn=Manager,dc=domain,d... | 0 | 2016-08-02T15:03:09Z | 38,753,219 | <p>I assume you're trying to change a password in an Active Directory domain.
First of all you must check the result of the bind() method. If bind is not successful you get an anonymous connection and you can't do anything with the password attribute. </p>
<p>Also you must establish a secure connection to change the p... | 0 | 2016-08-03T20:40:36Z | [
"python",
"ldap"
] |
Sorting and writing files in python | 38,724,115 | <p>I have text files that look like:</p>
<pre><code>2.8 3.0 1
28.4 3.0 1
36.2 3.0 1
70.49 3.0 1
85.19 3.0 1
</code></pre>
<p>And I have the following code:</p>
<pre><code>f = open('file.txt','r')
with open('file.txt') as fin:
lines = f.readline()
print lines
with open ('file_1.txt', 'w')... | -1 | 2016-08-02T15:04:27Z | 38,724,427 | <p>You could find out how long the file is with len() and then use two for loops to iterate through and create a new text file every time.</p>
<pre><code># Ask how long the file is
with open("file.txt", "r+b") as text_file:
lines = text_file.readlines() # returns a list of the lines in the file
num_lines = len(lin... | 0 | 2016-08-02T15:18:29Z | [
"python",
"sorting",
"text-files"
] |
Sorting and writing files in python | 38,724,115 | <p>I have text files that look like:</p>
<pre><code>2.8 3.0 1
28.4 3.0 1
36.2 3.0 1
70.49 3.0 1
85.19 3.0 1
</code></pre>
<p>And I have the following code:</p>
<pre><code>f = open('file.txt','r')
with open('file.txt') as fin:
lines = f.readline()
print lines
with open ('file_1.txt', 'w')... | -1 | 2016-08-02T15:04:27Z | 38,727,273 | <p>Here is a solution using the <code>with</code> context management and <code>readlines</code>/<code>writelines</code> to simplify I/O.</p>
<pre><code>with open('file.txt', 'r') as input:
linebuf = input.readlines()
# The context manager will automatically close `input`
# no matter what happens (including errors)... | 0 | 2016-08-02T17:49:47Z | [
"python",
"sorting",
"text-files"
] |
Remove HTML block in Python | 38,724,132 | <p>I'd like to know if there's a library or some method in Python to extract an element from an HTML document. For example:</p>
<p>I have this document:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-... | 0 | 2016-08-02T15:04:56Z | 38,724,362 | <p>Try using a HTML parser such as <a href="https://www.crummy.com/software/BeautifulSoup/" rel="nofollow" title="BeautifulSoup">BeautifulSoup</a> to select the <code><div></code> DOM element. Then you can remove it using regex or similar.</p>
| 0 | 2016-08-02T15:15:40Z | [
"python",
"html",
"parsing"
] |
Remove HTML block in Python | 38,724,132 | <p>I'd like to know if there's a library or some method in Python to extract an element from an HTML document. For example:</p>
<p>I have this document:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-... | 0 | 2016-08-02T15:04:56Z | 38,724,382 | <p>I personally feel that you don't need a library or something.</p>
<p>You can simply write a python script to read the html file and a regex to match your desired html tags and then do whatever you want to with it (delete in your case)</p>
<p>Though, there exist a library for the same.</p>
<p>See the official docu... | 0 | 2016-08-02T15:16:30Z | [
"python",
"html",
"parsing"
] |
Remove HTML block in Python | 38,724,132 | <p>I'd like to know if there's a library or some method in Python to extract an element from an HTML document. For example:</p>
<p>I have this document:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-... | 0 | 2016-08-02T15:04:56Z | 38,724,722 | <p>You don't need a library for this. Just use built in string methods.</p>
<pre><code>def removeOneTag(text, tag):
return text[:text.find("<"+tag+">")] + text[text.find("</"+tag+">") + len(tag)+3:]
</code></pre>
<p>This will remove everything in-between the first opening and closing tag. So your inpu... | 0 | 2016-08-02T15:30:40Z | [
"python",
"html",
"parsing"
] |
parsing xml doc with multiple grandchild in python | 38,724,153 | <p>I have been researching a way to parse an xml document with more than one root in python but have been unsuccessful. Does anyone know of any helpful sites to accomplish this or have any isight as to whether this can be done? I have the xml file and python code below. I get a 'NoneType' object has no attribute 'text'... | 0 | 2016-08-02T15:06:14Z | 38,724,495 | <p>Have you tried <a href="https://docs.python.org/2/library/xml.dom.html" rel="nofollow">xml.dom</a> or <a href="https://docs.python.org/2/library/xml.dom.minidom.html" rel="nofollow">minidom</a>?</p>
| 1 | 2016-08-02T15:21:13Z | [
"python",
"xml"
] |
Another Cannot set values on a ManyToManyField which specifies an intermediary model | 38,724,203 | <p>I am getting the error:</p>
<p><code>Cannot set values on a ManyToManyField which specifies an intermediary model. Use ipaswdb.ProviderLocations's Manager instead.</code></p>
<p>I am getting tripped up by the ipaswdb.ProviderLocations manager portion, I thought in my code in the views.py I was properly addressing ... | 3 | 2016-08-02T15:08:37Z | 38,884,854 | <p>Don't commit when saving your save. As documented <a href="https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method" rel="nofollow">here</a> if you specify <code>commit=True</code> it will try to write the M2M mapping at the same time. You don't want that to happen. </p>
<p>By specifying a ... | 3 | 2016-08-10T22:56:29Z | [
"python",
"django",
"django-forms",
"many-to-many"
] |
Sending pandas dataframe to java application | 38,724,255 | <p>I have created a python script for predictive analytics using pandas,numpy etc. I want to send my result set to java application . Is their simple way to do it. I found we can use Jython for java python integration but it doesn't use many data analysis libraries. Any help will be great . Thank you .</p>
| 1 | 2016-08-02T15:10:45Z | 38,724,313 | <p>Have you tried using xml to transfer the data between the two applications ?
My next suggestion would be to output the data in JSON format in a txt file and then call the java application which will read the JSON from the text file. </p>
| 0 | 2016-08-02T15:13:09Z | [
"java",
"python",
"pandas",
"numpy",
"jython"
] |
Captcha recognizing with convnet, how to define loss function | 38,724,286 | <p>I have small research project where I try to decode some captcha images. I use convnet implemented in Tensorflow 0.9, based on MNIST example (<a href="https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/convolutional_network.py" rel="nofollow">https://github.com/aymericdamien/T... | 0 | 2016-08-02T15:11:58Z | 39,098,141 | <p>The real problem was that my network get stuck, the network output was constant for any input.</p>
<p>When I have changed loss function to <code>loss = tf.nn.sigmoid_cross_entropy_with_logits(pred,y)</code> and normalize input, then the net start to learn the patterns. </p>
<p>Standarization (substract mean and d... | 0 | 2016-08-23T10:04:48Z | [
"python",
"neural-network",
"tensorflow",
"captcha",
"conv-neural-network"
] |
How to run Python Script in PHP/Laravel | 38,724,318 | <p>I wanted to know how to run python script using php code. I have tried different options like</p>
<pre><code> $output = exec("python /var/GAAutomationScript.py");
$command = escapeshellcmd('/var/GAAutomationScript.py');
$output = shell_exec($command);
</code></pre>
<p>But unable to run the python script. My ap... | 3 | 2016-08-02T15:13:28Z | 38,724,392 | <p>In PHP:</p>
<pre><code><?php
$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);
echo $output;
?>
</code></pre>
<p>In Python file 'test.py' verify this text in first line: (<a href="http://stackoverflow.com/questions/2429511/why-do-people-write-usr-bin-env-python-on-the-first... | 6 | 2016-08-02T15:16:46Z | [
"php",
"python",
"laravel"
] |
Select and merge pandas dataframe (dates) | 38,724,347 | <p>I have two dataframes and I need to subselect data from the first and merge with the second. Consider the first df1:</p>
<pre><code> ob_time air_temperature
0 2016-02-01 00:00 11.2
4 2016-02-01 01:00 11.1
8 2016-02-01 02:00 11.1
12 2016-02-01 03:00 10.8
16 ... | 2 | 2016-08-02T15:14:46Z | 38,724,606 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a>:</p>
<pre><code>#if dtypes is not datetime
df1['ob_time'] = pd.to_datetime(df1.ob_time)
df2['response_date'] = pd.to_datetime(df2.response_date)
#replace minutes, seconds and microsec... | 2 | 2016-08-02T15:24:44Z | [
"python",
"pandas",
"dataframe",
"merge"
] |
Python Print Distinct Values | 38,724,349 | <p>Using Tweepy in Python 2.7 to store results of a search query into a CSV file. I am trying to figure out how I can print only the number of unique tweet.ids from my result set. I know that (len(list)) works but obviously I haven't initialized a list here. I am new to python programming so the solution may be obvious... | 0 | 2016-08-02T15:14:57Z | 38,724,473 | <p>You could use a <a href="https://docs.python.org/2/library/sets.html" rel="nofollow"><code>set</code></a> to keep track of the unique ids you've seen so far, and then print that:</p>
<pre><code>ids = set()
for tweet in tweepy.Cursor(api.search,
q="Wookie",
#since="2014-02-14",
... | 2 | 2016-08-02T15:20:07Z | [
"python",
"tweepy",
"api-design"
] |
DRF canned filter - best practice? | 38,724,411 | <p>I use Django REST Framework in my Django app to provide an API, and have recently added filtering. To support a couple of things in the UI, I'd like to be able to provide some canned/named filter presets - for example, there's a <code>/api/tasks</code> viewset that gives you a list of all the tasks. Tasks have a com... | 0 | 2016-08-02T15:17:49Z | 38,729,072 | <p>You can use <strong>DjangoFilterBackend</strong>. For detailed information, see the <a href="http://www.django-rest-framework.org/api-guide/filtering/#djangofilterbackend" rel="nofollow">documentation</a>.
After installation <code>django-filter</code> lib don't forget to add <strong>DjangoFilterBackend</strong> in t... | 1 | 2016-08-02T19:35:52Z | [
"python",
"django",
"django-rest-framework"
] |
SyntaxError: Missing parentheses in call to 'print' | 38,724,612 | <p>I've been trying to scrape some twitter's data, but when ever I run this code I get the error <code>SyntaxError: Missing parentheses in call to 'print'</code>.</p>
<p>Can someone please help me out with this one?</p>
<p>Thanks for your time :)</p>
<pre><code>"""
Use Twitter API to grab user information from list ... | -4 | 2016-08-02T15:25:08Z | 38,724,686 | <p>Within pytyon 2, print has been a <strong>statement</strong>, not a function. That means you can use it without parentheses. In python 3, that has changed. It is a function there and you need to use print(foo) instead of print foo.</p>
| 0 | 2016-08-02T15:29:05Z | [
"python",
"json",
"helpers"
] |
SyntaxError: Missing parentheses in call to 'print' | 38,724,612 | <p>I've been trying to scrape some twitter's data, but when ever I run this code I get the error <code>SyntaxError: Missing parentheses in call to 'print'</code>.</p>
<p>Can someone please help me out with this one?</p>
<p>Thanks for your time :)</p>
<pre><code>"""
Use Twitter API to grab user information from list ... | -4 | 2016-08-02T15:25:08Z | 38,724,687 | <p>It seems like you are using python 3.x, however the code you are running here is python 2.x code. Two ways to solve this:</p>
<ul>
<li>Download python 2.x on <a href="https://www.python.org/downloads/" rel="nofollow">Python's website</a> and use it to run your script </li>
<li>Add parentheses around your print call... | 1 | 2016-08-02T15:29:06Z | [
"python",
"json",
"helpers"
] |
SyntaxError: Missing parentheses in call to 'print' | 38,724,612 | <p>I've been trying to scrape some twitter's data, but when ever I run this code I get the error <code>SyntaxError: Missing parentheses in call to 'print'</code>.</p>
<p>Can someone please help me out with this one?</p>
<p>Thanks for your time :)</p>
<pre><code>"""
Use Twitter API to grab user information from list ... | -4 | 2016-08-02T15:25:08Z | 38,724,688 | <p>Looks like you trying to run Python 2 code in Python 3, where <code>print</code> is <a href="https://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function" rel="nofollow"><strong>function</strong></a> and required parentheses:</p>
<pre><code>print(foo)
</code></pre>
| 0 | 2016-08-02T15:29:07Z | [
"python",
"json",
"helpers"
] |
SyntaxError: Missing parentheses in call to 'print' | 38,724,612 | <p>I've been trying to scrape some twitter's data, but when ever I run this code I get the error <code>SyntaxError: Missing parentheses in call to 'print'</code>.</p>
<p>Can someone please help me out with this one?</p>
<p>Thanks for your time :)</p>
<pre><code>"""
Use Twitter API to grab user information from list ... | -4 | 2016-08-02T15:25:08Z | 38,724,983 | <p>You just need to add pranethesis to your print statmetnt to convert it to a function, like the error says:</p>
<pre><code>print expression -> print(expression)
</code></pre>
<p>In Python 2, print is a statement, but in Python 3, print is a function. So you could alternatively just run your code with Python 2. <... | 0 | 2016-08-02T15:41:56Z | [
"python",
"json",
"helpers"
] |
Too Much Data for SVM? | 38,724,623 | <p>So I'm running a SVM classifier (with a linear kernel and probability false) from sklearn on a dataframe with about 120 features and 10,000 observations. The program takes hours to run and keeps crashing due to exceeding computational limits. Just wondering if this dataframe is perhaps too large? </p>
| 1 | 2016-08-02T15:25:32Z | 38,724,749 | <p>You could try changing the parameters for the algorithm.</p>
<p><a href="http://scikit-learn.org/stable/modules/svm.html#tips-on-practical-use" rel="nofollow">Tips on practical use from the documentation.</a></p>
<p>You could try a different algorithm, here's a cheat sheet you might find helpful:</p>
<p><a href="... | 0 | 2016-08-02T15:31:32Z | [
"python",
"scikit-learn",
"svm"
] |
Too Much Data for SVM? | 38,724,623 | <p>So I'm running a SVM classifier (with a linear kernel and probability false) from sklearn on a dataframe with about 120 features and 10,000 observations. The program takes hours to run and keeps crashing due to exceeding computational limits. Just wondering if this dataframe is perhaps too large? </p>
| 1 | 2016-08-02T15:25:32Z | 38,737,932 | <p>In short <strong>no</strong>, this is not too big at all. Linear svm can scale much further. The libSVC library on the other hand cannot. The good thing, even in scikit-learn you do have large scale svm implementation - LinearSVC which is based on <a href="https://www.csie.ntu.edu.tw/~cjlin/liblinear/" rel="nofollow... | 2 | 2016-08-03T08:09:28Z | [
"python",
"scikit-learn",
"svm"
] |
Searching a tree structure with a nested value? | 38,724,662 | <p><strong>Input:</strong> The tree structure is a list of financial accounts that are separated out in a hierarchical order of parent/children accounts. Any given account can have any number of parents/children. In the Python structure, each child is a list that can contain any number of dictionaries and/or text value... | 0 | 2016-08-02T15:27:46Z | 38,725,866 | <p>Incomplete (out of time, but I am sure you will manage to integrate your tests):</p>
<pre><code>tree = [
{"Assets": [
{"Bank": [
"Car",
"House"
]
},
... | 0 | 2016-08-02T16:26:41Z | [
"python",
"search",
"recursion",
"tree",
"nested"
] |
Searching a tree structure with a nested value? | 38,724,662 | <p><strong>Input:</strong> The tree structure is a list of financial accounts that are separated out in a hierarchical order of parent/children accounts. Any given account can have any number of parents/children. In the Python structure, each child is a list that can contain any number of dictionaries and/or text value... | 0 | 2016-08-02T15:27:46Z | 38,725,965 | <p>Im not going to actually answer your question (with regards to your specific stdout output requirements) but i will help show you how to search a tree structure</p>
<p>first describe your tree structure</p>
<ol>
<li>tree = List of Nodes</li>
<li>nodeType1 = a dictionary consisting of nodeName=>children</li>
<li>no... | 2 | 2016-08-02T16:32:31Z | [
"python",
"search",
"recursion",
"tree",
"nested"
] |
How do I capture string between certain Character and String in multi line String? Python | 38,724,767 | <p>Let's say we have a string </p>
<pre><code>string="This is a test code [asdf -wer -a2 asdf] >(ascd asdfas -were)\
test \
(testing test) test >asdf \
test"
</code></pre>
<p>I need to get the string between character > and string "test".</p>
<p>I tried</p>
<pre><code>re.findall(r'>[^)](.*)test... | 3 | 2016-08-02T15:32:07Z | 38,724,930 | <p>What about:</p>
<pre><code>import re
s="""This is a test code [asdf -wer -a2 asdf] >(ascd asdfas -were)
test
(testing test) test >asdf
test"""
print(re.findall(r'>(.*?)\btest\b', s, re.DOTALL))
</code></pre>
<p>Output:</p>
<pre><code>['(ascd asdfas -were)\n', 'asdf\n']
</code></pre>
<p>The only somewh... | 2 | 2016-08-02T15:39:08Z | [
"python",
"regex",
"python-2.7",
"python-3.x"
] |
Pandas - ValueError on datetime format mismatch | 38,724,777 | <p>This is my data:</p>
<pre><code>date = df['Date']
print (date.head())
0 2015-01-02
1 2015-01-02
2 2015-01-02
3 2015-01-02
4 2015-01-02
Name: Date, dtype: datetime64[ns]
</code></pre>
<p>my code:</p>
<pre><code>def date_to_days(date):
return date2num(datetime.datetime.strptime(date, '%Y-%m-%d'))
</c... | 0 | 2016-08-02T15:32:23Z | 38,725,597 | <p>It works fine for me without any errors. </p>
<pre><code>In [74]: from matplotlib.dates import date2num
In [75]: df['Number of days'] = df['Date'].apply(lambda x: date2num(datetime.datetime.strptime(x, '%Y-%m-%d')))
In [76]: df
Out[76]:
Date Number of days
0 2015-01-02 735600.0
1 2015-01-02 ... | 0 | 2016-08-02T16:10:21Z | [
"python",
"datetime",
"pandas"
] |
Writing and running tests. ImportError: No module named generic | 38,724,829 | <p>I'm new to <a href="https://docs.djangoproject.com/ja/1.9/topics/testing/overview/" rel="nofollow">tests in Django</a>. And I need to write a couple. </p>
<p>Django version 1.9.7.
OS: <code>Linux version 4.2.0-42-generic (buildd@lgw01-54) (gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) ) #49-Ubuntu SMP Tue Jun... | 0 | 2016-08-02T15:34:59Z | 38,724,945 | <p>Your installed version of django-autofixture does not support Django 1.9, because it has out of date imports for <code>GenericRelation</code>.</p>
<p>Try upgrading to the latest version. The project's <a href="https://github.com/gregmuellegger/django-autofixture/blob/d38ae8feaf159178ebea65fbc343970e6f440258/CHANGES... | 1 | 2016-08-02T15:39:59Z | [
"python",
"django",
"django-testing"
] |
Writing and running tests. ImportError: No module named generic | 38,724,829 | <p>I'm new to <a href="https://docs.djangoproject.com/ja/1.9/topics/testing/overview/" rel="nofollow">tests in Django</a>. And I need to write a couple. </p>
<p>Django version 1.9.7.
OS: <code>Linux version 4.2.0-42-generic (buildd@lgw01-54) (gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) ) #49-Ubuntu SMP Tue Jun... | 0 | 2016-08-02T15:34:59Z | 38,725,045 | <p>You have the wrong import, the correct import is from </p>
<pre><code>django.contrib.contenttypes.fields import GenericRelation
</code></pre>
<p>But that seems to actually come from django auto-fixtures rather than from your own code. The good news is that you don't need auto-fixtures for this sort of simple tests... | 2 | 2016-08-02T15:45:08Z | [
"python",
"django",
"django-testing"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.