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 |
|---|---|---|---|---|---|---|---|---|---|
Tkinter Tix Checklist Hlist Header Configuration Options | 39,441,438 | <p>I'm hoping a tcl/tk expert can help answer this super-niche question regarding a <strong>Tix CheckList Hlist Header</strong>. All I want to do is change the background color from an ugly gray to white.</p>
<p>I find it very difficult to even know what options (<code>cnf={}</code> or <code>**kw</code>) I can use fo... | 0 | 2016-09-11T22:56:16Z | 39,445,503 | <p>Simply, add <code>headerbackground</code> parameter to <code>header_create()</code> method:</p>
<pre><code>...
self.checklist.hlist.header_create(0, itemtype=tix.TEXT, text='My Heading Text',
headerbackground="red", relief='flat')
...
</code></pre>
| 1 | 2016-09-12T07:43:15Z | [
"python",
"tkinter",
"checklistbox",
"hlist",
"tix"
] |
Need Help Using python-quickbooks library and Quickbooks Accounting API | 39,441,467 | <p>I'm trying to implement the Quickbooks API for Python, to generate invoices based on transactions, and send them to my quickbooks account. I'm using <a href="https://github.com/sidecars/python-quickbooks" rel="nofollow">this</a> python library for accessing the API, which is currently in version 0.5.1 and is availab... | 0 | 2016-09-11T23:00:43Z | 39,461,234 | <p>I found the answer to my problem. After reading this <a href="http://stackoverflow.com/questions/16078366/reuse-oauth1-authorization-tokens-with-rauth">thread</a>, where they had the same error, I got a better sense of what the library was doing; mainly the flow that was going on behind the scenes. I ultimately foun... | 0 | 2016-09-13T02:08:13Z | [
"python",
"web2py",
"quickbooks-online"
] |
pandas: groupby and aggregate without losing the column which was grouped | 39,441,484 | <p>I have a pandas dataframe as below. For each Id I can have multiple Names and Sub-ids.</p>
<pre><code>Id NAME SUB_ID
276956 A 5933
276956 B 5934
276956 C 5935
287266 D 1589
</code></pre>
<p>I want to condense the dataframe such that there is only one row for each id and all the names... | 3 | 2016-09-11T23:03:57Z | 39,441,498 | <p>The groupby column becomes the index. You can simply reset the index to get it back:</p>
<pre><code>In [4]: df.groupby('Id').agg(lambda x: set(x)).reset_index()
Out[4]:
Id NAME SUB_ID
0 276956 {A, C, B} {5933, 5934, 5935}
1 287266 {D} {1589}
</code></pre>
| 5 | 2016-09-11T23:07:08Z | [
"python",
"pandas",
"dataframe",
"group-by"
] |
pandas: groupby and aggregate without losing the column which was grouped | 39,441,484 | <p>I have a pandas dataframe as below. For each Id I can have multiple Names and Sub-ids.</p>
<pre><code>Id NAME SUB_ID
276956 A 5933
276956 B 5934
276956 C 5935
287266 D 1589
</code></pre>
<p>I want to condense the dataframe such that there is only one row for each id and all the names... | 3 | 2016-09-11T23:03:57Z | 39,442,599 | <p>If you don't want the groupby as an index, there is an argument for it to avoid further reset:</p>
<pre><code>df.groupby('Id', as_index=False).agg(lambda x: set(x))
</code></pre>
| 1 | 2016-09-12T02:23:13Z | [
"python",
"pandas",
"dataframe",
"group-by"
] |
python linklist pointer and size | 39,441,511 | <p>I am a rookie python programmer. I see the leetcode's definition of a linked list below. I got 2 questions for this concept, any help would be appreciated. Thanks in advance</p>
<pre><code># Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# se... | 0 | 2016-09-11T23:09:33Z | 39,441,618 | <p>Question 1:</p>
<p>Python variables are dynamically typed. (i.e. a variable could hold an int, and then hold a list, and then any other arbitrary object, etc).</p>
<p>In your case, <code>Head.next</code> starts by referencing, <code>None</code> a <code>NoneType</code> object.</p>
<p>After you assign it a differen... | 0 | 2016-09-11T23:26:54Z | [
"python",
"c++",
"class",
"pointers",
"linked-list"
] |
python linklist pointer and size | 39,441,511 | <p>I am a rookie python programmer. I see the leetcode's definition of a linked list below. I got 2 questions for this concept, any help would be appreciated. Thanks in advance</p>
<pre><code># Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# se... | 0 | 2016-09-11T23:09:33Z | 39,441,620 | <p>My interpretation of a linked list. </p>
<pre><code>class LinkedList(object):
class Node(object):
def __init__(self, val=None, next=None, previous=None):
self.val = val
self.next = next
self.last = previous
def __init__(self):
self.length = 0
self... | 0 | 2016-09-11T23:27:11Z | [
"python",
"c++",
"class",
"pointers",
"linked-list"
] |
How to draw rotated stripe patterns | 39,441,563 | <p>I want to draw stripe patterns given a rotated angle. I figured out how to draw vertical lines but not rotated. For example, given the image below with an input of 45 degrees I want to generate the second image.</p>
<p>Here's my code for generating the first image:
from <strong>future</strong> import division</p>
... | -1 | 2016-09-11T23:18:17Z | 39,442,913 | <p>You need to have a rotate method with respect to some <code>center</code>. For example below is a sample method. You will have to modify it for your needs, but that should be sufficient to start your code</p>
<pre><code> def rotate_point(center, point, angle):
"""Rotate point around center by angle
... | 0 | 2016-09-12T03:18:38Z | [
"python",
"numpy"
] |
Python 3.5 While loop not entering the If Statements | 39,441,606 | <p>My apologies in advance. I know this question has probably been asked on stack exchange before and I do see some relevant posts,but I'm having some issue interpreting the responses.</p>
<p>I've been asked to create a guessing program that uses 'bisection search' to guess the number that you've selected (in your min... | 1 | 2016-09-11T23:25:12Z | 39,441,822 | <p>Ok I figured it out after my code graded correctly. I was using the wrong console in scipython IDE to evaluate my code D'Oh</p>
<p>Anyways the code is a good example of taking an input() inside a while loop and using if/elsif/else to meet conditions.</p>
<p>Just remeber that in python 2 you'll want to use raw_inpu... | 1 | 2016-09-12T00:05:28Z | [
"python",
"python-3.x",
"bisection"
] |
Getting the date of the first day of the week | 39,441,639 | <p>I had a record in a table which contains a date field which will always be the date of the Sunday of a given week.</p>
<p>I would like to query the table so that the records that are returned are in the same week as the week in the date field of the records.</p>
<p>How could I use python's <code>datetime</code> li... | -3 | 2016-09-11T23:30:27Z | 39,448,093 | <p>To get the beginning date of the week:</p>
<pre><code>datetime.today() - timedelta(days=datetime.today().isoweekday() % 7)
</code></pre>
<p>I use this with a filter to get the Sunday date of a record.</p>
| 0 | 2016-09-12T10:19:08Z | [
"python",
"datetime"
] |
Methods to search and replace values in nested lists | 39,441,646 | <p>I'd like to search and replace values in a list of of list. I've cobbled together answers to:</p>
<ol>
<li><a href="http://stackoverflow.com/a/952952/2694260">Flatten a nested list</a></li>
<li><a href="http://stackoverflow.com/a/1540069/2694260">Search for and replace a value</a></li>
<li><a href="http://stackover... | 0 | 2016-09-11T23:32:22Z | 39,441,668 | <p>You're already using list comprehensions, just combine them:</p>
<pre><code>replaced_list_of_lists = [
[-1 if e > 5 else e for e in inner_list]
for inner_list in list_of_lists
]
</code></pre>
| 1 | 2016-09-11T23:36:41Z | [
"python"
] |
Methods to search and replace values in nested lists | 39,441,646 | <p>I'd like to search and replace values in a list of of list. I've cobbled together answers to:</p>
<ol>
<li><a href="http://stackoverflow.com/a/952952/2694260">Flatten a nested list</a></li>
<li><a href="http://stackoverflow.com/a/1540069/2694260">Search for and replace a value</a></li>
<li><a href="http://stackover... | 0 | 2016-09-11T23:32:22Z | 39,441,670 | <p>Make the replacements in the sublists in a <em>nested list comprehension</em> without having to flatten and regroup:</p>
<pre><code>numbers = list(range(10))
list_of_lists = [numbers[i:i+2] for i in range(0, len(numbers), 2)]
# here
list_of_lists = [[-1 if e > 5 else e for e in sublist] for sublist in list_of_li... | 2 | 2016-09-11T23:37:08Z | [
"python"
] |
How to create tuples from a single list with alpha-numeric chacters? | 39,441,730 | <p>I have the following list with 2 elements:</p>
<pre><code>['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
</code></pre>
<p>I need to make a list or zip file such that each alphabet corresponds to its number further in the list. For example in list[0] the list/zip should read</p>
<pre><code>{"A":"6", "G":"6", "C":"35"... | 2 | 2016-09-11T23:46:30Z | 39,441,768 | <p>This code would work, assuming the elements in the list are correctly formed.
This means the number of letters and numbers must match!</p>
<p>And it will overwrite the value if the key already exists.</p>
<pre><code>list = ['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
dictionary = {}
for line in list:
split_lin... | -1 | 2016-09-11T23:54:41Z | [
"python",
"list",
"dictionary",
"zip",
"tuples"
] |
How to create tuples from a single list with alpha-numeric chacters? | 39,441,730 | <p>I have the following list with 2 elements:</p>
<pre><code>['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
</code></pre>
<p>I need to make a list or zip file such that each alphabet corresponds to its number further in the list. For example in list[0] the list/zip should read</p>
<pre><code>{"A":"6", "G":"6", "C":"35"... | 2 | 2016-09-11T23:46:30Z | 39,441,797 | <p>Use tuples splitting once to get the pairs, then split the second element of each pair, <em>zip</em> together:</p>
<pre><code>l =['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
pairs = [zip(a,b.split()) for a,b in (sub.split(None,1) for sub in l]
</code></pre>
<p>Which would give you:</p>
<pre><code>[[('A', '6'),... | 3 | 2016-09-11T23:59:07Z | [
"python",
"list",
"dictionary",
"zip",
"tuples"
] |
How to create tuples from a single list with alpha-numeric chacters? | 39,441,730 | <p>I have the following list with 2 elements:</p>
<pre><code>['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
</code></pre>
<p>I need to make a list or zip file such that each alphabet corresponds to its number further in the list. For example in list[0] the list/zip should read</p>
<pre><code>{"A":"6", "G":"6", "C":"35"... | 2 | 2016-09-11T23:46:30Z | 39,441,824 | <p>If you consider using tuples to pair the items, then this works: </p>
<pre><code>>>> from pprint import pprint
>>> lst = ['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
>>> new_lst = [list(zip(sub[0], sub[1:])) for sub in [i.split() for i in lst]]
>>> pprint(new_lst)
[[('A', '6'), ... | 1 | 2016-09-12T00:05:56Z | [
"python",
"list",
"dictionary",
"zip",
"tuples"
] |
How to create tuples from a single list with alpha-numeric chacters? | 39,441,730 | <p>I have the following list with 2 elements:</p>
<pre><code>['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
</code></pre>
<p>I need to make a list or zip file such that each alphabet corresponds to its number further in the list. For example in list[0] the list/zip should read</p>
<pre><code>{"A":"6", "G":"6", "C":"35"... | 2 | 2016-09-11T23:46:30Z | 39,444,830 | <p>Iterate through list > iterate through items (alpha numeric) of the list and construct list of characters and numbers > and then construct list of tuple.</p>
<pre><code>alphanum = ['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
list_of_tuple = []
for s in alphanum:
ints = []
chars = []
for i in s.split():
... | 0 | 2016-09-12T06:56:48Z | [
"python",
"list",
"dictionary",
"zip",
"tuples"
] |
Postgresql/Python compressing text column with a lot of redundant rows | 39,441,734 | <p>Note:</p>
<ul>
<li>We're using Amazon RDS, so we're very limited on the number of PostgreSQL extensions we can use.</li>
<li>I've said PostgreSQL on RDS , because 1) we must use AWS, 2) we want the safest solution on data integrity with lowest time spent on maintenance. (so if an other service is better suited with... | 1 | 2016-09-11T23:46:59Z | 39,539,195 | <p>I finally went with the dictionnary table idea</p>
<p>for the dictionnary_id I actually used a <code>murmurhash 64 bits</code> (and named the id <code>hash_message</code> so that I can precompute it on the python side first, and as it is a non-crytographic, it's pretty to call, for python there's a pure C implement... | 0 | 2016-09-16T19:53:54Z | [
"python",
"algorithm",
"postgresql",
"compression"
] |
I am unable to get my code to count and reset to zero | 39,441,863 | <p>I am having an issue with creating code that will count when a pattern is not matched and reset back to 0 once that pattern has a match using regular expression. I will list a an example of the file and try to attempt to demonstrate what I am looking to do. No matter how many matches are in the file I receive a -1. ... | -2 | 2016-09-12T00:13:34Z | 39,442,831 | <p>First of all:</p>
<pre><code>for line in my_p3text:
match=regEx56.search(line)
count = 0
print (match)
else:
count = -1
</code></pre>
<p>means that when there are no more lines, it will print -1, which is always. Put an if-else statement inside the for loop.</p>
<p>Also, right now your numbers c... | 0 | 2016-09-12T03:04:28Z | [
"python",
"regex"
] |
former form fields no longer found by mechanize python script | 39,441,880 | <p>Let me start by apologizing for my utter newbness. I was asked by a friend a couple years ago if I could write a program to automatically grab substitute teaching openings. It wasn't an area I knew anything about, but a couple tutorials allowed me to bang something out despite ignorance about html (and more than a l... | 0 | 2016-09-12T00:15:32Z | 39,441,959 | <p>Try something like this if that html code is exactly what is on that page. When you put b.select_form(nr=0) there is the possibility that for some reason the first form is not what you are selecting. By looking for the form name in the b.select_form() you can ensure you find the correct form. Test it out and see if ... | 0 | 2016-09-12T00:30:34Z | [
"python",
"html",
"forms",
"mechanize",
"hidden"
] |
Run same loop twice, but getting different results | 39,441,896 | <p>I cannot figure this out, but say I have a depth-3 array of strings called "text".</p>
<p>How can it be that in the following code:</p>
<pre><code>print "FIRST"
for gate in text[1:]:
print "GATE"
for text in gate:
print "TEXT"
for entry in text:
print "ENTRY"
print w... | 1 | 2016-09-12T00:18:52Z | 39,441,910 | <p><code>text</code> has been modified. Before the SECOND loop, <code>text</code> has its value taken from the last iteration of <code>for text in gate: ...</code></p>
<p>You should consider renaming the inner loop variable to something different.</p>
| 6 | 2016-09-12T00:22:02Z | [
"python"
] |
Run same loop twice, but getting different results | 39,441,896 | <p>I cannot figure this out, but say I have a depth-3 array of strings called "text".</p>
<p>How can it be that in the following code:</p>
<pre><code>print "FIRST"
for gate in text[1:]:
print "GATE"
for text in gate:
print "TEXT"
for entry in text:
print "ENTRY"
print w... | 1 | 2016-09-12T00:18:52Z | 39,441,913 | <p><code>for</code> loops "leak" variables. You might expect <code>gate</code>, <code>text</code>, and <code>entry</code> to be scoped to their respective loops, but they're actually global. So, at the end of this loop</p>
<pre><code>for text in gate:
</code></pre>
<p>The value of <code>text</code> has been altered, ... | 7 | 2016-09-12T00:22:21Z | [
"python"
] |
Reindexing a multiindex in pandas dataframe | 39,441,925 | <p>I'm trying to reindex a 2-level multiindex pandas dataframe. Data struct looks like this:</p>
<pre><code>In [1]: df.head(5)
Out [1]: arrivals departs
station datetime
S1 2014-03-03 07:45:00 1 1
2014-03-03 09:00:00 2 ... | 1 | 2016-09-12T00:24:10Z | 39,442,551 | <p>Turn it back into a simple datetimeindex and fill the gaps:</p>
<pre><code>df = (df.unstack(level=0)
.reindex(pd.date_range(start='2014-03-03 07:45:00',
end='2014-03-04 07:45:00', freq='15min')))
df = df.fillna(0) # for the data, 0 is the desired value
df.stack('station').swaplevel(0... | 1 | 2016-09-12T02:14:22Z | [
"python",
"pandas",
"multi-index"
] |
How to get x,y position of contours in Python OpenCV | 39,441,935 | <p>I'm trying to get x and y positions of contours from the following image, but I messed up.
<a href="http://i.stack.imgur.com/ctBI9.png" rel="nofollow">the image</a></p>
<p>I just need to find x and y positions of contours or center of the contours.</p>
<p>The results will be something like the following as I manua... | -2 | 2016-09-12T00:26:08Z | 39,458,083 | <p>Indeed, you can do that with <code>findContours</code>. Since you have your contours there are several options:</p>
<ol>
<li>Calculate enclosing rectangle and take e.g. the center point.</li>
<li>Calculate moments and take the centroid </li>
<li>Fit minimum enclosing circle and take the center</li>
<li>and so on...... | 0 | 2016-09-12T20:11:38Z | [
"python",
"opencv"
] |
If statements with undefined variable | 39,442,055 | <p>I'm not sure what I'm doing wrong I tried to define "if the answer was <code>'Y'</code> Then <code>premium_membership=true</code>" but I keep getting this error. The beginning is as far as I get when I run the code and the second is my code.</p>
<pre><code>What is your name? John Smith
How many books are you purch... | 0 | 2016-09-12T00:47:56Z | 39,442,079 | <p>In this section of code</p>
<pre><code>if membership =='Y':
premium_member=True
else:
join=input("Would you like to join our membership program for $4.95? Enter Y for yes or N for no.")
</code></pre>
<p>you're assigning <code>premium_member=True</code> in the case that <code>membership</code> is equal to <... | 4 | 2016-09-12T00:53:13Z | [
"python",
"python-3.x"
] |
Scraping several pages with BeautifulSoup | 39,442,058 | <p>I'd like to scrape through several pages of a website using Python and BeautifulSoup4. The pages differ by only a single number in their URL, so I could actually make a declaration like this:</p>
<pre><code>theurl = "beginningofurl/" + str(counter) + "/endofurl.html"
</code></pre>
<p>The link I've been testing wit... | 1 | 2016-09-12T00:48:21Z | 39,442,266 | <p>Try with <code>requests</code> (avoiding redirections) and check if you get new quotes.</p>
<pre><code>import requests
from bs4 import BeautifulSoup
def category_crawler():
''' This function will crawl through an entire category, regardless how many pages it consists of. '''
pager = 1
while pager &l... | 0 | 2016-09-12T01:27:10Z | [
"python",
"beautifulsoup"
] |
Scraping several pages with BeautifulSoup | 39,442,058 | <p>I'd like to scrape through several pages of a website using Python and BeautifulSoup4. The pages differ by only a single number in their URL, so I could actually make a declaration like this:</p>
<pre><code>theurl = "beginningofurl/" + str(counter) + "/endofurl.html"
</code></pre>
<p>The link I've been testing wit... | 1 | 2016-09-12T00:48:21Z | 39,442,352 | <p>Here is my attempt. </p>
<p>Minor issue: put a <code>try-except</code> block in the code in case the redirection leads you somewhere that doesn't exist. </p>
<p>Now, the main issue: how to avoid parsing stuff you already parsed. Keep a record of urls that you have parsed. Then detect if the <em>actual</em> url fro... | 0 | 2016-09-12T01:38:06Z | [
"python",
"beautifulsoup"
] |
Scraping several pages with BeautifulSoup | 39,442,058 | <p>I'd like to scrape through several pages of a website using Python and BeautifulSoup4. The pages differ by only a single number in their URL, so I could actually make a declaration like this:</p>
<pre><code>theurl = "beginningofurl/" + str(counter) + "/endofurl.html"
</code></pre>
<p>The link I've been testing wit... | 1 | 2016-09-12T00:48:21Z | 39,442,359 | <p>The idea is to <em>have an endless loop and break it once you don't have the "arrow right" element on the page</em> which would mean you are on the last page, simple and quite logical:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
page = 1
url = "http://www.worldofquotes.com/topic/Nature/{page}/ind... | 0 | 2016-09-12T01:39:05Z | [
"python",
"beautifulsoup"
] |
Merging with more than one level overlap not allowed | 39,442,064 | <p>So, I'm using pandas and essentially trying to calculate a normalized weight. For each day in my dataframe, I want the 'SECTOR' weight grouped by 'CAP', but they won't sum up to 1, so I want to normalize them as well. I thought I could accomplish this by dividing two groupbys, but I'm getting an error on my code tha... | 2 | 2016-09-12T00:50:07Z | 39,447,470 | <p><strong><em>Option 1</em></strong><br>
Very close to what you had</p>
<pre><code>cols = ['EFFECTIVE DATE', 'CAP', 'SECTOR', 'INDEX WEIGHT']
sector_sum = df.groupby(cols[:3])[cols[-1]].sum()
cap_sum = df.groupby(cols[:2])[cols[-1]].transform(pd.Series.sum).values
sector_sum / cap_sum
</code></pre>
<p><strong><em>Op... | 2 | 2016-09-12T09:42:34Z | [
"python",
"pandas"
] |
Confused by results from simple calculation | 39,442,102 | <p>I am not sure why the below code is not working. I am running this in python 3.5.2 and the problem appears to be in the calculation portion of the code. It returns no errors but gives huge values that shouldn't be the average of the 5 inputs.</p>
<pre><code>#inputs
year1 = input("Enter wins for year 1: ")
year2 = i... | -2 | 2016-09-12T00:58:03Z | 39,442,111 | <p>you need to cast the input values to integer individually</p>
<pre><code>averageWin = (int(year1) + int(year2) + int(year3) + int(year4) + int(year5)) / 5
</code></pre>
<p>What you did before was concatenating the strings:</p>
<pre><code>int('100' + '100') => int('100100') => 100100
</code></pre>
| 1 | 2016-09-12T01:00:09Z | [
"python",
"python-3.x",
"average"
] |
Confused by results from simple calculation | 39,442,102 | <p>I am not sure why the below code is not working. I am running this in python 3.5.2 and the problem appears to be in the calculation portion of the code. It returns no errors but gives huge values that shouldn't be the average of the 5 inputs.</p>
<pre><code>#inputs
year1 = input("Enter wins for year 1: ")
year2 = i... | -2 | 2016-09-12T00:58:03Z | 39,442,125 | <p>You are concatenating strings, and then turning that into an integer. You have to turn each individual string into an integer before adding them.</p>
<pre><code>>>> a = '3'
>>> b = '5'
>>> c = '4'
>>> x = a+b+c
>>> int(x)
354
>>> x
'354'
>>> int(a)+int(... | 0 | 2016-09-12T01:02:15Z | [
"python",
"python-3.x",
"average"
] |
Confused by results from simple calculation | 39,442,102 | <p>I am not sure why the below code is not working. I am running this in python 3.5.2 and the problem appears to be in the calculation portion of the code. It returns no errors but gives huge values that shouldn't be the average of the 5 inputs.</p>
<pre><code>#inputs
year1 = input("Enter wins for year 1: ")
year2 = i... | -2 | 2016-09-12T00:58:03Z | 39,442,127 | <h2>By default, <code>input()</code> returns a string. You are adding the strings and then converting the result into an <code>int.</code></h2>
<p>Assume we have the inputs <code>1, 2, 3, 4, 5</code> as our variables. Your code does <code>'1'+ '2' + '3' + '4' + '5'</code> instead of <code>1 + 2 + 3 + 4 + 5</code>. You... | 0 | 2016-09-12T01:02:28Z | [
"python",
"python-3.x",
"average"
] |
Confused by results from simple calculation | 39,442,102 | <p>I am not sure why the below code is not working. I am running this in python 3.5.2 and the problem appears to be in the calculation portion of the code. It returns no errors but gives huge values that shouldn't be the average of the 5 inputs.</p>
<pre><code>#inputs
year1 = input("Enter wins for year 1: ")
year2 = i... | -2 | 2016-09-12T00:58:03Z | 39,442,193 | <p>Try this.</p>
<pre><code> year = 0
for i in range(5):
ann = "{:,.0f}".format(i+1)
year=year+input("Enter wins for year "+ann+": ")
print year/5.
</code></pre>
<p>Shorter and works.</p>
| 0 | 2016-09-12T01:12:27Z | [
"python",
"python-3.x",
"average"
] |
itertools.groupby function seems inconsistent | 39,442,128 | <p>I'm having trouble understanding exactly what it is that this function does because of I guess, the programming magic around its use?</p>
<p>It seems to me like it returns a list of keys (unique letters in a string) paired with iterators, that reference a list of the number of each of those letters in the original ... | 2 | 2016-09-12T01:02:38Z | 39,442,145 | <p>To get the answers you expect, convert the returned iterators to a list.</p>
<p><a href="https://docs.python.org/3/library/itertools.html#itertools.groupby" rel="nofollow"><em>Groupby</em></a> consumes an input iterator lazily (that means that it reads data only as needed). To find a new group, it needs to read up... | 4 | 2016-09-12T01:06:07Z | [
"python",
"group-by",
"list-comprehension",
"itertools"
] |
itertools.groupby function seems inconsistent | 39,442,128 | <p>I'm having trouble understanding exactly what it is that this function does because of I guess, the programming magic around its use?</p>
<p>It seems to me like it returns a list of keys (unique letters in a string) paired with iterators, that reference a list of the number of each of those letters in the original ... | 2 | 2016-09-12T01:02:38Z | 39,442,179 | <p>The docs already explain why your listcomps aren't equivalent:</p>
<blockquote>
<p>The returned group is itself an iterator that shares the underlying iterable with groupby(). Because the source is shared, when the groupby() object is advanced, the previous group is no longer visible. So, if that data is needed l... | 6 | 2016-09-12T01:11:21Z | [
"python",
"group-by",
"list-comprehension",
"itertools"
] |
Calling methods from classes | 39,442,181 | <p>I'm writing some classes:</p>
<pre><code>bean_version = "1.0"
from random import randint
console = []
print "Running Bean v%s" % bean_version
#Math Function
class math(object):
def __init__(self, op1 = 0, op2 = 0):
self.op1 = op1
self.op2 = op2
def add(self):
return self.op1 + self.o... | -1 | 2016-09-12T01:11:35Z | 39,442,219 | <p>Yes, of course. The problem currently is that you are defining your class such that the operands must be passed to the <em>constructor</em>, not the operators. Try this:</p>
<pre><code>class math(object):
def add(self, op1=0, op2=0):
return op1 + op2
def sub(self, op1=0, op2=0):
return op1 -... | 0 | 2016-09-12T01:15:43Z | [
"python",
"python-2.7"
] |
Calling methods from classes | 39,442,181 | <p>I'm writing some classes:</p>
<pre><code>bean_version = "1.0"
from random import randint
console = []
print "Running Bean v%s" % bean_version
#Math Function
class math(object):
def __init__(self, op1 = 0, op2 = 0):
self.op1 = op1
self.op2 = op2
def add(self):
return self.op1 + self.o... | -1 | 2016-09-12T01:11:35Z | 39,442,242 | <p>That is possible. In this case you use the class just as a way to logically group your operators (add, sub, mul, div) and you don't really need to initialize the operands in the class instance itself. This calls for the <a href="https://docs.python.org/2/library/functions.html#staticmethod" rel="nofollow"><code>stat... | 1 | 2016-09-12T01:19:30Z | [
"python",
"python-2.7"
] |
Update dictionary keys to be in ascending order? | 39,442,207 | <p>I have a dictionary:</p>
<pre><code>A = {'cat': {0: {'variable_1': 'xxx', 'variable_2': 'yyy'},
1: {'variable_1': 'ttt', 'variable_2': 'kkk'}},
'dog': {0: {'variable_1': 'xxx', 'variable_2': 'ppp'},
1: {'variable_1': 'qqq', 'variable_2': 'www'}},
'fox': {0: {'variable_1': 'xxx', ... | 2 | 2016-09-12T01:13:47Z | 39,442,531 | <p>As martineau mentioned, If you want to keep a data set sorted, you'll want to use a collection/data type that preserves order. For a record like this, you can use tuples or namedtuples. These will allow you to keep data sorted, and having them in a list allows them compatibility with built in functions that allow to... | 0 | 2016-09-12T02:11:26Z | [
"python",
"dictionary",
"key",
"value",
"auto-update"
] |
Update dictionary keys to be in ascending order? | 39,442,207 | <p>I have a dictionary:</p>
<pre><code>A = {'cat': {0: {'variable_1': 'xxx', 'variable_2': 'yyy'},
1: {'variable_1': 'ttt', 'variable_2': 'kkk'}},
'dog': {0: {'variable_1': 'xxx', 'variable_2': 'ppp'},
1: {'variable_1': 'qqq', 'variable_2': 'www'}},
'fox': {0: {'variable_1': 'xxx', ... | 2 | 2016-09-12T01:13:47Z | 39,442,646 | <p>Regular dictionaries are unordered, so you will need to use <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" rel="nofollow"><em>OrderedDict</em></a>.</p>
<p>A global <em>counter</em> variable can keep track of the total number of entries.</p>
<p>The <a href="https://docs.python.... | 1 | 2016-09-12T02:30:26Z | [
"python",
"dictionary",
"key",
"value",
"auto-update"
] |
Update dictionary keys to be in ascending order? | 39,442,207 | <p>I have a dictionary:</p>
<pre><code>A = {'cat': {0: {'variable_1': 'xxx', 'variable_2': 'yyy'},
1: {'variable_1': 'ttt', 'variable_2': 'kkk'}},
'dog': {0: {'variable_1': 'xxx', 'variable_2': 'ppp'},
1: {'variable_1': 'qqq', 'variable_2': 'www'}},
'fox': {0: {'variable_1': 'xxx', ... | 2 | 2016-09-12T01:13:47Z | 39,442,813 | <p>if u don't need to keep the orderï¼u can copy the dict to other dict. A global variable can keep the second level key.</p>
<pre><code># coding=utf-8
A={'cat':{0:{'variable_1':'xxx','variable_2':'yyy'},1:{'variable_1':'ttt','variable_2':'kkk'}},
'dog':{0:{'variable_1':'xxx','variable_2':'ppp'},1:{'variable_1':... | 0 | 2016-09-12T03:00:39Z | [
"python",
"dictionary",
"key",
"value",
"auto-update"
] |
Why won't functions run in parallel? | 39,442,239 | <p>I've been reading up and trying to implement multithreading into my program, but no matter how I do it, it will not run my functions in parallel. I'm using sensors for a raspberry pi 3, trying to have them print out statuses in parallel rather than wait for one to finish and then move to the next function.</p>
<p>W... | 2 | 2016-09-12T01:19:02Z | 39,442,494 | <p>I don't know why your example isn't working, but I tried this:</p>
<pre><code> import time
from threading import Thread
''' Define pins and setup the sensors '''
status = 0
def runInParallel(*fns):
proc = []
for fn in fns:
p = Thread(target=fn)
proc.appen... | 1 | 2016-09-12T02:05:32Z | [
"python",
"linux",
"raspberry-pi",
"gpio"
] |
issue with nested try else statement | 39,442,247 | <p>I am a beginner programmer and am writing a program that converts letter grades to GPA, or GPA to letter grades as entered by the user. I reference two functions to do the conversions in other programs. I am using the try statement to start by assuming it is a letter grade to convert to GPA, and that doesn't work i ... | 0 | 2016-09-12T01:21:50Z | 39,442,277 | <p>You can use an else statement with try catch. However, checkout how the docs recommends using try catch else. Catch should take an error. You should figure out what kind of error you want to catch. </p>
<p><a href="https://docs.python.org/3/tutorial/errors.html" rel="nofollow">https://docs.python.org/3/tutorial/err... | 0 | 2016-09-12T01:28:28Z | [
"python"
] |
issue with nested try else statement | 39,442,247 | <p>I am a beginner programmer and am writing a program that converts letter grades to GPA, or GPA to letter grades as entered by the user. I reference two functions to do the conversions in other programs. I am using the try statement to start by assuming it is a letter grade to convert to GPA, and that doesn't work i ... | 0 | 2016-09-12T01:21:50Z | 39,442,361 | <p>Your inner <code>try-except</code> will swallow any exceptions, which means that even if <code>gpa_converter</code> raises an exception, the outermost <code>try</code> suite will still be 'successful' and thus the <code>else</code> clause will execute. </p>
<p>There are several ways to fix this, but the way that in... | 0 | 2016-09-12T01:39:52Z | [
"python"
] |
issue with nested try else statement | 39,442,247 | <p>I am a beginner programmer and am writing a program that converts letter grades to GPA, or GPA to letter grades as entered by the user. I reference two functions to do the conversions in other programs. I am using the try statement to start by assuming it is a letter grade to convert to GPA, and that doesn't work i ... | 0 | 2016-09-12T01:21:50Z | 39,442,444 | <p>If you're trying to catch exceptions raised by functions on invalid inputs, probably you would like to rewrite the code to something like this:</p>
<pre><code>while grade != '':
try:
grade = grade.upper()
conversion = letter_converter(grade)
except:
try:
conversion = gpa_... | 0 | 2016-09-12T01:57:40Z | [
"python"
] |
What is wrong with the following quadratic equation code? | 39,442,260 | <p>I am trying to make a program that converts standard form quadratic equations to factored form using the quadratic formula, but I'm getting an error on the part where I begin to do math. It seems like it has a problem with the floats I am using, but I do not know why, nor do I know how to fix it.</p>
<p>This is the... | 1 | 2016-09-12T01:26:06Z | 39,442,284 | <p>The <code>^</code> operator probably doesn't do what you expect. It's a binary XOR, or e<strong>X</strong>clusive <strong>OR</strong> operator. The XOR operator doesn't work with floating point numbers, thus producing the error. The error basically says it can't do the operation on two floats. With exponents, use a ... | 2 | 2016-09-12T01:29:34Z | [
"python",
"variables",
"math",
"floating-point",
"quadratic"
] |
How do I stop Appium/Python script hanging when connecting to app? | 39,442,270 | <p>I have an Appium script (written in Python) which freezes when connecting the web driver.</p>
<p>It is at the following line of code:</p>
<pre><code>self.driver = webdriver.Remote(self.webdriver_url,
desired_capabilities=self.desired_capabilities)
</code></pre>
<p>I am using the following url:
<a href... | 1 | 2016-09-12T01:27:26Z | 39,443,224 | <p>I think you should deal with it , not Appium.You should design the test cases run independently,i mean test case 002 should not depend on test case 001.You will need clean installation for each testcase.</p>
<p>Eg: u want to test order test case (005),you should repeat the actions from test case login (001).It will... | 0 | 2016-09-12T04:06:41Z | [
"python",
"ios",
"appium"
] |
Django, Querysets. How to perform search on 400mb sql query set faster? | 39,442,274 | <p>I Have a problem. I'm working with a 400mb postgres database. I have to perform searches with a lot of different filters. It takes me around a minute to load the page. </p>
<p>example from views.py, the task is to search all the possible combinations of word's letters. Like cat > act > atc etc. :</p>
<pre><code>de... | 0 | 2016-09-12T01:28:01Z | 39,443,260 | <p>There few things you are not doing optimally.</p>
<p><strong>First:</strong> don't join strings like this</p>
<pre><code>for letters in comb:
result += letters
</code></pre>
<p>do this</p>
<pre><code>result = ''.join(comb)
</code></pre>
<p><strong>Second:</strong> you should always try to do as less db queri... | 1 | 2016-09-12T04:12:20Z | [
"python",
"django",
"postgresql"
] |
How to rewrite the following zip code in nested for and if loops? | 39,442,294 | <p>List l has the following elements</p>
<pre><code>l = ['AGCTT 6 6 35 25 10', 'AGGGT 7 7 28 29 2']
</code></pre>
<p>List l was split into pairs using tuples, such that every alphabet corresponded as A:6, G:6, C:35 ..etc
If a value for less than 10, then the alphabets were converted to Z.
The following is the code:</... | 2 | 2016-09-12T01:31:02Z | 39,442,548 | <p>To reverse engineer the code, usually working on the python console is the best way to proceed. So, I would start taking the different statements apart one by one and see what each does. Now, there will probably be many different ways to explain/rewrite that code, so mine will be one that hopefully will help you und... | 1 | 2016-09-12T02:14:13Z | [
"python",
"if-statement",
"for-loop"
] |
Select option from javascript span with python and selenium | 39,442,316 | <p>I'm trying to generate a bot to automatically make orders from walmart, but it seems like I just can't get selected the color and the quantity, since they are not really selectors and they have no id.
I'm working with python and selenium.</p>
<p>The item using for tests right now is this one:
<a href="https://www.w... | -2 | 2016-09-12T01:33:34Z | 39,442,449 | <p>As far as <code>quantity</code> goes, you can operate <em>the actual <code>select</code> element</em> (via the <a href="http://selenium-python.readthedocs.io/api.html#selenium.webdriver.support.select.Select" rel="nofollow"><code>Select</code> class</a>) which is not visually detected, but is actually visible. As fo... | 0 | 2016-09-12T01:58:51Z | [
"python",
"selenium"
] |
Training a neural network with two groups of spacial coordinates per observation? | 39,442,327 | <p>I'm trying to predict an output (regression) where multiple groups have spacial (x,y) coordinates. I've been using scikit-learn's neural network packages (MLPClassifier and MLPRegressor), which I know can be trained with spacial data by inputting a 1-D array per observation (ex. the MNIST dataset). </p>
<p>I'm tryi... | 0 | 2016-09-12T01:34:52Z | 39,446,832 | <p>If I got this right, you are basically trying to implement classification variables into your input, and this is basically done by adding an input variable for each possible class (in your case "group 1" and "group 2") that holds binary values (1 if the sample belongs to the group, 0 if it doesn't). Wheather or not ... | 0 | 2016-09-12T09:09:17Z | [
"python",
"machine-learning",
"scikit-learn",
"neural-network",
"regression"
] |
WIN32COM saving/exporting multiple sheets as PDF | 39,442,476 | <p>I'd like to select multiple sheets (in a certain order) in a workbook and export them as a single PDF using win32com. I tried:</p>
<pre><code>wb_HC.Sheets(['sheetname1','sheetname2']).ExportAsFixedFormat(0, workdir+'\\'+run_date+'_MD_Summary.pdf')
</code></pre>
<p>But this does not work. I know that in VBA sheets ... | 0 | 2016-09-12T02:02:45Z | 39,442,728 | <p>Consider using Python's list <code>[]</code> method which could correspond to VBA's <code>Array()</code>. Apply it to the <code>Worksheets()</code> method passing either Sheet index number or Sheet name. Then in the <code>ExportAsFixedFormat</code> qualify the method with <code>xlApp.ActiveSheet</code>:</p>
<pre><c... | 0 | 2016-09-12T02:46:05Z | [
"python",
"excel",
"win32com"
] |
logging - rewrite if size gets too big? | 39,442,558 | <p>I have a daemon and it logs its operations:</p>
<pre><code>LOG_FILE = '%s/%s.log' % (LOG_DIR, machine_name)
logging.basicConfig(filename=LOG_FILE,
level=logging.DEBUG,
format='%(asctime)s,%(msecs)05.1f '
'(%(funcName)s) %(message)s',
... | 3 | 2016-09-12T02:15:40Z | 39,442,697 | <p>You could use <a href="https://docs.python.org/3.5/library/logging.handlers.html#logging.handlers.RotatingFileHandler" rel="nofollow"><code>RotatingFileHandler</code></a> to do the log rotation for you. There's an example in <a href="https://docs.python.org/3.5/library/logging.handlers.html#logging.handlers.Rotating... | 3 | 2016-09-12T02:38:06Z | [
"python",
"logging"
] |
Error while installing OpenCV for Python 2.7 on OSX Yosemite - error: no matching function | 39,442,642 | <p>I was using this guide for installing OpenCV on my Mac: <a href="http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/" rel="nofollow">http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/</a></p>
<p>Everything worked until the last step:</p>
<pre><code>make ... | 0 | 2016-09-12T02:29:59Z | 40,022,348 | <p>If you're using <a href="http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/" rel="nofollow">this guide</a>, make sure you remember to clone both opencv and opencv-contrib in your home folder rather than nesting them. It's easy to miss the instruction where it tells you to go back to <c... | 1 | 2016-10-13T13:27:11Z | [
"python",
"osx",
"python-2.7",
"opencv",
"install"
] |
Calculate all possible combinations from differnt array in Python | 39,442,702 | <p>I have some group data like below a, b, c and so on. What I want to do is to calculate all possible combinations from the data. It's ok if the count of input data is always same. But in my case, I want to assume that the count of input data is from 0 to N, I mean a, b, c, d, e ...</p>
<p>I think I have to use recur... | 1 | 2016-09-12T02:39:05Z | 39,442,783 | <p>If I am understanding what you're looking for, you can use <a href="https://docs.python.org/2.7/library/itertools.html#itertools.product" rel="nofollow"><em>itertools.product()</em></a> over the <a href="https://en.wikipedia.org/wiki/Power_set" rel="nofollow">powersets</a> of the inputs (there is a recipe for <a hre... | 5 | 2016-09-12T02:54:53Z | [
"python",
"combinations"
] |
Running Python Script with lynx command in Terminal | 39,442,746 | <p>I just installed emacs and python on my Mac and I'm trying to learn how to run my Python Scripts through my terminal and I'm getting an error message
"sh: lynx: command not found". From what I have researched it sounds like i need to install lynx on my mac but I do not know how to get it installed so if that is the... | 0 | 2016-09-12T02:49:05Z | 39,442,772 | <p>You should already have Python on your mac. My Macbook Air came with python 2.x on El Capitan OSX. When you open up the Terminal and type in "python" without any quotations does the python interpreter come up? From the look of your image, there is something wrong inside the file you are trying to run with python. </... | 0 | 2016-09-12T02:52:47Z | [
"python",
"emacs",
"terminal",
"lynx"
] |
Running Python Script with lynx command in Terminal | 39,442,746 | <p>I just installed emacs and python on my Mac and I'm trying to learn how to run my Python Scripts through my terminal and I'm getting an error message
"sh: lynx: command not found". From what I have researched it sounds like i need to install lynx on my mac but I do not know how to get it installed so if that is the... | 0 | 2016-09-12T02:49:05Z | 39,443,191 | <p>You might see the above error if Lynx package is not installed on your server. Follow the below steps to install lynx on your Linux Server</p>
<p>Login to your Linux Server via SSH as root. Run <code>yum install lynx</code> to install lynx package</p>
| 0 | 2016-09-12T04:01:27Z | [
"python",
"emacs",
"terminal",
"lynx"
] |
How to block a number from texting me in python via Twilio | 39,442,833 | <p>I've been trying to find a way to block numbers that have texted my Twilio once, so that I don't get charged after the first time because they will be blocked. I've checked around and seen that rejecting calls is possible, but I have yet to find anything that 'rejects' incoming sms's.</p>
| 0 | 2016-09-12T03:04:46Z | 39,443,759 | <p>According to the <a href="https://support.twilio.com/hc/en-us/articles/223181648-Is-there-a-way-to-block-incoming-SMS-on-my-Twilio-phone-number-" rel="nofollow">Twilio documentation</a> it is not possible to block SMS to a Twilio number selectively. </p>
<p>You are only able to toggle on/off SMS for an entire accou... | 1 | 2016-09-12T05:19:57Z | [
"python",
"python-2.7",
"twilio",
"twilio-api"
] |
Can a process update a shared queue while threads consume the queue? | 39,442,945 | <p>I'm trying to create a multithreaded hash cracker/bruteforcer in Python and I'm encountering an issue when having a thread generate all possible word combinations and put them on a queue while having 10 other threads hash the queue. The issue is that the 10 hashing threads hog execution time from the 1 thread genera... | 0 | 2016-09-12T03:24:59Z | 39,464,290 | <p>The <a href="https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Queue" rel="nofollow">multiprocessing.Queue</a> object is process and thread safe.</p>
<p>I'd let the main loop of your solution populate the Queue while multiple processes hash its content.</p>
<p>As you work seems to be CPU bound... | 0 | 2016-09-13T07:21:12Z | [
"python",
"multithreading",
"concurrency",
"multiprocessing"
] |
Scipy sparse matrix as DataFrame column | 39,442,979 | <p>I'm developing tooling based on pandas DataFrame objects. I would like to keep scipy sparse matrices around as column of a DataFrame without converting it row-wise to a list / numpy array of dtype('O').</p>
<p>The snippet below doesn't work as pandas treats the matrix as a scalar, and suggests to add an index. When... | 1 | 2016-09-12T03:30:48Z | 39,443,506 | <p>There is a sparse dataframe or dataseries feature. It is still experimental. I've answered a few SO questions about converting back and forth between that and <code>scipy</code> sparse matrices.</p>
<p>From the sidebar:</p>
<p><a href="http://stackoverflow.com/questions/34181494/populate-a-pandas-sparsedataframe... | 0 | 2016-09-12T04:49:59Z | [
"python",
"pandas",
"dataframe",
"scipy",
"sparse-matrix"
] |
Need Haar Casscade xml for open mouth | 39,442,984 | <p>I need to detect an open mouth using Opencv Haar cascade. </p>
<p>I find Haar Casscade for mouth, but it detects mouth in general. I need to distinguish between a close mouth and an open mouth. </p>
| 0 | 2016-09-12T03:31:13Z | 39,457,236 | <p>I have a few steps to build my own haar cascade classifier quickly:</p>
<ol>
<li>I always think about sources for my training samples </li>
</ol>
<p>Try to extract positive samples showing different open mouths from free sources like <a href="https://www.flickr.com/search/?text=open%20mouth%20smile" rel="nofollow"... | 1 | 2016-09-12T19:16:53Z | [
"python",
"opencv",
"detection",
"haar-classifier"
] |
create polymial in powers of (x-1) from given coefficients in python | 39,443,005 | <p>I have the following coefficient matrix.</p>
<pre><code>import numpy as np
coeffMatrix = np.array([[ 1. , 1.46599761, 0. , 0.25228421],
[ 2.71828183, 2.22285026, 0.75685264, 1.69107137],
[ 7.3890561 , 8.80976965, 5.83006675, -1.94335558],
[ 20.08553692, 0. , 0. ... | 1 | 2016-09-12T03:33:43Z | 39,465,758 | <p>Use <code>variable</code> parameter. I used <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.poly1d.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.poly1d.html</a></p>
<p>(I prefer to look on <code>np.array</code> as matrix and not as list of arrays)</p>
<pre><code>... | 1 | 2016-09-13T08:45:06Z | [
"python",
"numpy",
"scipy",
"polynomials"
] |
Python TypeError: not enough arguments for format string in case of string %s | 39,443,037 | <pre><code>wrapper = """<html>
<head>
</head>
<body>
<table style="height: 100px;" width="500">
<tbody>
<tr>
<td rowspan="3"><a id="imgrec1" href="http://www.w3.org"><img src="%s" alt="Smiley face" width="50" height="100" /><br /><br /></a>&l... | 3 | 2016-09-12T03:39:56Z | 39,443,372 | <p>I suppose you get an error because you pass a string as a single argument when formatting a string.
You can create a list initially:</p>
<pre><code>str = []
for i in reclist[:2]:
str += [I[i], T[i] etc.]
</code></pre>
<p>and then use:</p>
<pre><code>whole = wrapper % tuple(str)
</code></pre>
<p>so that every... | 0 | 2016-09-12T04:28:59Z | [
"python",
"html",
"string",
"typeerror"
] |
3 level dictionary to dataframe in Python | 39,443,135 | <p>I have a 3 level dictionary, which I need to convert to a dataframe in Python.
I am fairly new to python and tried to run a loop in loop to write the file in a dataframe but doesn't give me the required output.</p>
<p>The current dictionary format:
<a href="http://i.stack.imgur.com/UZmbj.png" rel="nofollow">enter ... | -2 | 2016-09-12T03:53:51Z | 39,445,705 | <pre><code>def order_from_chaos(data):
result = []
ids = [id_ for id_ in data]
id_content = [data[id_][0] for id_ in data]
links_in_id_content = [dictionary.keys() for dictionary in id_content]
for i in range(len(ids)):
id_ = ids[i]
links = links_in_id_content[i]
description... | 0 | 2016-09-12T07:56:15Z | [
"python",
"json",
"pandas",
"dictionary"
] |
can't get <p>'s text when useing python scrapy a website | 39,443,136 | <p>Here is the website's source html code:</p>
<pre><code> <p class="fc-gray">
hello
<span class="">2010-10</span>
<em class="shuxian">|</em>
4.2
</p>
</code></pre>
<p>I want to get the value 4.2.
The following is m... | 0 | 2016-09-12T03:53:58Z | 39,444,197 | <p>I don't know xpath very much. but regular expression may help you</p>
<p>this is not so elegant, but will work for you</p>
<pre><code>>>> import re
>>> html = """
<p class="fc-gray">
hello
<span class="">2010-10</span>
<em class="shuxian">|</em>
... | 0 | 2016-09-12T06:04:57Z | [
"python",
"scrapy"
] |
can't get <p>'s text when useing python scrapy a website | 39,443,136 | <p>Here is the website's source html code:</p>
<pre><code> <p class="fc-gray">
hello
<span class="">2010-10</span>
<em class="shuxian">|</em>
4.2
</p>
</code></pre>
<p>I want to get the value 4.2.
The following is m... | 0 | 2016-09-12T03:53:58Z | 39,445,677 | <p>You are after the last text child of the <code><P></code> element, so you can add a <code>[last()]</code> predicate to your XPath expression:</p>
<pre><code>>>> import scrapy
>>> s = scrapy.Selector(text=""" <p class="fc-gray">
... hello
... <span class="">... | 0 | 2016-09-12T07:54:25Z | [
"python",
"scrapy"
] |
How to read this file on Python 3.4.4? | 39,443,156 | <pre><code>readme = open (r'c:\users\user\desktop\br.txt','r',encoding = 'utf-8')
print (readme.read)
</code></pre>
<p>I have been trying to open a file, but this script isn't working, it says </p>
<blockquote>
<p>built-in method read of _io.TextIOWrapper object at 0x00000000036A83A8</p>
</blockquote>
| -4 | 2016-09-12T03:56:55Z | 39,443,237 | <p>you want to call <code>readme.read()</code> method to read file.</p>
<pre><code>readme = open (r'c:\users\user\desktop\br.txt','r',encoding = 'utf-8')
readme.read()
</code></pre>
<p>if you want to read file line by line you can use.</p>
<pre><code>readme.readlines()
</code></pre>
| 2 | 2016-09-12T04:08:33Z | [
"python"
] |
python I want to set_index dateFrame with datetime | 39,443,206 | <pre><code>poorList = [datetime.date(2016, 5, 2),
datetime.date(2016, 8, 26),
datetime.date(2016, 6, 9),
datetime.date(2016, 3, 4)]
dateForm.set_index(poorList)
</code></pre>
<p>then it was Errorï¼</p>
<blockquote>
<p>File "pandas\index.pyx", line 137, in pandas.index.IndexE... | 3 | 2016-09-12T04:04:04Z | 39,443,311 | <p>DataFrame.set_index() expects a column name or list of columns as an argument, so you should do:</p>
<pre><code>dateForm['date'] = poorList
dateForm.set_index('date', inplace=True)
</code></pre>
| 2 | 2016-09-12T04:20:00Z | [
"python",
"list",
"date",
"pandas",
"datetimeindex"
] |
python I want to set_index dateFrame with datetime | 39,443,206 | <pre><code>poorList = [datetime.date(2016, 5, 2),
datetime.date(2016, 8, 26),
datetime.date(2016, 6, 9),
datetime.date(2016, 3, 4)]
dateForm.set_index(poorList)
</code></pre>
<p>then it was Errorï¼</p>
<blockquote>
<p>File "pandas\index.pyx", line 137, in pandas.index.IndexE... | 3 | 2016-09-12T04:04:04Z | 39,444,208 | <p>To generate an index with time stamps, you can use either the <code>DatetimeIndex</code> or Index constructor and pass in a list of datetime objects:</p>
<pre><code>dateForm.set_index(pd.DatetimeIndex(poorList), inplace=True) # Even pd.Index() works
</code></pre>
<p>Another way of doing would be to convert the li... | 1 | 2016-09-12T06:06:21Z | [
"python",
"list",
"date",
"pandas",
"datetimeindex"
] |
python I want to set_index dateFrame with datetime | 39,443,206 | <pre><code>poorList = [datetime.date(2016, 5, 2),
datetime.date(2016, 8, 26),
datetime.date(2016, 6, 9),
datetime.date(2016, 3, 4)]
dateForm.set_index(poorList)
</code></pre>
<p>then it was Errorï¼</p>
<blockquote>
<p>File "pandas\index.pyx", line 137, in pandas.index.IndexE... | 3 | 2016-09-12T04:04:04Z | 39,444,255 | <p>Another solutions is assign list converted <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>to_datetime</code></a> or <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.html" rel="nofollow"><code>DatetimeIndex</code></a>:</p... | 1 | 2016-09-12T06:12:03Z | [
"python",
"list",
"date",
"pandas",
"datetimeindex"
] |
pip ssl certificate error OSX installing scrapy | 39,443,240 | <p>Getting an error from pip when installing scrapy on OS X El Capitan</p>
<pre><code> ~ pip install scrapy
Requirement already satisfied (use --upgrade to upgrade): scrapy in /usr/local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/lib/python2.7/s... | 0 | 2016-09-12T04:08:52Z | 39,500,160 | <p>The entire environment was broken.</p>
<p>I deleted the following folders out of ~/usr/lib/</p>
<ul>
<li>python2.7</li>
<li>python3.4</li>
<li>python3.5</li>
</ul>
<p>Then did the following</p>
<pre><code>brew uninstall python
brew update
brew upgrade
brew doctor
brew cleanup
brew install python
pip install scra... | 0 | 2016-09-14T21:48:38Z | [
"python",
"osx",
"ssl",
"https",
"pip"
] |
How can I populate a txt with results from a mechanized results? | 39,443,370 | <p>I am trying to populate a txt file with the response I get from a mechanized form. Here's the form code</p>
<pre><code>import mechanize
from bs4 import BeautifulSoup
br = mechanize.Browser()
br.open ('https://www.cpsbc.ca/physician_search')
first = raw_input('Enter first name: ')
last = raw_input('Enter last name:... | 0 | 2016-09-12T04:28:54Z | 39,443,648 | <p>This should not be too complicated. Assuming your file with all the names you want to query upon is called "names.txt" and the output file you want to create is called "output.txt", the code should look something like:</p>
<pre><code>with open('output.txt', 'w') as file_out:
with open('names.txt', 'r') as file_... | 0 | 2016-09-12T05:07:27Z | [
"python",
"mechanize"
] |
Top 7 most common tags Taggit | 39,443,376 | <pre><code>def most_common(self):
return self.get_queryset().annotate(
num_times=models.Count(self.through.tag_relname())
).order_by('-num_times')
</code></pre>
<p>How would I edit this to only view the top 7 tags. This is a function from taggit and I would only like to see only 7. thanks. </p>
| 0 | 2016-09-12T04:30:11Z | 39,444,097 | <p>How about most_common()[:7]? docs.djangoproject.com/en/1.10/topics/db/queries/⦠â ozgur</p>
<p>This is the correct asnwer, thanks ozgur</p>
| 0 | 2016-09-12T05:54:59Z | [
"python",
"django",
"django-views"
] |
How to fix encoding issue when writing to csv file | 39,443,394 | <p>i have some encoding issuse when writing to csv file</p>
<p>how can i fix it</p>
<pre><code>import csv
a = [s.encode('utf-8') for s in a]
f3 = open('test.csv', 'at')
writer = csv.writer(f3,delimiter = ',', lineterminator='\n',quoting=csv.QUOTE_ALL)
writer.writerow(a)
</code></pre>
<p>Error </p>
<pre><code>Trac... | 0 | 2016-09-12T04:32:03Z | 39,443,463 | <p>I ran your code and it works without throwing any errors. Only thing is that your csv file contains byte encoded values. Values with a b' at the front. Is this what you were trying to accomplish? I am using python 3.5.2 .</p>
<p>In the event you do not want byte encoded data just remove the </p>
<pre><code>a = [s.... | 0 | 2016-09-12T04:42:07Z | [
"python",
"csv",
"encoding"
] |
How to fix encoding issue when writing to csv file | 39,443,394 | <p>i have some encoding issuse when writing to csv file</p>
<p>how can i fix it</p>
<pre><code>import csv
a = [s.encode('utf-8') for s in a]
f3 = open('test.csv', 'at')
writer = csv.writer(f3,delimiter = ',', lineterminator='\n',quoting=csv.QUOTE_ALL)
writer.writerow(a)
</code></pre>
<p>Error </p>
<pre><code>Trac... | 0 | 2016-09-12T04:32:03Z | 39,443,467 | <pre><code># encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
</code></pre>
| 0 | 2016-09-12T04:42:21Z | [
"python",
"csv",
"encoding"
] |
TypeError: 'bool' object is not iterable, when reading a text file | 39,443,473 | <p>I'm busy with a Uni project where I need to read text files and ten populate a table with their information. It was working fine last week when I first coded it. Now however, when I try to run it, I get the TypeError: bool, it occurs in my for loop, when I read_ln from the text file, the code is :</p>
<pre><code>fr... | -1 | 2016-09-12T04:43:06Z | 39,443,564 | <p>Your statements <code>from webbrowser import *</code> at the top of your module imports the <code>webbrowser.open</code> function (which opens a new browser window), shadowing the builtin <code>open</code> function (that opens files) which you were intending to call in your later code. <code>webbrowser.open</code> r... | 0 | 2016-09-12T04:56:25Z | [
"python",
"boolean",
"text-files",
"typeerror"
] |
How to call a function correctly | 39,443,478 | <p>Here is the function which has four parameters. </p>
<pre><code>import urllib
import xlrd
from xlwt import Workbook
def getClose(q, i ,p, f):
inputQ=q;
inputI=str(i);
inputP=str(p);
inputF=f;
address='http://www.google.com/finance/getprices?q='+inputQ+'&i='+inputI+'&p='+inputP+'d&f... | -2 | 2016-09-12T04:43:35Z | 39,443,584 | <p>Doing too many things in a single function is not advisable. Looking at the function, there are three main operations:</p>
<ol>
<li>from a spreadsheet (test1.xlsx) get a query parameter (q) retrieve</li>
<li>and parse values from a webpage save the parsed results in a</li>
<li>spreadsheet (close price.xls)</li>
</... | 0 | 2016-09-12T04:58:30Z | [
"python",
"python-3.x"
] |
Syntax error: unexpected EOF while parsing. Am I inputting incorrectly? | 39,443,524 | <p>While trying to solve <a href="http://www.usaco.org/index.php?page=viewproblem2&cpid=94" rel="nofollow" title="this">this</a> computer olympiad problem, I ran into this error:</p>
<pre><code>Traceback (most recent call last):
File "haybales.py", line 5, in <module>
s = input()
File "<string>", l... | 0 | 2016-09-12T04:51:59Z | 39,444,580 | <p>There are a number of problems with your code:</p>
<ul>
<li><p><strong>Indentation</strong>:
In Python indentation is very important. You can't ignore it, or your code will either fail to run or give unexpected results. This may be due to the way you pasted the code into stack overflow, which I admit can sometimes... | 0 | 2016-09-12T06:39:16Z | [
"python"
] |
Syntax error: unexpected EOF while parsing. Am I inputting incorrectly? | 39,443,524 | <p>While trying to solve <a href="http://www.usaco.org/index.php?page=viewproblem2&cpid=94" rel="nofollow" title="this">this</a> computer olympiad problem, I ran into this error:</p>
<pre><code>Traceback (most recent call last):
File "haybales.py", line 5, in <module>
s = input()
File "<string>", l... | 0 | 2016-09-12T04:51:59Z | 39,445,011 | <p>In addition to the fixes suggeted by Andrew Hewitt, the error you see is caused by your use of <code>input</code> instead of <code>raw_input</code> in python2 (in python3 <code>raw_input</code> was renamed to <code>input</code> ). If you check the <a href="https://docs.python.org/2/library/functions.html#input" rel=... | 1 | 2016-09-12T07:09:00Z | [
"python"
] |
How to load this dataset into Pandas | 39,443,549 | <p><a href="http://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data" rel="nofollow">data</a></p>
<p>I tried reading the pandas.read_csv doc to see how I could use newlines to delimit each row as a separate sample. Which parameter should I use to do this?</p>
| 1 | 2016-09-12T04:54:42Z | 39,443,776 | <p>You can read it right in with <code>pd.read_csv</code>.</p>
<pre><code>df = pd.read_csv(r'http://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data', header=None)
</code></pre>
| 0 | 2016-09-12T05:21:52Z | [
"python",
"pandas"
] |
Receiving and empty list when trying to make a webscraper to parse websites for links | 39,443,570 | <p>I was reading <a href="http://docs.python-guide.org/en/latest/scenarios/scrape/" rel="nofollow">this</a> website and learning how to make a webscraper with <code>lxml</code> and `Requests. This is the webscraper code:</p>
<pre><code>from lxml import html
import requests
web_page = requests.get('http://econpy.pytho... | 1 | 2016-09-12T04:57:09Z | 39,451,123 | <p>First off, your xpath is wrong, there are no classes with <em>data-url</em>, it is an <em>attribute</em> so you would want <code>div[@data-url]</code> and to extract the attribute you would use <code>/@data-url</code>:</p>
<pre><code>from lxml import html
import requests
headers = {"User-Agent":"Mozilla/5.0 (X11;... | 2 | 2016-09-12T13:09:49Z | [
"python",
"html",
"web-scraping",
"lxml"
] |
NameError: name 'form' is not defined (Python3) | 39,443,624 | <p>Basically the <code>main</code> method takes user input, checks it and calls the <code>first</code> method if the user doesn't enter <code>quit</code>.</p>
<p>The <code>first</code> method checks the first section of the input and calls one of the other methods depending on what the user enters. This is the point I... | 0 | 2016-09-12T05:04:24Z | 39,443,789 | <p>It depends if you use python 2.7 or 3, but your code works with some minor changes.</p>
<pre><code>import sys
def reconnect(one=""):
print("Reconnect")
def ls(one=""):
print("list")
def mkfile(one=""):
print("make file")
def mkdir(one=""):
print("make drive")
def append(one="", two=""):
prin... | 0 | 2016-09-12T05:22:57Z | [
"python",
"error-handling"
] |
NameError: name 'form' is not defined (Python3) | 39,443,624 | <p>Basically the <code>main</code> method takes user input, checks it and calls the <code>first</code> method if the user doesn't enter <code>quit</code>.</p>
<p>The <code>first</code> method checks the first section of the input and calls one of the other methods depending on what the user enters. This is the point I... | 0 | 2016-09-12T05:04:24Z | 39,444,435 | <p>this error is because of </p>
<pre><code> elif word == "format":
form(a[1])
</code></pre>
<p>python basically doesn't know what form is.</p>
<p>let me show you:</p>
<pre><code>gaf@$[09:21:56]~> python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", ... | 1 | 2016-09-12T06:26:24Z | [
"python",
"error-handling"
] |
python 3 how to make .exe from .py | 39,443,717 | <p>Could someone please give me a step-by-step recipe for how, in September 2016, one makes in Windows 10 an exe from a python script? Nowhere can I find instructions on exactly what to do, although there is much written on the general subject. </p>
<p>Also, there are a number of .wav files that need to be incorpor... | 0 | 2016-09-12T05:15:25Z | 39,444,010 | <p>You can use <a href="http://www.pyinstaller.org/" rel="nofollow">PyInstaller</a>.it have a option for pack everything to a one file exe.</p>
| 0 | 2016-09-12T05:46:47Z | [
"python"
] |
list comprehension and map without lambda on long string | 39,443,809 | <pre><code>$ python -m timeit -s'tes = "987kkv45kk321"*100' 'a = [list(i) for i in tes.split("kk")]'
10000 loops, best of 3: 79.4 usec per loop
$ python -m timeit -s'tes = "987kkv45kk321"*100' 'b = list(map(list, tes.split("kk")))'
10000 loops, best of 3: 66.9 usec per loop
$ python -m timeit -s'tes = "987kkv45kk321"... | 1 | 2016-09-12T05:25:26Z | 39,451,839 | <p>This kind of timing is basically useless. </p>
<p>The time frames you are getting are in microseconds - and you are just creating tens of different one-character-long-elements list in each interaction. You get basically linear type, because the number of objects you create is proportional to your string lengths. ... | 0 | 2016-09-12T13:46:14Z | [
"python",
"python-3.x",
"built-in"
] |
list comprehension and map without lambda on long string | 39,443,809 | <pre><code>$ python -m timeit -s'tes = "987kkv45kk321"*100' 'a = [list(i) for i in tes.split("kk")]'
10000 loops, best of 3: 79.4 usec per loop
$ python -m timeit -s'tes = "987kkv45kk321"*100' 'b = list(map(list, tes.split("kk")))'
10000 loops, best of 3: 66.9 usec per loop
$ python -m timeit -s'tes = "987kkv45kk321"... | 1 | 2016-09-12T05:25:26Z | 39,461,331 | <p>The fixed setup costs for <code>map</code> are higher than the setup costs for the listcomp solution. But the per-item costs for <code>map</code> are lower. So for short inputs, <code>map</code> is paying more in fixed setup costs than it saves on the per item costs (because there are so few items). When the number ... | 0 | 2016-09-13T02:20:00Z | [
"python",
"python-3.x",
"built-in"
] |
Self attribute not working pygame | 39,443,815 | <p>I am trying to create a simple object-oriented pong game. I have a <code>Player</code> object and one method (<code>create_paddle</code>). When I create an instance of <code>Player</code> and call the <code>create_paddle</code> method it gives me the following error:</p>
<pre><code>Traceback (most recent call last)... | 0 | 2016-09-12T05:25:48Z | 39,443,831 | <p>You're missing parentheses when creating the object:</p>
<pre><code>player1 = Player()
</code></pre>
<p>Which means you're just assigning player1 to Player and trying to call your method like a static method....so self isn't getting passed for you.</p>
<pre><code>player1.create_paddle(player1, 30, 180, 15, 120)
<... | 4 | 2016-09-12T05:27:44Z | [
"python",
"python-3.x",
"oop",
"compiler-errors",
"pygame"
] |
Convert date to timestamp using lambda function while reading the file | 39,443,887 | <p>I am reading csv file which contains date in this format:</p>
<pre><code>date
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
</code></pre>
<p>I can not use date like this in string format, which I need to convert into numeric timestamp.</p>
<p>So I wrote this co... | 2 | 2016-09-12T05:33:41Z | 39,443,907 | <p>You need add parameter <code>parse_dates</code> to <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a> with column name converted to <code>datetime</code>:</p>
<pre><code>import pandas as pd
import io
temp=u"""date
01/05/2014
01/05/2014
01/0... | 1 | 2016-09-12T05:35:49Z | [
"python",
"csv",
"pandas",
"lambda",
"timestamp"
] |
Convert date to timestamp using lambda function while reading the file | 39,443,887 | <p>I am reading csv file which contains date in this format:</p>
<pre><code>date
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
01/05/2014
</code></pre>
<p>I can not use date like this in string format, which I need to convert into numeric timestamp.</p>
<p>So I wrote this co... | 2 | 2016-09-12T05:33:41Z | 39,443,968 | <p>Another short way to go about this is to use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow">to_datetime()</a>:</p>
<pre><code>In [209]: df['date']
Out[209]:
0 01/05/2014
1 01/05/2014
2 01/05/2014
3 01/05/2014
4 01/05/2014
5 01/05/2014
6 0... | 1 | 2016-09-12T05:42:24Z | [
"python",
"csv",
"pandas",
"lambda",
"timestamp"
] |
Using loop(Efficient Looping technique): To extract certain url's out of my string in Python | 39,443,911 | <p>The following lines of code gives me the source code to a specific playlist and stores all url's in a variable "newlink". I wish to write a loop that can go through this string of url's and store the ones that say '/watch?v=' into an array in Python so that array[0] would give me the first link, array[1] the second ... | 0 | 2016-09-12T05:36:08Z | 39,444,084 | <p>This code is tested with a playlist that actually created the array. </p>
<pre><code>import re
from selenium import webdriver
from bs4 import BeautifulSoup
import requests
#Asks which playlist you want downloaded
print ('Which playlist do you want to download?')
playlist = raw_input()
#Access my youtube playlists... | 0 | 2016-09-12T05:53:44Z | [
"python"
] |
I am trying to delete a node from chef server using PyChef but i am getting a error given below | 39,444,153 | <p>I am trying to delete a node on chef server using PyChef but getting an error given below. And here is my script:</p>
<pre><code>import json
import requests
import chef
import base64
from chef import Node
from chef import auth
from chef.rsa import Key
from chef.api import ChefAPI
from chef import api
import request... | 0 | 2016-09-12T06:01:16Z | 39,445,444 | <p>PyChef already does all the authentication headers for you, why are you duplicating things? For the specific question, a 404 means the node you are trying to delete doesn't exist. You can see what nodes exist on the server with <code>Node.list()</code>.</p>
| 0 | 2016-09-12T07:39:15Z | [
"python",
"chef",
"pychef"
] |
python create nested directory based on two lists | 39,444,360 | <p>Good morning,</p>
<p>This might be easy but I´m just starting with python. For learning:
Is there are 'cleaner' way creating a nested dict based on two lists than this:</p>
<pre><code>person = ['mama.a','mama.b', 'mama.c',
'mama.d', 'papa.a', 'papa.b']
kind = ['a', 'b', 'c', 'd']
combined = {}
# GOAL:
#... | 2 | 2016-09-12T06:19:55Z | 39,444,446 | <pre><code>{p.split('.')[0]: {k: [] for k in kind} for p in person}
</code></pre>
| 3 | 2016-09-12T06:27:04Z | [
"python",
"list"
] |
python create nested directory based on two lists | 39,444,360 | <p>Good morning,</p>
<p>This might be easy but I´m just starting with python. For learning:
Is there are 'cleaner' way creating a nested dict based on two lists than this:</p>
<pre><code>person = ['mama.a','mama.b', 'mama.c',
'mama.d', 'papa.a', 'papa.b']
kind = ['a', 'b', 'c', 'd']
combined = {}
# GOAL:
#... | 2 | 2016-09-12T06:19:55Z | 39,444,485 | <p>What about making a <code>set</code> of the names. To ensure you only try to add each one to <code>dict</code> once.</p>
<pre><code>combined = {}
for n in set(p.split('.')[0] for p in person):
combined[n] = {k:[] for k in kind}
</code></pre>
<p>This could probably be made into a monster one-liner nested <code>... | 0 | 2016-09-12T06:30:38Z | [
"python",
"list"
] |
python create nested directory based on two lists | 39,444,360 | <p>Good morning,</p>
<p>This might be easy but I´m just starting with python. For learning:
Is there are 'cleaner' way creating a nested dict based on two lists than this:</p>
<pre><code>person = ['mama.a','mama.b', 'mama.c',
'mama.d', 'papa.a', 'papa.b']
kind = ['a', 'b', 'c', 'd']
combined = {}
# GOAL:
#... | 2 | 2016-09-12T06:19:55Z | 39,444,619 | <pre><code>combined = {x.split('.')[0]:{i:[] for i in kind} for x in person} #if you require no check as to whether mama or papa contain a, b, c, or d
print combined
neutral = {i.split('.')[0]:[n.split('.')[1] for n in person if n.split('.')[0] == i.split('.')[0]] for i in person} #if you require a check
combined = {k... | 0 | 2016-09-12T06:41:59Z | [
"python",
"list"
] |
How to make Table sort of thing which is in line? | 39,444,472 | <p>I want to find out the way to keep my table all proper and lined up but when the size of the variable changes, the borders change aswell. Take a look at my code.I need a solution to keep my table straight.</p>
<pre><code>generation = int(input('how many generations do you need?'))
population_calf = int(input('how m... | 2 | 2016-09-12T06:29:53Z | 39,444,774 | <p>You can use <a href="https://pypi.python.org/pypi/terminaltables" rel="nofollow">terminaltables</a> or <a href="https://pypi.python.org/pypi/texttable/0.8.4" rel="nofollow">texttable</a>.</p>
| 0 | 2016-09-12T06:52:48Z | [
"python",
"python-3.x"
] |
How to make Table sort of thing which is in line? | 39,444,472 | <p>I want to find out the way to keep my table all proper and lined up but when the size of the variable changes, the borders change aswell. Take a look at my code.I need a solution to keep my table straight.</p>
<pre><code>generation = int(input('how many generations do you need?'))
population_calf = int(input('how m... | 2 | 2016-09-12T06:29:53Z | 39,444,979 | <p>You can use formatting in <code>print()</code>:</p>
<pre><code>fmt = '%-15s || %15s | %15s | %18s ||'
print(fmt % ('', 'POPULATION calf', 'POPULATION cows', 'POPULATION old_cow'))
for i in range(generation):
print(fmt % ('GENERATION %d'%i, int(population_calf), int(population_cows), int(population_old_cow)), en... | 0 | 2016-09-12T07:06:48Z | [
"python",
"python-3.x"
] |
how to use my drive api downloaded file as an attachment on my app engine application | 39,444,477 | <p>I used the drive api to download a pdf file, and I want to use that file as an attachment using the app engine mail api (python). I have tried the following code below, the file downloaded and the email was sent but in the email there is no attachment at all. Please help me out</p>
<pre><code>class ManageGoogleDriv... | 0 | 2016-09-12T06:30:04Z | 39,463,490 | <p>I finally figured what happened...</p>
<p>Instead of:</p>
<pre><code>attachments=[(filename, fh.read())])
</code></pre>
<p>Do this:</p>
<pre><code>attachments=[(filename, fh.getvalue())])
</code></pre>
| 0 | 2016-09-13T06:27:46Z | [
"python",
"google-app-engine",
"google-drive-sdk"
] |
Set handler for GPIO state change using python signal module | 39,444,591 | <p>I want to detect change in <code>gpio</code> input of raspberry pi and set handler using signal module of python. I am new to signal module and I can't understand how to use it. I am using this code now:</p>
<pre><code>import RPi.GPIO as GPIO
import time
from datetime import datetime
import picamera
i=0
j=0
camera... | 1 | 2016-09-12T06:39:52Z | 39,491,922 | <p>I just changed code in a different manner tough you are free to implement same using SIGNAL module.You can start new thread and poll or register call back event their, by using following code and write whatever your functional logic in it's run() method.</p>
<pre><code>import threading
import RPi.GPIO as GPIO
impor... | 0 | 2016-09-14T13:35:23Z | [
"python",
"raspberry-pi",
"interrupt",
"gpio",
"django-signals"
] |
Using PBKDF2 SHA512 data in other languages | 39,444,627 | <p>I'm using pbkdf2_sha512 as the hashing algorithm in a Flask web app.</p>
<p>I don't want to lose my user data in my database. Can I use same hashing algorithm in the future if I want to change the backend programming language to any other language (like node.js, PHP, Ruby, etc)?</p>
<p>Will the same password hashi... | 1 | 2016-09-12T06:42:16Z | 39,444,678 | <p><a href="https://en.wikipedia.org/wiki/PBKDF2" rel="nofollow">PBKDF2</a> is a <em>standard</em>; in this case configured to use SHA256 as the hashing function. You'll find implementations for the standard in most programming languages. It is not unique to Flask or Python.</p>
<p>So yes, you can calculate the hash f... | 0 | 2016-09-12T06:46:34Z | [
"python",
"postgresql",
"flask",
"pbkdf2"
] |
Add data labels to Seaborn factor plot | 39,444,665 | <p>I would like to add data labels to factor plots generated by Seaborn. Here is an example: </p>
<pre><code>import pandas as pd
from pandas import Series, DataFrame
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
titanic_df = pd.read_csv('train.csv')
sns.factorplot('Sex',d... | 0 | 2016-09-12T06:45:18Z | 39,448,291 | <p>You could do it this way:</p>
<pre><code>import math
# Set plotting style
sns.set_style('whitegrid')
# Rounding the integer to the next hundredth value plus an offset of 100
def roundup(x):
return 100 + int(math.ceil(x / 100.0)) * 100
df = pd.read_csv('train.csv')
sns.factorplot('Sex', data=df, kind='count',... | 2 | 2016-09-12T10:29:58Z | [
"python",
"matplotlib",
"seaborn"
] |
os.walk works with non-escaped backslash? | 39,444,763 | <p>Just found a bug in a bit of code I was writing that wasn't actually bugging?</p>
<pre><code>for folderName, subfolders, filenames in os.walk('C:\FOLDER'):
print('The current folder is ' + folderName)
for subfolder in subfolders:
print('SUBFOLDER OF ' + folderName + ': ' + subfolder)
for filename in filenames:
... | 0 | 2016-09-12T06:51:52Z | 39,444,782 | <p>Python ignores unrecognised escape sequences and leaves the original backslash and letter in place.</p>
<p><code>\F</code> is not a valid escape sequence, so your string contains a literal <code>\</code> backslash followed by a literal <code>F</code>:</p>
<pre><code>>>> 'C:\FOLDER'
'C:\\FOLDER'
</code></p... | 5 | 2016-09-12T06:53:26Z | [
"python",
"python-3.x"
] |
How to set the column width to be the whole QTableWidget width? | 39,444,808 | <p>I have an object of type QTableWidget. It contains only one column.
How do I set the column width to be the whole QTableWidget width?</p>
<p><img src="http://i.stack.imgur.com/7Yq3o.png" alt="Graphical representation"></p>
<p>Also: is there a way to delete the header of the column?</p>
| 0 | 2016-09-12T06:55:11Z | 39,451,105 | <p>Try to use the following (assuming your table widget is called <code>tableWidget</code>)...</p>
<pre><code>tableWidget.horizontalHeader().setStretchLastSection(True)
</code></pre>
| 0 | 2016-09-12T13:09:15Z | [
"python",
"pyqt",
"width",
"pyqt5",
"qtablewidget"
] |
Using logistic regression to predict the parameter value | 39,444,955 | <p>I have written vary basic sklearn code using logistic regression to predict the value. </p>
<p>Training data looks like - </p>
<p><a href="https://gist.github.com/anonymous/563591e0395e8d988277d3ce63d7438f" rel="nofollow">https://gist.github.com/anonymous/563591e0395e8d988277d3ce63d7438f</a></p>
<pre><code>date ... | 0 | 2016-09-12T07:05:21Z | 39,447,049 | <ol>
<li>You are using <strong><em>predict_proba()</em></strong> which gives class probabilities, instead of that you should use <strong><em>predict()</em></strong> function.</li>
<li>You are using a <strong><em>wrong model</em></strong>. The target variable in your data has <strong>continuous data</strong>, therefore ... | 3 | 2016-09-12T09:20:44Z | [
"python",
"machine-learning",
"scikit-learn",
"classification",
"logistic-regression"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.