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 |
|---|---|---|---|---|---|---|---|---|---|
Have Pandas column containing lists, how to pivot unique list elements to columns? | 39,459,321 | <p>I wrote a web scraper to pull information from a table of products and build a dataframe. The data table has a Description column which contains a comma separated string of attributes describing the product. I want to create a column in the dataframe for every unique attribute and populate the row in that column wit... | 6 | 2016-09-12T21:50:30Z | 39,459,814 | <p>you can build up a sparse matrix:</p>
<pre><code>In [27]: df
Out[27]:
PRODUCTS DATE DESCRIPTION
0 Product A 2016-9-12 Steel, Red, High Hardness
1 Product B 2016-9-11 Blue, Lightweight, Steel
2 Product C 2016-9-12 Red
In [28]: (df.set_index(['PRODUCTS','DATE'... | 5 | 2016-09-12T22:41:19Z | [
"python",
"pandas",
"numpy",
"dataframe",
"pivot"
] |
Have Pandas column containing lists, how to pivot unique list elements to columns? | 39,459,321 | <p>I wrote a web scraper to pull information from a table of products and build a dataframe. The data table has a Description column which contains a comma separated string of attributes describing the product. I want to create a column in the dataframe for every unique attribute and populate the row in that column wit... | 6 | 2016-09-12T21:50:30Z | 39,460,028 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.get_dummies.html" rel="nofollow"><code>pd.get_dummies</code></a></p>
<pre><code>cols = ['PRODUCTS', 'DATE']
pd.get_dummies(
df.set_index(cols).DESCRIPTION \
.str.split(',\s*', expand=True).stack()
).groupby(level=cols).sum().astype(... | 5 | 2016-09-12T23:09:04Z | [
"python",
"pandas",
"numpy",
"dataframe",
"pivot"
] |
opening several txt files using while loop | 39,459,322 | <p>I have some txt files that their names have the following pattern: </p>
<pre><code>arc.1.txt, arc.2.txt,...,arc.100.txt,..., arc.500.txt,...,arc.838.txt
</code></pre>
<p>I know that we can write a program using <code>for loop</code> to open the files one by one, if we now the total numbers of files. I want to kno... | 0 | 2016-09-12T21:50:34Z | 39,459,351 | <p>It is definitely possible to use a while loop assuming that the files are numbered in sequential order:</p>
<pre><code>i = 0
while True:
i += 1
filename = 'arc.%d.txt' % i
try:
with open(filename, 'r') as file_handle:
...
except IOError:
break
</code></pre>
<p>Though thi... | 3 | 2016-09-12T21:53:03Z | [
"python",
"for-loop",
"text",
"while-loop"
] |
opening several txt files using while loop | 39,459,322 | <p>I have some txt files that their names have the following pattern: </p>
<pre><code>arc.1.txt, arc.2.txt,...,arc.100.txt,..., arc.500.txt,...,arc.838.txt
</code></pre>
<p>I know that we can write a program using <code>for loop</code> to open the files one by one, if we now the total numbers of files. I want to kno... | 0 | 2016-09-12T21:50:34Z | 39,459,358 | <pre><code>import glob
for each_file in glob.glob("arc\.\d+\.txt"):
print(each_file)
</code></pre>
| 4 | 2016-09-12T21:53:27Z | [
"python",
"for-loop",
"text",
"while-loop"
] |
opening several txt files using while loop | 39,459,322 | <p>I have some txt files that their names have the following pattern: </p>
<pre><code>arc.1.txt, arc.2.txt,...,arc.100.txt,..., arc.500.txt,...,arc.838.txt
</code></pre>
<p>I know that we can write a program using <code>for loop</code> to open the files one by one, if we now the total numbers of files. I want to kno... | 0 | 2016-09-12T21:50:34Z | 39,459,374 | <p>If you add them all to a list and then remove them one by one and set the while condition to while (name of list) > 0: then open the next file </p>
| 0 | 2016-09-12T21:55:01Z | [
"python",
"for-loop",
"text",
"while-loop"
] |
Python code works 20 times slower than Java. Is there a way to speed up Python? | 39,459,386 | <p>I wrote a program in Python and in Java to search for the smallest integer solution of the equation:</p>
<p>a^5+b^5+c^5+d^5=e^5 (expected output is 133^5+110^5+84^5+27^5=144^5)</p>
<p>Powers and roots are either computed directly ("direct calculation" method) or computed and stored in an array ("power lookup" met... | 1 | 2016-09-12T21:56:05Z | 39,459,872 | <pre><code>from array import *
import time
import numpy as np
#PYTHON, BRUTEFORCE : ~30 s
millis1 = int(round(time.time() * 1000))
keep_searching = True
a = 1
result = ""
while(keep_searching):
a += 1
a_pow = a ** 5
for b in xrange(1, a+1):
b_pow = b ** 5
for c in xrange(1, b+1):
... | 1 | 2016-09-12T22:49:09Z | [
"java",
"python",
"performance"
] |
Python code works 20 times slower than Java. Is there a way to speed up Python? | 39,459,386 | <p>I wrote a program in Python and in Java to search for the smallest integer solution of the equation:</p>
<p>a^5+b^5+c^5+d^5=e^5 (expected output is 133^5+110^5+84^5+27^5=144^5)</p>
<p>Powers and roots are either computed directly ("direct calculation" method) or computed and stored in an array ("power lookup" met... | 1 | 2016-09-12T21:56:05Z | 39,460,548 | <p>What about improving the java code?</p>
<pre><code>int size = 200;
long[] pow5 = new long[size];
for (int i = 1; i < size; ++i)
{
long sqr = i * i;
pow5[i] = sqr * sqr * i;
}
for (int a = 1; a < size; ++a)
{
for (int b = 1; b <= a; ++b)
{
for (int c = 1; c <= b; ++c)
{
... | 1 | 2016-09-13T00:26:34Z | [
"java",
"python",
"performance"
] |
python code not working after copied from windows to linux | 39,459,440 | <p>I just wrote a small program in python, which is:</p>
<pre><code>#!/usr/bin/env python
print "hello"
</code></pre>
<p>It works in windows. And when I type this code in linux, it works, too.</p>
<p>But when I copy the python file from windows to linux in my VBox, this code doesn't work, and an error appears which ... | 0 | 2016-09-12T22:00:46Z | 39,459,708 | <p>Perhaps you get an error because of different line endings on windows and linux? Windows uses "\r\n" and Linux just "\n". </p>
<p>You could write script that would get rid of "\r" on linux, for example:</p>
<p>EDIT: I have realized that carriage returns are seen only in binary mode. So script should do something l... | 0 | 2016-09-12T22:28:32Z | [
"python",
"linux",
"windows"
] |
Comparing nested list Python | 39,459,456 | <p>I guess the code will most easily explain what I'm going for...</p>
<pre><code>list1 = [("1", "Item 1"), ("2", "Item 2"), ("3", "Item 3"), ("4", "Item 4")]
list2 = [("1", "Item 1"), ("2", "Item 2"), ("4", "Item 4")]
newlist = []
for i,j in list1:
if i not in list2[0]:
entry = (i,j)
newlist.app... | 1 | 2016-09-12T22:02:30Z | 39,459,658 | <p>If I understand correctly from your comment you would like to take as newlist: </p>
<pre><code>newlist = [("3", "Item 3")]
</code></pre>
<p>You can do this using:</p>
<p>1) list comprehension:</p>
<pre><code>newlist = [item for item in list1 if item not in list2]
print newlist
</code></pre>
<p>This will give yo... | 2 | 2016-09-12T22:23:17Z | [
"python",
"list",
"nested"
] |
Comparing nested list Python | 39,459,456 | <p>I guess the code will most easily explain what I'm going for...</p>
<pre><code>list1 = [("1", "Item 1"), ("2", "Item 2"), ("3", "Item 3"), ("4", "Item 4")]
list2 = [("1", "Item 1"), ("2", "Item 2"), ("4", "Item 4")]
newlist = []
for i,j in list1:
if i not in list2[0]:
entry = (i,j)
newlist.app... | 1 | 2016-09-12T22:02:30Z | 39,459,851 | <p>I think you just want to create a set of the first elements of list2, if you're only looking to compare the first element of the lists.</p>
<pre><code>newlist = []
list2_keys = set(elem[0] for elem in list2)
for entry in list1:
if entry[0] not in list2_keys:
newlist.append(entry)
</code></pre>
| 1 | 2016-09-12T22:46:25Z | [
"python",
"list",
"nested"
] |
Create new shapely polygon by subtracting the intersection with another polygon | 39,459,496 | <p>I have two shapely MultiPolygon instances (made of lon,lat points) that intersect at various parts. I'm trying to loop through, determine if there's an intersection between two polygons, and then create a new polygon that excludes that intersection. From the attached image, I basically don't want the red circle to o... | 0 | 2016-09-12T22:06:49Z | 39,459,906 | <p>I guess you can use the <a href="http://toblerity.org/shapely/manual.html#object.symmetric_difference" rel="nofollow"><code>symmetric_difference</code></a> between theses two polygons, combined by the difference with the second polygon to achieve what you want to do (the <em>symmetric difference</em> will brings you... | 1 | 2016-09-12T22:54:36Z | [
"python",
"python-2.7",
"polygon",
"shapely"
] |
How to integrate a python program into a kivy app | 39,459,530 | <p>I'm working on an app written in python with the kivy modules to develop a cross-platform app. Within this app I have a form which takes some numerical values. I would like these numerical values to be passed to another python program I've written, used to calculate some other values, and passed back to the app and ... | 0 | 2016-09-12T22:10:13Z | 39,461,951 | <p>As far as I understood you want the labels in your GridLayout in the last section of your code to get their texts from your python code. You could do something like this:</p>
<pre><code>from otherprogram import results1, results2, results3, results4
class ResultsScreen(Screen):
label1_text = results1
labe... | 2 | 2016-09-13T03:51:31Z | [
"android",
"python",
"kivy",
"kivy-language"
] |
Extracting column labels of the cells meeting a given condition | 39,459,541 | <p>Suppose the data at hand is in the following form:</p>
<pre><code>import pandas as pd
df = pd.DataFrame({'A':[1,10,20], 'B':[4,40,50], 'C':[10,11,12]})
</code></pre>
<p>I can compute the minimum by row with:</p>
<pre><code>df.min(axis=1)
</code></pre>
<p>which returns <code>1 10 12</code>.</p>
<p>Instead of the... | 3 | 2016-09-12T22:11:14Z | 39,459,585 | <p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.idxmin.html" rel="nofollow">idxmin(axis=1)</a> method:</p>
<pre><code>In [8]: df.min(axis=1)
Out[8]:
0 1
1 10
2 12
dtype: int64
In [9]: df.idxmin(axis=1)
Out[9]:
0 A
1 A
2 C
dtype: object
In [11]: df.idx... | 3 | 2016-09-12T22:15:22Z | [
"python",
"pandas",
"dataframe"
] |
Default instance for Django model | 39,459,559 | <p>My questionis: is there anyway to create a default instance for class Language? Like this : </p>
<pre><code>class Language(models.
default_instance = Language(name="unknown")
name = models.CharField(max_length=100)
</code></pre>
<p>so class Student can use this: </p>
<pre><code>class Student(models.Mod... | 0 | 2016-09-12T22:13:16Z | 39,460,234 | <p>You could set it by overriding the save method:</p>
<pre><code>#your model
class Student(models.Model):
name = models.CharField(max_length=50)
language = models.ForeignKey(Language)
# override save
def save(self,**args,**kwargs):
if self.language is None:
default_language = Language.get(p... | 2 | 2016-09-12T23:35:19Z | [
"python",
"django",
"django-models"
] |
How to verify text using Squish | 39,459,668 | <p>I am automating a windows application using Squish. I am trying to verify if the required text is displayed in a window after I make some changes in the GUI. I used object spy to get the object ID, but I am confused how to give a test verification point. The following Verification point says in the results window ... | 0 | 2016-09-12T22:24:34Z | 39,567,937 | <p>Instead of the <code>enabled</code> property, you can also compare any other property - e.g. the <code>text</code>:</p>
<pre><code>test.compare(findObject("{name ='textObjective'}").text, "4X")
</code></pre>
| 0 | 2016-09-19T07:50:08Z | [
"python",
"squish"
] |
Sorting a Two Dimensional List in python using Insertion Sort | 39,459,677 | <p>So I want to sort a list of namedtuples using insertion sort in python, and here is my code.</p>
<pre><code> def sortIt(tripods):
for i in range(1, len(tripods)):
tmp = tripods[i][3]
k = i
while k > 0 and tmp < tripods[k - 1][3]:
tripods[k] = trip... | -1 | 2016-09-12T22:25:10Z | 39,461,599 | <pre><code>def sortIt(tripods):
for i in range(1, len(tripods)):
tmp = tripods[i]
k = i
while k > 0 and tmp[3] < tripods[k - 1][3]:
tripods[k] = tripods[k - 1]
k -= 1
tripods[k] = tmp
</code></pre>
<p>I have modified your code. You were assigning <code>... | 0 | 2016-09-13T02:59:13Z | [
"python",
"list",
"sorting"
] |
Space complexity of list creation | 39,459,701 | <p>Could someone explain me what is the space complexity of beyond program, and why is it?</p>
<pre><code>def is_pal_per(str):
s = [i for i in str]
nums = [0] * 129
for i in s:
nums[ord(i)] += 1
count = 0
for i in nums:
if i != 0 and i / 2 == 0:
count += 1
print count
if count > 1:
return ... | 1 | 2016-09-12T22:27:13Z | 39,459,729 | <p>You have found the only two lines that allocate memory:</p>
<pre><code>s = [i for i in str]
nums = [0] * 129
</code></pre>
<p>The first grows linearly with <code>len(str)</code>, the second is a constant. Therefore, the space complexity of your function is O(N), N=length of <code>str</code>.</p>
| 0 | 2016-09-12T22:30:57Z | [
"python",
"algorithm",
"python-2.7",
"space-complexity"
] |
Space complexity of list creation | 39,459,701 | <p>Could someone explain me what is the space complexity of beyond program, and why is it?</p>
<pre><code>def is_pal_per(str):
s = [i for i in str]
nums = [0] * 129
for i in s:
nums[ord(i)] += 1
count = 0
for i in nums:
if i != 0 and i / 2 == 0:
count += 1
print count
if count > 1:
return ... | 1 | 2016-09-12T22:27:13Z | 39,459,730 | <p>I'm unclear where you're having trouble with this. <strong>s</strong> is simply a list of individual characters in <strong>str</strong>. The space consumption is <strong>len(s)</strong>.</p>
<p><strong>nums</strong> is a constant size, dominated by the <strong>O(N)</strong> term.</p>
<p>Is this code you wrote, o... | 0 | 2016-09-12T22:31:04Z | [
"python",
"algorithm",
"python-2.7",
"space-complexity"
] |
Paths in python | 39,459,716 | <p>Consider a rectangular grid.</p>
<p>I want a short and elegant way of generating a straight path from <code>[x0,y0]</code> to <code>[x1,y1]</code>, where either <code>x0=x1</code> or <code>y0 = y1</code>.</p>
<p>For example, on input <code>[1,3], [3,3]</code> the output <code>[[1,3],[2,3],[3,3]</code> should be ge... | 0 | 2016-09-12T22:29:29Z | 39,459,785 | <p>Add the <strong>step</strong> argument to your range, deriving the sign of the start & end difference:</p>
<pre><code>x_dir = copysign(1, self.end[0] - self.origin[0])
... for i in range(self.origin[0], self.end[0]+1, x_dir) ...
</code></pre>
<p>Do likewise for the y direction.</p>
| 1 | 2016-09-12T22:37:37Z | [
"python",
"python-3.x"
] |
Paths in python | 39,459,716 | <p>Consider a rectangular grid.</p>
<p>I want a short and elegant way of generating a straight path from <code>[x0,y0]</code> to <code>[x1,y1]</code>, where either <code>x0=x1</code> or <code>y0 = y1</code>.</p>
<p>For example, on input <code>[1,3], [3,3]</code> the output <code>[[1,3],[2,3],[3,3]</code> should be ge... | 0 | 2016-09-12T22:29:29Z | 39,459,850 | <p>Your question states that the solution from <code>x -> y</code> should be the same as the solution <code>y -> x</code>, i.e. we're only interested in defining the points on the path, not in any ordering of those points. If that's true, then simply find out which path has the smaller <code>x</code> (or <code>y<... | 3 | 2016-09-12T22:46:18Z | [
"python",
"python-3.x"
] |
Non decreasing sequences | 39,459,775 | <p>I am trying to write a simple python script that will find all the non-decreasing sequences made up of positive integers summing to 7. My code does not seem to work as it's supposed to no matter what I try. Here's what I have</p>
<pre><code>components = [1,2,3,4,5,6,7]
ans = []
def sumSeq(seq):
sumA = 0
f... | 0 | 2016-09-12T22:36:58Z | 39,459,796 | <pre><code>newSeq = seq
</code></pre>
<p>This line doesn't do what you think it does. Specifically, it does <em>not</em> create a new list. It merely creates a new name that refers to the existing list. Try:</p>
<pre><code>newSeq = seq[:]
</code></pre>
| 2 | 2016-09-12T22:38:52Z | [
"python",
"sequence"
] |
Non decreasing sequences | 39,459,775 | <p>I am trying to write a simple python script that will find all the non-decreasing sequences made up of positive integers summing to 7. My code does not seem to work as it's supposed to no matter what I try. Here's what I have</p>
<pre><code>components = [1,2,3,4,5,6,7]
ans = []
def sumSeq(seq):
sumA = 0
f... | 0 | 2016-09-12T22:36:58Z | 39,459,864 | <p>When you do the following assignment:</p>
<pre><code>newSeq = seq
</code></pre>
<p>you actually bind a different name (newSeq) to the same object (seq), you do not create a new object with similar values. So as you change the contents of newSeq, you change the contents of seq, too, since they are both aliases of t... | 2 | 2016-09-12T22:48:12Z | [
"python",
"sequence"
] |
Python: how to instal "requests" | 39,459,799 | <p>I have Python version 3.5.2. I am trying to use <code>requests</code> called through <code>import requests</code> but I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
import requests
ImportError: No module named 'requests'
</code... | -3 | 2016-09-12T22:39:13Z | 39,460,030 | <p>First check what version of python your shell will be running; sometimes the Python 3 executable is installed as <code>python3</code> in <code>/usr/bin</code> (or wherever else it could be installed; ie. <code>/usr/local/bin)</code>, but I've seen it as just plain <code>python</code> on some machines depending on ho... | 1 | 2016-09-12T23:09:19Z | [
"python",
"terminal",
"python-requests"
] |
How can I get all media from my own Instagram api? | 39,459,809 | <p>I want to get number of likes each photo or video got. Can I get all the media like count or just the last 20 of them?</p>
| 3 | 2016-09-12T22:40:39Z | 39,459,924 | <p>If you get your API access reviewed and approved by Instagram you will be able to get more than 20 photos using pagination.</p>
<p>Check documentation here: <a href="https://www.instagram.com/developer/sandbox/" rel="nofollow">https://www.instagram.com/developer/sandbox/</a></p>
| 1 | 2016-09-12T22:57:07Z | [
"python",
"instagram-api"
] |
Django: 400 Error with Debug=False and ALLOWED_HOSTS=["*"] | 39,459,819 | <p>I'm trying to run a relatively simple Django server on python 3.5.3 on an Ubuntu DigitalOcean droplet. I'm using a Gunicorn server with nginx. The server runs fine when DEBUG=True in settings.py. But when I set it to False, I get a 400 error when trying to visit the page. I tried setting ALLOWED_HOSTS to ['*'], but ... | 3 | 2016-09-12T22:42:24Z | 39,461,321 | <p>Make sure that the config in nginx has the proper alias using absolute paths (ie: <code>/etc/nginx/sites-enabled</code>)
It doesn't work if the alias was done with a relative path for whatever reason. </p>
<p>This are the appropriate settings for nginx at the <code>location / {}</code> section:</p>
<pre><code>pro... | 1 | 2016-09-13T02:18:46Z | [
"python",
"django",
"nginx",
"gunicorn",
"digital-ocean"
] |
beautifulsoup could not find class | 39,459,947 | <p>I tried to use bs4 to get the table from one NBA stat site.</p>
<p>The website seems did not use the JavaScript.</p>
<p>The <code>soup.prettify</code> print result looks normal, but I could not use <code>soup.find_all</code> to get the table I want. Here's the code I'm using:</p>
<pre><code>import requests
from b... | 3 | 2016-09-12T23:00:27Z | 39,460,304 | <p>The website loads data with <a href="https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started" rel="nofollow">ajax</a>, and this data will not be available to you simply by getting page contents with BeautifulSoup. However, you probably don't need BeautifulSoup at all.</p>
<p>If you're using Chrome, visit the ... | 3 | 2016-09-12T23:46:51Z | [
"python",
"python-3.x",
"web-scraping",
"beautifulsoup"
] |
How can I fix my function? | 39,460,031 | <p>I am being told.. from comments to fix my function to make it look "cleaner". I've tried alot.. but i don't know how to use llambda to accomplish what I'm trying to do. My code works.. it just isn't what is being asked of me. </p>
<p>Here is my code with suggestions on how to fix it.</p>
<pre><code>def immutable_f... | -1 | 2016-09-12T23:09:29Z | 39,460,412 | <p>The <code>append</code> function returns None. You need to return a renewed array</p>
<pre><code>next_series = lambda series: series + [series[-1] + series[-2]]
</code></pre>
<p>Also renaming <code>range</code> isn't serving any purpose.</p>
<pre><code>def immutable_fibonacci(position):
next_series = lambda s... | 0 | 2016-09-13T00:02:06Z | [
"python",
"function"
] |
I have been learning python 3.5, and trying to get a string to reprint a user input variable? | 39,460,040 | <pre><code>print ("how old are you??"),
age = input()
print("How tall are you"),
height = input()
print("How much do you weigh"),
weight = input()
print("So, you're '%r' old, '%r' tall and weigh '%r' ") % ('age, height weight')
</code></pre>
<p>TypeError: unsupported operand type(s) for %: 'NoneType' and 'str</p>
| 1 | 2016-09-12T23:10:17Z | 39,460,068 | <p>Don't put your variables in quotes. Instead of </p>
<pre><code>print("So, you're '%r' old, '%r' tall and weigh '%r' ") % ('age, height weight')
</code></pre>
<p>put</p>
<pre><code>print("So, you're '%r' old, '%r' tall and weigh '%r' " % (age, height weight))
</code></pre>
| 2 | 2016-09-12T23:14:38Z | [
"python",
"string",
"user-input"
] |
I have been learning python 3.5, and trying to get a string to reprint a user input variable? | 39,460,040 | <pre><code>print ("how old are you??"),
age = input()
print("How tall are you"),
height = input()
print("How much do you weigh"),
weight = input()
print("So, you're '%r' old, '%r' tall and weigh '%r' ") % ('age, height weight')
</code></pre>
<p>TypeError: unsupported operand type(s) for %: 'NoneType' and 'str</p>
| 1 | 2016-09-12T23:10:17Z | 39,460,181 | <p>As a bit of a fellow noob. A simple way of achieving this is asking your question while assigning the variable </p>
<pre><code>age = input("how old are you??")
height = input("How tall are you")
weight = input("How much do you weigh")
print("So, you're", age, "years old", height, "tall and weigh", weight)
</code><... | 0 | 2016-09-12T23:30:07Z | [
"python",
"string",
"user-input"
] |
I have been learning python 3.5, and trying to get a string to reprint a user input variable? | 39,460,040 | <pre><code>print ("how old are you??"),
age = input()
print("How tall are you"),
height = input()
print("How much do you weigh"),
weight = input()
print("So, you're '%r' old, '%r' tall and weigh '%r' ") % ('age, height weight')
</code></pre>
<p>TypeError: unsupported operand type(s) for %: 'NoneType' and 'str</p>
| 1 | 2016-09-12T23:10:17Z | 39,460,217 | <pre><code>print ("how old are you??"),
age = input()
print("How tall are you"),
height = input()
print("How much do you weigh"),
weight = input()
print("So, you're '%r' old, '%r' tall and weigh '%r' " %(age, height, weight))
</code></pre>
<p>If you put the variables in quotes it becomes a string. Also make sure each... | 0 | 2016-09-12T23:33:22Z | [
"python",
"string",
"user-input"
] |
Accessing the choices passed to argument in argparser? | 39,460,102 | <p>Is it possible to access the tuple of choices passed to an argument? If so, how do I go about it</p>
<p>for example if I have </p>
<pre><code>parser = argparse.ArgumentParser(description='choose location')
parser.add_argument(
"--location",
choices=('here', 'there', 'anywhere')
)
args = parser.parse_args()... | 7 | 2016-09-12T23:19:12Z | 39,460,230 | <p>It turns out that <code>parser.add_argument</code> actually returns the associated <code>Action</code>. You can pick the choices off of that:</p>
<pre><code>>>> import argparse
>>> parser = argparse.ArgumentParser(description='choose location')
>>> action = parser.add_argument(
... "... | 7 | 2016-09-12T23:35:10Z | [
"python",
"argparse"
] |
Accessing the choices passed to argument in argparser? | 39,460,102 | <p>Is it possible to access the tuple of choices passed to an argument? If so, how do I go about it</p>
<p>for example if I have </p>
<pre><code>parser = argparse.ArgumentParser(description='choose location')
parser.add_argument(
"--location",
choices=('here', 'there', 'anywhere')
)
args = parser.parse_args()... | 7 | 2016-09-12T23:19:12Z | 39,460,237 | <p>There might be a better way, but I don't see any in the documentation. If you know the parser option you should be able to do:</p>
<pre><code>parser = argparse.ArgumentParser()
parser.add_argument("--location", choices=("here", "there", "everywhere"))
storeaction = next(a for a in parser._actions if "--location" i... | 2 | 2016-09-12T23:35:50Z | [
"python",
"argparse"
] |
Accessing the choices passed to argument in argparser? | 39,460,102 | <p>Is it possible to access the tuple of choices passed to an argument? If so, how do I go about it</p>
<p>for example if I have </p>
<pre><code>parser = argparse.ArgumentParser(description='choose location')
parser.add_argument(
"--location",
choices=('here', 'there', 'anywhere')
)
args = parser.parse_args()... | 7 | 2016-09-12T23:19:12Z | 39,460,941 | <p>On the question of what <code>add_argument</code> returns, if you do any testing in an interactive session like <code>ipython</code>, the return stares you in the face:</p>
<pre><code>In [73]: import argparse
In [74]: parser=argparse.ArgumentParser()
In [75]: parser.add_argument('foo',choices=['one','two','three'])... | 1 | 2016-09-13T01:25:50Z | [
"python",
"argparse"
] |
Python 3.x - How to get the directory where user installed package | 39,460,193 | <p>Suppose that I am building a Python package with the following folder tree:</p>
<pre><code>main
|-- setup.py
|-- the_package
|--globar_vars.py
|--the_main_script.py
</code></pre>
<p>When the user performs anyway to install it, like:</p>
<pre><code>sudo python setup.py install
python setup.py install --u... | 2 | 2016-09-12T23:30:55Z | 39,460,684 | <pre><code>import wtv_module
print(wtv_module.__file__)
import os
print(os.path.dirname(wtv_module.__file__))
</code></pre>
| 0 | 2016-09-13T00:48:24Z | [
"python",
"installation",
"packages"
] |
Python 3.x - How to get the directory where user installed package | 39,460,193 | <p>Suppose that I am building a Python package with the following folder tree:</p>
<pre><code>main
|-- setup.py
|-- the_package
|--globar_vars.py
|--the_main_script.py
</code></pre>
<p>When the user performs anyway to install it, like:</p>
<pre><code>sudo python setup.py install
python setup.py install --u... | 2 | 2016-09-12T23:30:55Z | 39,460,715 | <p>Assuming your <code>SomeProject</code> package is a <a href="https://packaging.python.org/distributing/" rel="nofollow">well-formed Python package</a> (which can be done using <a href="https://setuptools.readthedocs.io/en/latest/setuptools.html" rel="nofollow">setuptools</a>), a user can derive the location simply u... | 1 | 2016-09-13T00:52:07Z | [
"python",
"installation",
"packages"
] |
Python datetime difference between .localize and tzinfo | 39,460,236 | <p>Why do these two lines produce different results? </p>
<pre><code>>>> import pytz
>>> from datetime ipmort datetime
>>> local_tz = pytz.timezone("America/Los_Angeles")
>>> d1 = local_tz.localize(datetime(2015, 8, 1, 0, 0, 0, 0)) # line 1
>>> d2 = datetime(2015, 8, 1, 0... | 4 | 2016-09-12T23:35:36Z | 39,460,268 | <p>When you create <code>d2=datetime(2015, 8, 1, 0, 0, 0, 0, local_tz)</code> in this way. It does not handle daylight savings time correctly. But, <code>local_tz.localize()</code> does.</p>
<p>d1 is </p>
<pre><code>datetime.datetime(2015, 8, 1, 0, 0,
tzinfo=<DstTzInfo 'America/Los_Angeles' PDT-... | 5 | 2016-09-12T23:40:42Z | [
"python",
"datetime",
"timezone",
"pytz"
] |
How to resize a Splash Screen Image using Tkinter? | 39,460,247 | <p>I am working on a game for a school project and as a part of it a Splash Screen is to load to simulate the 'loading' of the game. I have the code and it does bring up the image, but what I want it to do is bring up the defined .gif file onto the screen. Here is the code:</p>
<pre><code>import tkinter as tk
root = t... | 0 | 2016-09-12T23:38:18Z | 39,460,974 | <p>I recommend you to use <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a>.<br>
Here is the code: </p>
<pre><code>from PIL import Image, ImageTk
import Tkinter as tk
root = tk.Tk()
root.overrideredirect(True)
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry('%... | 0 | 2016-09-13T01:29:46Z | [
"python",
"canvas",
"tkinter",
"tkinter-canvas"
] |
Find generic sub-lists within a list | 39,460,277 | <p>Just learning Python as my first coding language. Given a list with many possible sub-lists which have a variable number of elements, is there a way of using regex (or something similar) to identify which lists contain sub-lists with 1) the number of elements specified and 2) a given type of content in a certain ord... | 2 | 2016-09-12T23:42:45Z | 39,460,342 | <p>I agree that converting to string doesn't make any sense here, but regular expressions explicitly search strings so you're not looking for that either. You're looking for a recursive solution that tests for your rules, which are (essentially)</p>
<blockquote>
<p>somelist IS or CONTAINS a list that begins with the... | 3 | 2016-09-12T23:52:01Z | [
"python",
"regex",
"list",
"recursion"
] |
Tensorflow - adding L2 regularization loss simple example | 39,460,338 | <p>I am familiar with machine learning, but I am learning Tensorflow on my own by reading some slides from universities. Below I'm setting up the loss function for linear regression with only one feature. I'm adding an L2 loss to the total loss, but I am not sure if I'm doing it correctly:</p>
<pre><code># Regularizat... | 2 | 2016-09-12T23:50:45Z | 39,461,004 | <p>Almost </p>
<p><a href="https://github.com/tensorflow/tensorflow/blob/d42facc3cc9611f0c9722c81551a7404a0bd3f6b/tensorflow/core/kernels/l2loss_op.h#L32" rel="nofollow">According to the L2Loss operation code</a></p>
<pre><code>output.device(d) = (input.square() * static_cast<T>(0.5)).sum();
</code></pre>
<p>I... | 1 | 2016-09-13T01:34:44Z | [
"python",
"machine-learning",
"tensorflow"
] |
Tensorflow - adding L2 regularization loss simple example | 39,460,338 | <p>I am familiar with machine learning, but I am learning Tensorflow on my own by reading some slides from universities. Below I'm setting up the loss function for linear regression with only one feature. I'm adding an L2 loss to the total loss, but I am not sure if I'm doing it correctly:</p>
<pre><code># Regularizat... | 2 | 2016-09-12T23:50:45Z | 39,461,326 | <blockquote>
<p>Are these two L2 implementations equivalent?</p>
</blockquote>
<p>Almost, as @fabrizioM pointed out, you can see <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/nn.html#l2_loss" rel="nofollow">here</a> for the introduction to the l2_loss in TensorFlow docs. </p>
<blockquote>
<p>... | 1 | 2016-09-13T02:19:39Z | [
"python",
"machine-learning",
"tensorflow"
] |
python with open invalid argument windows | 39,460,348 | <pre><code>import datetime
import os
import sys
import time
if "ZLOG_FILE" not in globals():
global ZLOG_FILE
script_dir = os.path.realpath(sys.argv[0]).replace(sys.argv[0], "")
ZLOG_FILE = os.path.join(script_dir, "log", datetime.datetime.fromtimestamp(time.time()).strftime("%m-%d-%Y %H:%M:%S"))
with ... | 0 | 2016-09-12T23:52:57Z | 39,460,476 | <p>Windows cant use colons in file names, and I forgot to remove the main script from the path once I got the directory it was in</p>
| 0 | 2016-09-13T00:13:20Z | [
"python",
"windows",
"file"
] |
How can I prevent unauthorized connections to my python socket server? | 39,460,386 | <p>I have a simple server written in python that opens and listens on a TCP socket:</p>
<pre><code>import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(("", 4242)) server_socket.listen(5)
print("TCPServer Waiting for client on port 4242")
while 1:
client_socket, add... | 0 | 2016-09-12T23:58:31Z | 39,460,550 | <p>You don't need SSL here. TSL and SSL are protocols that provide an encrypted communication over a network, so even if someone is 'listening' to that communication, they can't understand it.</p>
<p>The accept() method returns a tuple (conn, <em>address</em>) (<a href="https://docs.python.org/2/library/socket.html" ... | 0 | 2016-09-13T00:26:49Z | [
"python",
"sockets",
"tcp"
] |
SQLAlchemy: filtering on values stored in nested list of the JSONB field | 39,460,387 | <p>Lets say I have a model named <code>Item</code>, which contains a JSONB field <code>data</code>. One of the records has the following JSON object stored there:</p>
<pre><code>{
"name": "hello",
"nested_object": {
"nested_name": "nested"
},
"nested_list": [
{
"nested_key":... | 0 | 2016-09-12T23:58:42Z | 39,467,149 | <p>SQLAlchemy's <a href="http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSONB" rel="nofollow"><code>JSONB</code></a> type has the <a href="http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSONB.Comparator.contains" rel="nofollow">... | 0 | 2016-09-13T09:56:12Z | [
"python",
"json",
"postgresql",
"sqlalchemy"
] |
pync interacting with tweepy | 39,460,426 | <p>am python newbie here. What I am trying to do is to filter certain tweets using tweepy and its streaming function, and then push it alert me via pync.</p>
<p>Using the notifier function, I've noticed that all is well when the notification is pure text. However the moment there is a url in there, I no longer see a n... | 2 | 2016-09-13T00:04:16Z | 39,460,683 | <p>I've solved it myself! It seems like notifier cannot take in the character brackers [ and ]. All I did was to filter it out and it was A OK.</p>
| 0 | 2016-09-13T00:48:20Z | [
"python",
"twitter",
"tweepy"
] |
Use python list IN postgresql query | 39,460,508 | <p>My question is very similar to <a href="http://stackoverflow.com/questions/283645/python-list-in-sql-query-as-parameter">this</a> but I have strings instead of integers in my list.</p>
<p>My <code>python list</code>:<br></p>
<pre><code>list = ['a', 'b'] #number of items varies from 1 to 6
</code></pre>
<p>I want ... | 0 | 2016-09-13T00:19:07Z | 39,460,580 | <p>Try ",".join(["'{0}'".format(s) for s in list]).</p>
| -3 | 2016-09-13T00:31:38Z | [
"python",
"postgresql"
] |
Use python list IN postgresql query | 39,460,508 | <p>My question is very similar to <a href="http://stackoverflow.com/questions/283645/python-list-in-sql-query-as-parameter">this</a> but I have strings instead of integers in my list.</p>
<p>My <code>python list</code>:<br></p>
<pre><code>list = ['a', 'b'] #number of items varies from 1 to 6
</code></pre>
<p>I want ... | 0 | 2016-09-13T00:19:07Z | 39,460,954 | <p>I haven't used python's bindings to postgresql so I don't know if it is possible to bind a python list (or a tuple) to a placeholder in a query, but if it is, then you could use the <code>ANY</code> operator as follows:</p>
<pre><code>SELECT * FROM sample WHERE sub = ANY (%s);
</code></pre>
<p>and bind the list th... | 1 | 2016-09-13T01:27:04Z | [
"python",
"postgresql"
] |
Use python list IN postgresql query | 39,460,508 | <p>My question is very similar to <a href="http://stackoverflow.com/questions/283645/python-list-in-sql-query-as-parameter">this</a> but I have strings instead of integers in my list.</p>
<p>My <code>python list</code>:<br></p>
<pre><code>list = ['a', 'b'] #number of items varies from 1 to 6
</code></pre>
<p>I want ... | 0 | 2016-09-13T00:19:07Z | 39,461,021 | <p>Use psycopg2 and it will handle this for you correctly for all sorts of edge cases you haven't thought of yet. For your specific problem see <strong><a href="http://initd.org/psycopg/docs/usage.html#adapt-tuple" rel="nofollow">http://initd.org/psycopg/docs/usage.html#adapt-tuple</a></strong></p>
| 1 | 2016-09-13T01:36:47Z | [
"python",
"postgresql"
] |
In ggplot for Python, using discrete X scale with geom_point()? | 39,460,617 | <p>The following example returns an error. It appears that using a discrete (not continuous) scale for the x-axis in ggplot in Python is not supported? </p>
<pre><code>import pandas as pd
import ggplot
df = pd.DataFrame.from_dict({'a':['a','b','c'],
'percentage':[.1,.2,.3]})
p = ggplot.ggplot(data... | 2 | 2016-09-13T00:37:55Z | 39,460,802 | <p>One option is to generate a continuous series, and use the original variable as labels. But this seems like a painful workaround. </p>
<pre><code>df = pd.DataFrame.from_dict( {'a':[0,1,2],
'a_name':['a','b','c'],
'percentage':[.1,.2,.3]})
p = ggplot.ggplot(data=df,
... | 0 | 2016-09-13T01:05:57Z | [
"python",
"matplotlib",
"ggplot2",
"scatter",
"python-ggplot"
] |
Enabling or disabling checkbox with conditionals | 39,460,728 | <p>In my code i'm trying to disable the hi box when no is checked and enable it when yes is checked. I attempt to do this in the changed function. However when running the code and checking the yes box hi is still fine and when checking the yes only the yes box i get:</p>
<p>Exception in Tkinter callback
Traceback (mo... | 0 | 2016-09-13T00:55:19Z | 39,517,588 | <p>Alright, so disabling and enabling goes like so:</p>
<pre><code>button.state(['disabled']) # set the disabled flag, disabling the button
button.state(['!disabled']) # clear the disabled flag
button.instate(['disabled']) # return true if the button is disabled, else false
button.instate... | 0 | 2016-09-15T18:04:35Z | [
"python",
"checkbox",
"tkinter"
] |
Return two responses in Flask/JavaScript | 39,460,769 | <p>I have a Flask/JavaScript application wherein I take a form's inputs and pass them to a Flask app to retrieve distance information from the GoogleMaps API and subsequently return the resulting JSON to JavaScript.This works fine for a single instance of an origin/destination. </p>
<p>I want to receive two origin/des... | 0 | 2016-09-13T01:00:24Z | 39,461,118 | <p>You need to wrap both values in a dict and then return the dict.</p>
<pre><code>payload = {
"current_response": current_response,
"future_response": future_response
}
return jsonify(payload)
</code></pre>
| 0 | 2016-09-13T01:49:57Z | [
"javascript",
"python",
"json"
] |
Numpy : Calculating the average of values between two indices | 39,460,832 | <p>I need to calculate the average of values that are between 2 indices. Lets say my indices are 3 and 10, and i would like to sum up all the values between them and divide by the number of values.</p>
<p>Easiest way would be just using a for loop starting from 3, going until 10, summing 'em up, and dividing. This see... | 2 | 2016-09-13T01:10:10Z | 39,460,883 | <p>To access all elements between two indices <code>i</code> and <code>j</code> you can use slicing:</p>
<pre><code>slice_of_array = array[i: j+1] # use j if you DO NOT want index j included
</code></pre>
<p>and the average is calculated with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.average.... | 2 | 2016-09-13T01:17:34Z | [
"python",
"python-3.x",
"numpy"
] |
Numpy : Calculating the average of values between two indices | 39,460,832 | <p>I need to calculate the average of values that are between 2 indices. Lets say my indices are 3 and 10, and i would like to sum up all the values between them and divide by the number of values.</p>
<p>Easiest way would be just using a for loop starting from 3, going until 10, summing 'em up, and dividing. This see... | 2 | 2016-09-13T01:10:10Z | 39,460,975 | <pre><code>import numpy as np
np.mean(yourarray[3:11])
</code></pre>
<p>Assumed your array name is "yourarray" </p>
| 1 | 2016-09-13T01:29:47Z | [
"python",
"python-3.x",
"numpy"
] |
Gunicorn, no module named 'myproject | 39,460,892 | <p>I'm installing a previously built website on a new server. I'm not the original developer.</p>
<p>I've used Gunicorn + nginx in the past to keep the app alive (basically following <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04" rel="no... | 0 | 2016-09-13T01:19:38Z | 39,461,113 | <p>Your error message is </p>
<pre><code>ImportError: No module named 'myproject.wsgi'
</code></pre>
<p>You ran the app with</p>
<pre><code>gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
</code></pre>
<p>And wsgi.py has the line</p>
<pre><code>os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
</... | 1 | 2016-09-13T01:49:36Z | [
"python",
"django",
"nginx",
"gunicorn"
] |
Can't Query by Key in NDB | 39,460,976 | <p>I'm attempting to query an entity by key assuming ordering by key with ndb.</p>
<p>the line is</p>
<pre><code>query = User.query().filter(User.key > ndb.Key('User', key_id))
</code></pre>
<p>and it's throwing a server error: </p>
<pre><code> File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/... | 0 | 2016-09-13T01:30:01Z | 39,461,251 | <p>Try this</p>
<pre><code>query = User.query().filter(User._key > ndb.Key('User', key_id))
</code></pre>
| 0 | 2016-09-13T02:10:45Z | [
"python",
"google-app-engine",
"google-cloud-platform",
"app-engine-ndb"
] |
Python parse SQL and find relationships | 39,460,980 | <p>I've got a large list of SQL queries all in strings, they've been written for <a href="http://prestodb.io" rel="nofollow">Presto</a>, so kinda formatted for MySQL.</p>
<p>I want to be able to tease out the table relationships written in some queries. </p>
<p>Let's start with something simple:</p>
<pre><code>SELEC... | 1 | 2016-09-13T01:30:39Z | 39,461,102 | <p>With some minor changes to the select_parser.py (<a href="https://sourceforge.net/p/pyparsing/code/HEAD/tree/trunk/src/examples/select_parser.py" rel="nofollow">https://sourceforge.net/p/pyparsing/code/HEAD/tree/trunk/src/examples/select_parser.py</a>) that is part of the pyparsing examples, I get this after parsing... | 1 | 2016-09-13T01:48:09Z | [
"python",
"sql",
"parsing",
"pyparsing",
"sql-parser"
] |
Mongo Update of Array Query using Upsert | 39,461,017 | <p>Given</p>
<ol>
<li>menuItems is a list ['foo', 'bar', 'fooz', 'ball'] and </li>
<li>menudb collection has 3 records: 'foo', 'bar', 'fooz'</li>
</ol>
<p>When I run</p>
<pre><code>menudb.update({"_id" : {"$in": menuItems}}, {"$addToSet": {"staleCount": 100}}, upsert=True)
</code></pre>
<p>Instead of creating a new... | 0 | 2016-09-13T01:36:16Z | 39,461,148 | <p>you can remove upsert if you do not want new item in the menudb collection. I seems like your id is objectId instead of string.</p>
<p><a href="https://docs.mongodb.com/manual/reference/operator/query/in/" rel="nofollow">https://docs.mongodb.com/manual/reference/operator/query/in/</a></p>
<p>you can verify if the ... | 0 | 2016-09-13T01:54:59Z | [
"python",
"mongodb"
] |
Assignment build in functions | 39,461,146 | <p>I found an example which make me curious:</p>
<pre><code>int = float
def parse_string(s):
return int(s)
print(parse_string('42'))
</code></pre>
<p>The returned result is <code>42.0</code>. Int and float are build in functions. How come that we can assign float to int (build in functions)? It seems to be wired... | 2 | 2016-09-13T01:54:35Z | 39,461,824 | <p>Python use references to objects.</p>
<p>When you write <code>int = float</code>, you only change the <code>int</code> reference to point to the same object (a built-in function here) than the one pointed by <code>float</code> reference.</p>
<p>You don't change the nature of <code>int</code> of course.</p>
<p>You... | 1 | 2016-09-13T03:33:47Z | [
"python"
] |
looping the data using date variable in python | 39,461,381 | <p>I have the following dataframe with datetime, lon and lat variables. This data is collected for each second which means each date is repeated 60 times</p>
<p>I am doing some calculations using lat, lon values and at the end I need to write
this data to Postgres table.</p>
<pre><code>2016-07-27 06:43:45 50.62 ... | 0 | 2016-09-13T02:28:13Z | 39,463,413 | <p>Have you considered using the <code>groupby()</code> function? You can use it to treat each 'date' as a seperate DataFrame and then run your computations. </p>
<pre><code>for sub_df in df.groupby('date'):
# your computations
</code></pre>
| 1 | 2016-09-13T06:22:36Z | [
"python",
"loops",
"date",
"pandas"
] |
button in frames in python | 39,461,394 | <p><a href="http://i.stack.imgur.com/urPO6.png" rel="nofollow"><img src="http://i.stack.imgur.com/urPO6.png" alt="enter image description here"></a>
Design of my game is something like this
I need to develop Strategic tic tac toe(where in each block of tic tac toe we will find a tic tac toe)....so here i created 9 fram... | 1 | 2016-09-13T02:30:10Z | 39,461,641 | <p>There is a problem with your button handler: how can each button know its coordinates?</p>
<p>Just replace:</p>
<pre><code>handler = lambda a=i, b=j: self.update(a, b)
</code></pre>
<p>By:</p>
<pre><code>handler = lambda: self.update(i, j)
</code></pre>
<p>There is also a bug in <code>frame</code> method:
You i... | 0 | 2016-09-13T03:06:09Z | [
"python",
"button",
"tkinter",
"frames"
] |
Python serial.readline() not blocking | 39,461,414 | <p>I'm trying to use hardware serial port devices with Python, but I'm having timing issues. If I send an interrogation command to the device, it should respond with data. If I try to read the incoming data too quickly, it receives nothing.</p>
<pre><code>import serial
device = serial.Serial("/dev/ttyUSB0", 9600, ti... | 0 | 2016-09-13T02:33:54Z | 39,461,487 | <p>I couldn't add a commend so I will just add this as an answer. You can reference <a href="http://stackoverflow.com/questions/13017840/using-pyserial-is-it-possble-to-wait-for-data">this stackoverflow thread</a>. Someone attempted something similar to your question.</p>
<p>Seems they put their data reading in a loop... | 0 | 2016-09-13T02:44:08Z | [
"python",
"blocking",
"pyserial"
] |
Installing BioPython and Numpy | 39,461,473 | <p>I am working with Python 2.7.11. I've working problems on Rosalind.com from scratch, but I decided to try using tools that are openly available- in order to start familiarizing myself with finding and using said packages and extensions. Good thing too, because I can't figure out how to get any of the third party ext... | 0 | 2016-09-13T02:42:57Z | 39,461,676 | <p>So you need to install your modules into your python path. There is some (windows) documentation to that <a href="https://docs.python.org/2/using/windows.html" rel="nofollow">here</a> and <a href="https://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7">here</a> but should be easily add... | 0 | 2016-09-13T03:12:48Z | [
"python",
"numpy",
"installation-package",
"installation-path"
] |
Use of domain in search of One2many field in List view in Odoo-9 | 39,461,701 | <p>i have One2many field <b>product_attributes</b> in <b>product.template</b> and <b>value</b> field in <b>product.attributes.custom</b></p>
<pre><code>class ProductTemplateCus(models.Model):
_inherit = 'product.template'
product_attributes = fields.One2many('product.attributes.custom','product_id')
class Pro... | 0 | 2016-09-13T03:16:50Z | 39,484,050 | <p>AFAIK <code>search_domain</code> means nothing here. You should use <code>domain</code> instead.</p>
| 1 | 2016-09-14T06:45:11Z | [
"python",
"listview",
"openerp",
"odoo-9"
] |
Use of domain in search of One2many field in List view in Odoo-9 | 39,461,701 | <p>i have One2many field <b>product_attributes</b> in <b>product.template</b> and <b>value</b> field in <b>product.attributes.custom</b></p>
<pre><code>class ProductTemplateCus(models.Model):
_inherit = 'product.template'
product_attributes = fields.One2many('product.attributes.custom','product_id')
class Pro... | 0 | 2016-09-13T03:16:50Z | 39,484,984 | <p>There are a few types of domain for field in the search view:</p>
<ul>
<li><code>domain</code> - just like the domain on the field declaration in the python class, limits the records got from the database;</li>
<li><code>filter_domain</code> - overrides the <code>name_search</code> method which would normally have ... | 1 | 2016-09-14T07:40:28Z | [
"python",
"listview",
"openerp",
"odoo-9"
] |
Use of domain in search of One2many field in List view in Odoo-9 | 39,461,701 | <p>i have One2many field <b>product_attributes</b> in <b>product.template</b> and <b>value</b> field in <b>product.attributes.custom</b></p>
<pre><code>class ProductTemplateCus(models.Model):
_inherit = 'product.template'
product_attributes = fields.One2many('product.attributes.custom','product_id')
class Pro... | 0 | 2016-09-13T03:16:50Z | 39,524,315 | <p>For solving my problem I used search function to get product ids which have selected attribute name and value only and included that in arguments in search function as</p>
<pre><code>args += [['id', 'in', productids]]
</code></pre>
<p>I don't know if it was a right approach to do it. But it solved my problem.</p>
| 0 | 2016-09-16T05:32:27Z | [
"python",
"listview",
"openerp",
"odoo-9"
] |
How to remove empty separators from read files in Python? | 39,461,705 | <p>Here is my input file sample (z.txt)</p>
<pre><code>>qrst
ABCDE-- 6 6 35 25 10
>qqqq
ABBDE-- 7 7 28 29 2
</code></pre>
<p>I store the alpha and numeric in separate lists. Here is the output of numerics list
#Output : ['', '6', '', '6', '35', '25', '10']
['', '7', '', '7', '28', '29',... | 1 | 2016-09-13T03:17:31Z | 39,461,727 | <p>You can take advantage of <code>filter</code> with <code>None</code> as function for that:</p>
<pre><code>numbers = ['', '7', '', '7', '28', '29', '', '2']
numbers = filter(None, numbers)
print numbers
</code></pre>
<p>See it in action here: <a href="https://eval.in/640707" rel="nofollow">https://eval.in/640707</a... | 1 | 2016-09-13T03:20:37Z | [
"python",
"input",
"split",
"emptydatatext"
] |
How to remove empty separators from read files in Python? | 39,461,705 | <p>Here is my input file sample (z.txt)</p>
<pre><code>>qrst
ABCDE-- 6 6 35 25 10
>qqqq
ABBDE-- 7 7 28 29 2
</code></pre>
<p>I store the alpha and numeric in separate lists. Here is the output of numerics list
#Output : ['', '6', '', '6', '35', '25', '10']
['', '7', '', '7', '28', '29',... | 1 | 2016-09-13T03:17:31Z | 39,461,899 | <p>A quick fix would be a conditional within a list comprehension:</p>
<pre><code>In [4]: a = ['', '7', '', '7', '28', '29', '', '2']
In [5]: [i for i in a if i]
Out[5]: ['7', '7', '28', '29', '2']
</code></pre>
<p>List comprehensions are generally considered more pythonic than filter and map.</p>
| 0 | 2016-09-13T03:43:41Z | [
"python",
"input",
"split",
"emptydatatext"
] |
How to remove empty separators from read files in Python? | 39,461,705 | <p>Here is my input file sample (z.txt)</p>
<pre><code>>qrst
ABCDE-- 6 6 35 25 10
>qqqq
ABBDE-- 7 7 28 29 2
</code></pre>
<p>I store the alpha and numeric in separate lists. Here is the output of numerics list
#Output : ['', '6', '', '6', '35', '25', '10']
['', '7', '', '7', '28', '29',... | 1 | 2016-09-13T03:17:31Z | 39,462,009 | <p>I guess there are many ways to do this. I prefer using regular expressions, although this might be slower if you have a large input file with tens of thousands of lines. For smaller files, it's okay. </p>
<p>Few points:</p>
<ol>
<li><p>Use context manager (<code>with</code> statement) to open files. When the <code... | 0 | 2016-09-13T03:58:53Z | [
"python",
"input",
"split",
"emptydatatext"
] |
How to remove empty separators from read files in Python? | 39,461,705 | <p>Here is my input file sample (z.txt)</p>
<pre><code>>qrst
ABCDE-- 6 6 35 25 10
>qqqq
ABBDE-- 7 7 28 29 2
</code></pre>
<p>I store the alpha and numeric in separate lists. Here is the output of numerics list
#Output : ['', '6', '', '6', '35', '25', '10']
['', '7', '', '7', '28', '29',... | 1 | 2016-09-13T03:17:31Z | 39,462,073 | <p>If your input looks like this:</p>
<pre><code>>>> li=[' 6 6 35 25 10', ' 7 7 28 29 2']
</code></pre>
<p>Just use <code>.split()</code> which will handle the repeated whitespace as a single delimiter:</p>
<pre><code>>>> [e.split() for e in li]
[['6', '6', '35', '25', '10'], ['7', '7', '28', ... | 0 | 2016-09-13T04:08:03Z | [
"python",
"input",
"split",
"emptydatatext"
] |
NoReverseMatch Reverse for 'profile_user' with arguments '()' and keyword arguments '{}' not found | 39,461,793 | <p>Views.py</p>
<pre><code>@login_required
def profile_edit(request):
profile, created = UserProfile.objects.get_or_create(user=request.user)
form = UserProfileForm(request.POST or None, request.FILES or None, instance=profile)
if form.is_valid():
instance = form.save(commit=False)
instan... | 0 | 2016-09-13T03:29:54Z | 39,461,852 | <p>Your url requires 1 parameter for username. But in <code>reverse()</code> you are not passing any parameter. Hence the error. Change the reverse call as</p>
<pre><code>return redirect('profile_user', args=(instance.user.username,))
</code></pre>
| 0 | 2016-09-13T03:38:11Z | [
"python",
"django"
] |
NoReverseMatch Reverse for 'profile_user' with arguments '()' and keyword arguments '{}' not found | 39,461,793 | <p>Views.py</p>
<pre><code>@login_required
def profile_edit(request):
profile, created = UserProfile.objects.get_or_create(user=request.user)
form = UserProfileForm(request.POST or None, request.FILES or None, instance=profile)
if form.is_valid():
instance = form.save(commit=False)
instan... | 0 | 2016-09-13T03:29:54Z | 39,461,879 | <p>Your URL requires a named argument <code>username</code>. You have to give it to <code>redirect()</code> as keyword argument. Example:</p>
<pre><code>redirect('view-name', username='joe')
</code></pre>
| 0 | 2016-09-13T03:41:24Z | [
"python",
"django"
] |
Connecting to Azure SQL with Python | 39,461,850 | <p>I am trying to connect to a SQL Database hosted in Windows Azure through MySQLdb with Python. </p>
<p>I keep getting an error mysql_exceptions.OperationalError: (2001, 'Bad connection string.')</p>
<p>This information works when connecting through .NET (vb, C#) but I am definitely not having any luck here. </p>
<... | 0 | 2016-09-13T03:37:47Z | 39,496,806 | <p>@Kyle Moffat, what OS are you on? Here is how you can use pyodbc on Linux and Windows:
<a href="https://msdn.microsoft.com/en-us/library/mt763261(v=sql.1).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/mt763261(v=sql.1).aspx</a></p>
<p><strong>Windows:</strong></p>
<ul>
<li>Download and install Pyth... | 3 | 2016-09-14T17:55:41Z | [
"python",
"azure",
"sql-azure"
] |
Python Regex findall But Not Including the conditional string | 39,461,865 | <p>i have this string:</p>
<p><code>The quick red fox jumped over the lazy brown dog lazy</code></p>
<p>And i wrote this regex which gives me this:</p>
<pre><code>s = The quick red fox jumped over the lazy brown dog lazy
re.findall(r'[\s\w\S]*?(?=lazy)', ss)
</code></pre>
<p>which gives me below output:</p>
<p><c... | 0 | 2016-09-13T03:40:09Z | 39,461,903 | <p>Make the pattern <em>non-greedy</em> by adding a <code>?</code>:</p>
<pre><code>>>> m = re.search(r'[\s\w\S]*?(?=lazy)', s)
# ^
>>> m.group()
'The quick red fox jumped over the '
</code></pre>
| 0 | 2016-09-13T03:44:09Z | [
"python",
"regex",
"findall"
] |
softlayer apiï¼How to buy the bandwidth package, changes and upgrades | 39,461,928 | <p>I am a developer, recently I was doing development work on the softlayer api. Now I have a problem about bandwidth package api interface. Specific questions are as follows:
1. Bandwidth package can be replaced after purchasing finish? Where is the api ?
2. Where is the bandwidth package purchase and upgrade api?</p>... | -3 | 2016-09-13T03:47:31Z | 39,468,929 | <p>you need to upgrade your server here some similar questions</p>
<p><a href="http://stackoverflow.com/questions/35197429/modify-device-configuration/35209731#35209731">Modify Device Configuration</a></p>
<p><a href="http://stackoverflow.com/questions/37782460/how-to-add-two-or-more-disk-to-softlayer-virtual-server-... | 1 | 2016-09-13T11:30:02Z | [
"python",
"api",
"bandwidth",
"softlayer"
] |
Printing numbers from 1-100 as words in Python 3 | 39,461,937 | <pre><code>List_of_numbers1to19 = ['one', 'two', 'three', 'four', 'five', 'six', 'seven',
'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen',
'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen',
'nineteen']
List_of_numbers1to9 = List_of_numbers1to19[0:9... | -1 | 2016-09-13T03:49:07Z | 39,462,035 | <p>I think you're overcomplicating the 20-100 case. From 20-100, numbers are very regular. (i.e. they come in the form <code><tens_place> <ones_place></code>).</p>
<p>By using just one loop instead of nested loops makes the code simpler to follow. Now we just need to figure out what the tens place is, and ... | 1 | 2016-09-13T04:02:47Z | [
"python",
"python-3.x",
"numbers"
] |
Printing numbers from 1-100 as words in Python 3 | 39,461,937 | <pre><code>List_of_numbers1to19 = ['one', 'two', 'three', 'four', 'five', 'six', 'seven',
'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen',
'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen',
'nineteen']
List_of_numbers1to9 = List_of_numbers1to19[0:9... | -1 | 2016-09-13T03:49:07Z | 39,462,267 | <p>I know you already accepted an answer, but you particularly mentioned nested loops - which it doesn't use - and you're missing what's great about Python's iteration and not needing to do that kind of <code>i//10-2</code> and <code>print(j,k)</code> stuff to work out indexes into lists. </p>
<p>Python's <code>for</c... | 5 | 2016-09-13T04:34:25Z | [
"python",
"python-3.x",
"numbers"
] |
Kafka Consumer didn't receiving any messages from its Producer | 39,461,979 | <p>the following is my python coding for a kafka producer, I'm not sure is the messages able to be published to a Kafka Broker or not. Because the consumer side is didn't receiving any messages. My Consumer python program is working fine while i testing it using producer console command.</p>
<pre><code>from __future__... | 0 | 2016-09-13T03:55:25Z | 39,482,762 | <p>I usually debug such issues using kafka-console-consumer (part of Apache Kafka) to consume from the topic you tried producing to. If the console consumer gets messages, you know they arrived to Kafka.</p>
<p>If you first run the producer, let it finish, and then start the consumer, then the issue may be that the co... | 0 | 2016-09-14T04:58:27Z | [
"python",
"apache-spark",
"apache-kafka",
"spark-streaming",
"python-kafka"
] |
Kafka Consumer didn't receiving any messages from its Producer | 39,461,979 | <p>the following is my python coding for a kafka producer, I'm not sure is the messages able to be published to a Kafka Broker or not. Because the consumer side is didn't receiving any messages. My Consumer python program is working fine while i testing it using producer console command.</p>
<pre><code>from __future__... | 0 | 2016-09-13T03:55:25Z | 39,485,368 | <p>You can check the number of messages in the topic if they are increasing with Produce requests:</p>
<pre><code>./bin/kafka-run-class.sh kafka.tools.GetOffsetShell \
--broker-list <Kafka_broker_hostname>:<broker_port> --topic Que1 \
--time -1 --offsets 1 | awk -F ":" '{sum += $3} END {print sum}'
</cod... | 0 | 2016-09-14T08:02:41Z | [
"python",
"apache-spark",
"apache-kafka",
"spark-streaming",
"python-kafka"
] |
Kafka Consumer didn't receiving any messages from its Producer | 39,461,979 | <p>the following is my python coding for a kafka producer, I'm not sure is the messages able to be published to a Kafka Broker or not. Because the consumer side is didn't receiving any messages. My Consumer python program is working fine while i testing it using producer console command.</p>
<pre><code>from __future__... | 0 | 2016-09-13T03:55:25Z | 39,606,786 | <p>Alright I think there's something wrong with my local Zookeeper or Kafka, because I test it on another server it work perfectly. However , thanks for those who reply me ;)</p>
| 0 | 2016-09-21T02:54:32Z | [
"python",
"apache-spark",
"apache-kafka",
"spark-streaming",
"python-kafka"
] |
NLTK sentiment vader: polarity_scores(text) not working | 39,462,021 | <p>I am trying to use <code>polarity_scores()</code> from the Vader sentiment analysis in NLTK, but it gives me error: </p>
<blockquote>
<p>polarity_scores() missing 1 required positional argument: 'text'</p>
</blockquote>
<p>I am totally a beginner in Python. Appreciate your help! </p>
<pre><code>from nltk.sentim... | 0 | 2016-09-13T04:00:17Z | 39,462,068 | <p><code>SentimentIntensityAnalyzer</code> is a class. You need to initialize an object of <code>SentimentIntensityAnalyzer</code> and call the <code>polarity_scores()</code> method on that.</p>
<pre><code>from nltk.sentiment.vader import SentimentIntensityAnalyzer as SIA
sentences=["hello","why is it not working?!"]
... | 0 | 2016-09-13T04:07:14Z | [
"python",
"nltk",
"sentiment-analysis"
] |
Index of each element within list of lists | 39,462,049 | <p>I have something like the following list of lists:</p>
<pre><code>>>> mylist=[['A','B','C'],['D','E'],['F','G','H']]
</code></pre>
<p>I want to construct a new list of lists where each element is a tuple where the first value indicates the index of that item within its sublist, and the second value is the... | 2 | 2016-09-13T04:05:03Z | 39,462,103 | <pre><code>final_list = [list(enumerate(l)) for l in mylist]
</code></pre>
| 9 | 2016-09-13T04:10:33Z | [
"python",
"list"
] |
Keras model.predict won't accept input of size one (scalar number) | 39,462,142 | <p>I'm new to Keras and python, now I'm working on Keras to find a model of data and use that model.predict for optimization, however the model.predict can only take input as numpy array of at least 2 elements.</p>
<p>My code is</p>
<pre><code>import keras
from keras.models import Sequential
from keras.layers import ... | 1 | 2016-09-13T04:15:37Z | 39,529,769 | <p>Try: </p>
<pre><code>model.predict(np.asarray(0.0).reshape((1,1)))
</code></pre>
<p>In Keras first dimension is always connected with example number, so it must be provided.</p>
| 0 | 2016-09-16T10:55:56Z | [
"python",
"keras"
] |
Number guessing game: How can I accept input that says "guess =" before the number? | 39,462,287 | <pre><code>import random
guess = input("What is your guess?")
answer = random.randint(0,100)
while guess != answer:
try:
guess = float(guess)
if guess > answer:
print ("Your guess is too high!")
elif guess < answer:
print ("Your guess is too low!")
elif... | 0 | 2016-09-13T04:36:06Z | 39,462,367 | <p>I copied and pasted your code into Python 3.5, and....apart from needing to indent everything after the while statement it worked fine.</p>
<p>Are you inputting just the number: 30</p>
<p>...or "guess = 30"? Because that does cause a problem since it's not a number.
You only need to input the number. :)</p>
<p>If... | 0 | 2016-09-13T04:47:13Z | [
"python",
"python-3.x"
] |
Number guessing game: How can I accept input that says "guess =" before the number? | 39,462,287 | <pre><code>import random
guess = input("What is your guess?")
answer = random.randint(0,100)
while guess != answer:
try:
guess = float(guess)
if guess > answer:
print ("Your guess is too high!")
elif guess < answer:
print ("Your guess is too low!")
elif... | 0 | 2016-09-13T04:36:06Z | 39,462,482 | <p>It depends on how much you have learnt in that class, but adding the following line should allow you to accept both <code>30</code> and <code>guess = 30</code> (or even <code>foo=bar=30</code>):</p>
<pre><code>...
while guess != answer:
guess = guess.split('=')[-1] # Add this line
try:
guess = fl... | 0 | 2016-09-13T05:01:18Z | [
"python",
"python-3.x"
] |
Number guessing game: How can I accept input that says "guess =" before the number? | 39,462,287 | <pre><code>import random
guess = input("What is your guess?")
answer = random.randint(0,100)
while guess != answer:
try:
guess = float(guess)
if guess > answer:
print ("Your guess is too high!")
elif guess < answer:
print ("Your guess is too low!")
elif... | 0 | 2016-09-13T04:36:06Z | 39,462,551 | <p>So I reordered your code:</p>
<ul>
<li><p>I narrowed <code>try/except</code> down to just the line which can cause the ValueError, because that makes it clear what particular error this <code>except</code> block is trying to handle - puts the error handling near the source of the error. This also makes a good reaso... | 0 | 2016-09-13T05:09:36Z | [
"python",
"python-3.x"
] |
Unable to decorate a class method using Pint units | 39,462,299 | <p>Here's a very simple example in an effort to decorate a class method using Pint,</p>
<pre><code>from pint import UnitRegistry
ureg = UnitRegistry()
Q_ = ureg.Quantity
class Simple:
def __init__(self):
pass
@ureg.wraps('m/s', (None, 'm/s'), True)
def calculate(self, a, b):
return a*b
if __name__ == "... | 2 | 2016-09-13T04:37:10Z | 39,462,382 | <p>I think the error message is pretty clear. <a href="https://pint.readthedocs.io/en/0.7.2/wrapping.html#strict-mode" rel="nofollow">In strict mode all arguments have to be given as <code>Quantity</code></a>
yet you only give the second argument as such.</p>
<p>You either give the first argument as a <code>Quantity</... | 1 | 2016-09-13T04:50:00Z | [
"python",
"pint"
] |
Unable to decorate a class method using Pint units | 39,462,299 | <p>Here's a very simple example in an effort to decorate a class method using Pint,</p>
<pre><code>from pint import UnitRegistry
ureg = UnitRegistry()
Q_ = ureg.Quantity
class Simple:
def __init__(self):
pass
@ureg.wraps('m/s', (None, 'm/s'), True)
def calculate(self, a, b):
return a*b
if __name__ == "... | 2 | 2016-09-13T04:37:10Z | 39,477,452 | <p>Thanks for the answer. Keeping the strict mode, your first answer produces an output, i.e. make the first argument a pint Quantity too. However, the units of the output include a multiplication of the output unit specified in the wrapper and the units of the first argument too, which is incorrect. </p>
<p>The solut... | 1 | 2016-09-13T19:16:58Z | [
"python",
"pint"
] |
reading data in tensorflow - TypeError("%s that don't all match." % prefix) | 39,462,343 | <p>I am trying to load the following data file (with 225805 rows) in tensor flow. The data file looks like this:</p>
<pre><code>1,1,0.05,-1.05
1,1,0.1,-1.1
1,1,0.15,-1.15
1,1,0.2,-1.2
1,1,0.25,-1.25
1,1,0.3,-1.3
1,1,0.35,-1.35
</code></pre>
<p>the code that reads the data is</p>
<pre><code>import tensorflow as tf
#... | 3 | 2016-09-13T04:43:31Z | 39,462,574 | <p>The <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/array_ops.html#pack" rel="nofollow"><code>tf.pack()</code></a> operator requires that all of the tensors passed to it have the same element type. In your program, the first two tensors have type <code>tf.int32</code>, while the third tensor has t... | 1 | 2016-09-13T05:12:21Z | [
"python",
"tensorflow"
] |
How to correct this for loop over tuple function in Python? | 39,462,393 | <p>Here is a program where each line was split into pairs using tuples, such that every alphabet had a corresponding numeric as A:6, B:6, C:35 ..etc If a value for less than 10, then the alphabets were converted to N. The following is the code. I find that my code does not loop over the tuple function in the last part ... | 0 | 2016-09-13T04:51:18Z | 39,462,880 | <pre><code>all_inputs = [] # <---- add this
for i in range(0,ll):
sq = l[i]
sequence = sq.split(" ")[0] ## Stores only the alphabets
qualities = sq.split(" ")[1:] ## Stores only the numeric
qualities = filter(None, qualities)
for sub in sequence:
if sub == "-":
idx = list(seq... | 0 | 2016-09-13T05:40:58Z | [
"python",
"loops",
"tuples"
] |
Stacking arrays in numpy using vstack | 39,462,433 | <p><code>array1.shape</code> gives (180, )
<code>array2.shape</code> gives (180, 1)</p>
<p>What's the difference between these two?
And because of this difference I'm unable to stack them using</p>
<pre><code>np.vstack((array2, array1))
</code></pre>
<p>What changes should I make to array1 shape so that I can stack ... | 2 | 2016-09-13T04:56:21Z | 39,462,489 | <p>Let's define some arrays:</p>
<pre><code>>>> x = np.zeros((4, 1))
>>> y = np.zeros((4))
</code></pre>
<p>As is, these arrays fail to stack:</p>
<pre><code>>>> np.vstack((x, y))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/... | 0 | 2016-09-13T05:02:07Z | [
"python",
"numpy"
] |
Stacking arrays in numpy using vstack | 39,462,433 | <p><code>array1.shape</code> gives (180, )
<code>array2.shape</code> gives (180, 1)</p>
<p>What's the difference between these two?
And because of this difference I'm unable to stack them using</p>
<pre><code>np.vstack((array2, array1))
</code></pre>
<p>What changes should I make to array1 shape so that I can stack ... | 2 | 2016-09-13T04:56:21Z | 39,462,663 | <pre><code>In [81]: x1=np.ones((10,)); x2=np.ones((10,1))
</code></pre>
<p>One array is 1d, the other 2d. <code>vertical</code> stack requires 2 dimensions, vertical and horizontal. So <code>np.vstack</code> passes each input through <code>np.atleast_2d</code>:</p>
<pre><code>In [82]: np.atleast_2d(x1).shape
Out[82... | 0 | 2016-09-13T05:22:15Z | [
"python",
"numpy"
] |
How to impute each categorical column in numpy array | 39,462,449 | <p>There are good solutions to impute panda dataframe. But since I am working mainly with numpy arrays, I have to create new panda DataFrame object, impute and then convert back to numpy array as follows:</p>
<pre><code>nomDF=pd.DataFrame(x_nominal) #Convert np.array to pd.DataFrame
nomDF=nomDF.apply(lambda x:x.fillna... | 0 | 2016-09-13T04:57:56Z | 39,462,695 | <p>We could use <a href="http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.stats.mstats.mode.html" rel="nofollow"><code>Scipy's mode</code></a> to get the highest value in each column. Leftover work would be to get the <code>NaN</code> indices and replace those in input array with the <code>mode</code> v... | 1 | 2016-09-13T05:25:34Z | [
"python",
"pandas",
"numpy"
] |
Pandas aggregate list in resample/groupby | 39,462,522 | <p>I have a dataframe in which each instance has a timestamp, an id and a list of numbers as follows: </p>
<pre><code>timestamp | id | lists
----------------------------------
2016-01-01 00:00:00 | 1 | [2, 10]
2016-01-01 05:00:00 | 1 | [9, 10, 3, 5]
2016-01-01 10:00:00 | 1 | [1, 10, 5]
2016-01-02 01:00:00... | 3 | 2016-09-13T05:06:12Z | 39,463,226 | <p>As pointed out by @jezrael, this only works in <strong><em>pandas version 0.18.1+</em></strong></p>
<ul>
<li><code>set_index</code> with <code>'timestamp'</code> to prep for later <code>resample</code></li>
<li><code>groupby</code> <code>'id'</code> column and select <code>lists</code> columns</li>
<li>after <code>... | 6 | 2016-09-13T06:09:22Z | [
"python",
"pandas",
"dataframe"
] |
Pandas aggregate list in resample/groupby | 39,462,522 | <p>I have a dataframe in which each instance has a timestamp, an id and a list of numbers as follows: </p>
<pre><code>timestamp | id | lists
----------------------------------
2016-01-01 00:00:00 | 1 | [2, 10]
2016-01-01 05:00:00 | 1 | [9, 10, 3, 5]
2016-01-01 10:00:00 | 1 | [1, 10, 5]
2016-01-02 01:00:00... | 3 | 2016-09-13T05:06:12Z | 39,472,326 | <p>for the unique count of each list item use list comprehension:</p>
<pre><code>a = [list(set(l)) for l in df.lists]
df.loc[:,'lists'] = a
</code></pre>
| 0 | 2016-09-13T14:17:43Z | [
"python",
"pandas",
"dataframe"
] |
how to run python files in windows command prompt? | 39,462,632 | <p>I want to run a python file in my command prompt but it does nothing.
These are the screen shots of my program i am testing with and the output the command prompt gives me.
<a href="http://i.stack.imgur.com/yHFIW.png" rel="nofollow"><img src="http://i.stack.imgur.com/yHFIW.png" alt="enter image description here"></a... | -4 | 2016-09-13T05:19:06Z | 39,462,781 | <p>First set path of <code>python</code> <a href="http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7">http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows</a></p>
<p>and run <code>python</code> file </p>
<p><code>python filename.py</code></p>
<p>comman... | 1 | 2016-09-13T05:32:21Z | [
"python",
"python-2.7",
"command-line",
"cmd",
"command"
] |
how to run python files in windows command prompt? | 39,462,632 | <p>I want to run a python file in my command prompt but it does nothing.
These are the screen shots of my program i am testing with and the output the command prompt gives me.
<a href="http://i.stack.imgur.com/yHFIW.png" rel="nofollow"><img src="http://i.stack.imgur.com/yHFIW.png" alt="enter image description here"></a... | -4 | 2016-09-13T05:19:06Z | 39,462,799 | <p>You have to <code>install</code> <a href="https://www.python.org" rel="nofollow">Python</a> and add it to <a href="https://docs.python.org/2/using/windows.html" rel="nofollow">PATH</a> on <code>Windows</code>. After that you can try:</p>
<pre><code>python `C:/pathToFolder/prog.py`
</code></pre>
<p>or go to the fil... | 1 | 2016-09-13T05:33:37Z | [
"python",
"python-2.7",
"command-line",
"cmd",
"command"
] |
how to run python files in windows command prompt? | 39,462,632 | <p>I want to run a python file in my command prompt but it does nothing.
These are the screen shots of my program i am testing with and the output the command prompt gives me.
<a href="http://i.stack.imgur.com/yHFIW.png" rel="nofollow"><img src="http://i.stack.imgur.com/yHFIW.png" alt="enter image description here"></a... | -4 | 2016-09-13T05:19:06Z | 39,463,070 | <p>First go to the directory where your python script is present by using-</p>
<pre><code>cd path/to/directory
</code></pre>
<p>then simply do:</p>
<pre><code>python file_name.py
</code></pre>
| 0 | 2016-09-13T05:57:38Z | [
"python",
"python-2.7",
"command-line",
"cmd",
"command"
] |
RawPostDataException: You cannot access body after reading from request's data stream | 39,462,717 | <p>I am hosting a site on Google Cloud and I got everything to work beautifully and then all of the sudden I start getting this error..</p>
<pre><code>01:16:22.222
Internal Server Error: /api/v1/auth/login/ (/base/data/home/apps/s~crs-portal/1.395605052160854207/lib/django/core/handlers/exception.py:124)
Traceback (mo... | 0 | 2016-09-13T05:27:20Z | 39,463,487 | <p>This is occuring is because you are trying to access the data from <code>body</code></p>
<p>use -> <code>data = json.loads(request.data)</code></p>
| 0 | 2016-09-13T06:27:42Z | [
"python",
"django",
"django-rest-framework"
] |
RawPostDataException: You cannot access body after reading from request's data stream | 39,462,717 | <p>I am hosting a site on Google Cloud and I got everything to work beautifully and then all of the sudden I start getting this error..</p>
<pre><code>01:16:22.222
Internal Server Error: /api/v1/auth/login/ (/base/data/home/apps/s~crs-portal/1.395605052160854207/lib/django/core/handlers/exception.py:124)
Traceback (mo... | 0 | 2016-09-13T05:27:20Z | 39,472,657 | <p>hey thanks for the response but I figured it out! It wasn't working because I found a small bug where I am able to access the login page even though I am already logged in, so the error was caused by trying to login again. I fixed the issue by redirecting to home page if login page is tried to be reached</p>
| 0 | 2016-09-13T14:35:23Z | [
"python",
"django",
"django-rest-framework"
] |
strange exceptions.SystemExit in Python 2.7 | 39,462,919 | <p>Here is my code and error message, anyone have any ideas why there are such exception? Thanks.</p>
<p><strong>Source Code</strong>,</p>
<pre><code>import sys
import tensorflow as tf
def main(argv):
print 'in main'
def f():
# this method will call def main(argv)
try:
tf.app.run()
except:
... | 0 | 2016-09-13T05:43:49Z | 39,462,989 | <p>It's coming from the <a href="https://docs.python.org/3/library/sys.html#sys.exit" rel="nofollow"><code>sys.exit()</code></a> call, about which the following is said:</p>
<blockquote>
<p>Since exit() ultimately âonlyâ raises an exception, it will only exit the process when called from the main thread, and the... | 1 | 2016-09-13T05:51:06Z | [
"python",
"python-2.7",
"exception",
"tensorflow"
] |
strange exceptions.SystemExit in Python 2.7 | 39,462,919 | <p>Here is my code and error message, anyone have any ideas why there are such exception? Thanks.</p>
<p><strong>Source Code</strong>,</p>
<pre><code>import sys
import tensorflow as tf
def main(argv):
print 'in main'
def f():
# this method will call def main(argv)
try:
tf.app.run()
except:
... | 0 | 2016-09-13T05:43:49Z | 39,463,046 | <p>This is expected behavior: <a href="https://github.com/tensorflow/tensorflow/blob/4f9a3a4def1d0e0bcc0c2ca4cd06d993024fd469/tensorflow/python/platform/app.py#L26" rel="nofollow"><code>tf.app.run()</code></a> passes the result of <code>main()</code> to <a href="https://docs.python.org/2/library/sys.html#sys.exit" rel=... | 1 | 2016-09-13T05:55:28Z | [
"python",
"python-2.7",
"exception",
"tensorflow"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.