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 |
|---|---|---|---|---|---|---|---|---|---|
Unexpected design choice in Python's ConfigParser | 37,903,723 | <p>I tried to read from and write to a config file like so:</p>
<pre><code>with open(file, 'r') as ini:
config = ConfigParser()
config.read(ini)
config['section'] = {'foo':45}
with open(file, 'w') as ini:
config.write(ini)
</code></pre>
<p>I just couldn't get it to read the already sav... | 0 | 2016-06-19T03:38:48Z | 37,903,779 | <p>From the docs there are actually two (sort of three if you count the <code>list</code> argument) ways to do it:</p>
<pre><code>import ConfigParser, os
config = ConfigParser.ConfigParser()
config.readfp(open('defaults.cfg'))
config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
</code></pre>
<p>The <code>f... | 2 | 2016-06-19T03:53:16Z | [
"python",
"python-3.x",
"io",
"config",
"built-in"
] |
Error with expected an indented block, any one know? | 37,903,745 | <pre><code>a = "aabb"
words = list(a)
new_words = []
count = 1
for i in range(0,len(words)-1):
if words[i] == words[i+1]:
count = count + 1
if i+2 == len(words):
print words[i+1],count
else:
print words[i],count
count = 1
</code></pre>
| -1 | 2016-06-19T03:45:29Z | 37,903,756 | <p>You have a file with mixed tabs and spaces and it's confusing you vs the interpreter. Replace all the tab characters in your file with spaces and then correctly indent the program.</p>
| 2 | 2016-06-19T03:48:17Z | [
"python"
] |
Changing a specific value from a list into an integer | 37,903,818 | <p>I've been trying to have a program print out a sorted list depending on the requested item. When I request the list from the CSV file I'm not sure how to set only 2 of the 4 values into an integer as when it displays in the program the numbers are treated as strings and it doesn't sort properly.</p>
<p>Eg:</p>
<p>... | 0 | 2016-06-19T04:03:07Z | 37,903,937 | <pre><code>sort = sorted(csv1, key=lambda ch: (ch[0], ch[1], int(ch[2]), int(ch[3])))
</code></pre>
<p>That will sort the last two values as integers.</p>
<p><strong>EDIT:</strong></p>
<p>Upon further reading the question, I realize <code>choice</code> is the index of the list that you want to sort on. You could do ... | 1 | 2016-06-19T04:26:59Z | [
"python",
"sorting"
] |
Selenium error - ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host | 37,903,985 | <p>I was using the selenium module but all of a sudden I get this error </p>
<pre><code>ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
</code></pre>
<p>here is my simple code that gives me the error</p>
<pre><code>from selenium import webdriver
browser = webdriv... | 0 | 2016-06-19T04:35:58Z | 37,904,139 | <p>I figured out that the new firefox 47 update was the problem and I had to downgrade it to firefox 46</p>
<p>i got the infor from here
<a href="http://stackoverflow.com/questions/21445406/selenium-webdriver-halting-with-errno-10054">Selenium Webdriver halting with [Errno 10054]</a></p>
| 0 | 2016-06-19T05:10:37Z | [
"python",
"python-3.x"
] |
how to create an gray-scale image from existing 2D array data in python | 37,904,078 | <p>I have a problem creating a grey-scale image from existing 2D array in python. </p>
<p>Supposing I have a 2D array, X at dimension 504x896 data type is unit8. How could I create a gray-scale image from this 2D array? Will OpenCV provide an function for it or do I have to include other image processing library?</p>
... | 0 | 2016-06-19T04:59:51Z | 37,921,007 | <p>This should work as expected. I have used Float32 as both arguments cv.CvtColor must have the same depth.</p>
<pre><code>import numpy as np
import cv2
nArray = np.zeros((504, 896), np.float32)
h,w = mArray.shape
cArray1 = cv2.CreateMat(h, w, cv2.CV_32FC3)
cArray2 = cv2.fromarray(nArray)
cv2.CvtColor(cArray2, cArray... | 0 | 2016-06-20T11:09:21Z | [
"python",
"opencv",
"image-processing"
] |
map(int, raw_input().split()) gets infinite input | 37,904,143 | <p>Here's the code:</p>
<pre><code>a = input()
b = map(int, raw_input().split())
maxcnt=1
for k in range(0,a):
cnt=1
j=k+1
while b[k]%b[j] == 0 or b[j]%b[k] == 0 :
cnt += 1
if maxcnt < cnt:
maxcnt = cnt
print maxcnt
</code></pre>
<p>While giving the list values, after giving the... | 0 | 2016-06-19T05:11:42Z | 37,904,184 | <p>The statement <code>b = map(int, raw_input().split())</code> is perfectly okay. The problem is that you are encountering an <strong>infinite loop</strong> in the later <code>while</code> part of your code. There should be some issue with the logic.</p>
<p>So, you are taking <code>modulo</code> of consecutive number... | 0 | 2016-06-19T05:20:59Z | [
"python",
"loops"
] |
map(int, raw_input().split()) gets infinite input | 37,904,143 | <p>Here's the code:</p>
<pre><code>a = input()
b = map(int, raw_input().split())
maxcnt=1
for k in range(0,a):
cnt=1
j=k+1
while b[k]%b[j] == 0 or b[j]%b[k] == 0 :
cnt += 1
if maxcnt < cnt:
maxcnt = cnt
print maxcnt
</code></pre>
<p>While giving the list values, after giving the... | 0 | 2016-06-19T05:11:42Z | 37,904,247 | <p>Your code shows a <code>while</code> statement which does not change it's conditions while looping:</p>
<pre><code>while (b[s] % b[j]) == 0 or
(b[j] % b[s]) == 0:
cnt += 1
</code></pre>
<p>As you can see here, <code>cnt</code> is not in the condition <code>(b[s] % b[j]) == 0 or (b[j] % b[s]) == 0</code>,... | 0 | 2016-06-19T05:33:48Z | [
"python",
"loops"
] |
Pandas - Error in if function when creating a new column in a dataframe | 37,904,176 | <p>I have a column <code>lastseason</code>type object (no NULL or NaN) in the df <code>draft</code>. I would like to create a new column <code>Age_retired</code> based on the comparison of the last 2 digits of <code>lastseason</code> to 50.</p>
<p>Here is the last season column</p>
<pre><code>0 1993-94
1 ... | 0 | 2016-06-19T05:18:43Z | 37,904,378 | <p>Yes, the if-else construct won't be evaluated element-wise. However, this is solved easily using the series <code>.map</code> method which applies a function elementwise. First you define the function, then you map it. You can simply assign the result of the mapping to <code>draft['age_retired']</code> to create the... | 2 | 2016-06-19T05:53:20Z | [
"python",
"pandas"
] |
Get Element Containing Hyphen - Eve | 37,904,178 | <p>I receive 404's when performing a get request for elements containing hyphens. I am running the python-eve API framework.</p>
<pre><code>$ curl -i http://api/words/apple
HTTP/1.0 200 OK
$ curl -i http://api/words/a-be
HTTP/1.0 404 NOT FOUND
</code></pre>
<p>Is anyone familiar with this issue? A cursory search ret... | 1 | 2016-06-19T05:18:53Z | 37,905,545 | <p>Yes, the regex does not include hyphens. Try setting <code>url</code> to something like <code>\w+(?:-\w+)+</code>.</p>
| 1 | 2016-06-19T09:00:38Z | [
"python",
"jsonschema",
"eve"
] |
Tkinter : Button in frame not visible | 37,904,180 | <p>I'm trying to implement a TicTacToe program. I am an absolute beginner in python. After viewing many tutorials and reading a few books, I have understood the basics of Python. I'm trying to get the buttons to display in a frame, but all I get is a blank window.</p>
<p><a href="http://i.stack.imgur.com/2P2jk.png" re... | 1 | 2016-06-19T05:19:34Z | 37,904,364 | <p>Okay the problem was I needed to add a variable at the end of the code. Something like b=Buttons(root). It's working now.</p>
| 0 | 2016-06-19T05:51:17Z | [
"python",
"python-2.7",
"tkinter",
"tic-tac-toe"
] |
Tkinter : Button in frame not visible | 37,904,180 | <p>I'm trying to implement a TicTacToe program. I am an absolute beginner in python. After viewing many tutorials and reading a few books, I have understood the basics of Python. I'm trying to get the buttons to display in a frame, but all I get is a blank window.</p>
<p><a href="http://i.stack.imgur.com/2P2jk.png" re... | 1 | 2016-06-19T05:19:34Z | 37,904,395 | <p>You defined your <code>Buttons</code> class but you didn't create an instance of that class, so no buttons were actually constructed. Also, you had a typo / syntax error: </p>
<pre><code>root=mainloop()
</code></pre>
<p>should be </p>
<pre><code>root.mainloop()
</code></pre>
<p>Also, you didn't define the <code>... | 2 | 2016-06-19T05:57:12Z | [
"python",
"python-2.7",
"tkinter",
"tic-tac-toe"
] |
Plot a pandas dataframe using the dataframe index for x coordinate in bokeh | 37,904,231 | <p>I want to prepare a bokeh plot that uses a <code>ColumnDataSource</code>. The <code>pandas</code> <code>DataFrame</code> that is the source of the data has one column and a <code>datetime</code> index:</p>
<p><a href="http://i.stack.imgur.com/fzeee.png" rel="nofollow"><img src="http://i.stack.imgur.com/fzeee.png" a... | 1 | 2016-06-19T05:30:51Z | 37,905,026 | <p>I usually reset the index and this makes the index a column. Similar to your ugly solution. Then plot the specified columns.</p>
<pre><code>df.reset_index(inplace = True)
</code></pre>
<p>Alternatively you could reference just the column and in matplotlib it usually uses the index by default in the way you want. N... | 2 | 2016-06-19T07:42:30Z | [
"python",
"pandas",
"plot",
"dataframe",
"bokeh"
] |
Plot a pandas dataframe using the dataframe index for x coordinate in bokeh | 37,904,231 | <p>I want to prepare a bokeh plot that uses a <code>ColumnDataSource</code>. The <code>pandas</code> <code>DataFrame</code> that is the source of the data has one column and a <code>datetime</code> index:</p>
<p><a href="http://i.stack.imgur.com/fzeee.png" rel="nofollow"><img src="http://i.stack.imgur.com/fzeee.png" a... | 1 | 2016-06-19T05:30:51Z | 38,133,417 | <p>The issue is that you have to specify which column should be the "x" column. If you don't specify the "x" value, the default behavior in bokeh.plotting is to try to find a column called "x" in your ColumnDataSource (which doesn't exist).</p>
<p>One tricky thing here is that you're using a named index ('timeseries')... | 2 | 2016-06-30T21:17:23Z | [
"python",
"pandas",
"plot",
"dataframe",
"bokeh"
] |
Python: invalid literal for int() with base 10 | 37,904,312 | <p>I'm getting an <code>invalid literal for int() with base 10</code> where it seems as if the input stream is concatenating values generated in a loop.</p>
<pre><code>def collectData():
lst = makeCases()
cases = int(input())
for i in range(cases):
size = int(input())
case = []
for ... | 0 | 2016-06-19T05:43:28Z | 37,904,471 | <p>As Tom Karzes has said, <code>input()</code> is returning something other than a number. Looking at the error message that is produced by Python, I assume you are using Python 3 but I will cover Python 2 too.</p>
<h1>Python 2</h1>
<p><code>input()</code> checks if the given input from stdin is something it can <co... | 2 | 2016-06-19T06:11:05Z | [
"python",
"input"
] |
Scrapy submit form repeatly | 37,904,319 | <p>It can work with only one username plus password and verification code.</p>
<p>Here is the logic:</p>
<pre><code>def start_requests(self):
yield request(indexUrl, headers=headers, callback=self.downloadPic)
def downloadPic(self, response):
# get cookies from the response and add it to the headers
yiel... | 1 | 2016-06-19T05:44:23Z | 37,906,445 | <p>I write a script to call my spider, pass the form data to it. and it works!</p>
| -1 | 2016-06-19T10:54:11Z | [
"python",
"scrapy"
] |
how to delete a row in 2D list for some specific column values? | 37,904,343 | <p>for example if we have 2D list :</p>
<pre><code>list1 = [['tom',67,'engineer',2],
['ron',42,'scientist',4],
['alie',56,'doctor',3],
['rambo',29,'lawyer',7]]
</code></pre>
<p>now i have to delete rows in which column 4 has odd values. Is there any way in python3 to do so using pop or something els... | 1 | 2016-06-19T05:48:09Z | 37,904,374 | <p>The easiest way it to create a new list from <code>list1</code>. You can assign this to <code>list1</code> if you wish to replace it. You can use:</p>
<pre><code>list2 = [v for v in list1 if v[3] % 2 == 0]
</code></pre>
<p>In your example, <code>list2</code> gets the following value:</p>
<pre><code>[['tom', 67,... | 0 | 2016-06-19T05:52:59Z | [
"python",
"python-3.x"
] |
how to delete a row in 2D list for some specific column values? | 37,904,343 | <p>for example if we have 2D list :</p>
<pre><code>list1 = [['tom',67,'engineer',2],
['ron',42,'scientist',4],
['alie',56,'doctor',3],
['rambo',29,'lawyer',7]]
</code></pre>
<p>now i have to delete rows in which column 4 has odd values. Is there any way in python3 to do so using pop or something els... | 1 | 2016-06-19T05:48:09Z | 37,904,730 | <p>The solution with using <code>remove</code>. It's easy to understand you. </p>
<pre><code>for value in list1[:]:
if value[3] % 2 != 0:
list1.remove(value)
</code></pre>
<p><strong>Result</strong></p>
<pre><code>[['tom', 67, 'engineer', 2], ['ron', 42, 'scientist', 4]]
</code></pre>
| 0 | 2016-06-19T06:58:18Z | [
"python",
"python-3.x"
] |
Python import CSV short code (pandas?) delimited with ';' and ',' in entires | 37,904,450 | <p>I need to import a CSV file in Python on Windows. My file is delimited by ';' and has strings with non-English symbols and commas (','). </p>
<p>I've read posts:</p>
<p><a href="http://stackoverflow.com/questions/2887878/importing-a-csv-file-into-a-sqlite3-database-table-using-python">Importing a CSV file into a s... | 1 | 2016-06-19T06:08:07Z | 37,904,733 | <p>Unless your CSV file is broken, you can try to make <code>csv</code> guess your format.</p>
<pre><code>import csv
with open('d:/trade/test.csv', 'r') as f1:
dialect = csv.Sniffer().sniff(f1.read(1024))
f1.seek(0)
r = csv.reader(f1, dialect=dialect)
for row in r:
print(row)
</code></pre>
| 1 | 2016-06-19T06:58:36Z | [
"python",
"csv",
"pandas",
"dataframe",
"separator"
] |
Python import CSV short code (pandas?) delimited with ';' and ',' in entires | 37,904,450 | <p>I need to import a CSV file in Python on Windows. My file is delimited by ';' and has strings with non-English symbols and commas (','). </p>
<p>I've read posts:</p>
<p><a href="http://stackoverflow.com/questions/2887878/importing-a-csv-file-into-a-sqlite3-database-table-using-python">Importing a CSV file into a s... | 1 | 2016-06-19T06:08:07Z | 37,904,829 | <p>Pandas documentation says for parameters:</p>
<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html</a></p>
<pre><code>sep : str, default â,â
Delimiter to use. If sep is None, will try to a... | 1 | 2016-06-19T07:12:58Z | [
"python",
"csv",
"pandas",
"dataframe",
"separator"
] |
Python import CSV short code (pandas?) delimited with ';' and ',' in entires | 37,904,450 | <p>I need to import a CSV file in Python on Windows. My file is delimited by ';' and has strings with non-English symbols and commas (','). </p>
<p>I've read posts:</p>
<p><a href="http://stackoverflow.com/questions/2887878/importing-a-csv-file-into-a-sqlite3-database-table-using-python">Importing a CSV file into a s... | 1 | 2016-06-19T06:08:07Z | 37,905,437 | <p><strong>Pandas</strong> solution - use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a> with regex separator <code>[;,]</code>. You need add <code>engine='python'</code>, because warning:</p>
<blockquote>
<p>ParserWarning: Falling back t... | 1 | 2016-06-19T08:46:06Z | [
"python",
"csv",
"pandas",
"dataframe",
"separator"
] |
Illegal instruction (core dumped) while running Dlib Face detection | 37,904,503 | <p>I am trying to run face_landmark_detection.py example sample which was provided by the Dlib library.</p>
<p>But when i am trying to run the command via ubuntu terminal I am getting error: Illegal instruction (core dumped)</p>
<p>I debug it so i get to know it is because of this line :<br>
win=dlib.image_window()</... | 1 | 2016-06-19T06:17:36Z | 37,904,953 | <p>Looks like dlib can't create image window in your case. Possible reason of it - incorrect dlib installation. As Dlib's documentation describes (readme.txt), you should install it by running setup.py:</p>
<pre><code>COMPILING DLIB Python API
Before you can run the Python example programs you must compile dlib. Ty... | 2 | 2016-06-19T07:32:34Z | [
"python",
"face-detection",
"coredump",
"dlib"
] |
Django creating reusable app that loads specific js | 37,904,538 | <p>I'm trying to make a django reusable app that will basically contain bunch of template tags.</p>
<p>How and what are the best practices for allowing app-specific js to be easily loaded using the app.</p>
<p>Is there a way a user can just put <code>{% load app_name %}</code> and the app will load its js in the html... | 0 | 2016-06-19T06:23:09Z | 37,905,070 | <p>Just put <code><script ...></code> in a template in your reusable app, and include that template in any app you want:</p>
<pre><code>{% include "reusable_app/js_header.html" %}
</code></pre>
<p>The reusable app needs to be listed in <code>INSTALLED_APPS</code> to find the templates.</p>
| 1 | 2016-06-19T07:47:44Z | [
"python",
"django"
] |
Using Psycopg2 in virtualenv (Ubuntu 14.4, Python 3.4) | 37,904,631 | <p>I have installed <code>postgres</code> and <code>Psycopg2</code> using <code>apt-get</code> on my linux.</p>
<p>I want to use <code>postgres</code> for one of my <code>django</code> project. </p>
<p>I have created <code>virtualenv</code> but i am not able to work with psycopg2 when i add it in <code>db settings</c... | 2 | 2016-06-19T06:41:35Z | 37,904,704 | <p>The problem here is that you have used <code>apt-get</code> to install the driver, which has installed it in your system python's package directory; and by default the virtual environment is created with no system packages.</p>
<p>So even though the command works when you are outside the virtual environment (using ... | 2 | 2016-06-19T06:53:03Z | [
"python",
"django",
"virtualenv",
"psycopg2"
] |
Using Psycopg2 in virtualenv (Ubuntu 14.4, Python 3.4) | 37,904,631 | <p>I have installed <code>postgres</code> and <code>Psycopg2</code> using <code>apt-get</code> on my linux.</p>
<p>I want to use <code>postgres</code> for one of my <code>django</code> project. </p>
<p>I have created <code>virtualenv</code> but i am not able to work with psycopg2 when i add it in <code>db settings</c... | 2 | 2016-06-19T06:41:35Z | 37,904,816 | <p>The solution is to install server version of postgresql (It seems like you have only client installed). On Ubuntu:</p>
<pre><code>sudo apt-get install postgresql-server-dev-X.Y
</code></pre>
<p>where the <code>X.Y</code> is version of the package.</p>
<p>Then, inside <code>virtualenv</code> environment install <c... | 1 | 2016-06-19T07:11:26Z | [
"python",
"django",
"virtualenv",
"psycopg2"
] |
PySpark - Connect to s3 - read a file to rdd | 37,904,683 | <p>Am trying to connect to my s3 bucket using pyspark.<br>
Below is the code: </p>
<pre><code>from boto.s3.connection import S3Connection
AWS_KEY = '...'
AWS_SECRET = '...'
aws_connection = S3Connection(AWS_KEY, AWS_SECRET)
bucket = aws_connection.get_bucket('activitylogs-prod')
sc._jsc.hadoopConfiguration().set("... | 1 | 2016-06-19T06:49:47Z | 37,904,837 | <p><code>textFile</code> only takes a path and <code>minPartitions</code> (optionally), I think what you are looking for is <code>hadoopFile</code>...which does take the different Format classes.</p>
| 1 | 2016-06-19T07:14:11Z | [
"python",
"apache-spark",
"amazon-s3",
"pyspark"
] |
How can I open another gui by push button? | 37,904,743 | <p>I made several gui by qt designer and want to connect them by push button</p>
<p>If I push button in my main gui I want to open the second gui</p>
<p>SecDialog is my second gui and MainWindow is the main gui</p>
<p>what is the problem? </p>
<pre><code>import sys
from PyQt4 import QtCore, QtGui
from mainwindow im... | 0 | 2016-06-19T07:00:41Z | 37,911,370 | <p>You need to put opening and closing parentheses after <code>window.show</code>:</p>
<pre><code>import sys
from PyQt4 import QtCore, QtGui
from mainwindow import Ui_MainWindow
from secdialog import Ui_SecDialog
class SecDialog(QtGui.QDialog, Ui_SecDialog):
def __init__(self, parent=None):
QtGui.QDialog.... | 0 | 2016-06-19T20:10:14Z | [
"python",
"python-2.7",
"qt",
"python-3.x"
] |
_tkinter.TclError: invalid command name ".54600176" error, what is going on? | 37,904,750 | <p>I am new to python and am trying to code a simple game, but am continuously receiving this error message after updating the main game loop. </p>
<pre><code> Traceback (most recent call last):
File "D:\python shell\Bubble Blaster.py", line 75, in <module>
move_bubbles()
File "D:\python shell\Bubble Bla... | 1 | 2016-06-19T07:01:45Z | 37,905,680 | <p>In Tk the root window is named '.' (dot) and its children are named as a dot delimited path of parent names. Tkinter generates the names for you using numbers. The other thing to note is that in Tk the name of a window is also a command that provides operations on that window. So the error you have here is telling y... | 1 | 2016-06-19T09:16:47Z | [
"python",
"python-3.x",
"tkinter",
"collision"
] |
Explicit float conversion in python gives ParseError | 37,904,952 | <p>I'm learning python in Coursera, I tried the assignment for the course but am not getting the desired result. This program is supposed to extract '0.8475' and convert it to float before printing it.</p>
<pre><code>text = "X-DSPAM-Confidence: 0.8475";
pos=text.find('0');
s=text[pos:len(text)];
p=0.0;
p=(float)s;
... | -1 | 2016-06-19T07:32:33Z | 37,905,040 | <p>As @ZdaR mentions, the call to the <code>float</code> function must pass the parameter inside the parentheses as <code>p = float(s)</code>. I tested this in Python IDLE and the program worked correctly.</p>
<p>Also note that you should not end lines with <code>;</code> in Python. The whitespace itself will handle... | 1 | 2016-06-19T07:44:36Z | [
"python"
] |
Getting the last element of a level in a multiindex | 37,905,060 | <p>I have a dataframe in this format:</p>
<pre><code>a b x
1 1 31
1 2 1
1 3 42
1 4 423
1 5 42
1 6 3
1 7 44
1 8 65437
1 9 73
2 1 5656
2 2 7
2 3 5
2 4 5
2 5 34
</code></pre>
<p><code>a</code> and <code>b</code> are indexes, <code>x</code> is the value.</p>
<p... | 1 | 2016-06-19T07:46:34Z | 37,905,162 | <p>With <code>df</code> as the dataframe and the column <code>a</code> already being sorted, here's an approach -</p>
<pre><code>df[np.append(np.diff(df['a'])>0,True)]
</code></pre>
<p>The basic idea is that we perform differentiation along the sorted column <code>a</code> and look for positive change with <code>(... | 2 | 2016-06-19T08:00:15Z | [
"python",
"numpy",
"pandas",
"dataframe",
"multi-index"
] |
Getting the last element of a level in a multiindex | 37,905,060 | <p>I have a dataframe in this format:</p>
<pre><code>a b x
1 1 31
1 2 1
1 3 42
1 4 423
1 5 42
1 6 3
1 7 44
1 8 65437
1 9 73
2 1 5656
2 2 7
2 3 5
2 4 5
2 5 34
</code></pre>
<p><code>a</code> and <code>b</code> are indexes, <code>x</code> is the value.</p>
<p... | 1 | 2016-06-19T07:46:34Z | 37,905,369 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.last.html" rel="nofollow"><code>last</code></a>:</p>
<pre><code>print (df.... | 3 | 2016-06-19T08:34:33Z | [
"python",
"numpy",
"pandas",
"dataframe",
"multi-index"
] |
Can not import Celery object from flask app | 37,905,240 | <p>I am trying to learn and integrate Celery with my flask app. I tried to the things mentioned in the link:
<a href="http://flask.pocoo.org/docs/0.11/patterns/celery/" rel="nofollow">Flask Celery</a></p>
<p>But I want to move all the async tasks in the separate module. So here is my git repository where I am making m... | 0 | 2016-06-19T08:13:47Z | 38,820,971 | <p>I try to run your code and do not get this error. I comment out your system argument in your run.py and leave this code below.</p>
<pre><code>if __name__ == '__main__':
app.secret_key = str(uuid.uuid4())
port = '9000'
app.run(debug=False, port=port, host='0.0.0.0')
</code></pre>
<p>Then I execute pytho... | 0 | 2016-08-08T03:40:54Z | [
"python",
"flask",
"celery"
] |
request.POST.get('category_id') gives single value | 37,905,308 | <p>I have a post request and the request gives the following value:</p>
<pre><code>request.POST
<QueryDict: {u'csrfmiddlewaretoken': [u'AbyDcwOtSyPwuC1JxeVUKJFk33XhH2us'], u'category_id': [u'15', u'26', u'7', u'8']}>
</code></pre>
<p>I want all the values in category_id in a list. But if I try to access values ... | 0 | 2016-06-19T08:24:56Z | 37,905,348 | <p>Use <code>request.POST.getlist('category_id')</code></p>
<p><a href="https://docs.djangoproject.com/en/1.9/ref/request-response/#django.http.QueryDict.getlist" rel="nofollow">https://docs.djangoproject.com/en/1.9/ref/request-response/#django.http.QueryDict.getlist</a></p>
| 1 | 2016-06-19T08:30:43Z | [
"python",
"django"
] |
request.POST.get('category_id') gives single value | 37,905,308 | <p>I have a post request and the request gives the following value:</p>
<pre><code>request.POST
<QueryDict: {u'csrfmiddlewaretoken': [u'AbyDcwOtSyPwuC1JxeVUKJFk33XhH2us'], u'category_id': [u'15', u'26', u'7', u'8']}>
</code></pre>
<p>I want all the values in category_id in a list. But if I try to access values ... | 0 | 2016-06-19T08:24:56Z | 37,905,438 | <p>Yes, you need to <strong>change <code>.get()</code> to <code>.getlist()</code> to get all the values.</strong></p>
<pre><code>request.POST.getlist('category_id')
</code></pre>
<p><strong><code>.get()</code> QueryDict operation:</strong></p>
<p><code>.get()</code> operation on Django's <a href="https://docs.djang... | 0 | 2016-06-19T08:46:07Z | [
"python",
"django"
] |
How to skip 4-byte unicode word in a sentence | 37,905,326 | <p>There is a Warning when inserting 4-byte unicode to mysql(utf8).<br/>
I want to skip the 4-byte unicode word if it exist in a sentence.<br/>
So that it can insert to mysql successfully. :D<br/>
<br/>
<br/>
For example. '\xf0\x9f\x8e\x81' is a gift icon. í ¼í¾<br/>
The sentence is 'This í ¼í¾ is great.'<br/>
And it... | -1 | 2016-06-19T08:27:43Z | 37,905,638 | <p>Assuming you have the string in Unicode form initially, you can remove characters from outside the Basic-Multilingual-Plane characters by doing:</p>
<pre><code>if len(u'\U00010000') == 1:
s = re.sub(u'[\U00010000-\U001FFFFF]', u'', s)
else:
s = re.sub(u'[\uD800-\uDFFF]', u'', s)
</code></pre>
<p>(the two b... | 0 | 2016-06-19T09:11:49Z | [
"python",
"unicode",
"warnings"
] |
Printing same HTTPResponse Object returns different outputs - Python | 37,905,457 | <pre><code>def crawl(url):
html = getHTML(url) # getHTML() retruns HTTPResponse
print(html.read()) # PRINT STATMENT 1
if (html == None):
print("Error getting HTML")
else:
# parse html
bsObj = BeautifulSoup(html, "lxml")
# print data
try:
print(bsObj.h1... | 0 | 2016-06-19T08:48:13Z | 37,905,793 | <p><code>html</code> is an HTTPResponse object. HTTPResponse supports file-like operations, such as <code>read()</code>. </p>
<p>Just like when reading a file, a <code>read()</code> consumes the available data and moves the file pointer to the <strong>end</strong> of the file/data. A subsequent <code>read()</code> has... | 1 | 2016-06-19T09:33:12Z | [
"python",
"httpresponse"
] |
Multi dimensional array in Python | 37,905,700 | <p>As noob in python I struggle with a multidimensional array
I have this part </p>
<pre><code>def listMembers(Members):
for name in Names:
age=Ages[name]
print (name,age)
Names = ["John","William","Sarah"]
Ages = [22,33,44]
Members=[Names,Ages]
listMembers(Members)
</code></pre>
... | 0 | 2016-06-19T09:19:59Z | 37,905,748 | <p>You can use <code>enumerate</code> to do the task... </p>
<pre><code>def listMembers():
for i,name in enumerate(Names):
age=Ages[i]
print (name,age)
</code></pre>
<p>Output - </p>
<pre><code>John 22
William 33
Sarah 44
</code></pre>
<p>But as said in the comments... | 2 | 2016-06-19T09:27:53Z | [
"python"
] |
Multi dimensional array in Python | 37,905,700 | <p>As noob in python I struggle with a multidimensional array
I have this part </p>
<pre><code>def listMembers(Members):
for name in Names:
age=Ages[name]
print (name,age)
Names = ["John","William","Sarah"]
Ages = [22,33,44]
Members=[Names,Ages]
listMembers(Members)
</code></pre>
... | 0 | 2016-06-19T09:19:59Z | 37,905,800 | <p>You can use the <code>zip</code> built-in function:</p>
<pre><code>Names = ["John", "William", "Sarah"]
Ages = [22, 33, 44]
for name, age in zip(Names, Ages):
print name, ',', age
</code></pre>
| 1 | 2016-06-19T09:33:53Z | [
"python"
] |
Multi dimensional array in Python | 37,905,700 | <p>As noob in python I struggle with a multidimensional array
I have this part </p>
<pre><code>def listMembers(Members):
for name in Names:
age=Ages[name]
print (name,age)
Names = ["John","William","Sarah"]
Ages = [22,33,44]
Members=[Names,Ages]
listMembers(Members)
</code></pre>
... | 0 | 2016-06-19T09:19:59Z | 37,905,844 | <p>You can use the the built-in function <a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow">zip()</a></p>
<p>This will get you a list of tuples.</p>
<pre><code>zipped = zip(Names, Ages)
tup_list = (list(zipped))
print (tup_list)
[('John', 22), ('William', 33), ('Sarah', 44)]
</code></pre>
... | 0 | 2016-06-19T09:40:18Z | [
"python"
] |
Multi dimensional array in Python | 37,905,700 | <p>As noob in python I struggle with a multidimensional array
I have this part </p>
<pre><code>def listMembers(Members):
for name in Names:
age=Ages[name]
print (name,age)
Names = ["John","William","Sarah"]
Ages = [22,33,44]
Members=[Names,Ages]
listMembers(Members)
</code></pre>
... | 0 | 2016-06-19T09:19:59Z | 37,905,942 | <p>The other answers show the cool in-built shortcuts in Python. However, IMHO you should really re-visit the basics the first and take the long route.</p>
<p>The following code uses basic functionality to create a list of integers (<code>[0,1,2]</code> in your case), which are iterated over to slice the arrays accord... | 0 | 2016-06-19T09:53:49Z | [
"python"
] |
Multi dimensional array in Python | 37,905,700 | <p>As noob in python I struggle with a multidimensional array
I have this part </p>
<pre><code>def listMembers(Members):
for name in Names:
age=Ages[name]
print (name,age)
Names = ["John","William","Sarah"]
Ages = [22,33,44]
Members=[Names,Ages]
listMembers(Members)
</code></pre>
... | 0 | 2016-06-19T09:19:59Z | 37,906,106 | <p>Here's the solution you're looking for. It gets all the information it needs from the <code>Members</code> argument, which may cointain any number of lists. The list elements are grouped, converted to strings, joined with <code>", "</code>, and printed. There are no global references to <code>Names</code> or <cod... | 0 | 2016-06-19T10:12:19Z | [
"python"
] |
Save numpy array as binary to read from FORTRAN | 37,905,759 | <p>I have a series of numpy array, i need to save these numpy array in a loop as a raw binary float32 (without any header information) which need to be read from FORTRAN.</p>
<pre><code>import numpy as np
f=open('test.bin','wb+')
for i in range(0,10):
np_data=np.random.rand(10,5)
fortran_data=np.asfortranarray... | 1 | 2016-06-19T09:29:07Z | 37,924,893 | <p>You will need the meta data of the array to read it in FORTRAN. This website (<a href="https://scipy.github.io/old-wiki/pages/Cookbook/InputOutput.html" rel="nofollow">https://scipy.github.io/old-wiki/pages/Cookbook/InputOutput.html</a>) has some information on using libnpy to write and an example code fex.f95 to re... | 1 | 2016-06-20T14:19:40Z | [
"python",
"numpy",
"fortran"
] |
Using a python script to run a shell script (containing a make file and an executable for fortran) | 37,905,777 | <p>I am trying to execute a shell script using python. The shell script contains variables (which I want to set in the python script itself), a make file and an executable file for fortran. Is it possible to be done using python?
I tried with the following python code but unfortunately it does not work:</p>
<pre><code... | 0 | 2016-06-19T09:31:01Z | 37,905,976 | <p>You can use <a href="https://docs.python.org/2/library/subprocess.html#subprocess.Popen" rel="nofollow"><code>subprocess.Popen</code></a>, which allows you to pass in a set of environment variables to the process. You can also specify the working directory for the subprocess instead of changing the current one.</p>... | 0 | 2016-06-19T09:57:21Z | [
"python",
"shell",
"fortran90"
] |
How can I know when 'str' will be able to handle unicode, and when it won't? | 37,906,096 | <p>Why does the <code>str</code> operator able to convert a list of unicode objects to a <code>str</code> object, but not able to convert a single unicode object?</p>
<p>For example, in the code below I'm creating a list of unicode objects, and then attempting to print out that list. In the second print statement, I'm... | -1 | 2016-06-19T10:10:44Z | 37,906,121 | <p>You are looking for the <a href="https://docs.python.org/2/library/functions.html#repr" rel="nofollow"><code>repr()</code> function</a>; lists don't have direct support for <code>str()</code>, and the default fallback is to produce the output for <code>repr()</code> instead.</p>
<p><code>repr()</code> will always p... | 1 | 2016-06-19T10:13:50Z | [
"python",
"unicode"
] |
Installing Airflow on Windows | 37,906,110 | <p>I want to install an <strong>airflow worker</strong> on a <strong>windows</strong> machine.</p>
<p>I've pip installed it and then copied the airflow folder from a linux install however this has sent me down a rabbit hole of errors! Cygwin was briefly mentioned in the airflow google groups (see <a href="https://grou... | 3 | 2016-06-19T10:12:34Z | 37,908,688 | <p>1st) install pip </p>
<pre><code>https://pip.pypa.io/en/stable/installing/
</code></pre>
<p>with <code>python get-pip.py</code> or <code>python3 get-pip.py</code></p>
<p>2nd) install airflow</p>
<pre><code>https://pythonhosted.org/airflow/installation.html
</code></pre>
<p>with <code>pip install airflow</code>... | 0 | 2016-06-19T15:09:32Z | [
"python",
"windows",
"cygwin",
"celery",
"airflow"
] |
dill vs cPickle speed difference | 37,906,154 | <p>I am trying to serialize thousands of objects and some of these objects are lambda objects.</p>
<p>Since <code>cPickle</code> doesn't work for lambdas, I tried using <code>dill</code>. However, the drop in computational speed is more than 10 times when unpickleing (or undilling (?)). Looking through the source, it ... | 3 | 2016-06-19T10:17:54Z | 38,478,024 | <p>I'm the <code>dill</code> author. Yes, <code>dill</code> is slower typically, but that's the penalty you pay for more robust serialization. If you are serializing a lot of classes and functions, then you might want to try one of the <code>dill</code> variants in <code>dill.settings</code> If you use <code>byref=Tr... | 1 | 2016-07-20T09:56:07Z | [
"python",
"lambda",
"pickle",
"dill"
] |
Strange build error on Travis, local tests in tox work | 37,906,160 | <p>I have a strange error on Travis, the builds of <a href="https://travis-ci.org/edoburu/django-fluent-blogs" rel="nofollow">https://travis-ci.org/edoburu/django-fluent-blogs</a> fail in Django 1.7 and lower with:</p>
<pre><code>from django.utils.six import python_2_unicode_compatible
ImportError: cannot import name... | 1 | 2016-06-19T10:18:42Z | 37,906,208 | <p>Try with <a href="https://docs.djangoproject.com/en/dev/ref/utils/#module-django.utils.encoding" rel="nofollow">django.utils.encoding</a>:</p>
<pre><code>from django.utils.encoding import python_2_unicode_compatible
</code></pre>
| 1 | 2016-06-19T10:24:08Z | [
"python",
"django",
"travis-ci",
"tox"
] |
I'm trying to use sql command on Python 3.51 and dbf 0.96.005 (for VFP). it have error | 37,906,205 | <pre><code>import dbf
table = dbf.Table('C:/test/MAS.DBF')
table.open()
records = table.sql("select * where SUPCOD = 1.YATHAI")
</code></pre>
<p>which gives:</p>
<pre><code>Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
records = table.sql("select * where SUPCOD = 1.YATHA... | 1 | 2016-06-19T10:23:53Z | 37,908,982 | <p>For some examples of <code>dbf</code> and <code>sql</code> (called <code>pql</code> in the <code>dbf</code> module as it is not full sql syntax) check out <a href="http://stackoverflow.com/a/6709736/208880">this answer</a>.</p>
<p>I suspect your immediate problem will by fixed by adding quotes around the value you ... | 0 | 2016-06-19T15:44:27Z | [
"python",
"visual-foxpro",
"dbf"
] |
Applying pandas qcut bins to new data | 37,906,210 | <p>I am using pandas qcut to split some data into 20 bins as part of data prep for training of a binary classification model like so:</p>
<pre><code>data['VAR_BIN'] = pd.qcut(cc_data[var], 20, labels=False)
</code></pre>
<p>My question is, how can I apply the same binning logic derived from the qcut statement above t... | 1 | 2016-06-19T10:24:16Z | 37,906,403 | <p>You can do it by passing <code>retbins=True</code>.</p>
<p>Consider the following DataFrame:</p>
<pre><code>import pandas as pd
import numpy as np
prng = np.random.RandomState(0)
df = pd.DataFrame(prng.randn(100, 2), columns = ["A", "B"])
</code></pre>
<p><code>pd.qcut(df["A"], 20, retbins=True, labels=False)</co... | 3 | 2016-06-19T10:48:37Z | [
"python",
"pandas"
] |
How to multiply rows in matrices in PYTHON? | 37,906,269 | <p>My question is very intuitive in arrays but not in matrices. How can I multiple one element from row of one matrix in all equivalent row in other matrix. Let's assume I have: </p>
<pre><code>x = np.matrix([[1], [2]])
y = np.matrix([[3, 4], [5, 6]])
</code></pre>
<p>and I want to get as a result: </p>
<pre><code>[... | 2 | 2016-06-19T10:30:57Z | 37,906,300 | <p><strong>UPDATE:</strong> you can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.multiply.html" rel="nofollow">np.multiply()</a> function:</p>
<pre><code>In [57]: x
Out[57]:
matrix([[1],
[2]])
In [58]: y
Out[58]:
matrix([[3, 4],
[5, 6]])
In [59]: np.multiply(y, x)
Out[59]:
m... | 3 | 2016-06-19T10:35:25Z | [
"python",
"numpy",
"matrix"
] |
Selenium in python get the new tab page file(html) | 37,906,386 | <p>That is the code I use</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('http://www.youku.com')
inputElem = driver.find_element_by_id('headq')
inputElem.send_keys('æå²æå½±ç¤¾')
inputElem.send_Keys(Keys.RETURN)
print(driver.pag... | 1 | 2016-06-19T10:47:09Z | 37,907,435 | <p>One option would be to find the appropriate <code>form</code> element and <em>reset the <code>target</code> attribute</em> so that when you submit the form, it would happen in the same browser tab:</p>
<pre><code>form = driver.find_element_by_id("qheader_search")
driver.execute_script("arguments[0].setAttribute('ta... | 0 | 2016-06-19T12:52:44Z | [
"python",
"google-chrome",
"selenium"
] |
Error: File "python", line 31, in organise TypeError: can only concatenate list (not "int") to list | 37,906,392 | <p>I'm a very unexperienced programmer, so my code is probably extremely messy, but I'm trying to code something that gets the direction of each pixel in a p by p square. Each pixel van be black or white, 1 or 0, and is in list x. I don't understand why it throws this error now, because I only changed one thing. Before... | 0 | 2016-06-19T10:47:49Z | 37,918,164 | <pre><code>n[x+p]==1 or n[x+p+1]==1
</code></pre>
<p>This is wrong. It should be x[n] not the other way round.</p>
| 1 | 2016-06-20T08:49:07Z | [
"python"
] |
Is a member variable the same thing as an instance attribute in python? | 37,906,442 | <p>In the python wiki an attributes were described as variables defined within methods, and in this link: <a href="http://pythoncentral.io/introduction-to-python-classes/" rel="nofollow">http://pythoncentral.io/introduction-to-python-classes/</a> they describe val from the code below as a member variable.</p>
<pre><co... | 0 | 2016-06-19T10:53:48Z | 37,907,254 | <p>Instance/Member variables are values associated with a specific instance of a class. These can be different for each class, and are accessible via classes methods. A class variable is something that is originally the same in each instance of a class. By example, take the following class file:</p>
<pre><code>class M... | 1 | 2016-06-19T12:31:49Z | [
"python",
"attributes"
] |
How to compare 3 dictionaries and return keys and values | 37,906,452 | <p>I want to compare 3 dictionaries and find out what variables and their associated values are the same in all 3 dictionaries and what variables and their values are different.</p>
<p>The keys and values of the 3 dictionaries are found by reading 3 text files so I do not know which variable and value will come first ... | 1 | 2016-06-19T10:54:49Z | 37,906,907 | <p>Here is the answer for the first question (this is a more general answer - the function can receive any number of dictionary). at the end there is an example of how to use the code.</p>
<p>basically, the function checks for each key if a key is in all the dictionary an if yes AND the value is equal in all dictionar... | 2 | 2016-06-19T11:48:10Z | [
"python",
"python-2.7"
] |
How to compare 3 dictionaries and return keys and values | 37,906,452 | <p>I want to compare 3 dictionaries and find out what variables and their associated values are the same in all 3 dictionaries and what variables and their values are different.</p>
<p>The keys and values of the 3 dictionaries are found by reading 3 text files so I do not know which variable and value will come first ... | 1 | 2016-06-19T10:54:49Z | 37,907,193 | <p>Since the common and distinct dictionaries holds more than one value I prefer to store them in an array as below:</p>
<pre><code>def get_vals(key, *dicts):
vals = []
for d in dicts:
try:
vals.append(d[key])
except:
pass
return vals
def diff(*d):
common, d... | 1 | 2016-06-19T12:23:50Z | [
"python",
"python-2.7"
] |
Python- making a set from a text file | 37,906,459 | <p>I have a text file. The guts of it look like this/ all of it looks like this (has been edited. This was also not what it initially looked like)</p>
<pre><code> (0, 16, 0)
(0, 17, 0)
(0, 18, 0)
(0, 19, 0)
(0, 20, 0)
(0, 21, 0)
(0, 22, 0)
(0, 22, 1)
(0, 22, 2)
(0, 23, 0)
(0, 23, 4)
(0, 24, 0)
(0, 25, 0)
... | 0 | 2016-06-19T10:55:54Z | 37,906,504 | <p>Only need small modification.You can try this.</p>
<pre><code>om_set = set(eval(open('abc.txt').read()))
</code></pre>
<p><strong>Result</strong> </p>
<pre><code>{(0, 19, 0),
(0, 20, 0),
(0, 21, 1),
(0, 22, 0),
(0, 24, 3),
(0, 27, 0),
(0, 29, 2),
(0, 35, 2)}
</code></pre>
<p><strong>Edit</strong>
Here ... | 0 | 2016-06-19T11:02:47Z | [
"python",
"text",
"set"
] |
Python- making a set from a text file | 37,906,459 | <p>I have a text file. The guts of it look like this/ all of it looks like this (has been edited. This was also not what it initially looked like)</p>
<pre><code> (0, 16, 0)
(0, 17, 0)
(0, 18, 0)
(0, 19, 0)
(0, 20, 0)
(0, 21, 0)
(0, 22, 0)
(0, 22, 1)
(0, 22, 2)
(0, 23, 0)
(0, 23, 4)
(0, 24, 0)
(0, 25, 0)
... | 0 | 2016-06-19T10:55:54Z | 37,906,821 | <p>As @TimPietzcker suggested and trusting the file to only have these fixed representations of integers in comma separated triplets, surrounded by parentheses, a simple parser in one go (OP's question also had a greed "read" of file into memors):</p>
<pre><code>#! /usr/bin/env python
from __future__ import print_func... | 1 | 2016-06-19T11:39:04Z | [
"python",
"text",
"set"
] |
Odoo No module named base_multi_image | 37,906,493 | <p>i try start odoo with magento connector, but how i add extensions odoo crashed </p>
<pre><code> ERROR ? werkzeug: Error on request:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/us... | -1 | 2016-06-19T11:00:23Z | 37,907,021 | <p>you need to make sure that your add-on directory includes the following repo:
<a href="https://github.com/OCA/server-tools/tree/9.0/base_multi_image" rel="nofollow">https://github.com/OCA/server-tools/tree/9.0/base_multi_image</a></p>
| 1 | 2016-06-19T12:03:36Z | [
"python",
"openerp"
] |
How to wait for a specific manual action using Selenium Python | 37,906,534 | <p>How to make my script wait for a manual click on a submit button as in below website ? </p>
<pre><code>driver.get("http://www.propertyguru.com.sg/singapore-property-listing?listing_type=sale&search_type=district&property_id=&interest=&distance=1&property_type=&freetext=&districts%5B%5D=&... | -2 | 2016-06-19T11:05:50Z | 38,128,112 | <p>Add a breakpoint on the code you want to stop at. Run the script in debug mode (see help files for your IDE), it will break on that point, you do your manual task, and then start the script back up when you are done.</p>
| 0 | 2016-06-30T15:56:19Z | [
"python",
"selenium",
"web",
"selenium-webdriver",
"web-scraping"
] |
How to wait for a specific manual action using Selenium Python | 37,906,534 | <p>How to make my script wait for a manual click on a submit button as in below website ? </p>
<pre><code>driver.get("http://www.propertyguru.com.sg/singapore-property-listing?listing_type=sale&search_type=district&property_id=&interest=&distance=1&property_type=&freetext=&districts%5B%5D=&... | -2 | 2016-06-19T11:05:50Z | 38,208,750 | <pre><code>from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.events import EventFiringWebDriver, AbstractEventListener
# My custom event listener
class MyListener(AbstractEventListener):
clicked = False
def before_click(self, element, driver)... | 0 | 2016-07-05T16:52:53Z | [
"python",
"selenium",
"web",
"selenium-webdriver",
"web-scraping"
] |
How to keep trying urllib2 request via proxy when we get any type of error(or timeout)? | 37,906,560 | <p>I am making a html request using urllib2 method(inside a for loop) but sometimes i get errors or timeouts so i have to start all over the for loop. Could any one show me how i can modify my code so it keeps trying until we don't get error instead of restring the for loop all over again ?</p>
<pre><code> import u... | -1 | 2016-06-19T11:08:13Z | 37,906,994 | <p>As we discussed in comments, you can use <code>try/except</code> to avoid crashing while looping over (I see that you have changed you original code after this suggestion)</p>
<p>Then you can specify longer timeout in seconds, when using <code>urlopen</code> (see <a href="https://docs.python.org/2.7/library/urllib2... | -1 | 2016-06-19T12:00:10Z | [
"python",
"urllib2"
] |
For loop, how to reduece running time, pandas dataframe | 37,906,580 | <pre><code> Date Open Close Buying Selling Cut_Off_Price
2009.11.11 4.805 4.43 0 0 0
2009.11.12 4.51 4.505 0 0 0
2009.11.13 4.545 4.765 1 0 3.812
2009.11.16 4.78 4.76 0 0 0
2009.11.17 4.755 4.605 0 0 0
2009.11.18 4.56 4.495 0 ... | -1 | 2016-06-19T11:09:58Z | 37,908,349 | <p>Let pandas internals loop over the data for you, and just focus on providing appropriate chains of filters. Assume I have the file <strong>data.txt</strong> given below:</p>
<pre><code>Date,Open,Close,Buying,Selling,Cut_Off_Price
2009.11.11,4.805,4.43,0,0,0
2009.11.12,4.51,4.505,0,0,0
2009.11.13,4.545,4.765,1,0,5.... | 0 | 2016-06-19T14:35:36Z | [
"python",
"for-loop",
"pandas"
] |
Stream result of blocking function to client in python Tornado HTTP server | 37,906,584 | <p>I have various functions that are using blocking I/O to get some large amounts of data and can write it so stream/file-like object (with chunking etc); also I have tornado HTTP server to provide this data to clients. As far as I cannot store all data in memory, I should stream it to clients as I'm receiving it from ... | 0 | 2016-06-19T11:10:12Z | 39,781,016 | <p>Actually I faced some problems that lead me to solution that looks better for me. </p>
<p>RequestHandler <code>write()</code> and <code>flush()</code> methods are not thread-safe and should be called from thread where <code>ioloop</code> is running (see <a href="https://github.com/tornadoweb/tornado/issues/1350" re... | 0 | 2016-09-29T22:32:49Z | [
"python",
"tornado"
] |
add variable to PATH when activateing conda virtual env | 37,906,605 | <p>assume you want to add/remove a variable to your PATH variable whenever you (de)activate a virtual environment in conda. </p>
<p>I'm working with PyQt5 and by default it doesn't recognize pyuic5 as a command. So I would want to add the location of this command to the PATH env. variable, but only for the time the vi... | 0 | 2016-06-19T11:13:48Z | 37,906,707 | <p>Symlink it to the environment's <code>bin</code> directory, which gets added to the beginning of your <code>PATH</code> when you <code>activate</code> anyway.</p>
<p>As a distant secondary alternative, you could of course hack the <code>activate</code> script to do anything you want.</p>
| 0 | 2016-06-19T11:26:49Z | [
"python",
"environment-variables",
"conda"
] |
Pandas: reindex with custom function | 37,906,724 | <p>I am looking for a way to reindex data with custom a function. My data looks as follows: </p>
<pre><code> AAA BBB CCC DDD
Time
2009-01-30 09:30:00 6407.04 43.90 44.01 85.11
2009-01-30 09:39:00 6403.20 43.82 44.01 84.93
2009-01-30 ... | 1 | 2016-06-19T11:29:03Z | 37,907,326 | <p><strong>UPDATE:</strong></p>
<pre><code>In [182]: %paste
(df.groupby(df.index.date)
.apply(lambda x: x.resample('78T',
loffset=pd.Timedelta('24minute')).mean())
.ffill()
.pct_change()
)
## -- End pasted text --
Out[182]:
vxxc
Tim... | 3 | 2016-06-19T12:40:33Z | [
"python",
"pandas",
"dataframe"
] |
find google spreadsheet by title via api in python | 37,906,757 | <p>I would like to retrieve data of spreadsheet by searching for the spreadsheet by name. I wonder how it works?</p>
<pre><code>result = service.spreadsheets().values().get(title=spreadsheetTitle, range=rangeName).execute()
</code></pre>
| 0 | 2016-06-19T11:32:25Z | 37,939,162 | <p>From this <a href="https://github.com/burnash/gspread" rel="nofollow">example</a>, you can open a spreadsheet by its title or url.</p>
<p>Example:</p>
<pre><code>def open(self, title):
"""Opens a spreadsheet, returning a :class:`~gspread.Spreadsheet` instance.
:param title: A title of a spreadsheet... | 0 | 2016-06-21T08:24:06Z | [
"python",
"google-spreadsheet",
"google-sheets-api"
] |
Python remove space from string make it into int | 37,906,790 | <p>How would I remove the space in <code><span id="balance">1 268</span></code> and make it an <code>int</code></p>
<p>Code:</p>
<pre><code> Balance_afterWinORLoseBet.replace(" ", "")
Balance_afterWinORLoseBet = int(balance_new.text) #Makes new var, turns it into int.
if "10.1" in countdown_timer... | 1 | 2016-06-19T11:36:07Z | 37,906,818 | <p>int(balance_new.text.replace(" ",""))</p>
| 0 | 2016-06-19T11:38:49Z | [
"python",
"python-2.7",
"python-3.x",
"selenium"
] |
Python remove space from string make it into int | 37,906,790 | <p>How would I remove the space in <code><span id="balance">1 268</span></code> and make it an <code>int</code></p>
<p>Code:</p>
<pre><code> Balance_afterWinORLoseBet.replace(" ", "")
Balance_afterWinORLoseBet = int(balance_new.text) #Makes new var, turns it into int.
if "10.1" in countdown_timer... | 1 | 2016-06-19T11:36:07Z | 37,906,899 | <p>You might want to try this. It will work for all whitespace characters.</p>
<pre><code>int("".join(balance_new.text.split()))
</code></pre>
| 0 | 2016-06-19T11:47:09Z | [
"python",
"python-2.7",
"python-3.x",
"selenium"
] |
Python remove space from string make it into int | 37,906,790 | <p>How would I remove the space in <code><span id="balance">1 268</span></code> and make it an <code>int</code></p>
<p>Code:</p>
<pre><code> Balance_afterWinORLoseBet.replace(" ", "")
Balance_afterWinORLoseBet = int(balance_new.text) #Makes new var, turns it into int.
if "10.1" in countdown_timer... | 1 | 2016-06-19T11:36:07Z | 37,907,694 | <p>I guess you want the final output to be, '1268', and do not want to convert the entire string with HTML tags to 'int' type.</p>
<p>With this assumption, you can try this:</p>
<p><code>myvar = '<span id="balance">1 268</span>'
print int(myvar.replace(" ", "").split('>')[1].split('<')[0])</code></p... | -1 | 2016-06-19T13:21:57Z | [
"python",
"python-2.7",
"python-3.x",
"selenium"
] |
Python remove space from string make it into int | 37,906,790 | <p>How would I remove the space in <code><span id="balance">1 268</span></code> and make it an <code>int</code></p>
<p>Code:</p>
<pre><code> Balance_afterWinORLoseBet.replace(" ", "")
Balance_afterWinORLoseBet = int(balance_new.text) #Makes new var, turns it into int.
if "10.1" in countdown_timer... | 1 | 2016-06-19T11:36:07Z | 37,907,763 | <p>None of the other answers explain why your code doesn't work. The reason is that <code>.replace()</code> does not change the original variable, but returns <a href="https://docs.python.org/2/library/string.html#string.replace" rel="nofollow">"a copy of string s with all occurrences of substring old replaced by new"<... | 2 | 2016-06-19T13:30:07Z | [
"python",
"python-2.7",
"python-3.x",
"selenium"
] |
Entry command refers to function needing value entry | 37,906,835 | <p>I found this link above about buttons not being defined, and it was pretty straight forward. But what if you had an Entry and you needed the value of that Entry for the function that is in the command too.</p>
<pre><code>from tkinter import *
root = Tk()
textfile = open("savings.txt")
def save(maandag):
textfil... | 0 | 2016-06-19T11:40:59Z | 37,907,029 | <p>In this line:</p>
<pre><code>maandag = Entry(root, command=save(maandag))
</code></pre>
<p>You are calling for maandag widget which is in the process of creation (so not created yet). That is why you get that error.</p>
<p>An alternative is to use <a href="http://effbot.org/tkinterbook/button.htm#Tkinter.Button.c... | 0 | 2016-06-19T12:04:31Z | [
"python",
"tkinter",
"nameerror"
] |
How do I use a mapping variable to re-index a dataframe? | 37,906,882 | <p>I have the following data frame:</p>
<pre><code> population GDP
country
United Kingdom 4.5m 10m
Spain 3m 8m
France 2m 6m
</code></pre>
<p>I also have the following information in a 2 column dataframe(happy for this to be made into another dat... | 2 | 2016-06-19T11:45:37Z | 37,906,934 | <p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow"><code>Series.map</code></a>, but it works only with <code>Series</code>, so need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.to_series.html" rel="nofollow"><code>I... | 2 | 2016-06-19T11:51:36Z | [
"python",
"pandas",
"indexing",
"dataframe",
"mapping"
] |
How do I use a mapping variable to re-index a dataframe? | 37,906,882 | <p>I have the following data frame:</p>
<pre><code> population GDP
country
United Kingdom 4.5m 10m
Spain 3m 8m
France 2m 6m
</code></pre>
<p>I also have the following information in a 2 column dataframe(happy for this to be made into another dat... | 2 | 2016-06-19T11:45:37Z | 37,907,750 | <p>Here are some brief ways to approach your 3 questions. More details below:</p>
<p>1) How to change index based on mapping in separate df</p>
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_dict.html" rel="nofollow"><code>df_with_mapping.todict("split")</code></a> to create... | 0 | 2016-06-19T13:28:12Z | [
"python",
"pandas",
"indexing",
"dataframe",
"mapping"
] |
pandas.set_option to give detail of Dataframe rather than returning frame | 37,906,939 | <p>I have a <code>DataFrame</code> called <code>result</code>.</p>
<p>In the tutorial I'm watching Wes McKinney is getting the following return data when he executes a cell with just the name of the df in it - when I execute a cell with <code>result</code> in it I get the whole frame being returned.</p>
<p>Is there a... | 1 | 2016-06-19T11:52:28Z | 37,907,027 | <p>there is a <code>display.large_repr</code> option for that:</p>
<pre><code>In [95]: pd.set_option('large_repr', 'info')
In [96]: df
Out[96]:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000000 entries, 0 to 999999
Data columns (total 3 columns):
a 1000000 non-null int32
b 1000000 non-null int32
c... | 1 | 2016-06-19T12:04:17Z | [
"python",
"pandas"
] |
pandas.set_option to give detail of Dataframe rather than returning frame | 37,906,939 | <p>I have a <code>DataFrame</code> called <code>result</code>.</p>
<p>In the tutorial I'm watching Wes McKinney is getting the following return data when he executes a cell with just the name of the df in it - when I execute a cell with <code>result</code> in it I get the whole frame being returned.</p>
<p>Is there a... | 1 | 2016-06-19T11:52:28Z | 37,907,095 | <p><code>df.info(verbose=None, buf=None, max_cols=None, memory_usage=None, null_counts=None)</code> method will give you what you want. By default, information about the number of values and the size of the dataframe will be displayed. The documentation is <a href="http://pandas.pydata.org/pandas-docs/stable/generated/... | 1 | 2016-06-19T12:11:10Z | [
"python",
"pandas"
] |
How to append variables to a string inside for loop in python? | 37,907,007 | <p>I am trying to append variable inside for loop <code>(cname[0].decode('utf-8'))</code>. In php we could do like this :</p>
<pre><code> TotalData .= ",".$cname[0];
</code></pre>
<p>How we could achieve same thing using python ?(ouput be 1,2,3,,4)</p>
<pre><code>for cname in match:
TotalData .= ","+cname[0... | 0 | 2016-06-19T12:02:01Z | 37,907,497 | <p>you could do:</p>
<pre><code>my_list = ['boo', 'foo']
text= 'initial_text'
for item in my_list:
text += item
</code></pre>
| 0 | 2016-06-19T12:58:53Z | [
"python",
"string-concatenation"
] |
Inconsistent results in pyspark combineByKey (as opposed to groupByKey) | 37,907,017 | <p>I want to group by key some rows in a RDD so I can perform more advanced operations with the rows within one group. Please note, I do not want to calculate merely some aggregate values. The rows are key-value pairs, where the key is a GUID and the value is a complex object.</p>
<p>As per pyspark documentation, I fi... | -1 | 2016-06-19T12:03:02Z | 37,907,241 | <p>It is the case when understanding basic APIs is preferred. In particular if you check <code>list.append</code> docstring:</p>
<pre><code>?list.append
## Docstring: L.append(object) -> None -- append object to end
## Type: method_descriptor
</code></pre>
<p>you'll see that like the other mutating methods in... | 0 | 2016-06-19T12:29:10Z | [
"python",
"apache-spark",
"pyspark"
] |
Python - why does eval fail on this string/expression? | 37,907,056 | <p>I am running anaconda on OS X 10.11.5 and am struggling to access data in a pandas DataFrame. Doing it directly works fine but, when I try to evaluate arguments in a string which I have generated by iteration, it fails. Here is a simpler version that produces the same problem without the iteration.</p>
<p>The direc... | 0 | 2016-06-19T12:07:22Z | 37,907,521 | <p><a href="http://pandas.pydata.org/pandas-docs/version/0.18.1/generated/pandas.eval.html" rel="nofollow">pandas.eval</a> <strong>returns</strong> the Series, so you want to use </p>
<pre><code>lukas@crash:~/sandbox$ cat a.csv
a,b
1,2
lukas@crash:~/sandbox$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4... | 0 | 2016-06-19T13:01:20Z | [
"python",
"csv",
"pandas",
"eval"
] |
Writing a dictionary with name and numpy array data to text file issue | 37,907,063 | <p>I'm newbie in python and I'm coding some project. I need to save some data in dictionary format {name: numpy array} (and not only one dictionary) saving it to text file and then reading it from this file too.
I use np.savetxt for this purpose. </p>
<pre><code>import numpy as np
from DIP import dip
name = 'name'
... | 0 | 2016-06-19T12:07:42Z | 37,907,424 | <p>In <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html" rel="nofollow"><code>numpy.savetxt</code></a> you can't save the dictionary. To save dictionary you can use <code>pickle</code>.</p>
<p>Loading dictionary in <code>pickle</code> file.</p>
<pre><code>In [1]: pickle_obj = open("dicts... | 0 | 2016-06-19T12:51:16Z | [
"python",
"arrays",
"numpy",
"dictionary"
] |
Deserialize nested fields in marshmallow | 37,907,224 | <p>I'm consuming an API that returns something like:</p>
<pre><code>{'name': 'foo', 'start': {'date': '2016-06-19', 'time': '18:00'}}
</code></pre>
<p>And I want to desearialize it with marshmallow to get only the name and the start date, so the desired result would be the following:</p>
<pre><code>{'name': 'foo', '... | 3 | 2016-06-19T12:26:24Z | 37,908,019 | <p>You will need to create a <code>NestedSchema</code> for the nested dictionary, and overwrite your parent schema's <code>load</code> method to append the nested field to parent. Specify a <code>only</code> attribute so the <code>Nested</code> field does not fetch all of its items:</p>
<pre><code>class DateTimeSchema... | 2 | 2016-06-19T13:59:11Z | [
"python",
"marshmallow"
] |
Deserialize nested fields in marshmallow | 37,907,224 | <p>I'm consuming an API that returns something like:</p>
<pre><code>{'name': 'foo', 'start': {'date': '2016-06-19', 'time': '18:00'}}
</code></pre>
<p>And I want to desearialize it with marshmallow to get only the name and the start date, so the desired result would be the following:</p>
<pre><code>{'name': 'foo', '... | 3 | 2016-06-19T12:26:24Z | 38,832,725 | <p>What you describe can be accomplished by <strong>transforming*</strong> your input data in a <strong>pre-processing*</strong> step. While the accepted answer looks like it will do that, <a href="http://marshmallow.readthedocs.io/en/latest/api_reference.html?highlight=uid#module-marshmallow.decorators" rel="nofollow"... | 2 | 2016-08-08T15:08:53Z | [
"python",
"marshmallow"
] |
PySys [0.9.2]. About running testcases when their ids are of the form 'token1<blank>token2<blank>...' | 37,907,231 | <p>I've named a testcase as 'Delete Trades', so when I try to run it, from its parent directory, in any of the following ways:</p>
<pre><code>pysys run Delete Trades
pysys run Delete\ Trades
pysys run "Delete Trades"
</code></pre>
<p>I always get the same outcome:</p>
<pre><code>2016-06-19 14:18:41,405 INFO Unable ... | 1 | 2016-06-19T12:26:52Z | 37,907,284 | <p>Is this on windows? A quick try (renaming the first example Fibonacci test) on linux shows that "pysys.py run Delete\ Trades" does work;</p>
<pre><code>$ mv Fibonacci_test_001 "Delete Trades"
$ pysys.py run Delete\ Trades
2016:06:19 13:31:42 INFO ==============================================================
... | 0 | 2016-06-19T12:35:17Z | [
"python",
"automated-tests"
] |
Kivy: ID error on dinamic TabbedPanel | 37,907,334 | <p>I want to create TabbedPanel in Kivy dynamically from a stringarray:</p>
<pre><code>tg_folders = [['0','Folder1'],['1','Folder2']]
tgflen=len(tg_folders)
for i in range(0,tgflen):
fl_id = 'fl-'+tg_folders[i][0]
menu_screen.ids.tg_folder_list.add_widget(TabbedPanelItem(height=0,
... | 0 | 2016-06-19T12:41:31Z | 37,908,515 | <p>ids can only be set in kv. YOu can instead keep track of the object references another way, e.g. keeping them in a list.</p>
| 0 | 2016-06-19T14:53:03Z | [
"python",
"kivy",
"kivy-language"
] |
Defining a function within a class in Python 2.7 | 37,907,393 | <p>I tried to add a pgdc function in the <code>Fraction</code> class in order to calculate the biggest common divided or a number <code>pgdc</code> ... The function should be recursive. However, I keep getting the following error:</p>
<pre><code>Traceback (most recent call last):
File "C:/Users/jf/Desktop/Python-jEd... | 0 | 2016-06-19T12:46:56Z | 37,907,453 | <p>You need to declare <code>self</code> as a parameter of your function and use it when you want to recursively call <code>pgcd</code>:</p>
<pre><code>def pgcd(self,a, b):
if a == b:
return a
if a > b:
return self.pgcd(a-b, b)
else:
return self.pgcd(a, b-a)
</code></pre>
<p>A... | 0 | 2016-06-19T12:54:08Z | [
"python",
"function",
"class"
] |
How can i execute a python function(which takes a parameter) from php? | 37,907,396 | <p>I have a python script which has a python function inside it and function takes a parameter. Now i want to execute the python function. and the parameter is given from php.
But python file is in another directory. </p>
<p>Ex: php is in <code>site/ph</code> directory and python is in <code>site/pyt</code> directory... | 1 | 2016-06-19T12:47:58Z | 37,908,549 | <p>Consider passing the PHP parameter as a command line argument into Python using PHP's <a href="http://php.net/manual/en/function.exec.php" rel="nofollow"><code>exec()</code></a>. Then have Python receive it with its <a href="https://docs.python.org/2/library/sys.html" rel="nofollow"><code>sys.argv</code></a> list:</... | 0 | 2016-06-19T14:55:54Z | [
"php",
"python",
"function",
"parameters",
"execute"
] |
Strange lines in specgram using matplotlib | 37,907,405 | <p>I am using <code>matplotlib.specgram</code> to create spectrograms of recordings of spoken words. For a reason unknown to me the spectrograms have strange lines in them as seen from the images below.</p>
<p>I am wondering what is causing these lines and how can I get rid of them?</p>
<p><a href="http://i.stack.img... | 0 | 2016-06-19T12:49:11Z | 37,910,240 | <p>I think that @farenorth is right. </p>
<p>When the spectrogram is calculated then for each timestep (x-axis) a certain grayscale is picked for a given intensity. Let's assume the grayscale is set globally. If suddenly you have higher intensities in a new timestep, the grayscale would saturate. </p>
<p>This would... | 0 | 2016-06-19T18:03:42Z | [
"python",
"matplotlib"
] |
Windows: Python + OpenCV + Qt: "import cv2" gives "dll not found" error | 37,907,492 | <p>I have a problem when I'm trying to use OpenCV (v3.1.0) in Python (v3.4). To make things more complicated, OpenCV is built with the "contrib" package and Qt support (v5.5).</p>
<p>This is what I did (this has some pitfalls on it's own, but those are out of the scope of this question):</p>
<ol>
<li>Install required... | 0 | 2016-06-19T12:58:42Z | 37,907,493 | <p>What you may not want to do is just <a href="http://stackoverflow.com/questions/26929770/python-opencv-dll-load-failed-missing-environment-variables">adding paths that are likely needed to your environment variables</a>.</p>
<p>There <em>is</em> a way to find out what is missing:</p>
<ol>
<li>Download <a href="htt... | 1 | 2016-06-19T12:58:42Z | [
"python",
"qt",
"opencv",
"dll"
] |
Decorated function returns None | 37,907,505 | <p>I have a decorator that checks a function's argument for <code>int</code> type.</p>
<pre><code>def check_type_int(old_function):
def new_function(arg):
if not isinstance(arg, int):
print 'Bad Type' # raise TypeError('Bad Type')
else:
old_function(arg)
return new_fu... | 1 | 2016-06-19T13:00:17Z | 37,907,583 | <p>You don't <code>return</code> any value from <code>new_function</code> inside the decorator, therefore it returns <code>None</code> by default. Just change this line:</p>
<pre><code>old_function(arg)
</code></pre>
<p>to </p>
<pre><code>return old_function(arg)
</code></pre>
| 2 | 2016-06-19T13:08:38Z | [
"python",
"python-decorators"
] |
Decorated function returns None | 37,907,505 | <p>I have a decorator that checks a function's argument for <code>int</code> type.</p>
<pre><code>def check_type_int(old_function):
def new_function(arg):
if not isinstance(arg, int):
print 'Bad Type' # raise TypeError('Bad Type')
else:
old_function(arg)
return new_fu... | 1 | 2016-06-19T13:00:17Z | 37,907,643 | <p>Adding to the <a href="http://stackoverflow.com/a/37907583/2873538">answer</a> by @eugeney: it would be easier if you used <code>return</code> for both cases in <code>if</code>:</p>
<pre><code>if not isinstance(arg, int):
return 'Bad Type' # return
else:
return old_function(arg) # return
</code>... | 0 | 2016-06-19T13:15:05Z | [
"python",
"python-decorators"
] |
Decorated function returns None | 37,907,505 | <p>I have a decorator that checks a function's argument for <code>int</code> type.</p>
<pre><code>def check_type_int(old_function):
def new_function(arg):
if not isinstance(arg, int):
print 'Bad Type' # raise TypeError('Bad Type')
else:
old_function(arg)
return new_fu... | 1 | 2016-06-19T13:00:17Z | 37,908,254 | <p>You need to use *args and **kwargs</p>
<pre><code>def dec(function):
def new_f(*args, **kwargs):
return function(*args, **kwargs)
return new_f
</code></pre>
| -1 | 2016-06-19T14:24:39Z | [
"python",
"python-decorators"
] |
Python Random forest and machine learning - improvements | 37,907,616 | <p>I am quite new to using python for machine learning. I come from a background of programming in Fortran, so as you may imagine, python is quite a leap. I work in chemistry and have become involved in chemiformatics (applying data science techniques to chemistry). As such, the application of pythons extensive machine... | -1 | 2016-06-19T13:12:47Z | 37,909,727 | <p>you can also add Feature Selection to your data:</p>
<p><a href="http://scikit-learn.org/stable/modules/feature_selection.html" rel="nofollow">sickit learn feature selection</a></p>
<p>some feature selection techniques are provided in sickit learn and you can use it to improve some aspect of your DM project </p>
| 1 | 2016-06-19T17:05:50Z | [
"python",
"performance",
"machine-learning",
"scikit-learn",
"random-forest"
] |
Access frame inside frameset that is inside another frameset | 37,907,635 | <p>How do I access a frame that's present inside a frameset which is inside another frameset?</p>
<p><a href="http://i.stack.imgur.com/KTHFK.png" rel="nofollow"><img src="http://i.stack.imgur.com/KTHFK.png" alt="enter image description here"></a></p>
<p>Here's my code which returns <code>selenium.common.exceptions.No... | 0 | 2016-06-19T13:14:13Z | 37,907,684 | <p>You don't need to handle <code>frameset</code>s in any special way - these are just containers for the frames, they are not frames themselves. Here is what worked for me:</p>
<ul>
<li>add a wait to wait for the frame to be present</li>
<li>switch to the frame</li>
</ul>
<p>The code:</p>
<pre><code>from selenium i... | 2 | 2016-06-19T13:20:26Z | [
"python",
"selenium",
"selenium-webdriver"
] |
Scikitklearns TfidfTransformer makes my pipeline predict just one label | 37,907,775 | <p>I have a pandas dataframe containing texts and labels, and I'm trying to predict the labels using scikit-learn's <code>CountVectorizer</code>, <code>TfidfTransformer</code> and <code>MultinomialNB</code>. Here's what the dataframe looks like:</p>
<pre><code> text party... | 0 | 2016-06-19T13:31:22Z | 37,911,783 | <p>The reason that you are getting so much difference is because of smoothing. If you checkout the documentation of <a href="http://scikit-learn.org/stable/modules/generated/sklearn.naive_bayes.MultinomialNB.html" rel="nofollow">MultinomialNB class</a>, checkout the <code>alpha</code> parameter. The default value for t... | 1 | 2016-06-19T20:58:30Z | [
"python",
"pandas",
"scikit-learn",
"classification"
] |
Creating multiple instances of PhantomJS or only one? | 37,907,798 | <p>I have a script which needs to crawl a website. For every request(each URL), I initialize a new web driver with selenium/phantomJS .
Is this approach unscalable and will it cost a lot of CPU usage over time?
Should I rather only create a single driver and save it somewhere in a global variable and reuse it for all ... | 1 | 2016-06-19T13:33:57Z | 37,907,823 | <blockquote>
<p>For every request(each URL), I initialize a new web driver with selenium/phantomJS . Is this approach unscalable and will it cost a lot of CPU usage over time?</p>
</blockquote>
<p>This is definitely a problem. <code>PhantomJS</code> instances are usually heavy on CPU and it is not a reliable way to ... | 3 | 2016-06-19T13:37:47Z | [
"python",
"selenium",
"phantomjs"
] |
Creating multiple instances of PhantomJS or only one? | 37,907,798 | <p>I have a script which needs to crawl a website. For every request(each URL), I initialize a new web driver with selenium/phantomJS .
Is this approach unscalable and will it cost a lot of CPU usage over time?
Should I rather only create a single driver and save it somewhere in a global variable and reuse it for all ... | 1 | 2016-06-19T13:33:57Z | 37,908,020 | <p>PhantomJS has an embedded webserver (<a href="https://github.com/cesanta/mongoose" rel="nofollow">Mongoose</a>) that you can run and receive requests to. This avoids the need to initialize it every time. Warming up is quite costly in PhantomJS.</p>
<p>Here is a sample webserver code in PhantomJS that you could star... | 1 | 2016-06-19T13:59:15Z | [
"python",
"selenium",
"phantomjs"
] |
Fields in all subclasses of a class | 37,907,965 | <p>Let's say we have a class <code>A</code>, a class <code>B</code> that inherits from <code>A</code> and classes <code>C</code>, <code>D</code> and <code>E</code> that inherit from <code>B</code>.</p>
<p>We want all of those classes to have an attribute <code>_f</code> initialized with a default value, and we want th... | 0 | 2016-06-19T13:54:17Z | 37,908,600 | <p>If your goal is to simplify subclass constructors by eliminating the need the call the base class constructor, but still be able to override the default value in subclasses, there's a common paradigm of exploiting the fact that Python will return the class's value for an attribute if it doesn't exist on the instance... | 0 | 2016-06-19T15:01:42Z | [
"python",
"inheritance"
] |
Change state attributes to a group of widgets in Tkinter | 37,908,018 | <p>I have a checkbutton which is associated to a group of other widgets. What I would like to do is when the checkbutton is checked I want to change all the the associated/child widgets state from disabled to active. </p>
<p>I was thinking to change the state of my associated widgets from a callback function but I don... | 1 | 2016-06-19T13:59:11Z | 37,909,643 | <p>You can resolve your problem by designing your program as follows:</p>
<ul>
<li>Hold each checkbutton whith its associated group of other widgets inside one single widget (Frame or Label will be more appropriate)</li>
<li>To use a Checkbutton, you must create a Tkinter variable. To inspect the button state, query... | 0 | 2016-06-19T16:56:14Z | [
"python",
"tkinter"
] |
"Message: unknown error: cannot focus element" in python selenium driver | 37,908,026 | <p>Why does this piece of code throw an exception <code>selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element</code>? </p>
<p>As far as I can tell, I'm choosing the right element. Googling suggested to have a <code>.click()</code> on element before sending keys but that didn't hel... | 0 | 2016-06-19T13:59:33Z | 37,908,046 | <p>This is because what element you've located by the <code>pwd_field</code> class name - you've actually got a <code>span</code> element matching the locator. Instead, you meant to get to the password <code>input</code> element:</p>
<pre><code>elem = login_wait.until(EC.visibility_of_element_located((By.CLASS_NAME, '... | 1 | 2016-06-19T14:02:44Z | [
"python",
"selenium",
"selenium-webdriver"
] |
recursion with creating unique combinations | 37,908,034 | <p>I'm trying to write function that will be adding unique combinations to the list from given number.
For example when input = 3 I expect list with 123, 132, 213, 231 ... etc elements</p>
<pre><code>resultss = []
def fun(number, result=''):
if len(result) == number:
return resultss.append(result)
els... | 0 | 2016-06-19T14:00:22Z | 37,909,614 | <p>As previously stated above, in case this is not just a recursion exercise, you can do it using itertools:</p>
<pre><code>from itertools import permutations
def fun(number):
return [''.join(p)
for p in permutations([str(n) for n in range(1, number)])]
</code></pre>
| 0 | 2016-06-19T16:52:30Z | [
"python",
"recursion"
] |
Find document in MongoDB collection based on time condition and write timestamp back? | 37,908,045 | <p>I have a DB with "accounts" collection like this:</p>
<pre><code>{u'timestamp': u'2016-06-09 23:29:50.083093', u'account': u'admin:password', u'_id': ObjectId('5766932f6f340ca9a70cdb16'), u'is_valid': u'True'}
</code></pre>
<p>I need to select one document based on this condition: if is_valid is true and if timest... | 1 | 2016-06-19T14:02:30Z | 37,908,085 | <p>Use the <a href="https://docs.mongodb.com/manual/reference/operator/query/lt/" rel="nofollow"><code>$lt</code> operator</a> with a <code>datetime</code> instance passed as an argument:</p>
<pre><code>from datetime import datetime, timedelta
dt = datetime.now() - timedelta(hours=24)
res = collection.find_one({"is_v... | 2 | 2016-06-19T14:06:49Z | [
"python",
"mongodb",
"time",
"pymongo"
] |
Lyapunov Exponent Python Implementation | 37,908,104 | <p>I have 10k data points like this:</p>
<pre><code>0.010222
0.010345
0.010465
0.010611
0.010768
0.010890
0.011049
0.011206
0.011329
0.011465
0.011613
0.11763
0.011888
0.012015
0.012154
0.012282
0.012408
0.012524
....
</code></pre>
<p>I want to calculate Lyapunov exponent for that. This is what I've done so far:</p>
... | 0 | 2016-06-19T14:09:03Z | 37,909,492 | <p>I would calculate the Lyapunov Exponent in this way and then output the results as tuples in a file see blog:</p>
<p><a href="https://blog.abhranil.net/2014/07/22/calculating-the-lyapunov-exponent-of-a-time-series-with-python-code/" rel="nofollow">https://blog.abhranil.net/2014/07/22/calculating-the-lyapunov-expone... | 0 | 2016-06-19T16:37:54Z | [
"python",
"statistics"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.