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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Errors installing CUDA back-end (or cudarray) in Python in Windows 10 | 38,293,639 | <p>I am trying to follow the instructions to install CUDA (<a href="https://github.com/andersbll/cudarray" rel="nofollow">https://github.com/andersbll/cudarray</a>). </p>
<p>I am able to install the cudarray python package WITHOUT CUDA back-end following the instruction. The installation seems to be successful. When "... | -1 | 2016-07-10T15:45:19Z | 38,304,994 | <p>This doesn't directly answer your question; however, it should provide insight into your issue or you can directly follow the outlined steps to get PyCUDA installed:
I have recently (within the past 4 months) successfully completed a PyCUDA install on my Win 10 machine. The steps I followed including links to the re... | 1 | 2016-07-11T10:45:57Z | [
"python",
"python-2.7",
"pycuda"
] |
How can I add multiple product variations for the same product? | 38,293,647 | <p>I have made product for clothing, and I want to have two variations of same product: size and color.</p>
<p>Here is my <code>models.py</code>:</p>
<pre><code>class Product (models.Model):
title = models.CharField(max_length=120)
description = models.TextField(blank=True, null=True)
price = models.Decim... | 0 | 2016-07-10T15:46:01Z | 38,293,981 | <pre><code>class Product(models.Model):
title = models.CharField(max_length=120)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(decimal_places=2,max_digits=1000)
brand = models.CharField(max_length=300)
active =models.BooleanField(default=True)
weight = models.... | 0 | 2016-07-10T16:19:40Z | [
"python",
"django"
] |
flask_httpauth decorators missing required positional argument f | 38,293,683 | <p>I've been working with some of Miguel Grinberg's auth tutorials and have come across an issue using flask_httpauth's HTTPBasicAuth decorators. Whenever I use one of them on a function I get an error stating that the decorator is missing required positional argument f. It was my understanding that the function beneat... | 0 | 2016-07-10T15:50:11Z | 38,296,660 | <p>Change this:</p>
<pre><code>auth = HTTPBasicAuth
</code></pre>
<p>to this:</p>
<pre><code>auth = HTTPBasicAuth()
</code></pre>
| 0 | 2016-07-10T21:34:18Z | [
"python",
"flask",
"flask-httpauth"
] |
Tensorflow - What does ops constructors mean? | 38,293,688 | <p>In this <a href="https://www.tensorflow.org/versions/r0.9/get_started/basic_usage.html#basic-usage" rel="nofollow">link</a> under the building the graph heading there's a line that says </p>
<blockquote>
<p>"The ops constructors in the Python library return objects that stand for the output of the constructed ops... | 1 | 2016-07-10T15:50:35Z | 38,294,089 | <p>This is actually something in between. "Ops constructor" refers to functions creating new instances of objects being Ops. For example <code>tf.constant</code> constructs a new op, but actualy returns a reference to Tensor being a result of this operation, namely instance of <code>tensorflow.python.framework.ops.Tens... | 0 | 2016-07-10T16:31:17Z | [
"python",
"c++",
"constructor",
"machine-learning",
"tensorflow"
] |
Why I am getting these errors? AttributeError: can't set attribute | 38,293,812 | <p>I am trying to test my properties but it's not working and I have no idea why.</p>
<pre><code>import smtplib
class EmailService(object):
def __init__(self):
self._sender=None
self._receiver=None
self._message=None
@property
def sender(self):
return self._sender
@s... | 0 | 2016-07-10T16:04:33Z | 38,293,830 | <p>The methods wrapped with <code>@property</code> are already your <code>getter</code>s. </p>
<p>So replace <code>@receiver.getter</code> with <code>@receiver.setter</code> to make the corresponding methods <code>setter</code>s</p>
| 1 | 2016-07-10T16:05:56Z | [
"python",
"python-decorators"
] |
Why I am getting these errors? AttributeError: can't set attribute | 38,293,812 | <p>I am trying to test my properties but it's not working and I have no idea why.</p>
<pre><code>import smtplib
class EmailService(object):
def __init__(self):
self._sender=None
self._receiver=None
self._message=None
@property
def sender(self):
return self._sender
@s... | 0 | 2016-07-10T16:04:33Z | 38,293,851 | <blockquote>
<p>AttributeError: can't set attribute</p>
</blockquote>
<p>This is happening because you're trying to set the <code>sender</code> and <code>receiver</code> attributes but you don't have setters for them. </p>
<p>You need to replace:</p>
<ul>
<li><code>@sender.getter</code> with <code>@sender.setter</... | 1 | 2016-07-10T16:07:23Z | [
"python",
"python-decorators"
] |
Print a number table in a simple format | 38,293,878 | <p>I am stuck trying to print out a table in Python which would look like this (first number stands for amount of numbers, second for amount of columns):</p>
<pre><code>>>> print_table(13,4)
0 1 2 3
4 5 6 7
8 9 10 11
12 13
</code></pre>
<p>Does anyone know a way to achieve this?</p>
| 0 | 2016-07-10T16:10:12Z | 38,294,316 | <p>This is slightly more difficult than it sounds initially.</p>
<pre><code>def numbers(n, r):
print('\n'.join(' '.join(map(str, range(r*i, min(r*(i + 1), n + 1)))) for i in range(n//r + 1)))
numbers(13, 4)
#>>> 0 1 2 3
4 5 6 7
8 9 10 11
12 13
</code></pre>
| 1 | 2016-07-10T16:57:17Z | [
"python",
"python-2.7",
"python-3.x"
] |
Print a number table in a simple format | 38,293,878 | <p>I am stuck trying to print out a table in Python which would look like this (first number stands for amount of numbers, second for amount of columns):</p>
<pre><code>>>> print_table(13,4)
0 1 2 3
4 5 6 7
8 9 10 11
12 13
</code></pre>
<p>Does anyone know a way to achieve this?</p>
| 0 | 2016-07-10T16:10:12Z | 38,294,396 | <pre><code>def numbers(a,b):
i=0;
c=0;
while i<=a:
print(i,end="") #prevents printing a new line
c+=1
if c>=b:
print("\n") #prints a new line when the number of columns is reached and then reset the current column number
c=0;
</code></pre>
<p>I think it should work</p>
| 0 | 2016-07-10T17:05:26Z | [
"python",
"python-2.7",
"python-3.x"
] |
Print a number table in a simple format | 38,293,878 | <p>I am stuck trying to print out a table in Python which would look like this (first number stands for amount of numbers, second for amount of columns):</p>
<pre><code>>>> print_table(13,4)
0 1 2 3
4 5 6 7
8 9 10 11
12 13
</code></pre>
<p>Does anyone know a way to achieve this?</p>
| 0 | 2016-07-10T16:10:12Z | 38,296,576 | <pre><code>def num2(n=10, r=3):
print('\n'.join(' '.join(tuple(map(str, range(n+1)))[i:i+r]) for i in range(0, n+1, r)))
<<<
0 1 2
3 4 5
6 7 8
9 10
</code></pre>
| 0 | 2016-07-10T21:21:37Z | [
"python",
"python-2.7",
"python-3.x"
] |
Need help saving a list and then loading it later | 38,293,879 | <p>Say I have this list:</p>
<pre><code>SOME_LIST = []
</code></pre>
<p>And the data in it comes from user input as the program goes on. </p>
<p>So after the program is run it ends up like:</p>
<pre><code>SOME_LIST = [1, 2, 3, 5, 4]
</code></pre>
<p>How can I save <code>some_list</code> to a CSV file so that when... | 0 | 2016-07-10T16:10:30Z | 38,294,249 | <p>Why do you want to import the <code>csv</code> module? As far as I know a <code>csv</code> file is just a regular text file with values separated by commas, hence why </p>
<blockquote>
<p>"Comma Separated Values"</p>
</blockquote>
<p>The fact that you only want to store a single list makes it useless to import a... | 0 | 2016-07-10T16:50:09Z | [
"python",
"python-3.x"
] |
Need help saving a list and then loading it later | 38,293,879 | <p>Say I have this list:</p>
<pre><code>SOME_LIST = []
</code></pre>
<p>And the data in it comes from user input as the program goes on. </p>
<p>So after the program is run it ends up like:</p>
<pre><code>SOME_LIST = [1, 2, 3, 5, 4]
</code></pre>
<p>How can I save <code>some_list</code> to a CSV file so that when... | 0 | 2016-07-10T16:10:30Z | 38,297,482 | <p>Here you have a working version that can both save the list and load it:</p>
<pre><code>def main():
SOME_LIST = []
for i in range(1 , 6):
SOME_LIST.append(int(input('Enter an integer')))
print ('Press 1 to save your list')
print ('Press 2 to load your previous list')
user_answer = int(input('Enter your selectio... | 0 | 2016-07-10T23:57:12Z | [
"python",
"python-3.x"
] |
Need help saving a list and then loading it later | 38,293,879 | <p>Say I have this list:</p>
<pre><code>SOME_LIST = []
</code></pre>
<p>And the data in it comes from user input as the program goes on. </p>
<p>So after the program is run it ends up like:</p>
<pre><code>SOME_LIST = [1, 2, 3, 5, 4]
</code></pre>
<p>How can I save <code>some_list</code> to a CSV file so that when... | 0 | 2016-07-10T16:10:30Z | 38,297,923 | <p>I modified your code as little as possible. Basically you need to open the file in write mode to write the csv file. Also you have to specify the extension (in this case you were writing to a csv so it will be .csv, but there are other options such as .txt). To read the file you can use the csv reader and I gave an ... | 0 | 2016-07-11T01:19:13Z | [
"python",
"python-3.x"
] |
Defining instance variables using functions and instance methods in __init__ | 38,293,927 | <p>I have the defined the following class as:</p>
<pre><code>def user_kitchen(handle):
# return a BeautifulSoup object
class User(object):
def __init__(self, handle):
self.handle = str(handle)
self.soup = user_kitchen(handle)
self.details = self.find_details()
def find_details(s... | 0 | 2016-07-10T16:14:38Z | 38,294,186 | <p>According to your stack trace, I see a method with the signature - <code>_find_details(detail)</code>. Inside that method, there's a line like - <code>value = (self.soup).find_all(attrs=attribute)[0].text</code>. </p>
<p>Your method doesn't take in <code>self</code> as the first parameter. So it can't find <code>se... | 1 | 2016-07-10T16:43:02Z | [
"python",
"oop",
"instance"
] |
Creating file loop | 38,294,000 | <p>How can I ask the user for a file name and if it already exists, ask the user if they want to overwrite it or not, and obey their request. If the file does not exist, a new file (with the selected name) should be created.
From some research on both the Python website and Stack Overflow, I've come up with this code</... | 0 | 2016-07-10T16:21:08Z | 38,294,036 | <p>You can use <code>os.path.exists</code> to check if a file already exists are not. </p>
<pre><code>if os.path.exists(file path):
q = input("Do you want to overwrite the existing file? ")
if q == (your accepted answer):
#stuff
else:
#stuff
</code></pre>
<p>You could do this with a try / except if... | 1 | 2016-07-10T16:25:36Z | [
"python",
"file",
"while-loop",
"user-input"
] |
Creating file loop | 38,294,000 | <p>How can I ask the user for a file name and if it already exists, ask the user if they want to overwrite it or not, and obey their request. If the file does not exist, a new file (with the selected name) should be created.
From some research on both the Python website and Stack Overflow, I've come up with this code</... | 0 | 2016-07-10T16:21:08Z | 38,294,105 | <p>Alternative soltution would be (however the user would need to provide a full path):</p>
<pre><code>import os
def func():
if os.path.exists(input("Enter name: ")):
if input("File already exists. Overwrite it? (y/n) ")[0] == 'y':
my_file = open("filename.txt", 'w+')
else:
... | 1 | 2016-07-10T16:33:54Z | [
"python",
"file",
"while-loop",
"user-input"
] |
CSS 404 not found google app engine | 38,294,038 | <p>i am using google app engine (python) to develop my web application, now i found a little problem. I would like to add bootstrap css file to google app engine, and here is my folder directory</p>
<ul>
<li>project
<ul>
<li>app.yaml</li>
<li>favicon.ico</li>
<li>index.yaml</li>
<li>main.py</li>
<li>templates
<ul>
<... | 0 | 2016-07-10T16:25:50Z | 38,294,939 | <p>Try</p>
<pre><code>- url: /css/bootstrap/
static_dir: /templates/css/bootstrap/css
</code></pre>
<p>and reference it via</p>
<pre><code><link rel="stylesheet" type="text/css" href="/css/bootstrap/bootstrap.css" />
</code></pre>
| 0 | 2016-07-10T18:04:07Z | [
"python",
"html",
"css",
"twitter-bootstrap",
"google-app-engine"
] |
Cycle through combinations of 3 out of 5 | 38,294,039 | <p>I'm working on writing a poker simulation. I already got some parts ready.
But I stuck with comparing my hand with cards on the table.
My idea was to get my 2 cards and take 3 random cards from the deck and see if that makes a flush or something. But of course I have to cycle through so I take all combinations with ... | 2 | 2016-07-10T16:25:57Z | 38,294,126 | <p>Possibly try the <code>combinations</code> from <code>itertools</code>:</p>
<pre><code>[c for c in itertools.combinations(range(5), 3)]
[(0, 1, 2),
(0, 1, 3),
(0, 1, 4),
(0, 2, 3),
(0, 2, 4),
(0, 3, 4),
(1, 2, 3),
(1, 2, 4),
(1, 3, 4),
(2, 3, 4)]
</code></pre>
| 3 | 2016-07-10T16:36:18Z | [
"python",
"arrays"
] |
Cycle through combinations of 3 out of 5 | 38,294,039 | <p>I'm working on writing a poker simulation. I already got some parts ready.
But I stuck with comparing my hand with cards on the table.
My idea was to get my 2 cards and take 3 random cards from the deck and see if that makes a flush or something. But of course I have to cycle through so I take all combinations with ... | 2 | 2016-07-10T16:25:57Z | 38,294,143 | <p>The way you have represented the output is confusing but since you want to select 3 cards from a set of 5 cards, you need 5C3. You can achieve this using <code>itertools.combinations</code>.</p>
<p>From the <a href="https://docs.python.org/2.7/library/itertools.html#itertools.combinations" rel="nofollow">doc</a> :-... | 4 | 2016-07-10T16:37:53Z | [
"python",
"arrays"
] |
Simple Recurrent Neural Network with Keras | 38,294,046 | <p>I am trying to code a very simple RNN example with keras but the results are not as expected.</p>
<p>My X_train is a repeated list with length 6000 like: <code>1, 0, 0, 0, 0, 0, 1, 0, 0, 0, ...</code></p>
<p>I formatted this to shape: <code>(6000, 1, 1)</code></p>
<p>My y_train is a repeated list with length 6000... | 0 | 2016-07-10T16:26:41Z | 38,296,255 | <p>The input format should be three-dimensional: the three components represent sample size, number of time steps and output dimension</p>
<p>Once appropriately reformatted the RNN does indeed manage to predict the target sequence well.</p>
<pre><code>np.random.seed(1337)
sample_size = 256
x_seed = [1, 0, 0, 0, 0, 0... | 1 | 2016-07-10T20:36:27Z | [
"python",
"neural-network",
"keras",
"recurrent-neural-network"
] |
Returning n times the nth number of different lists in a list of dictionaries | 38,294,070 | <p>I have a dictionary that resembles this :</p>
<pre><code>[{ 'key' : 10, 'values' : [ [1,2] [3,4,5] [6,7,8,9] ] }, { ... }]
</code></pre>
<p>I'm trying to return new dictionaries with 'intersection' as key and the nth element of each list as values for as long as there are values in the longest list. The lists bein... | 1 | 2016-07-10T16:29:02Z | 38,294,181 | <p>Here is a one-liner that should work, but note that your output cannot be a dictionary because you canât have the same key show up more than once in a dictionary.</p>
<pre><code>def intersection(key, values):
return [(key, [L[i] if len(L) > i else L[-1] for L in values]) for i in range(max(map(len, values)... | 0 | 2016-07-10T16:42:20Z | [
"python",
"dictionary",
"list-comprehension"
] |
Returning n times the nth number of different lists in a list of dictionaries | 38,294,070 | <p>I have a dictionary that resembles this :</p>
<pre><code>[{ 'key' : 10, 'values' : [ [1,2] [3,4,5] [6,7,8,9] ] }, { ... }]
</code></pre>
<p>I'm trying to return new dictionaries with 'intersection' as key and the nth element of each list as values for as long as there are values in the longest list. The lists bein... | 1 | 2016-07-10T16:29:02Z | 38,296,967 | <p>You need to <strong>iterate as many times as there are items in the longest list of numbers</strong>. In every iteration you use the incremental index to get the nth value out of every list.</p>
<p>Try something like this:</p>
<pre><code>def intersect(key,values):
"""
Return n times the nth number of every lis... | 1 | 2016-07-10T22:25:51Z | [
"python",
"dictionary",
"list-comprehension"
] |
beautiful soup and parsing reddit | 38,294,136 | <p>just been trying to parse reddit shower thoughts for the submissions and have run into a problem:</p>
<pre><code> path = 'https://www.reddit.com/r/Showerthoughts/'
with requests.Session() as s:
r = s.get(path)
soup = BeautifulSoup(r.content, "lxml")
# print(soup.prettify())
threads = soup.find_... | 2 | 2016-07-10T16:37:02Z | 38,294,207 | <p>They are <em>css</em> classes, also you need to add a user-agent:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
path = 'https://www.reddit.com/r/Showerthoughts/'
headers ={"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"}
with re... | 2 | 2016-07-10T16:45:09Z | [
"python",
"parsing",
"lxml",
"bs4"
] |
Pythonic way to Call a function with set of arguments until it return any thing but None | 38,294,155 | <p>I know to use for loop and call my function till I get not None as return value, But I am looking for some python built in which can help here. </p>
<p>e.g. - <code>iter(myfunc(), None)</code> It will call <code>myfunc()</code> until it return <code>None</code></p>
<p>I am looking to code exactly opposite to this ... | 3 | 2016-07-10T16:39:53Z | 38,294,187 | <p>There is no ready builtin, but it is easy enough to build a generator function:</p>
<pre><code>def iter_while_none(f):
while True:
value = f()
if value is not None:
return
yield value
</code></pre>
<p>although the value yielded is not that interesting; it is, after all, <cod... | 1 | 2016-07-10T16:43:04Z | [
"python",
"python-2.7"
] |
Pythonic way to Call a function with set of arguments until it return any thing but None | 38,294,155 | <p>I know to use for loop and call my function till I get not None as return value, But I am looking for some python built in which can help here. </p>
<p>e.g. - <code>iter(myfunc(), None)</code> It will call <code>myfunc()</code> until it return <code>None</code></p>
<p>I am looking to code exactly opposite to this ... | 3 | 2016-07-10T16:39:53Z | 38,294,202 | <p>Do not look for a builtin for everything. In my opinion even the usual two-argument form of <code>iter</code> is not worth using because it's not a well known feature, and that makes it harder for most people to read. Just keep it simple and straightforward. An extra line or two will not hurt.</p>
<pre><code>while ... | 2 | 2016-07-10T16:44:57Z | [
"python",
"python-2.7"
] |
Pythonic way to Call a function with set of arguments until it return any thing but None | 38,294,155 | <p>I know to use for loop and call my function till I get not None as return value, But I am looking for some python built in which can help here. </p>
<p>e.g. - <code>iter(myfunc(), None)</code> It will call <code>myfunc()</code> until it return <code>None</code></p>
<p>I am looking to code exactly opposite to this ... | 3 | 2016-07-10T16:39:53Z | 38,294,224 | <p>With just three lines:</p>
<pre><code>x = None
while x is None:
x = f()
</code></pre>
| 3 | 2016-07-10T16:47:38Z | [
"python",
"python-2.7"
] |
Pythonic way to Call a function with set of arguments until it return any thing but None | 38,294,155 | <p>I know to use for loop and call my function till I get not None as return value, But I am looking for some python built in which can help here. </p>
<p>e.g. - <code>iter(myfunc(), None)</code> It will call <code>myfunc()</code> until it return <code>None</code></p>
<p>I am looking to code exactly opposite to this ... | 3 | 2016-07-10T16:39:53Z | 38,296,363 | <p>This answer is a bit of an exercise in the power of Python. I just get frustrated that <code>iter</code>s 2-arity form doesn't take a function for its second parameter.</p>
<p>But it does, if you're crazy enough. See, you can redefine equality on an object, like so:</p>
<pre><code>class Something:
def __eq__(s... | 1 | 2016-07-10T20:50:26Z | [
"python",
"python-2.7"
] |
How to construct a matrix based on user input? | 38,294,271 | <p>How to solve the problem to create a matrix with random numbers (user input)?
I also how a problem with this: </p>
<blockquote>
<p>UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
23: ordinal not in range(128)</p>
</blockquote>
<pre><code>array = list()
i = int(input("How many row: ")) ... | -3 | 2016-07-10T16:52:42Z | 38,294,381 | <p>I changed <code>np.reshape((i,j))</code> to <code>a = np.reshape(array,(i,j))</code> and it works fine. I dont see any error in the code like you mentioned.</p>
<pre><code>import numpy as np
array = list()
i = int(input("How many row: "))
j = int(input("How many column: "))
for x in range(i):
if i <= 0 or ... | 0 | 2016-07-10T17:03:47Z | [
"python",
"matrix",
"input"
] |
How can I match items from one list to the other in python? | 38,294,325 | <p>I have a list called users2 which is a master list of users. I have another list called codes has codes for each user in users2. The codes for the associated users are in the same order as in users2. So for example the code for bil is 56 because it is the second item in users2 and the second item in codes.</p>
<p>... | 3 | 2016-07-10T16:58:38Z | 38,294,395 | <p>You can construct a dictionary from <code>users2</code> and <code>codes</code> and then loop through <code>users1</code> and look up:</p>
<pre><code>[dict(zip(users2, codes)).get(u) for u in users1]
# ['56', '10', None, '34']
</code></pre>
<p>You can specify a different value for the missing user in the <code>get<... | 1 | 2016-07-10T17:05:22Z | [
"python",
"list"
] |
How can I match items from one list to the other in python? | 38,294,325 | <p>I have a list called users2 which is a master list of users. I have another list called codes has codes for each user in users2. The codes for the associated users are in the same order as in users2. So for example the code for bil is 56 because it is the second item in users2 and the second item in codes.</p>
<p>... | 3 | 2016-07-10T16:58:38Z | 38,294,407 | <p>You are probably using the wrong data structure. You want <code>users2</code> and <code>codes</code> to be combined into a dictionary.</p>
<pre><code>users1=['bil','kim','john','tim']
users2 = ['jim','bil','kim','tim','mike']
codes=['12','56','10','34','67']
users2_codes = dict(zip(users2, codes))
users1_codes = [... | 2 | 2016-07-10T17:06:13Z | [
"python",
"list"
] |
How can I match items from one list to the other in python? | 38,294,325 | <p>I have a list called users2 which is a master list of users. I have another list called codes has codes for each user in users2. The codes for the associated users are in the same order as in users2. So for example the code for bil is 56 because it is the second item in users2 and the second item in codes.</p>
<p>... | 3 | 2016-07-10T16:58:38Z | 38,294,542 | <p>Just keep it nice and simple. A list and dict with a couple of loops solves the problem.</p>
<pre><code>users1=['bil','kim','john','tim']
users2 = ['jim','bil','kim','tim','mike']
codes=['12','56','10','34','67']
name_codes = {}
for key, value in zip(users2, codes):
name_codes[key] = value
result = []
for use... | 1 | 2016-07-10T17:19:51Z | [
"python",
"list"
] |
How can I match items from one list to the other in python? | 38,294,325 | <p>I have a list called users2 which is a master list of users. I have another list called codes has codes for each user in users2. The codes for the associated users are in the same order as in users2. So for example the code for bil is 56 because it is the second item in users2 and the second item in codes.</p>
<p>... | 3 | 2016-07-10T16:58:38Z | 38,294,735 | <p>You can try using dictionaries to store the users2 list and the codes list as a key:value pair. Then run a comparison between the users1 list and this list and print out the codes. </p>
<p>code:</p>
<pre><code> user2=dict()
users2 = {'jim':'12','bil':'56','kim':'10','tim':'34','mike':'67'}
users1=["bil"... | 0 | 2016-07-10T17:41:25Z | [
"python",
"list"
] |
Using slicers on a multi-index | 38,294,332 | <p>I've got a dataframe of the form:</p>
<pre><code>Contract Date
201501 2014-04-29 1416.0
2014-04-30 1431.1
2014-05-01 1430.6
2014-05-02 1443.9
2014-05-05 1451.6
2014-05-06 1461.4
2014-05-07 1456.0
2014-05-08 1441.... | 5 | 2016-07-10T16:59:02Z | 38,294,646 | <p>Pandas needs you to be explicit about whether you're selecting columns or sub-levels of a hierarchical index. In this case, <code>df.loc[:,'2014-09']</code> fails because pandas tries to get all rows and then look for a column labelled <code>'2014-09'</code> (which doesn't exist).</p>
<p>Instead, you need to give b... | 2 | 2016-07-10T17:30:45Z | [
"python",
"pandas",
"indexing",
"slice"
] |
Using slicers on a multi-index | 38,294,332 | <p>I've got a dataframe of the form:</p>
<pre><code>Contract Date
201501 2014-04-29 1416.0
2014-04-30 1431.1
2014-05-01 1430.6
2014-05-02 1443.9
2014-05-05 1451.6
2014-05-06 1461.4
2014-05-07 1456.0
2014-05-08 1441.... | 5 | 2016-07-10T16:59:02Z | 38,294,650 | <p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/basics.html#dt-accessor" rel="nofollow"><code>.dt accessor</code></a> to extract all values of the month September as follows:</p>
<pre><code>df.loc[(pd.to_datetime(df['Date']).dt.month == 9)]
</code></pre>
<p>Timing constraints:</p>
<pre><code>ti... | 1 | 2016-07-10T17:30:54Z | [
"python",
"pandas",
"indexing",
"slice"
] |
Using slicers on a multi-index | 38,294,332 | <p>I've got a dataframe of the form:</p>
<pre><code>Contract Date
201501 2014-04-29 1416.0
2014-04-30 1431.1
2014-05-01 1430.6
2014-05-02 1443.9
2014-05-05 1451.6
2014-05-06 1461.4
2014-05-07 1456.0
2014-05-08 1441.... | 5 | 2016-07-10T16:59:02Z | 38,294,661 | <p>You can use <code>pd.Indexslice</code> to select based on ranges for each <code>level</code> of your <code>MultiIndex</code> like so (<a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html#using-slicers" rel="nofollow">see docs</a>):</p>
<pre><code>idx = pd.IndexSlice
df.loc[idx[:, '2014-05'], :]
</code... | 2 | 2016-07-10T17:32:20Z | [
"python",
"pandas",
"indexing",
"slice"
] |
pygame blinking text | 38,294,342 | <p>I'm making a game in pygame, and when making this game I use a lot of text on the screen. but when I get to this point in my code the text that is written in first doesn't blink but the second does and I would like to change that. Also when I hold a key that letter gets written rapidly over and over when I only want... | 1 | 2016-07-10T16:59:47Z | 38,644,704 | <p>I believe the reason your text is blinking is because your calling <code>pygame.display.update()</code> in way to many places. Just call <code>pygame.display.update()</code> once near the end of your code.</p>
<p>~Mr.Python</p>
| 0 | 2016-07-28T19:01:25Z | [
"python",
"text",
"pygame"
] |
I can't get the user in django templates | 38,294,350 | <p>I already saw all the links on stackoverflow related to this.
I am using Django 1.9.7 an I try to see in template if theuser is authenticated but I can't get the user.</p>
<p>Template code which is not printing anything: </p>
<pre><code>{{ user.is_authenticate }}
{{ request.user.is_authenticate }}
</code></pre>
<... | 0 | 2016-07-10T17:00:33Z | 38,295,238 | <p>Make sure you pass the request context in the view, it's what adds the user to the context...</p>
<pre><code>from django.template import RequestContext
def some_view(request):
form = None
# request.user accesses user here
return render_to_response('some_template.html', {'form':form}, context_instance=Request... | 1 | 2016-07-10T18:36:27Z | [
"python",
"django"
] |
Trying to find the circular reference in my django urlpatterns using django-subdomains? | 38,294,394 | <p>I'm getting a the url conf correct for my web app, and I'm at a loose end.</p>
<p>I <em>think</em> the idea behind <a href="https://django-subdomains.readthedocs.io/en/latest/index.html" rel="nofollow"><code>django-subdomains</code></a> is that the subdomain routing is stored in the <code>SUBDOMAIN_URLCONFS</code><... | 1 | 2016-07-10T17:05:21Z | 38,294,474 | <p>Your <code>ROOT_URLCONF</code> points to a module without any patterns. The <code>ROOT_URLCONF</code>module must at least have a <code>urlpatterns</code> attribute, even if it's an empty list. You probably want this to point to <code>creativeflow.urls</code>. </p>
| 1 | 2016-07-10T17:12:46Z | [
"python",
"django",
"django-subdomains"
] |
Running a check_output in python3 with mediainfo produces an error, even though the same call in terminal works fine | 38,294,482 | <p>This is the code:</p>
<pre><code>try:
s = check_output(['mediainfo', '--Inform=General;%Format%', filename]) # Gets the output from mediainfo
</code></pre>
<p>When running it, I get</p>
<pre><code>subprocess.CalledProcessError: Command '['mediainfo', '--Inform=General;%Format%', 'xyz']' returned non-zero exi... | 0 | 2016-07-10T17:13:32Z | 38,294,722 | <p>There is nothing wrong with the first two arguments. there are two strong possibilities, you are reading from a file and you have trailing whitespace on the filename:</p>
<pre><code>"sample.mkv\n"
</code></pre>
<p>Or you <em>current working directory</em> is not where the file is so you need to pass the full path ... | 1 | 2016-07-10T17:40:25Z | [
"python",
"python-3.x",
"subprocess",
"mediainfo"
] |
Cannot create database, while having init script in AppConfig. django.db.utils.OperationalError: no such table | 38,294,521 | <p>In my django application i have next code in <code>apps.py</code> file:</p>
<pre><code>class NewsConfig(AppConfig):
name = 'app_news'
def ready(self):
super().ready()
from service.cache import cache
cache.init_cache()
</code></pre>
<p>Purpose of <code>init_cache</code> method is to... | 0 | 2016-07-10T17:17:33Z | 38,294,645 | <p>You should avoid doing queries in <code>ready</code> method, as it has been mentioned here: <a href="https://docs.djangoproject.com/en/1.9/ref/applications/#django.apps.AppConfig.ready" rel="nofollow">https://docs.djangoproject.com/en/1.9/ref/applications/#django.apps.AppConfig.ready</a></p>
<p>Maybe you can call y... | 0 | 2016-07-10T17:30:39Z | [
"python",
"django",
"python-3.x"
] |
WTForms FieldList required Optional validation | 38,294,524 | <p>Currently I'm using Flask with WTForms via Flask-WTForms but being stuck with FieldList. I use FieldList for a list of email address like this:</p>
<pre><code>class MailToForm(Form):
emailAddress = StringField(
'Email',
validators=[
validators.DataRequired(),
validators.E... | 0 | 2016-07-10T17:17:54Z | 38,692,242 | <p>I got how to get away with this. I have to add the WTF's hidden fields of subforms so it can be validated.</p>
| 0 | 2016-08-01T06:28:21Z | [
"python",
"validation",
"flask",
"wtforms",
"flask-wtforms"
] |
how do I create a pipe using popen and communicate through it in Python? | 38,294,544 | <p>I have a process that writes to stdout and reads from stdin. I would like, in Python, to use that process to read and write from its stdout/stdin.</p>
<p>I tried:</p>
<pre><code> process = Popen(['the_program_name'], stdout=PIPE, stderr=PIPE, stdin=PIPE)
</code></pre>
<p>and then I try to use</p>
<pre><code... | 0 | 2016-07-10T17:20:13Z | 38,294,583 | <p>Read <a href="https://pymotw.com/2/subprocess/" rel="nofollow">here</a>:</p>
<p>Relevant code:</p>
<pre><code>import subprocess
print '\npopen2:'
proc = subprocess.Popen(['cat', '-'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
stdout_v... | 0 | 2016-07-10T17:24:21Z | [
"python",
"pipe"
] |
Python: smallest denormalized double error | 38,294,554 | <p>Using WinPython 3.4.4.2, I get the following weird result:</p>
<pre><code>>>> 2**-1075
5e-324
</code></pre>
<p>That is, the same as <code>2**-1074</code>, whereas <code>2**-1075</code> should be zero in double float representation. With Python 3.5.1 at the address <a href="https://www.python.org/shell/" r... | 2 | 2016-07-10T17:21:41Z | 38,294,817 | <p>The smallest re-presentable denormalized floats larger, and smaller, than zero are: <strong>5e-324</strong> and <strong>-5e-324</strong>.</p>
<p><strong>5e-324</strong> is the denormalized minimum which can be achieved by multiplying minimum floating point number(2.2250738585072014e-308) with floating point epsilon... | 1 | 2016-07-10T17:50:06Z | [
"python",
"double",
"denormalized"
] |
Pandas: Add new column to df with condition | 38,294,592 | <p>I have df and I need to create new column in it. </p>
<pre><code>i,ID,url,used_at,active_seconds,domain,search_term, diff_time
322015,0120bc30e78ba5582617a9f3d6dfd8ca,vk.com/antoninaribina,2015-10-31 09:16:05,35,vk.com,None, 108
838267,0120bc30e78ba5582617a9f3d6dfd8ca,vk.com/feed,2015-10-31 09:16:38,54,vk.com,N... | 0 | 2016-07-10T17:25:25Z | 38,294,750 | <p>Construct a switch variable that stores true if the period needs to be increased and false otherwise and then call <code>cumsum()</code> function on the obtained series:</p>
<pre><code>switch = (df.diff_time > 500) | (df.ID != df.ID.shift().fillna(df.ID[0]))
switch.cumsum() + 1
# 0 1
# 1 1
# 2 2
# 3 ... | 2 | 2016-07-10T17:42:54Z | [
"python",
"pandas"
] |
Python multiprocessing.Pool new process for each variable | 38,294,608 | <p>I am using multiprocessing.Pool in order to loop through a variable and make API calls to a third party program. The problem is that the API has some garbage collection issues, so I need a completely new process for each variable value that I want to run. Is there any way to force multiprocessing to close and launch... | 1 | 2016-07-10T17:27:01Z | 38,295,025 | <p>Setting <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool" rel="nofollow">maxtasksperchild</a> to <code>1</code> should force Pool to create a new process for each task:</p>
<pre><code>pool = Pool(maxtasksperchild=1)
</code></pre>
| 1 | 2016-07-10T18:13:12Z | [
"python",
"multiprocessing"
] |
Python delete firefox history | 38,294,692 | <p>I want to clean the history of Chrome and Firefox (Windows 10 x64). What I do is delete the files that store the data. My code work's great for Chrome, but it seems like firefox can't find the path.</p>
<pre><code>def fileDel(paths,item):
if (os.path.exists(paths)):
os.remove(paths)
print "Deleted %s in %s"... | 0 | 2016-07-10T17:35:41Z | 38,297,057 | <p>According to the <a href="https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data" rel="nofollow">Firefox documentation</a>:</p>
<blockquote>
<p>Bookmarks, Downloads and Browsing History: The <strong>places.sqlite</strong> file
contains all your Firefox bookmarks and lists of all the files ... | 1 | 2016-07-10T22:39:32Z | [
"python",
"python-3.x"
] |
Flask - render template asynchronously | 38,294,753 | <p>I'm making a Flask app and I was wondering if I could render a template for a route, but redirect the user after a function is complete. Currently using Python 2.7 Here is my example</p>
<pre><code>@app.route('/loading/matched')
def match():
time_match()
return render_template('matched.html')
def time_matc... | 0 | 2016-07-10T17:43:04Z | 38,294,846 | <p>This sounds more like a client sided thing to me? Do you want something like a loading bar?</p>
<p>You could provide an ajax route which initiates heavy workload on the server side - while the client does show some progress. Once the workload finished you render a template which than gets loaded via ajax.</p>
<p>F... | 1 | 2016-07-10T17:53:26Z | [
"python",
"asynchronous",
"flask"
] |
How to use __getattr__ to delegate methods to attribute? | 38,294,904 | <p>I have the following class:</p>
<pre><code>class MyInt:
def __init__(self, v):
if type(v) != int:
raise ValueError('value must be an int')
self.v = v
def __getattr__(self, attr):
return getattr(self.v, attr)
i = MyInt(0)
print(i + 1)
</code></pre>
<p>I get the error: <... | 1 | 2016-07-10T17:59:34Z | 38,295,177 | <p><code>__getattr__</code> cannot be used to generate other magic methods. You'll need to implement all of them individually.</p>
<p>When the Python language internals look up magic methods like <code>__add__</code>, they completely bypass <code>__getattr__</code>, <code>__getattribute__</code>, and the instance dict... | 2 | 2016-07-10T18:29:28Z | [
"python",
"composition",
"getattr"
] |
How do I declare a function and then assign it to a variable in the same line? | 38,294,955 | <p>I have a <code>Button</code> class that has a variable, <code>when_pressed</code>, that is meant to be a function. For the sake of the question, let's assume that it will always be a function and not something like an <code>int</code>. When your instance of the <code>Button</code> class is pressed, the function cont... | 2 | 2016-07-10T18:05:01Z | 38,294,972 | <p>Use a <a href="http://www.diveintopython.net/power_of_introspection/lambda_functions.html" rel="nofollow"><code>lambda</code></a> function:</p>
<pre><code>button.when_pressed = lambda: print('pressed')
</code></pre>
<p>Here's a good chance for you to learn about them in case you haven't: <a href="http://www.divein... | 5 | 2016-07-10T18:06:54Z | [
"python"
] |
How do I declare a function and then assign it to a variable in the same line? | 38,294,955 | <p>I have a <code>Button</code> class that has a variable, <code>when_pressed</code>, that is meant to be a function. For the sake of the question, let's assume that it will always be a function and not something like an <code>int</code>. When your instance of the <code>Button</code> class is pressed, the function cont... | 2 | 2016-07-10T18:05:01Z | 38,294,975 | <p>Use a lambda:</p>
<pre><code>something = lambda: print("Hello")
</code></pre>
| 2 | 2016-07-10T18:07:20Z | [
"python"
] |
Error: You must build Spark with Hive | 38,295,021 | <p>I'm running Spark 1.6.2 with Hive 0.13.1 and Hadoop 2.6.0.</p>
<p>I try to run this pyspark script:</p>
<pre><code>import pyspark
from pyspark.sql import HiveContext
sc = pyspark.SparkContext('local[*]')
hc = HiveContext(sc)
hc.sql("select col from table limit 3")
</code></pre>
<p>with this command line:</p>
<p... | 2 | 2016-07-10T18:12:48Z | 38,295,174 | <p>I have an Apache Spark version that came with HiveContext by default, this is the link to download in case you are interested:</p>
<ul>
<li><a href="http://www-eu.apache.org/dist/spark/spark-1.6.2/spark-1.6.2-bin-hadoop2.6.tgz" rel="nofollow">Spark 1.6.2 with HiveContext</a></li>
</ul>
<p>Regarding the problem you... | 0 | 2016-07-10T18:28:54Z | [
"python",
"apache-spark",
"hive",
"pyspark"
] |
Pandas Groupby/Grouper group by starting index value | 38,295,053 | <p>How do adjust the starting time in Grouper?</p>
<p>Starting with this sample DF:</p>
<pre><code>import datetime as DT
df = pd.DataFrame({
'Buyer': 'Carl Mark Carl Joe Joe Carl'.split(),
'Quantity': [1,3,5,8,9,3],
'Date' : [
DT.datetime(2013,1,1,13,0),
DT.datetime(2013,3,1,13,5),
DT.datetime(2013,5,1,20,0),
DT.date... | 0 | 2016-07-10T18:16:20Z | 38,492,008 | <p>You want a forward rolling window while <code>pandas</code> makes backwards rolling windows. So the idea is to reversed the ordering of your series, take a rolling window and then revert the ordering.</p>
<p>This is what you already had:</p>
<pre><code>from datetime import datetime
import pandas as pd
df = pd.Da... | 0 | 2016-07-20T22:37:24Z | [
"python",
"pandas",
"group-by"
] |
Print cubes of the numbers 1 through 10 only if the cube is evenly divisible by four | 38,295,070 | <p>Is everything right with code_cademy here ?</p>
<p><a href="http://i.stack.imgur.com/KLQxt.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/KLQxt.jpg" alt="enter image description here"></a></p>
<pre><code>cubes_by_four = [x*x*x for x in range(1,10) if (x*x*x) % 4 == 0]
for x in cubes_by_four:
print x
<... | -4 | 2016-07-10T18:17:42Z | 38,295,094 | <p>Your range is off. You need <code>range(1, 11)</code>, because the second argument of <code>range()</code> is the <em>first value to exclude</em>. <code>range(1, 10)</code> only gives you number 1 through 9.</p>
| 0 | 2016-07-10T18:21:11Z | [
"python",
"list"
] |
Print cubes of the numbers 1 through 10 only if the cube is evenly divisible by four | 38,295,070 | <p>Is everything right with code_cademy here ?</p>
<p><a href="http://i.stack.imgur.com/KLQxt.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/KLQxt.jpg" alt="enter image description here"></a></p>
<pre><code>cubes_by_four = [x*x*x for x in range(1,10) if (x*x*x) % 4 == 0]
for x in cubes_by_four:
print x
<... | -4 | 2016-07-10T18:17:42Z | 38,295,104 | <p>If you want to include the value <code>10</code> you must change the range to <code>range(1, 11)</code>, since the range does <em>not</em> include the second parameter.</p>
<p>In regular Python, <code>x^3</code> does not mean exponentiation but rather the binary operation "bitwise exclusive or". That is exponentiat... | 0 | 2016-07-10T18:21:43Z | [
"python",
"list"
] |
Print cubes of the numbers 1 through 10 only if the cube is evenly divisible by four | 38,295,070 | <p>Is everything right with code_cademy here ?</p>
<p><a href="http://i.stack.imgur.com/KLQxt.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/KLQxt.jpg" alt="enter image description here"></a></p>
<pre><code>cubes_by_four = [x*x*x for x in range(1,10) if (x*x*x) % 4 == 0]
for x in cubes_by_four:
print x
<... | -4 | 2016-07-10T18:17:42Z | 38,295,107 | <p>When you write <code>range(1,10)</code>, you include 1 but exclude 10.</p>
<p>So correct code is:</p>
<pre><code>cubes_by_four = [x*x*x for x in range(1,11) if (x*x*x) % 4 == 0]
print cubes_by_four:
</code></pre>
<p>It will be a good practice to use x**3 for cubes.</p>
<p><code>cubes_by_four = [x**3 for x in ra... | 0 | 2016-07-10T18:21:48Z | [
"python",
"list"
] |
Print cubes of the numbers 1 through 10 only if the cube is evenly divisible by four | 38,295,070 | <p>Is everything right with code_cademy here ?</p>
<p><a href="http://i.stack.imgur.com/KLQxt.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/KLQxt.jpg" alt="enter image description here"></a></p>
<pre><code>cubes_by_four = [x*x*x for x in range(1,10) if (x*x*x) % 4 == 0]
for x in cubes_by_four:
print x
<... | -4 | 2016-07-10T18:17:42Z | 38,295,141 | <blockquote>
<p>Finally <strong>print that list</strong> to the console</p>
</blockquote>
<pre><code>>>> cubes_by_four = [x**3 for x in range(1,11) if x**3 % 4 == 0]
>>> print(cubes_by_four)
[8, 64, 216, 512, 1000]
</code></pre>
<p>It says print the list, not print each item in the list to console... | 0 | 2016-07-10T18:24:38Z | [
"python",
"list"
] |
Print cubes of the numbers 1 through 10 only if the cube is evenly divisible by four | 38,295,070 | <p>Is everything right with code_cademy here ?</p>
<p><a href="http://i.stack.imgur.com/KLQxt.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/KLQxt.jpg" alt="enter image description here"></a></p>
<pre><code>cubes_by_four = [x*x*x for x in range(1,10) if (x*x*x) % 4 == 0]
for x in cubes_by_four:
print x
<... | -4 | 2016-07-10T18:17:42Z | 38,295,154 | <p>The second argument to <code>range</code> is not included in the range.</p>
<p>Is it between 1 and 10? or is it 1 through 10?</p>
<p>between 1 and 10 is <code>range(2,10)</code></p>
<p>1 through 10 is <code>range(1,11)</code></p>
| 0 | 2016-07-10T18:25:28Z | [
"python",
"list"
] |
Print cubes of the numbers 1 through 10 only if the cube is evenly divisible by four | 38,295,070 | <p>Is everything right with code_cademy here ?</p>
<p><a href="http://i.stack.imgur.com/KLQxt.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/KLQxt.jpg" alt="enter image description here"></a></p>
<pre><code>cubes_by_four = [x*x*x for x in range(1,10) if (x*x*x) % 4 == 0]
for x in cubes_by_four:
print x
<... | -4 | 2016-07-10T18:17:42Z | 38,295,176 | <p>Okay , a couple of things to keep in mind :-
1) if you want numbers 1-10 , do <code>range(1,11)</code> , since the last number is excluded, while the first number is (obviously) , included.
2) instead of <code>(x*x*x)</code> , you can something better like :- <code>pow(x,3)</code> , which essentially means x to the ... | 0 | 2016-07-10T18:29:26Z | [
"python",
"list"
] |
Print cubes of the numbers 1 through 10 only if the cube is evenly divisible by four | 38,295,070 | <p>Is everything right with code_cademy here ?</p>
<p><a href="http://i.stack.imgur.com/KLQxt.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/KLQxt.jpg" alt="enter image description here"></a></p>
<pre><code>cubes_by_four = [x*x*x for x in range(1,10) if (x*x*x) % 4 == 0]
for x in cubes_by_four:
print x
<... | -4 | 2016-07-10T18:17:42Z | 38,295,184 | <p>There are two separate problems with the code you showed here:</p>
<p>First, change <code>range(1,10)</code> to <code>range(1,11)</code> because Python doesn't include the second parameter (10), and 10^3 is evenly divided by 4 (1000/4 = 250).</p>
<p>And finally, the tutorial wants you to print the numbers all in a... | 0 | 2016-07-10T18:30:19Z | [
"python",
"list"
] |
is it better to read from LIST or from Database? | 38,295,148 | <p>I work on a raspberry pi project and use Python + Kivy for such reasons:</p>
<p>I read some string values comming from a device installed in a field every 300ms. </p>
<p>As soon as I see certain value I trigger a python thread to run another function which takes the string and stores it in a list and timestamp it.... | 0 | 2016-07-10T18:24:57Z | 38,304,824 | <p>Both approaches have pros and cons.</p>
<p>A database is designed to store and query data. You can query data easily (SQL) from multiple processes. If you don't have multiple processes and no complicated querys a database doesn't really offers that much. Maybe persistence if that is a concern for you. If you don't ... | 0 | 2016-07-11T10:36:57Z | [
"python",
"database",
"kivy"
] |
Transform rows of pandas Dataframe into list of strings | 38,295,231 | <p>How can I transform rows of Pandas dataframe into list of strings? I want to map each row of data frame into string such as it contains name of column and value of column for selected columns of dataframe:</p>
<p>for example I would like to convert columns B,C,D into list of strings (result) as is shown below:</p>
... | 1 | 2016-07-10T18:35:33Z | 38,295,364 | <p>Not sure if it is the best way but this will do what you want:</p>
<pre><code>cols = ["B", "C", "D"]
[",".join("{}:{}".format(*t) for t in zip(cols, row)) for _, row in df[["B", "C", "D"]].iterrows()]
</code></pre>
<p>Which will give you:</p>
<pre><code>['B:5,C:2,D:4', 'B:6,C:3,D:5', 'B:7,C:4,D:6', 'B:8,C:5,D:7']... | 2 | 2016-07-10T18:49:22Z | [
"python",
"pandas"
] |
xlwings runpython install fails | 38,295,256 | <p>I'm trying to use xlwings on mac (10.11.5) with Excel 2016 for Mac (Version 15.23.2), but I get stuck pretty fast.</p>
<p>When I run
xlwings runpython install
I get the following error:</p>
<pre><code>$ xlwings runpython install
Traceback (most recent call last):
File "/usr/local/bin/xlwings", line 7, in &l... | 0 | 2016-07-10T18:38:18Z | 38,295,409 | <p>Not quite sure yet <em>why</em> it fails, but what <code>xlwings runpython install</code> tries to do, is simply to copy the <code>xlwings.appscript</code> file from the xlwings installation directory into the following directory: <code>~/Library/Application Scripts/com.microsoft.Excel</code>. Hence to fix the situa... | 0 | 2016-07-10T18:52:39Z | [
"python",
"excel",
"osx",
"xlwings"
] |
xlwings runpython install fails | 38,295,256 | <p>I'm trying to use xlwings on mac (10.11.5) with Excel 2016 for Mac (Version 15.23.2), but I get stuck pretty fast.</p>
<p>When I run
xlwings runpython install
I get the following error:</p>
<pre><code>$ xlwings runpython install
Traceback (most recent call last):
File "/usr/local/bin/xlwings", line 7, in &l... | 0 | 2016-07-10T18:38:18Z | 38,298,919 | <p>I found the problem:
Basically, I was running <code>xlwings runpython install</code> in a different user-environment than Excel.</p>
| 0 | 2016-07-11T03:53:58Z | [
"python",
"excel",
"osx",
"xlwings"
] |
Difference between tuples (all or none) | 38,295,363 | <p>I have two sets as follows:</p>
<pre><code>house_1 = {('Gale', '29'), ('Horowitz', '65'), ('Galey', '24')}
house_2 = {('Gale', '20'), ('Horowitz', '65'), ('Gale', '29')}
</code></pre>
<p>Each tuple in each set contains attributes that represent a person. I need to find a special case of the symmetric set differenc... | -3 | 2016-07-10T18:49:20Z | 38,295,471 | <p>You could count the occurences of names in the result and print only tuples that correspond to the names with the count of 1:</p>
<pre><code>from collections import defaultdict
count = defaultdict(list)
for x in house_1 ^ house_2:
count[x[0]].append(x)
for v in count.values()
if len(v) == 1:
print... | 1 | 2016-07-10T18:59:10Z | [
"python",
"set",
"tuples"
] |
Import error in Django models on importing from another app | 38,295,447 | <p>I'm having an app called project with the following models.py file (the hastags are put in the code for purpose, so as to nullify the lines of codes)</p>
<pre><code>#inside project.models.py
from django.db import models
# Create your models here.
from django.db.models import signals
from django.core.urlresolvers ... | -2 | 2016-07-10T18:56:56Z | 38,295,853 | <p>When you would like to use it as a ForeignKey in Django you could do this:</p>
<pre><code>po_item= models.Foreignkey("project.POItem", related_name="foos")
</code></pre>
<p>You have to use the full name and put them in quotes.<br>
This way you do not have to import the class at the top of the python file. </p>
| 0 | 2016-07-10T19:45:45Z | [
"python",
"django",
"django-models",
"import",
"importerror"
] |
How add column with time difference in Sqlite (python) | 38,295,451 | <p>I want to update a table (sqlite database) adding column with constant value. However I am having some issues. I create table with</p>
<pre><code>cursor.execute('''CREATE TABLE users(col1 text, col2 text,
dateCol datetime default current_timestamp,
diff float)''')
</code></pre>
<p>... | 0 | 2016-07-10T18:57:11Z | 38,316,338 | <p>SQLite has no <a href="http://www.sqlite.org/lang_datefunc.html" rel="nofollow">date function</a> to compute differences, but this is possible by using a numeric <a href="http://www.sqlite.org/datatype3.html#datetime" rel="nofollow">date format</a>:</p>
<pre class="lang-sql prettyprint-override"><code>UPDATE users
... | 1 | 2016-07-11T21:15:25Z | [
"python",
"database",
"sqlite"
] |
Is there special significance to 16331239353195370.0? | 38,295,501 | <p>Using <code>import numpy as np</code> I've noticed that </p>
<pre><code>np.tan(np.pi/2)
</code></pre>
<p>gives the number in the title and not <code>np.inf</code></p>
<pre><code>16331239353195370.0
</code></pre>
<p>I'm curious about this number. Is it related to some system machine precision parameter? Could I h... | 82 | 2016-07-10T19:02:56Z | 38,295,695 | <p><code>pi</code> isn't exactly representable as Python float (same as the platform C's <code>double</code> type). The closest representable approximation is used.</p>
<p>Here's the exact approximation in use on my box (probably the same as on your box):</p>
<pre><code>>>> import math
>>> (math.pi... | 109 | 2016-07-10T19:25:02Z | [
"python",
"numpy",
"numerical-methods"
] |
How to set random seed in sqlalchemy.sql.expression.func.random() in python? | 38,295,559 | <p>I would like to set a random seed when shuffling a sqlalchmy query result using order_by to get always the same query result: </p>
<pre><code>my_query.order_by(func.random())
</code></pre>
<p>I could not find how to do it in the documentation. I tried it with </p>
<pre><code>my_query.order_by(func.random(random_s... | 0 | 2016-07-10T19:09:03Z | 38,297,161 | <p>The SQLAlchemy <code>func</code> object just renders functions in SQL.</p>
<pre><code>>>> from sqlalchemy import func
>>> print(func.random())
random()
</code></pre>
<p>In some cases (including this one), it will render a different underlying function on different database backends, e.g. on MySQL... | 0 | 2016-07-10T22:55:30Z | [
"python",
"random",
"sqlalchemy"
] |
Django Login Form / Invalid User | 38,295,686 | <p>I am learning Django and started building a simple login form. My view is working(redirecting to '/person/) when providing authenticated Username/Password. But it's throwing an ERROR ''AnonymousUser' object has no attribute '_meta'" when providing invalid credentials. Below is my view.</p>
<pre><code>#views.py
def ... | 1 | 2016-07-10T19:24:04Z | 38,295,717 | <p>You are attempting to login a user (<code>'AnonymousUser'</code>) whose credentials are invalid. </p>
<p>Move the <code>auth_login</code> logic into the block for authenticated users:</p>
<pre><code>user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
auth_... | 3 | 2016-07-10T19:27:40Z | [
"python",
"django"
] |
Python memory of list in "for" loop | 38,295,731 | <p>Using some function I create a list of million items within and check memory consumption</p>
<pre><code>print ('Memory at start: {0} Mb'.format(memory_usage_psutil()))
my_list = people_list(1000000)
print ('Memory at end: {0} Mb'.format(memory_usage_psutil()))
</code></pre>
<p>What I get is:</p>
<pre><code>Memory... | 2 | 2016-07-10T19:29:05Z | 38,295,803 | <p>It's true that your two lists are different objects and have different addresses in memory. However, the individual objects in the list are the same. Using a slice basically gave you a view on some elements in your list.</p>
<p>You can confirm that with::</p>
<pre><code>>>> map(id, my_list)[0:500000] ==... | 2 | 2016-07-10T19:39:28Z | [
"python",
"list",
"memory"
] |
Flask SqlAlchemy MySQL connection timed out due to QueuePool overflow limit | 38,295,770 | <p>Please I need help with the following error which I get on the 16th database connection. None of the other answers on Stackoverflow seem to work:</p>
<pre><code>QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30
</code></pre>
<p>Backend configuration:</p>
<ul>
<li>Python 2.6.9 </li>
<... | 0 | 2016-07-10T19:33:55Z | 38,301,182 | <p>I've realized the problem is that I created a separate threadpool with threads that weren't terminating and were keeping all my database connections open even after the response has been returned to the client. This was a bad hack and terrible idea. I intend to get rid of this threadpool and use celery to schedule a... | 0 | 2016-07-11T07:17:23Z | [
"python",
"mysql",
"flask",
"flask-sqlalchemy",
"connection-timeout"
] |
AES-NI intrinsics in Cython? | 38,295,835 | <p>Is there a way to use AES-NI instructions within Cython code? </p>
<p>Closest I could find is how someone accessed SIMD instructions:
<a href="https://groups.google.com/forum/#!msg/cython-users/nTnyI7A6sMc/a6_GnOOsLuQJ" rel="nofollow">https://groups.google.com/forum/#!msg/cython-users/nTnyI7A6sMc/a6_GnOOsLuQJ</a><... | 1 | 2016-07-10T19:43:51Z | 38,356,117 | <p>You should be able to just define the intrinsics as if they're normal C functions in Cython. Something like</p>
<pre><code>cdef extern from "emmintrin.h": # I'm going off the microsoft documentation for where the headers are
# define the datatype as an opaque type
ctypedef struct __m128i x:
pass
... | 1 | 2016-07-13T15:38:21Z | [
"python",
"aes",
"cython",
"simd",
"cythonize"
] |
Substitute Multiple Alphabets Without Using Replace function in Python | 38,295,849 | <p>I am a beginner of python. I need to replace <em>ARED</em> with <em>TUXY</em> without using replace function. Example: Apple is behind a tree. After: TpplX is bXinY T tUXX.
Can you help? Thanks</p>
| 1 | 2016-07-10T19:45:30Z | 38,295,898 | <p>You can use <a href="https://docs.python.org/2.7/library/stdtypes.html#str.translate" rel="nofollow"><code>str.translate</code></a> and <a href="https://docs.python.org/2.7/library/string.html#string.maketrans" rel="nofollow"><code>string.maketrans</code></a>:</p>
<pre><code>import string
match = "ARED"
replace = "... | 2 | 2016-07-10T19:50:35Z | [
"python"
] |
Twitter streaming formatting JSON Output | 38,295,862 | <p>Maybe you can help me. This following python code retrieves Twitter Streaming data and stops when 1000 tweet data are got. It works but returns the fields "created_at, screen_name, and text" separated by tab. Instead I'd like to get the data in JSON format. How can I set the code in order to get the data formatted i... | -1 | 2016-07-10T19:46:43Z | 38,296,142 | <p>You can import <code>tweepy</code> (you need to install it first with pip) and override the <code>listener class</code> to be able to output the data in json format. Here is an example:</p>
<pre><code>from tweepy import Stream
from tweepy.streaming import StreamListener
#Listener Class Override
class listener(Stre... | 1 | 2016-07-10T20:20:51Z | [
"python",
"json",
"python-3.x",
"twitter"
] |
Python mysql statement returning error when called from php | 38,295,863 | <p>I have a python script which takes csv as an input and insert its data to Database. and I am calling this script from a php script where I am generating this CSV. If I call python script from terminal and pass csv to it, it works perfectly but if I call it from php using</p>
<pre><code>exec('python bulk_metadata_in... | 1 | 2016-07-10T19:46:43Z | 38,296,044 | <p>It looks like you are using a mySQL reserved word <code>OWNER</code> as a column name in your table and not using backticks. Try changing your select to:</p>
<pre><code>...("insert into test_table(asset_type, attribute_id, asset_title, is_publishable, `owner`")...
... | 1 | 2016-07-10T20:08:16Z | [
"php",
"python",
"mysql",
"csv",
"exec"
] |
What's the best way to serialize a Dataframe inline? | 38,295,878 | <p>I'm trying to create a piece of executable code that includes the following DataFrame embedded in it:</p>
<pre><code>Contract Date
201507 2014-06-18 1462.6
2014-07-03 1518.6
2014-09-05 10.2
201510 2015-09-14 977.9
201607 2016-05-17 1062.0
</code></pre>
<p>I'd l... | 2 | 2016-07-10T19:48:12Z | 38,295,998 | <p>Perhaps the <code>.to_dict</code> method might be able to provide what you need? </p>
<pre><code>In [22]: df
Out[22]:
0 1 2 3
first second
bar one 0.857213 2.541895 0.632027 -0.723664
two 0.670757 0.131845 0.44... | 2 | 2016-07-10T20:03:08Z | [
"python",
"pandas"
] |
Obtain only a single solution for System of Polynomials in Sage | 38,295,905 | <p>I am trying to solve a system of polynomial equations obtained by comparing coefficients of different polynomials.</p>
<pre><code># Statement of Problem:
# We are attempting to find complex numbers a, b, c, d, e, J, u, v, r, s where
# ((a*x + c)^2)*(x^3 + (3K)*x + 2K) - ((b*x^2 + d*x + e)^2) = a^2*(x - r)^2*(x ... | 0 | 2016-07-10T19:51:14Z | 38,327,143 | <p>Both equations have degree 5, which makes 12 identities. However, the degree 5 identities are identical and always satisfied for both equations. Thus you have effectively 10 or less equations for 10 variables.</p>
<p>Divide by <code>a^2</code>, i.e., replace <code>c, b, d, e</code> by <code>c/a, b/a, d/a, e/a</code... | 1 | 2016-07-12T11:08:20Z | [
"python",
"polynomial-math",
"sage",
"equation-solving"
] |
Python Multiprocessing outputting entire program | 38,295,920 | <p>I don't normally ask questions on the internet nor am i a very good programmer, but i have been struggling with this problem for a while but i cant fathom why it doesn't work. I'm trying to do some maths that i thought i could do in multiple threads, the code below shows my attempt to output the answers that each wo... | 0 | 2016-07-10T19:53:02Z | 38,296,155 | <p>If you are using Python 2.7, then <code>input()</code> will likely "crash", because it is "equivalent to <code>eval(raw_input(prompt))</code>" according to the documentation:
<a href="https://docs.python.org/2/library/functions.html#input" rel="nofollow">https://docs.python.org/2/library/functions.html#input</a></p>... | 0 | 2016-07-10T20:22:23Z | [
"python",
"multiprocessing"
] |
Python Multiprocessing outputting entire program | 38,295,920 | <p>I don't normally ask questions on the internet nor am i a very good programmer, but i have been struggling with this problem for a while but i cant fathom why it doesn't work. I'm trying to do some maths that i thought i could do in multiple threads, the code below shows my attempt to output the answers that each wo... | 0 | 2016-07-10T19:53:02Z | 38,296,772 | <p>The first worker crashes due to <code>name</code> not being defined <em>while holding the lock</em>. That prevents any of the other workers from giving their output, and since they never finish, it also stops the main process from starting up the next round of workers.</p>
<p>To work around this specific issue (and... | 0 | 2016-07-10T21:52:36Z | [
"python",
"multiprocessing"
] |
Python Multiprocessing outputting entire program | 38,295,920 | <p>I don't normally ask questions on the internet nor am i a very good programmer, but i have been struggling with this problem for a while but i cant fathom why it doesn't work. I'm trying to do some maths that i thought i could do in multiple threads, the code below shows my attempt to output the answers that each wo... | 0 | 2016-07-10T19:53:02Z | 38,302,561 | <p>It seems as though most of my questions have been answered. I shall now work on actually optimising the code to run efficiently now that my original problem is solved. It seems as though the workers begin to run all of the code in the parent program, and as such to stop them from printing the introductory text four ... | 0 | 2016-07-11T08:40:05Z | [
"python",
"multiprocessing"
] |
Expandable tree dict - making a map in python | 38,295,926 | <p>I am making a web crawler that maps a site as it crawls. This map is written to a file so that the crawler can resume its location if an exception is thrown.</p>
<p>The tree starts off like this:</p>
<pre><code>{
"root": [{}, "example.com"]
}
</code></pre>
<p>And additional pages are nested inside the empty d... | 0 | 2016-07-10T19:53:38Z | 38,296,143 | <p>You could return both the dictionary and the url in your <code>Crawler.next_url</code> method:</p>
<pre><code>return url, _path
</code></pre>
<p>That way, your crawling logic has access to both objects and can update the <code>_path</code> dictionary.</p>
| 1 | 2016-07-10T20:20:58Z | [
"python",
"dictionary"
] |
Iterating through a NxN matrix to form words with specific rule | 38,295,996 | <p>Recently I came across this interview question which has got me confused in terms of implementation:</p>
<p>"There is a <code>NxN</code> matrix (a sample shown below). From each point in the matrix you can go only forward(diagonally or normal but not backwards). So from <code>F</code> you can go only to <code>C,G,I... | 0 | 2016-07-10T20:03:00Z | 38,296,486 | <p>Ok you want a start.</p>
<p>Here is what I would try to work on with.</p>
<pre><code>def iterate(m):
for row in range(0,4):
for col in range(0,4):
print(m[row-1][col+1]+
m[row][col+1]+
m[row+1][col-1]+
m[row+1][col]+
m[... | 0 | 2016-07-10T21:08:18Z | [
"java",
"python",
"matrix"
] |
Simulating a coin flip experiment in Python | 38,296,039 | <p>I am having trouble getting a program to work properly. The goal is to simulate a coin flip as follows:</p>
<p>Consider a random sequence of numbers: <code>epsilon_1, epsilon_2, ... , epsilon_N</code>. Each term in this sequence takes on values <code>+1</code> or <code>-1</code>, depending on the outcome of the coi... | 0 | 2016-07-10T20:07:48Z | 38,296,245 | <p>There are several mistakes in your code. First, you are creating an empty list called result but later in your code result is a string. So you don't need that part.</p>
<pre><code>import numpy as np
import random
N = 10
epsilon = np.zeros(N)
</code></pre>
<p>This creates an array of length N for you to store the r... | 2 | 2016-07-10T20:35:34Z | [
"python",
"arrays",
"algorithm",
"random"
] |
seaborn distplot loop lazy evaluation | 38,296,074 | <p>I am using ipython notebook and trying to use the following function to export seaborn distplots. It works just fine if I call the function and execute with only one variable at a time. If I call the function in a loop, it continues to build on top of the distplot from the previous function call.</p>
<p>My desired ... | 1 | 2016-07-10T20:11:49Z | 38,626,093 | <p>So this has to do with matplotlib and closing figures. </p>
<p>additional code required is an import:</p>
<pre><code>import matplotlib.pyplot as plt
</code></pre>
<p>Then at the end of the func:</p>
<pre><code>plt.close(fig)
</code></pre>
<p>This should help with any looping with both seaborn and matplotlib</p>... | 1 | 2016-07-28T02:18:01Z | [
"python",
"matplotlib",
"ipython",
"seaborn"
] |
Ultisnips python interpolation snippet, extracting number from filename | 38,296,101 | <p>I am trying to make a snippet that will help me choose the right revision
number for migration, by reading all migration files from
<code>application/migrations</code>.</p>
<p>What I managed to do myself is that my filenames are being filtered while I am
typing, and when only one match left insert its revision numb... | 0 | 2016-07-10T20:15:49Z | 38,298,061 | <p>This can definitely be performed in pure vimscript.</p>
<p>Here is a working prototype. It does work but has some issues with portability: global variables, reliance on <code>iskeyword</code> and uses two keybindings instead of one. But it was put together in an hour or so:</p>
<pre><code>set iskeyword=@,48-57,_... | 1 | 2016-07-11T01:44:59Z | [
"python",
"vim",
"ultisnips"
] |
Ultisnips python interpolation snippet, extracting number from filename | 38,296,101 | <p>I am trying to make a snippet that will help me choose the right revision
number for migration, by reading all migration files from
<code>application/migrations</code>.</p>
<p>What I managed to do myself is that my filenames are being filtered while I am
typing, and when only one match left insert its revision numb... | 0 | 2016-07-10T20:15:49Z | 38,299,758 | <p>This can be achieved using <code>post-expand-actions</code>: <a href="https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt#L1602" rel="nofollow">https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt#L1602</a></p>
| 1 | 2016-07-11T05:33:13Z | [
"python",
"vim",
"ultisnips"
] |
conditional display of string in Python | 38,296,204 | <p>I have a program for enumerating the users with administrative privileges on Windows. I also want to display the number of accounts found which is stored in a variable called <code>num_administrator</code>.
I have the following piece of code:</p>
<pre><code>if num_administrators > 1:
print("[*] {} accounts w... | 1 | 2016-07-10T20:29:28Z | 38,296,292 | <p>Here's a crafty one-liner I made:</p>
<pre><code>"[*] {} account{} with administrative privileges found.\n".format("No" if num_administrators == 0 else str(num_administrators), "s" if num_administrators != 1 else "")
</code></pre>
<p>P.S. As for readability, I don't know... I maybe be wrong, but I think my eyes ar... | 2 | 2016-07-10T20:42:11Z | [
"python",
"string",
"python-3.x",
"if-statement",
"printing"
] |
conditional display of string in Python | 38,296,204 | <p>I have a program for enumerating the users with administrative privileges on Windows. I also want to display the number of accounts found which is stored in a variable called <code>num_administrator</code>.
I have the following piece of code:</p>
<pre><code>if num_administrators > 1:
print("[*] {} accounts w... | 1 | 2016-07-10T20:29:28Z | 38,296,301 | <p>You can do something like</p>
<pre><code> if num_administrators > 1:
print "The total number of administrators is %d"%(num_administrators)
</code></pre>
<p>or, if you want it to be a string:</p>
<pre><code> if num_administrators > 1:
print "The total number of administrators is %s"%(str(num_ad... | 0 | 2016-07-10T20:43:25Z | [
"python",
"string",
"python-3.x",
"if-statement",
"printing"
] |
conditional display of string in Python | 38,296,204 | <p>I have a program for enumerating the users with administrative privileges on Windows. I also want to display the number of accounts found which is stored in a variable called <code>num_administrator</code>.
I have the following piece of code:</p>
<pre><code>if num_administrators > 1:
print("[*] {} accounts w... | 1 | 2016-07-10T20:29:28Z | 38,297,171 | <p>If you want to go with one line solution, that's already been answered here. However, I'd recommend using if/else statements because that way, the solution is more readable:</p>
<pre><code>output = "[*] "
if num_administrators > 1:
output += "{} accounts ".format(num_administrators)
elif num_administrators ... | 1 | 2016-07-10T22:57:55Z | [
"python",
"string",
"python-3.x",
"if-statement",
"printing"
] |
conditional display of string in Python | 38,296,204 | <p>I have a program for enumerating the users with administrative privileges on Windows. I also want to display the number of accounts found which is stored in a variable called <code>num_administrator</code>.
I have the following piece of code:</p>
<pre><code>if num_administrators > 1:
print("[*] {} accounts w... | 1 | 2016-07-10T20:29:28Z | 38,302,584 | <p>I took a look at <em>dmitryro</em>'s solution and I like the use of <strong>lambda</strong> for displaying different strings according to a condition. I also would like to take into account the case of <code>num_admin == 1</code> though. I edited the code and I got this:</p>
<pre><code>l = lambda x:"No accounts" if... | 0 | 2016-07-11T08:41:35Z | [
"python",
"string",
"python-3.x",
"if-statement",
"printing"
] |
Python: Split a comma-delimited string directly into a set | 38,296,244 | <p>I have some code that does something like:</p>
<pre><code>if string in comma_delimited_string.split(','):
return True
</code></pre>
<p><a href="https://wiki.python.org/moin/PythonSpeed" rel="nofollow">This website</a> says that membership testing with sets and dicts is much faster that with lists or tuples. I ... | 1 | 2016-07-10T20:35:16Z | 38,296,266 | <p>No, the <code>str.split</code> operation always returns a list and trying to convert that into a <code>set</code> will cost time. Also writing your own handmade <code>split</code> that produces directly a set will be slower, because <code>str.split</code> is implemente in C (the source code should be under <a href="... | 2 | 2016-07-10T20:38:30Z | [
"python",
"string",
"performance",
"optimization"
] |
Python: Split a comma-delimited string directly into a set | 38,296,244 | <p>I have some code that does something like:</p>
<pre><code>if string in comma_delimited_string.split(','):
return True
</code></pre>
<p><a href="https://wiki.python.org/moin/PythonSpeed" rel="nofollow">This website</a> says that membership testing with sets and dicts is much faster that with lists or tuples. I ... | 1 | 2016-07-10T20:35:16Z | 38,296,321 | <p>You're ignoring the fact that in order to convert anything to a set, you need to iterate it. And that iteration is exactly the same as you are already doing in order to search the original list. So there cannot be any advantage in doing this, only overhead.</p>
<p>Searching against a set is more efficient if you're... | 3 | 2016-07-10T20:45:41Z | [
"python",
"string",
"performance",
"optimization"
] |
Python: Split a comma-delimited string directly into a set | 38,296,244 | <p>I have some code that does something like:</p>
<pre><code>if string in comma_delimited_string.split(','):
return True
</code></pre>
<p><a href="https://wiki.python.org/moin/PythonSpeed" rel="nofollow">This website</a> says that membership testing with sets and dicts is much faster that with lists or tuples. I ... | 1 | 2016-07-10T20:35:16Z | 38,296,533 | <p>While a membership test on an existing set may be faster (O(1)) than on a list (O(n)), you'd still need to create the set from the string, which will be O(n). So there's nothing you can do about the time complexity. </p>
<p>You can speed up the test by a constant factor though by just scanning the string instead of... | 1 | 2016-07-10T21:13:53Z | [
"python",
"string",
"performance",
"optimization"
] |
Getting Error when convert RDD to DataFrame PySpark | 38,296,434 | <p>I'm doing some study in Apache Spark and I'm facing something really strange. See this code below:</p>
<pre><code>ClimateRdd = ClimateRdd.map(lambda x: tuple(x))
print ClimateRdd.first()
</code></pre>
<p>these commands return to me this line:
<code>('1743-11-01', '4.3839999999999995', '2.294', '\xc3\x85land')</cod... | 1 | 2016-07-10T20:59:51Z | 38,310,943 | <p>That is a little bit weird.
Why do you need tuples ? List work fine with map.</p>
<pre><code>ClimateRdd.map(lambda x: [x[0], x[1], x[2], x[3]])
</code></pre>
| 0 | 2016-07-11T15:37:34Z | [
"python",
"apache-spark",
"pyspark",
"pyspark-sql"
] |
Getting Error when convert RDD to DataFrame PySpark | 38,296,434 | <p>I'm doing some study in Apache Spark and I'm facing something really strange. See this code below:</p>
<pre><code>ClimateRdd = ClimateRdd.map(lambda x: tuple(x))
print ClimateRdd.first()
</code></pre>
<p>these commands return to me this line:
<code>('1743-11-01', '4.3839999999999995', '2.294', '\xc3\x85land')</cod... | 1 | 2016-07-10T20:59:51Z | 39,691,756 | <p>The issue was the dirty data. The data was not in the default split parameter. The issue was there.</p>
<p>When I made the tuple convertion, that assumes that the structure has 4 fields according with the most part of the data. But at one specific line it wasnt true.</p>
<p>So that is the reason why my dataframe c... | 0 | 2016-09-25T20:54:01Z | [
"python",
"apache-spark",
"pyspark",
"pyspark-sql"
] |
UnicodeEncodeError: 'ascii' codec can't encode character error using writerow and map | 38,296,541 | <p>In Python 2.7 and Ubuntu 14.04 I am trying to write to a csv file:</p>
<p><code>csv_w.writerow( map( lambda x: flatdata.get( x, "" ), columns ))</code></p>
<p>this gives me the notorious </p>
<p><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\u265b' in position 19: ordinal not in range(128)
</co... | -2 | 2016-07-10T21:14:54Z | 38,302,786 | <p>Without seeing your data it would seem that your data contains Unicode data types (See <a href="http://stackoverflow.com/questions/21129020/how-to-fix-unicodedecodeerror-ascii-codec-cant-decode-byte/35444608#35444608">How to fix: "UnicodeDecodeError: 'ascii' codec can't decode byte"</a> for a b... | 1 | 2016-07-11T08:53:34Z | [
"python",
"csv",
"unicode",
"encoding",
"utf-8"
] |
UnicodeEncodeError: 'ascii' codec can't encode character error using writerow and map | 38,296,541 | <p>In Python 2.7 and Ubuntu 14.04 I am trying to write to a csv file:</p>
<p><code>csv_w.writerow( map( lambda x: flatdata.get( x, "" ), columns ))</code></p>
<p>this gives me the notorious </p>
<p><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\u265b' in position 19: ordinal not in range(128)
</co... | -2 | 2016-07-10T21:14:54Z | 38,317,619 | <pre><code>csv_w.writerow( map( lambda x: flatdata.get( unicode(x).encode("utf-8"), unicode("").encode("utf-8") ), columns ))
</code></pre>
<p>You've encoded the parameters passed to <code>flatdata.get()</code>, ie the dict key. But the unicode characters aren't in the key, they're in the value. You should encode the ... | 1 | 2016-07-11T23:12:14Z | [
"python",
"csv",
"unicode",
"encoding",
"utf-8"
] |
use polyglot package for Named Entity Recognition in hebrew | 38,296,602 | <p>I am trying to use the polyglot package for Named Entity Recognition in hebrew. <br>
this is my code:</p>
<pre><code># -*- coding: utf8 -*-
import polyglot
from polyglot.text import Text, Word
from polyglot.downloader import downloader
downloader.download("embeddings2.iw")
text = Text(u"in france and in germany")
p... | 1 | 2016-07-10T21:25:38Z | 38,391,682 | <p>I got it! <br>
It seems like a bug to me.<br>
The language detection defined the language as <code>'iw'</code> which is the The former ISO 639 language code for Hebrew, and was changed to <code>'he'</code>.
The <code>text.entities</code> did not recognize the <code>iw</code> code, so i changes it like so:</p>
<pre>... | 1 | 2016-07-15T08:43:14Z | [
"python",
"nlp",
"named-entity-recognition",
"polyglot"
] |
Where in the python docs does it allow the `in` operator to be chained? | 38,296,689 | <p>I recently discovered that the following returns <code>True</code>:</p>
<pre><code>'a' in 'ab' in 'abc'
</code></pre>
<p>I'm aware of the python comparison chaining such as <code>a < b < c</code>, but I can't see anything in the docs about this being legal.</p>
<p>Is this an accidental feature in the implem... | 3 | 2016-07-10T21:39:42Z | 38,296,699 | <p>This is fully specified behaviour, not an accidental feature. Operator chaining is defined in the <a href="https://docs.python.org/2/reference/expressions.html#not-in" rel="nofollow"><em>Comparison operators</em> section</a>:</p>
<blockquote>
<p>Comparisons can be chained arbitrarily, e.g., <code>x < y <= z... | 5 | 2016-07-10T21:40:52Z | [
"python",
"operators",
"comparison-operators"
] |
CSV file to a list in Python | 38,296,696 | <p>I have a csv file (named "test.csv") containing this list with tuples:</p>
<pre><code>[('calculation', 1468171987.4406562, None), ('calculation', 1468171988.5840397, None), ('calculation', 1468171989.8159678, 1.9041595458984375)]5)]
</code></pre>
<p>How can I import this csv file and save its contents to a list li... | 0 | 2016-07-10T21:40:17Z | 38,296,726 | <p>Now that you have a CSV reader (I assume your real code is indented correctly and runs without syntax error), you need to use it to input the lines from the file. The simplest way is like this:</p>
<pre><code>record = list(reader)
</code></pre>
| 0 | 2016-07-10T21:44:21Z | [
"python",
"python-3.x",
"csv"
] |
CSV file to a list in Python | 38,296,696 | <p>I have a csv file (named "test.csv") containing this list with tuples:</p>
<pre><code>[('calculation', 1468171987.4406562, None), ('calculation', 1468171988.5840397, None), ('calculation', 1468171989.8159678, 1.9041595458984375)]5)]
</code></pre>
<p>How can I import this csv file and save its contents to a list li... | 0 | 2016-07-10T21:40:17Z | 38,296,818 | <p>You can use <a href="http://docs.python.org/library/ast.html#ast.literal_eval" rel="nofollow">ast.literal_eval</a></p>
<pre><code>import ast
with open ("test.csv", 'r') as f:
for line in f:
list = ast.literal_eval(line)
print list
</code></pre>
| 0 | 2016-07-10T22:00:41Z | [
"python",
"python-3.x",
"csv"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.