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 |
|---|---|---|---|---|---|---|---|---|---|
Read range of files in pySpark | 37,732,766 | <p>I need to read contiguous files in pySpark. The following works for me.</p>
<pre><code>from pyspark.sql import SQLContext
file = "events.parquet/exportDay=2015090[1-7]"
df = sqlContext.read.load(file)
</code></pre>
<p>How do I read files 8-14?</p>
| 1 | 2016-06-09T17:38:20Z | 37,732,939 | <p>It uses shell globbing, I believe. </p>
<p>The post: <a href="http://stackoverflow.com/questions/24029873/how-to-read-multiple-text-files-into-a-single-rdd">How to read multiple text files into a single RDD?</a></p>
<p>Seems to suggest the below should work.</p>
<p>"events.parquet/exportDay=2015090[89],events.par... | 2 | 2016-06-09T17:48:44Z | [
"python",
"apache-spark",
"pyspark",
"pyspark-sql"
] |
Read range of files in pySpark | 37,732,766 | <p>I need to read contiguous files in pySpark. The following works for me.</p>
<pre><code>from pyspark.sql import SQLContext
file = "events.parquet/exportDay=2015090[1-7]"
df = sqlContext.read.load(file)
</code></pre>
<p>How do I read files 8-14?</p>
| 1 | 2016-06-09T17:38:20Z | 37,732,999 | <p>Use curly braces.</p>
<p>file = "events.parquet/exportDay=201509{08,09,10,11,12,13,14}"</p>
<p>Here's a similar question on stack overflow: <a href="http://stackoverflow.com/questions/31543766/pyspark-select-subset-of-files-using-regex-glob-from-s3">Pyspark select subset of files using regex glob</a>. They suggest... | 2 | 2016-06-09T17:52:13Z | [
"python",
"apache-spark",
"pyspark",
"pyspark-sql"
] |
Targeting nested nodegroups fails with "Minion did not return. [No response]", despite the hosts responding if targeted via other criteria | 37,732,774 | <p>I'm having an odd issue with nested nodegroups in that I can't seem to target them. Here's my nodegroups section of my master config file:</p>
<hr>
<p><strong>/etc/salt/master:</strong></p>
<pre><code>nodegroups:
linuxlabs: 'E@^pubbox'
linuxtest: 'N@linuxlabs'
</code></pre>
<hr>
<p>Now here's an example of... | 0 | 2016-06-09T17:38:46Z | 37,753,049 | <p>This does appear to be a bug. Would you mind opening an issue on SaltStack's github issue tracker?
<a href="http://github.com/saltstack/salt/issues/new" rel="nofollow">http://github.com/saltstack/salt/issues/new</a></p>
<p>Thanks!</p>
| 1 | 2016-06-10T16:26:51Z | [
"python",
"salt-stack"
] |
Failed to log in: 'NoneType' object has no attribute 'cancel' | 37,732,801 | <p><img src="http://i.stack.imgur.com/dWJ1m.jpg" alt="!!LOGIN ERROR !!">I am trying to login in Cassandra Opscenter i started seeing this message.How to get around this.</p>
<p>I was able to login yesterday also but from today morning i couldn't. I started seeing this error in opscenterd log file.</p>
<pre><code>Unha... | 1 | 2016-06-09T17:40:44Z | 37,733,353 | <p>This appears to be an instance of a bug we're tracking as OPSC-5380. Fortunately there is a workaround: refreshing your browser should allow you to login again.</p>
| 2 | 2016-06-09T18:13:43Z | [
"python",
"cassandra",
"datastax",
"opscenter"
] |
Failed to log in: 'NoneType' object has no attribute 'cancel' | 37,732,801 | <p><img src="http://i.stack.imgur.com/dWJ1m.jpg" alt="!!LOGIN ERROR !!">I am trying to login in Cassandra Opscenter i started seeing this message.How to get around this.</p>
<p>I was able to login yesterday also but from today morning i couldn't. I started seeing this error in opscenterd log file.</p>
<pre><code>Unha... | 1 | 2016-06-09T17:40:44Z | 37,734,374 | <p>Refreshing browser hasn't helped but Restarting opscenterd service on opscenter node has helped in fixing the issue.</p>
| 0 | 2016-06-09T19:13:09Z | [
"python",
"cassandra",
"datastax",
"opscenter"
] |
How to manipulate data from file and sort python | 37,732,808 | <p>I have a .dat file with this information inside (but the real file with thousans of lines): </p>
<pre><code> n a (au) k0 k1 P1 k2
1 3.156653 2 3 5 -18
2 3.152517 2 5 5 -23
3 3.154422 3 -18 5 29
4 3.151668 3 -16 5 24
5 3.158629 5 ... | 1 | 2016-06-09T17:41:17Z | 37,732,942 | <p>I suggest using the pandas library. Read the .dat file in as a dataframe - it's a very powerful tool through which you can manipulate data, add columns, etc. </p>
<pre><code>import pandas as pd
with open('../pascal.dat') as f:
df = pd.Dataframe(f)
center = 3.15
df['distance'] = abs(3.15 - df['a (au)'])
</cod... | 2 | 2016-06-09T17:48:48Z | [
"python",
"sorting"
] |
Install RPi module on Pycharm | 37,732,918 | <p>I've been using IDLE with my raspberry for a while, it's nice at the beginning, but <strong>Pycharm</strong> provides lots more of features and I'm used to them since I've been also using Android Studio.</p>
<p>The problem is I couldn't figure out how to install the <strong>RPi module</strong> to control the pins o... | 0 | 2016-06-09T17:48:01Z | 37,733,258 | <p>As far as I know there is no way of installing it on your desktop but PyCharm has a remote programming feature that allows you to use the PyCharm interface through an ssh connection to your raspberry pi. See this <a href="http://www.codeproject.com/Tips/987276/Remote-Programming-of-RaspberryPi-using-PyCharm" rel="no... | 1 | 2016-06-09T18:08:25Z | [
"python",
"raspberry-pi",
"pycharm"
] |
Crawling output into multiple csv files | 37,733,086 | <p>I would like to know how to export my results from crawling into multiple csv files for each different city that I have crawled. Somehow I´m running into walls, do not get a proper way to sort it out.</p>
<p>That is my code:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
import csv
user_agent = {'U... | 0 | 2016-06-09T17:58:30Z | 37,734,680 | <p>I did some minor modifications to your code. To make files for each locale, I moved the out_file name inside the loop.</p>
<p>Note, that I don't have time now, the very last line is a hack to ignore unicode errors -- it just skips trying to output a line with a non ascii character. Thas isn't good. Maybe someone... | 1 | 2016-06-09T19:30:18Z | [
"python",
"csv",
"beautifulsoup",
"web-crawler"
] |
Python nosetests with coverage no longer shows missing lines | 37,733,194 | <p>I've been using the following command to run tests and evaluate code coverage for a Python project for over a year now.</p>
<pre><code>nosetests -v --with-coverage --cover-package=genhub genhub/*.py
</code></pre>
<p>The coverage report used to include a column on the far right showing the lines missing coverage.</... | 7 | 2016-06-09T18:05:02Z | 37,746,141 | <p>In coverage.py 4.1, I fixed a problem with the coverage.py API defaulting two parameters to non-None values. One of them was <code>show_missing</code>.</p>
<p>The best way to fix this in your project is to set <code>show_missing</code> in your .coveragerc file:</p>
<pre><code># .coveragerc
[report]
show_missing =... | 10 | 2016-06-10T10:39:45Z | [
"python",
"nose",
"coverage.py"
] |
Python nosetests with coverage no longer shows missing lines | 37,733,194 | <p>I've been using the following command to run tests and evaluate code coverage for a Python project for over a year now.</p>
<pre><code>nosetests -v --with-coverage --cover-package=genhub genhub/*.py
</code></pre>
<p>The coverage report used to include a column on the far right showing the lines missing coverage.</... | 7 | 2016-06-09T18:05:02Z | 37,754,335 | <p>No need to revert back to 3.7.1
You can just downgrade to 4.0.0</p>
| 1 | 2016-06-10T17:46:07Z | [
"python",
"nose",
"coverage.py"
] |
Python nosetests with coverage no longer shows missing lines | 37,733,194 | <p>I've been using the following command to run tests and evaluate code coverage for a Python project for over a year now.</p>
<pre><code>nosetests -v --with-coverage --cover-package=genhub genhub/*.py
</code></pre>
<p>The coverage report used to include a column on the far right showing the lines missing coverage.</... | 7 | 2016-06-09T18:05:02Z | 38,290,650 | <p>Try to use <code>nosetest --verbosity=2</code> option. Prints missing column for me.</p>
| 0 | 2016-07-10T09:56:37Z | [
"python",
"nose",
"coverage.py"
] |
Python nosetests with coverage no longer shows missing lines | 37,733,194 | <p>I've been using the following command to run tests and evaluate code coverage for a Python project for over a year now.</p>
<pre><code>nosetests -v --with-coverage --cover-package=genhub genhub/*.py
</code></pre>
<p>The coverage report used to include a column on the far right showing the lines missing coverage.</... | 7 | 2016-06-09T18:05:02Z | 39,683,778 | <p>Beside having a configuration files to set <code>show_missing</code> you can also use coverage <code>set_option</code> to define it.</p>
<pre><code>cov.set_option('report:show_missing', True)
</code></pre>
<p>I have issue with getting the correct coverage for <code>models.py</code>, i solve it according to <a href... | 0 | 2016-09-25T05:40:13Z | [
"python",
"nose",
"coverage.py"
] |
Python: Set many variables to the same value â with automatic count of number of variables | 37,733,216 | <p>I want to create a lot of variables, all containing the same value.</p>
<p>Currently, I do this:</p>
<pre><code>foo, bar, qaxx, spat = ("1Value4All",)*4
</code></pre>
<p>I would like to keep the code footprint at a minimum (one line here), but at the same time it's troublesome if there are many variables, because... | 2 | 2016-06-09T18:06:02Z | 37,733,292 | <p>You can use multiple equal signs on the same line:</p>
<pre><code>foo = bar = qaxx = spat = "1Value4All"
</code></pre>
| 2 | 2016-06-09T18:10:17Z | [
"python"
] |
Python: Set many variables to the same value â with automatic count of number of variables | 37,733,216 | <p>I want to create a lot of variables, all containing the same value.</p>
<p>Currently, I do this:</p>
<pre><code>foo, bar, qaxx, spat = ("1Value4All",)*4
</code></pre>
<p>I would like to keep the code footprint at a minimum (one line here), but at the same time it's troublesome if there are many variables, because... | 2 | 2016-06-09T18:06:02Z | 37,733,298 | <p>You can chain all the variables together in one line.</p>
<pre><code>foo = bar = qaxx = spat = "1Value4All"
</code></pre>
<p>Edit: Below you state your data is either string or NoneType. This would work for both.</p>
<pre><code>>>> foo = bar = None
>>> type(foo); type(bar)
<type 'NoneType'>... | 3 | 2016-06-09T18:10:35Z | [
"python"
] |
Python: Set many variables to the same value â with automatic count of number of variables | 37,733,216 | <p>I want to create a lot of variables, all containing the same value.</p>
<p>Currently, I do this:</p>
<pre><code>foo, bar, qaxx, spat = ("1Value4All",)*4
</code></pre>
<p>I would like to keep the code footprint at a minimum (one line here), but at the same time it's troublesome if there are many variables, because... | 2 | 2016-06-09T18:06:02Z | 37,733,587 | <p>You can have a default dictionary, that will create a new value for a key whenever you want it. Then you should use values from that dictionary - not as stand alone variables. Variable names are supposed to be hard coded in your program - if names or quantity are varying, you should be using a dictionary and accessi... | 1 | 2016-06-09T18:27:47Z | [
"python"
] |
Explaining the difference between sklearn's scale() and multiplying by STD and adding the mean | 37,733,225 | <p>I'm running sklearn's PCA <code>fit_transform()</code> function on some data I'm looking to analyze, and I'm having trouble figuring out how exactly I need to transform scaled data back into numbers that make sense within the context of what I'm running. More specifically, when I run:</p>
<pre><code>import pandas ... | 2 | 2016-06-09T18:06:41Z | 37,733,499 | <p>sklearn uses zero degrees of freedom in their standard deviation calculation:</p>
<pre><code>import pandas as pd
import numpy as np
from sklearn.preprocessing import scale
np.random.seed([3,1415])
otr_df = pd.DataFrame(np.random.rand(10, 10))
X_scaled = scale(otr_df)
X_scaled2 = otr_df.sub(otr_df.mean())
X_scale... | 3 | 2016-06-09T18:22:47Z | [
"python",
"numpy",
"pandas",
"scikit-learn"
] |
Error instantiating the InteractiveSession using TensorFlow and Jupyter | 37,733,245 | <p>Recently I've been getting an error using the InteractiveSession in TensorFlow in my Jupyter / IPython notebook. The problem is so straight forward to recreate, my entire code is:</p>
<pre><code>import tensorflow as tf
sess = tf.InteractiveSession()
sess.graph
</code></pre>
<p>And the output is:</p>
<pre><code>... | 1 | 2016-06-09T18:07:46Z | 37,733,547 | <p>This error message is caused by a bug in TensorFlow versions 0.8 and earlier. The bug is triggered when a new <code>tf.InteractiveSession</code> is created before an old one is deleted by the Python garbage collector. It was <a href="https://github.com/tensorflow/tensorflow/commit/aec225cbc1d6c2dd9ee51e09996a38c868e... | 1 | 2016-06-09T18:25:15Z | [
"python",
"ipython",
"tensorflow",
"jupyter"
] |
How do I make pandas installed via Anaconda usable by PyCharm? | 37,733,276 | <p>I'm on Windows 10 and have installed Anaconda3 (2016-1). When I use Spyder that Anaconda installed, <code>import pandas</code> works.</p>
<p>From PyCharm I however can't <code>import pandas</code>. PyCharm is set to use <code>C:\Users\Chris>C:\Users\Chris\Anaconda3\envs\Conda\python.exe</code>.</p>
<p>If I call... | 0 | 2016-06-09T18:09:21Z | 37,733,721 | <p>It works when I set the path to <code>C:\Users\Chris>C:\Users\Chris\Anaconda3\python.exe</code> instead of using a virtual enviroment with <code>C:\Users\Chris>C:\Users\Chris\Anaconda3\envs\Conda\python.exe</code> as PyCharm suggests.</p>
| 0 | 2016-06-09T18:35:12Z | [
"python",
"pandas",
"pycharm",
"anaconda"
] |
Website google oauth needed | 37,733,407 | <p>Probably this was already answered somewhere, but my google-fu can't get proper keywords for this.
Ok so, I need to get a file from my site which is like <em>foo.bar/foobar/file.ext</em> . That file is always accessible but if you aren't google-authenticated on the site you get a blank file.
How can I get proper au... | 0 | 2016-06-09T18:16:50Z | 37,733,490 | <p>First install the <a href="https://developers.google.com/api-client-library/python/start/installation" rel="nofollow">Python SDK here</a>.</p>
<p>Then I would start reading about <a href="https://developers.google.com/api-client-library/python/guide/aaa_oauth" rel="nofollow">OAuth here</a>. </p>
<p>They have diffe... | -1 | 2016-06-09T18:22:03Z | [
"python",
"google-oauth"
] |
Django: Setting LOGGER doesn't work | 37,733,555 | <p>I'm having trouble with Django's logging system. My goal is to log all types of logs to the files, and only log to the console if <code>DEBUG</code> is set to <code>True</code> (which it is right now)</p>
<p>As it is, the log files remain blank (although they are created by Django). When I start the server (using <... | 0 | 2016-06-09T18:25:38Z | 37,734,831 | <p>Your <strong>__init__.py</strong> file is called before <strong>settings.py</strong></p>
<p>Move your code from <strong>__init__.py</strong> to any other file, which will be called after <strong>settings.py</strong></p>
| 1 | 2016-06-09T19:40:34Z | [
"python",
"django",
"debugging",
"logging",
"console"
] |
Django: Setting LOGGER doesn't work | 37,733,555 | <p>I'm having trouble with Django's logging system. My goal is to log all types of logs to the files, and only log to the console if <code>DEBUG</code> is set to <code>True</code> (which it is right now)</p>
<p>As it is, the log files remain blank (although they are created by Django). When I start the server (using <... | 0 | 2016-06-09T18:25:38Z | 38,685,513 | <p>I don't have enough points to add a comment, so I'll mention in here that if your logging format uses <code>%(name)s</code> then a useful extension to the above answer is, in the files where you have:</p>
<pre><code>logr = logging.getLogger('project')
</code></pre>
<p>you could use:</p>
<pre><code>logr = logging.... | 1 | 2016-07-31T15:28:30Z | [
"python",
"django",
"debugging",
"logging",
"console"
] |
Why does my script write every input string twice to the output file? | 37,733,703 | <p>When I look at what it wrote it's always double. For example if I write 'dog' ill get 'dogdog'. Why?</p>
<p>Reading and writing to file, filename taken from command line arguments: </p>
<pre><code>from sys import argv
script,text=argv
def reading(f):
print f.read()
def writing(f):
print f.write(line)
f... | 0 | 2016-06-09T18:34:09Z | 37,733,939 | <p>You are getting double value because you are writing two times
<br></p>
<p>1) From the Function call </p>
<pre><code>def writing(f):
print f.write(line)
</code></pre>
<p>2) By writing in file using <code>filename.write(line)</code></p>
<p>Use this code: </p>
<pre><code>from sys import argv
script,text=arg... | 0 | 2016-06-09T18:48:17Z | [
"python",
"python-2.7"
] |
Why does my script write every input string twice to the output file? | 37,733,703 | <p>When I look at what it wrote it's always double. For example if I write 'dog' ill get 'dogdog'. Why?</p>
<p>Reading and writing to file, filename taken from command line arguments: </p>
<pre><code>from sys import argv
script,text=argv
def reading(f):
print f.read()
def writing(f):
print f.write(line)
f... | 0 | 2016-06-09T18:34:09Z | 37,735,492 | <p>If you want to display each line and then write a new line, you should probably just read the entire file first, and then loop over the lines when writing new content. </p>
<p>Here's how you can do it. When you use <code>with open()</code>, you don't have to <code>close()</code> the file, since that's done automati... | 0 | 2016-06-09T20:25:02Z | [
"python",
"python-2.7"
] |
Importing strings from a file, into a list, using python | 37,733,843 | <p>I have a txt file, with these contents:</p>
<pre><code>a,b
c,d
e,f
g,h
i,j
k,l
</code></pre>
<p>And i am putting them into a list, using these lines:</p>
<pre><code>keywords=[]
solutions=[]
for i in file:
keywords.append((i.split(","))[0])
solutions.append(((i.split(","))[1]))
</code></pre>
<p>but when I... | 1 | 2016-06-09T18:42:43Z | 37,733,868 | <p>You need to <a href="https://docs.python.org/2/library/string.html#string.strip" rel="nofollow"><code>string.strip()</code></a> the whitespace/new-line characters from the string after reading it to remove the <code>\n</code>:</p>
<pre><code>keywords=[]
solutions=[]
for i_raw in file:
i = i_raw.strip() # <--... | 0 | 2016-06-09T18:43:39Z | [
"python",
"list"
] |
Importing strings from a file, into a list, using python | 37,733,843 | <p>I have a txt file, with these contents:</p>
<pre><code>a,b
c,d
e,f
g,h
i,j
k,l
</code></pre>
<p>And i am putting them into a list, using these lines:</p>
<pre><code>keywords=[]
solutions=[]
for i in file:
keywords.append((i.split(","))[0])
solutions.append(((i.split(","))[1]))
</code></pre>
<p>but when I... | 1 | 2016-06-09T18:42:43Z | 37,733,952 | <p>You can use <code>str.strip()</code> in order to trimming the last whitespace. But as a more pythonic approach you better to use <code>csv</code> module for loading your file content which will accept a delimiter and return an iterable contain tuples of separated items (here, the characters). The use <code>zip()</co... | 2 | 2016-06-09T18:48:57Z | [
"python",
"list"
] |
Creating a BulletCollisionShape from an .egg file | 37,733,916 | <p>I'm writing a game using Panda3D 1.10 using the <a href="http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Main_Page" rel="nofollow">Bullet Open Source Physics Library 1.5.8</a>. How do I generate a collision shape from an egg file?</p>
<p>This is the code I have so far:</p>
<pre><code> tree = BulletRigidB... | 0 | 2016-06-09T18:46:20Z | 38,624,752 | <p>I think that I've got a soulution, however, I also have problems.</p>
<pre class="lang-python prettyprint-override"><code>def toShape(model):
shape=BulletTriangleMesh()
geomNodeCollection = model.findAllMatches('**/+GeomNode')
for nodePath in geomNodeCollection:
geomNode = nodePath.node()
... | 0 | 2016-07-27T23:23:48Z | [
"python",
"bulletphysics",
"panda3d"
] |
Dash in dictionary key and eval | 37,734,153 | <p>Before I get beat to death by the 'eval is evil' crowd, it's a necessary evil in this case and I can't change it. Eval has it's uses, and in a tightly controlled environment it's very powerful.</p>
<p>However, I have an issue with no obvious solution and I'm hoping for outside the box thinking.</p>
<pre><code>>... | 1 | 2016-06-09T18:59:54Z | 37,737,576 | <p>You're trying to make the string "a-b" a symbol during your evaluation. Traditionally, this doesn't work because "-" (hyphen) isn't <em>word</em>. Only the [A-Za-z0-9_] (<em>word</em>) characters can be used in symbol names. Changing hyphen to underscore works fine:</p>
<pre><code>>>> mydict = {"a_b": "... | 1 | 2016-06-09T23:06:38Z | [
"python"
] |
Dash in dictionary key and eval | 37,734,153 | <p>Before I get beat to death by the 'eval is evil' crowd, it's a necessary evil in this case and I can't change it. Eval has it's uses, and in a tightly controlled environment it's very powerful.</p>
<p>However, I have an issue with no obvious solution and I'm hoping for outside the box thinking.</p>
<pre><code>>... | 1 | 2016-06-09T18:59:54Z | 37,738,007 | <p>Instead of using <code>mydict</code> as the global variable dict for the evaluated expression, give the user access to it as a dict:</p>
<pre><code>eval(user_expression, {'data': mydict})
</code></pre>
<p>Then the user accesses it with expressions like</p>
<pre><code>data['a-b']
</code></pre>
<p>instead of tryin... | 1 | 2016-06-09T23:58:02Z | [
"python"
] |
Pytest: associate parameterized fixtures with expected results | 37,734,166 | <p>Say I have the following test:</p>
<pre class="lang-python prettyprint-override"><code>@pytest.fixture(params=['a'])
def ascii(request):
return ord(request.param)
def test_ascii(ascii):
assert ascii == 97
</code></pre>
<p>This works great. Now say I'd like to add <code>'b'</code> as a parameter. Ideally I... | 0 | 2016-06-09T19:00:22Z | 37,742,602 | <p>At least for the simple example you're giving, why use a parametrized fixture instead of parametrizing your test?</p>
<p>Something like this should work:</p>
<pre><code>@pytest.mark.parametrize('char, expected', [('a', 97), ('b', 98)])
def test_ascii(char, expected):
assert ord(char) == expected
</code></pre>
... | 1 | 2016-06-10T07:40:27Z | [
"python",
"unit-testing",
"py.test",
"fixtures"
] |
understanding method use inside a class | 37,734,168 | <p>I'm new to classes, this is a small piece of code I've written, but I'm still really shaky on this concept, and am wondering exactly how the method <code>node_name</code> comes into play here and if it's even needed? </p>
<pre><code>from rdflib import BNode
class HigherNode(object):
def node_name(name):
... | 0 | 2016-06-09T19:00:27Z | 37,734,523 | <p>So, first off, methods have to be called by an instance of the class. So, your behavior would look something like this:</p>
<pre><code># create an instance
node = HigherNode()
# get the name
print node.node_name()
</code></pre>
<p>However, you never declared name inside the class. So, you'll have to do something ... | 1 | 2016-06-09T19:21:51Z | [
"python"
] |
Python limit on input function in terminal | 37,734,180 | <p>I am currently using the input function to capture user inputs in the terminal and copy them to the clipboard where it is then used by another application. </p>
<p>Wierdly it appears that there is a limit to the number of characters that you can enter when using input in the terminal when running the script in batc... | 0 | 2016-06-09T19:01:22Z | 37,734,555 | <p>Just doing it in command prompt I'm not seeing any limits for either the input prompt or the value given in the input, it might be a powershell issue.</p>
<p>Test script I used:</p>
<pre><code>import os
var = ""
for i in range(0,500):
var += "Input"
var += "?: "
var2 = input(var)
print(var2)
os.system('pa... | 0 | 2016-06-09T19:23:38Z | [
"python",
"python-3.x",
"powershell",
"input",
"windows-7"
] |
openpyxl - convert one column to numbers | 37,734,197 | <p>I am a new programmer so please bare with me. </p>
<p>I have a program I am building - it asks for a csv file and saves it in excel. I have one column that is currency - $10.00 - I can convert other cells to number with my code but I assume since there is a '$' before the numbers it does not convert. How can I fix ... | 0 | 2016-06-09T19:02:36Z | 37,742,299 | <p>In a CSV file <strong>all</strong> values are strings. openpyxl workbooks have an <a href="http://openpyxl.readthedocs.io/en/latest/usage.html?highlight=guess_types#using-number-formats" rel="nofollow">option that will let them do type inference</a> but you are better managing the conversion yourself and, in this ca... | 0 | 2016-06-10T07:25:05Z | [
"python",
"openpyxl"
] |
mypy explicit type hint in quotes still gives not defined error | 37,734,209 | <p>I am trying to do the following thing:</p>
<pre><code>self.sender = None # type: 'Node'
</code></pre>
<p>I can't import Node because I would get an cycle. So I write it in quotes like mentioned here
<a href="http://mypy.readthedocs.io/en/latest/common_issues.html#import-cycles" rel="nofollow">http://mypy.readthedo... | 0 | 2016-06-09T19:03:24Z | 38,962,160 | <p>Short answer, you need to include the module name of the class, and you need to import that module within some unreachable code, like this:</p>
<pre><code>if False:
# for forward-reference type-checking:
import mymodule
class MyClass(object):
def __init__(self):
self.sender = None # type: 'mym... | 0 | 2016-08-15T19:59:28Z | [
"python",
"typing",
"mypy"
] |
When does Python raise UnicodeDecodeError when searching in string | 37,734,231 | <p>I have this piece of code that reads from a gunzip stream and checks if each line contains some pattern. What I have is </p>
<pre><code>if (pattern in line):
do_something()
</code></pre>
<p>Some lines contain non-ASCII characters, when my code reaches those lines, I get a UnicodeDecodeError. However, I am unab... | 1 | 2016-06-09T19:05:17Z | 37,734,704 | <p>I find the root cause of my problem. Somehow, in my actual code <code>pattern</code> has type <code>unicode</code> instead of <code>str</code>, but in manual testing my <code>pattern</code> is just a <code>str</code> that I type in. This causes the different behaviro I observed. </p>
| 1 | 2016-06-09T19:32:15Z | [
"python"
] |
Extract text between digits - Python | 37,734,262 | <p>(Using Python 2.7)</p>
<p>Imagine a contract that has, among other text, text blocks separated by section numbers. I am trying to extract each section's text and put it into a new document. So, if a two hundred page contract had thirty sections separated by section numbers I want these thirty sections in a new docu... | 1 | 2016-06-09T19:06:34Z | 37,734,386 | <p>Wouldn't this just work?</p>
<pre><code>import codecs
import re
# find anything that matches the header number pattern
regex = r'\d\.\d\.\d\.\d\.\s'
# read a contract in
with codecs.open("/Users/someuser/x/y/blah.txt", "r","utf-8") as ins:
text = ins.read()
# perform magics, replace with empty string
output ... | 1 | 2016-06-09T19:13:37Z | [
"python",
"regex"
] |
Extract text between digits - Python | 37,734,262 | <p>(Using Python 2.7)</p>
<p>Imagine a contract that has, among other text, text blocks separated by section numbers. I am trying to extract each section's text and put it into a new document. So, if a two hundred page contract had thirty sections separated by section numbers I want these thirty sections in a new docu... | 1 | 2016-06-09T19:06:34Z | 37,735,287 | <p>Ok, so if I understand correctly, you want to capture everything between the section numbers.</p>
<p>Here's the regex string I came up with: <code>regex = r'(?:\d\.){4}.(.+?)(?:\d\.){4}'</code></p>
<p>Let's break that down a little:</p>
<p><code>(?:\d\.){4}</code> this is our 4 numbers followed by a period. the <... | 1 | 2016-06-09T20:10:09Z | [
"python",
"regex"
] |
Python :: Intersecting lists of strings gone wrong | 37,734,335 | <p>I am trying to intersect lists of sentences divided into strings:</p>
<pre><code> user = ['The', 'Macbeth', 'Tragedie'] #this list
plays = []
hamlet = gutenberg.sents('shakespeare-hamlet.txt')
macbeth = gutenberg.sents('shakespeare-macbeth.txt')
caesar = gutenberg.sents('shakespeare-caesar.txt')... | 1 | 2016-06-09T19:10:30Z | 37,735,246 | <p>Doesn't sound like you should be using sets here. The most obvious problem is that you care about the number of occurrences of a word in a sentence (which starts life as a list), and by converting to a set you collapse all repeated words down to one occurrence, losing that information.</p>
<p>I would suggest rather... | 0 | 2016-06-09T20:07:24Z | [
"python",
"list"
] |
How does the collectAsMap() function work for Spark API | 37,734,398 | <p>I am trying to understand as to what happens when we run the collectAsMap() function in spark. As per the Pyspark docs,it says,</p>
<blockquote>
<p>collectAsMap(self)
Return the key-value pairs in this RDD to the master as a dictionary.</p>
</blockquote>
<p>and for core spark it says,</p>
<blockquote>
<p>de... | 0 | 2016-06-09T19:14:05Z | 37,735,069 | <p>The semantics of <code>collectAsMap</code> are identical between the Scala and Python APIs so I'll look at the first WLOG. The documentation for <a href="http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.rdd.PairRDDFunctions@collectAsMap():Map[K,V]" rel="nofollow"><code>PairRDDFunctions.colle... | 1 | 2016-06-09T19:55:11Z | [
"python",
"scala",
"apache-spark",
"pyspark"
] |
Multiple filters on mongoDB mongoengine | 37,734,406 | <p>For a project on network security that I'm working on, I have a list of every IP in my country (and other relevant fields) in a mongoDB collection. </p>
<p>Like this:</p>
<pre><code>{
"_id" : ObjectId("56674d3d9ee3d40b79167e09"),
"ip" : "200.6.116.75",
"server" : "Microsoft-IIS/7.5",
"date" : "2015... | 0 | 2016-06-09T19:14:31Z | 37,737,462 | <p>To have an efficient query parameter for IP lookup, I probably will go to extend the way how IP is stored.</p>
<p>As per normal notation we have just string which cannot be easily extracted to set of 4 integers in mongo, what do you think to store address in such form:</p>
<pre><code>{
"ip" : "200.6.116.75",
... | 1 | 2016-06-09T22:53:38Z | [
"python",
"mongodb",
"networking",
"mongoengine"
] |
Pandas series - only keep value if index month is in [1,2,3] | 37,734,413 | <p>I have a pandas.Series() object and I am trying to filter the data based on the month in the index. Here is an example Series object (index is ["2010-01-01", "2010-02-01", ..., "2016-06-01"]):</p>
<pre><code>d = pd.Series(1, pd.date_range("20100101", periods=100, freq="MS"))
</code></pre>
<p>I would like to keep o... | 1 | 2016-06-09T19:15:09Z | 37,734,475 | <p>try:</p>
<pre><code>d.loc[pd.Series(d.index.month, d.index).isin([1, 2, 3])]
</code></pre>
| 2 | 2016-06-09T19:18:52Z | [
"python",
"numpy",
"pandas",
"scipy"
] |
Exclude day from Pandas Dataframe date range | 37,734,417 | <p>If I want to select a range from the following dataframe I can use this command:</p>
<pre><code>bars_specified_days = bars['2016-05-27':'2016-06-03']
</code></pre>
<p>How do I exclude a single day (2016-05-30) from the range 2016-05-27:2016-06-03?</p>
<hr>
<pre><code>bars_specified_days.describe
<bound metho... | 0 | 2016-06-09T19:15:32Z | 37,734,460 | <pre><code>frame[frame.index != '2016-05-30']
</code></pre>
| 3 | 2016-06-09T19:18:13Z | [
"python",
"pandas"
] |
how to use scipy.optimize.minimize function when you want to compute gradient along with the objective function? | 37,734,430 | <p><code>scipy.optimize.minimze</code> takes <code>obj</code> and <code>jac</code> functions as input. and I believe it will call them separately as and when needed. But more often than not we come across objective functions whose gradient computation shares a lot of computations from the objective function. So ideally... | 2 | 2016-06-09T19:16:21Z | 37,735,355 | <p>You totally can. Just use <code>jac=True</code>:</p>
<pre><code>In [1]: import numpy as np
In [2]: from scipy.optimize import minimize
In [3]: def f_and_grad(x):
...: return x**2, 2*x
...:
In [4]: minimize(f_and_grad, [1], jac=True)
Out[4]:
fun: 1.8367099231598242e-40
hess_inv: array([[ 0.5]])... | 2 | 2016-06-09T20:14:35Z | [
"python",
"scipy",
"scikit-learn"
] |
Why is subprocess.run output different from shell output of same command? | 37,734,470 | <p>I am using <code>subprocess.run()</code> for some automated testing. Mostly to automate doing:</p>
<pre><code>dummy.exe < file.txt > foo.txt
diff file.txt foo.txt
</code></pre>
<p>If you execute the above redirection in a shell, the two files are always identical. But whenever <code>file.txt</code> is too lo... | 4 | 2016-06-09T19:18:38Z | 37,736,987 | <p>I'll start with a disclaimer: I don't have Python 3.5 (so I can't use the <code>run</code> function), and I wasn't able to reproduce your problem on Windows (Python 3.4.4) or Linux (3.1.6). That said...</p>
<h1>Problems with <code>subprocess.PIPE</code> and Family</h1>
<p>The <a href="https://docs.python.org/3/l... | 0 | 2016-06-09T22:07:21Z | [
"python",
"c++",
"python-3.x",
"subprocess",
"io-redirection"
] |
Why is subprocess.run output different from shell output of same command? | 37,734,470 | <p>I am using <code>subprocess.run()</code> for some automated testing. Mostly to automate doing:</p>
<pre><code>dummy.exe < file.txt > foo.txt
diff file.txt foo.txt
</code></pre>
<p>If you execute the above redirection in a shell, the two files are always identical. But whenever <code>file.txt</code> is too lo... | 4 | 2016-06-09T19:18:38Z | 37,751,832 | <p>To reproduce, the shell command:</p>
<pre><code>subprocess.run("dummy.exe < file.txt > foo.txt", shell=True, check=True)
</code></pre>
<p>without the shell in Python:</p>
<pre><code>with open('file.txt', 'rb', 0) as input_file, \
open('foo.txt', 'wb', 0) as output_file:
subprocess.run(["dummy.exe"]... | 2 | 2016-06-10T15:21:34Z | [
"python",
"c++",
"python-3.x",
"subprocess",
"io-redirection"
] |
Install Wheel on Raspberry Pi 2 failing - IncompleteRead | 37,734,499 | <p>I'm trying to install a wheel file and keep stumbling over the following error:</p>
<pre><code>pi@raspberrypi:~ $ pip-3.2 install DsController-1.0-py3-none-any.whl
Traceback (most recent call last):
File "/usr/bin/pip-3.2", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip3')()... | 0 | 2016-06-09T19:20:04Z | 37,763,789 | <p>You are not picking up the version of <code>pip</code> that you have installed when running <code>pip-3.2</code>.</p>
<p>As you can see, <a href="https://github.com/pypa/pip/blob/8.1.2/pip/download.py" rel="nofollow">version 8.1.2 of download.py</a> does not import IncompleteRead. However, <a href="https://github.... | 1 | 2016-06-11T12:35:07Z | [
"python",
"pip",
"raspberry-pi2"
] |
savefig loop adds previous plots to figure | 37,734,512 | <p>I am trying to use a forloop to produce figures for each set of data I have, but while the .show() command produces the correct figure, .savefig() keeps adding the previous plotted values to the new figure.
In my forloop, this is the relevant sample of the code.</p>
<pre><code>import matplotlib.pyplot as plt
plt.p... | 1 | 2016-06-09T19:21:07Z | 37,736,370 | <p>You have to close current figure after saving with function
<code>plt.close()</code>: <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.close" rel="nofollow">http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.close</a></p>
<p>Or you have to clean current figure after saving by <code>plt.... | 0 | 2016-06-09T21:19:51Z | [
"python",
"for-loop",
"matplotlib",
"plot"
] |
I got bad matching results with OpenCV and SIFT. How could I improve it? | 37,734,570 | <p>I tried to create a matcher which uses sift to detect and match key-points. I tried to use it but I didn't get the results what I expected. It turns out it's not so scale and rotation invariant in my implementation. What is wrong with my code?</p>
<pre><code>import numpy as np
import cv2
from matplotlib import pypl... | 0 | 2016-06-09T19:24:58Z | 37,735,783 | <p>You are using HAMMING norm and SIFT isn't a binary descriptor.</p>
<pre><code>bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
</code></pre>
<p>Use euclidean norm instead, should work much better.</p>
| 0 | 2016-06-09T20:42:10Z | [
"python",
"opencv",
"sift"
] |
I got bad matching results with OpenCV and SIFT. How could I improve it? | 37,734,570 | <p>I tried to create a matcher which uses sift to detect and match key-points. I tried to use it but I didn't get the results what I expected. It turns out it's not so scale and rotation invariant in my implementation. What is wrong with my code?</p>
<pre><code>import numpy as np
import cv2
from matplotlib import pypl... | 0 | 2016-06-09T19:24:58Z | 37,735,835 | <p>As @taarraas mentioned, SIFT is not a binary descriptor, but I also suggest adding this:</p>
<pre><code>good = []
for m,n in matches:
if m.distance < 0.75*n.distance:
good.append([m])
</code></pre>
<p>And then only using <code>good</code> instead of all your matches, that way you help eliminate nois... | 0 | 2016-06-09T20:45:38Z | [
"python",
"opencv",
"sift"
] |
Copy and paste cells with python | 37,734,659 | <p>I am trying to copy cells value from one workbook to another. I need to copy cells A1,A2,B4,B5,B6,B7 from Sheet2 and paste into new workbook in cells A1,B1,C1,D1,E1,F1.
How can I do this with python? </p>
<pre><code>import xlrd
file_location = "C:/attach/Source.xlsx"
workbook = xlrd.open_workbook(file_location)
sh... | 0 | 2016-06-09T19:29:16Z | 37,734,789 | <p>The process goes like this:</p>
<ul>
<li>open the workbook to read from with xlrd as your code does already</li>
<li>create a new workbook with <code>xlwt</code>: <code>wb = xlwt.Workbook()</code></li>
<li>create a new sheet in the new workbook: <code>ws = wb.add_sheet('Sheet1')</code></li>
<li>copy your cells to t... | 0 | 2016-06-09T19:38:52Z | [
"python",
"excel"
] |
AWS Python Lambda with Oracle | 37,734,748 | <p>I am trying to connect to an Oracle db from AWS Lambda using python. I managed to package cx_Oracle but the environment is not finding the dependencies.</p>
<p>I had zipped the content, which contained cx_Oracle.so and cx_Oracle-5.2.1-py2.7.egg-info (created on 64bit AWX Linux). I also added the files from instantc... | -1 | 2016-06-09T19:35:49Z | 37,753,311 | <p>Resolved. Added all dependencies by running
<code>ldd cx_Oracle.so| grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' /destination</code>
Added all those files in destination to lib folder in lambda zip</p>
| 0 | 2016-06-10T16:43:09Z | [
"python",
"oracle",
"amazon-web-services",
"lambda"
] |
Getting KeyError when parsing JSON containing three layers of keys, using Python | 37,734,752 | <p>I'm building a Python program to parse some calls to a social media API into CSV and I'm running into an issue with a key that has two keys above it in the hierarchy. I get this error when I run the code with PyDev in Eclipse.</p>
<pre><code>Traceback (most recent call last):
line 413, in <module>
main(... | 1 | 2016-06-09T19:36:07Z | 37,735,067 | <p>Edited(This works):</p>
<pre><code>JSON=json.loads(s)
for i in JSON:
print str(JSON[i][0]["ageCount"]["sortedAgeCounts"]["ZERO_TO_SEVENTEEN"])
</code></pre>
<p><code>s</code> is a string which contains the your JSON.</p>
| 0 | 2016-06-09T19:55:01Z | [
"python",
"json",
"python-3.x"
] |
How to get SQL server returned message? | 37,734,835 | <p>If I use SQL Management Studio. When I create/drop tables, or do any updates, I can see messages like:</p>
<pre><code>"Command(s) completed successfully."
"Cannot drop the table 'my_table', because it does not exist or you do not have permission."
</code></pre>
<p>But if I use python to execute the same query:</p>... | 1 | 2016-06-09T19:40:38Z | 37,738,806 | <p>The messages displayed in the messages tab in SSMS are passed as InfoMessage events on the connection. Here's the C# API doco</p>
<p><a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.infomessage.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/system.data.sqlclient.s... | 1 | 2016-06-10T01:58:41Z | [
"python",
"sql-server",
"sql-server-express"
] |
Django ORM order by expression | 37,734,942 | <p>Hi i could order by < 2 in ORM
my only idea is: </p>
<pre><code>players = GamePlayer.objects.raw('SELECT * FROM `Farmer_gameplayer` WHERE (`Farmer_gameplayer`.`game_id` = %d) ORDER BY `turn` < %d' % (game.pk, game.turn))
</code></pre>
<p>I'd like to order this:</p>
<pre><code>players = GamePlayer.objects.fi... | 1 | 2016-06-09T19:47:36Z | 37,735,047 | <p><sub><strong>Note:</strong> You can probably adapt your application to use <code>ORDER BY turn</code>, as <em>qualitatively</em> the result set isn't very different from <code>ORDER by turn < 2</code>. You'll see a difference only in that <code>ORDER BY turn</code> would alter the sort of all rows depending on th... | 0 | 2016-06-09T19:53:43Z | [
"python",
"django",
"django-orm"
] |
Write a table to CSV file in python | 37,735,066 | <p>I wrote this piece of code:</p>
<pre><code>import urllib.request
import re
import csv
from bs4 import BeautifulSoup
stocklist = ['aapl','goog','fb','amzn','COP']
for stocklist in stocklist:
optionsUrl = urllib.request.urlopen('http://finance.yahoo.com/q?s='+stocklist).read()
soup = BeautifulSoup(optionsUrl)
opt... | 0 | 2016-06-09T19:54:55Z | 37,735,233 | <p>The first thing you need to do is collect your column headers. Your headers have a lot of extra spaces, and we don't need the <code>:</code> at the end as well. So we do some formatting and cleanup.</p>
<pre><code>header = [re.sub(' +',' ',i[0][:-1].replace('\n', ' ')) for i in optionsTable[0]]
with open('test.csv... | 0 | 2016-06-09T20:06:58Z | [
"python",
"csv"
] |
Python: how to properly import a function from another file that depends on module | 37,735,182 | <p>Suppose I have two files. The first one contains all the functions I've written and which I usually import from my main file:</p>
<pre><code># my_functions.py
def sqrt_product(a, b):
from math import sqrt
return sqrt(a*b)
def create_df(lst):
from pandas import DataFrame as df
return df(lst)
</code... | 0 | 2016-06-09T20:03:28Z | 37,735,428 | <p>This is how. </p>
<pre><code> import my_functions as repo
</code></pre>
<p>Usage:</p>
<pre><code>repo.sqrt_product(a, b)
repo.create_df(lst)
print(repo.sqrt_product(3, 3))
print(repo.create_df([1, 2, 3])
</code></pre>
<p>"repo" is now in the namespace. Just like <code>import pandas as pd</code>, <code>pd</code... | 1 | 2016-06-09T20:19:50Z | [
"python"
] |
Python: how to properly import a function from another file that depends on module | 37,735,182 | <p>Suppose I have two files. The first one contains all the functions I've written and which I usually import from my main file:</p>
<pre><code># my_functions.py
def sqrt_product(a, b):
from math import sqrt
return sqrt(a*b)
def create_df(lst):
from pandas import DataFrame as df
return df(lst)
</code... | 0 | 2016-06-09T20:03:28Z | 37,735,482 | <p>U can do this as well.</p>
<pre><code># main.py
from my_functions import *
print(sqrt_product(3, 3))
print(create_df([1, 2, 3])
</code></pre>
| 0 | 2016-06-09T20:24:02Z | [
"python"
] |
Python: how to properly import a function from another file that depends on module | 37,735,182 | <p>Suppose I have two files. The first one contains all the functions I've written and which I usually import from my main file:</p>
<pre><code># my_functions.py
def sqrt_product(a, b):
from math import sqrt
return sqrt(a*b)
def create_df(lst):
from pandas import DataFrame as df
return df(lst)
</code... | 0 | 2016-06-09T20:03:28Z | 37,735,499 | <p>There are a few ways to do this.</p>
<ol>
<li><p>Import the file from the current directory.</p>
<ul>
<li>make sure the file you are importing from doesn't have any spaces or dashes in its file name. (Ex: <strong>thing_to_import_from.py</strong>, not <strong>thing to import from.py</strong>.)</li>
<li><p>make sure... | -1 | 2016-06-09T20:25:39Z | [
"python"
] |
Python: how to properly import a function from another file that depends on module | 37,735,182 | <p>Suppose I have two files. The first one contains all the functions I've written and which I usually import from my main file:</p>
<pre><code># my_functions.py
def sqrt_product(a, b):
from math import sqrt
return sqrt(a*b)
def create_df(lst):
from pandas import DataFrame as df
return df(lst)
</code... | 0 | 2016-06-09T20:03:28Z | 37,735,735 | <p>You can move the <code>from pandas import DataFrame</code> (optionally with <code>as df</code>) to the top of <code>my_functions.py</code> and redefine <code>create_df</code> just to be:</p>
<pre><code>def create_df(lst):
return DataFrame(lst) # or df(lst) if you used as
</code></pre>
<p>The <code>create_df<... | 0 | 2016-06-09T20:39:21Z | [
"python"
] |
Crawl a news website and getting the news content | 37,735,223 | <p>I'm trying to download the text from a news website. The HTML is:</p>
<pre><code><div class="pane-content">
<div class="field field-type-text field-field-noticia-bajada">
<div class="field-items">
<div class="field-item odd">
<p>"My Text" target="_blank">www... | -2 | 2016-06-09T20:06:00Z | 37,735,468 | <p>The problem is that <strong>you are not parsing the HTML, you are parsing the URL string</strong>:</p>
<pre><code>html = "My URL"
parsed_html = BeautifulSoup(html)
</code></pre>
<p>Instead, you need to <em>get/retrieve/download the source first</em>, example in Python 2:</p>
<pre><code>from urllib2 import urlopen... | 1 | 2016-06-09T20:23:01Z | [
"python",
"beautifulsoup",
"html-parser"
] |
Crawl a news website and getting the news content | 37,735,223 | <p>I'm trying to download the text from a news website. The HTML is:</p>
<pre><code><div class="pane-content">
<div class="field field-type-text field-field-noticia-bajada">
<div class="field-items">
<div class="field-item odd">
<p>"My Text" target="_blank">www... | -2 | 2016-06-09T20:06:00Z | 37,735,488 | <p><code>BeautifulSoup</code> accepts a string of HTML. You need to retrieve the HTML from the page using the URL.</p>
<p>Check out <a href="https://docs.python.org/2/library/urllib.html" rel="nofollow">urllib</a> for making HTTP requests. (Or <a href="http://docs.python-requests.org/en/master/" rel="nofollow">request... | 0 | 2016-06-09T20:24:43Z | [
"python",
"beautifulsoup",
"html-parser"
] |
graph_tool graph_draw vertex text box margins vertex overlaps | 37,735,245 | <p>Im trying to output a graph created using python graph_tool library to a png file. The final result is that the drawn graph vertexes overlaps. I realized that the problem is when i put text on the vertexes or edges, is like the margins of the text box are too big.</p>
<pre><code>size = 4000
v_size = size/my_graph
e... | 0 | 2016-06-09T20:07:20Z | 37,751,106 | <p>I think i've found a way. The thing is that when you set a text property to the vertexes it increases the size of vertexes to fit the text in, however if you set the property vertex_text_position to any negative value other than -1 it will not resize the vertex and then you can set the size of vertex you want.</p>
| 0 | 2016-06-10T14:44:36Z | [
"python",
"graph-tool",
"graph-drawing"
] |
"TypeError: Bool is not iterable" in any() iteration with boolean criteria | 37,735,337 | <p>In Python 2.7, I want to check the similarity between one string, and strings in a list, until it finds a match.</p>
<pre><code>from difflib import SequenceMatcher
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
correctList = ["thanks", "believe", "definitely"]
myString = "thansk"
for correctW... | 0 | 2016-06-09T20:13:50Z | 37,735,422 | <p><code>any</code> should only take a list of boolean expressions, so we need to find a way to evaluating <code>similar</code> between <code>myString</code> and every element of <code>correctList</code> first. We can use <code>map</code> here alongside a predicate <code>lambda s: similar(myString, s) > 0.9</code>:<... | 2 | 2016-06-09T20:19:21Z | [
"python",
"python-2.7"
] |
"TypeError: Bool is not iterable" in any() iteration with boolean criteria | 37,735,337 | <p>In Python 2.7, I want to check the similarity between one string, and strings in a list, until it finds a match.</p>
<pre><code>from difflib import SequenceMatcher
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
correctList = ["thanks", "believe", "definitely"]
myString = "thansk"
for correctW... | 0 | 2016-06-09T20:13:50Z | 37,735,496 | <p>You are stopping as soon as you find the first string with similarity > 0.9, starting with <code>"thansk"</code> as a candidate. So I think this is equivalent:</p>
<pre><code>myString = "thansk"
myString = next((w for w in correctList if similar(w, myString) > 0.9), myString)
</code></pre>
| 2 | 2016-06-09T20:25:34Z | [
"python",
"python-2.7"
] |
is there pandas.filter for values (not row or column labels)? | 37,735,403 | <p>Right now I have to do the following:</p>
<pre><code>ix=None
for ixi in [res[col].str.contains('string') for col in res.columns]:
if ix is not None:
ix = ix | ixi
else:
ix = ixi
res[ix]
</code></pre>
<p>Here is the notebook:</p>
<p><a href="https://gist.github.com/denfromufa/12379b62ef6eec... | 0 | 2016-06-09T20:18:09Z | 37,736,132 | <p>you can use <code>sum(axis=1)</code>:</p>
<pre><code>In [59]: res[res.sum(axis=1).str.contains('e|A')]
Out[59]:
ca cb cc
rb dmv enw fox
rc gpy hqz irA
</code></pre>
<p>or <code>apply()</code> in conjunction with <code>.str.contains()</code> and <code>any()</code>:</p>
<pre><code>In [51]: res[res.ap... | 1 | 2016-06-09T21:02:47Z | [
"python",
"performance",
"numpy",
"pandas",
"dataframe"
] |
Python time object drop seconds | 37,735,436 | <p>I'm trying to take a time from my mysql table (such as 14:00:00) and drop the seconds. I tried using strftime, but it wont print. Strftime works with my date objects, not sure why this doesn't work. </p>
<pre><code>print(time.strftime('%-H %M'))
</code></pre>
<p>fixed by changing timedelta object to time with: <co... | -2 | 2016-06-09T20:20:49Z | 37,735,603 | <p><code>import time; print(time.strftime('%H:%M'))</code></p>
| 0 | 2016-06-09T20:31:01Z | [
"python",
"datetime"
] |
Psycopg2 Python Inserting List | 37,735,449 | <p>I'm trying to insert a list into the SQL query via psycopg2 but every time it see's a ' it doubles it...</p>
<p>heres the code:</p>
<pre><code>for Line in ListFile:
if CountLigne == 1:
IDList = "'" + (Line[1].replace('"', '')) + "', "
CountLigne += 1
elif CountLigne < NbrLigne:
I... | 0 | 2016-06-09T20:21:44Z | 37,735,929 | <p>Pyscopg2 automatically converts tuples to sql list. Take a look on <a href="http://initd.org/psycopg/docs/usage.html#adaptation-of-python-values-to-sql-types" rel="nofollow">Adaptation of Python values to SQL types</a>. So you need just to change list to tuple and then pass it.</p>
<pre><code>FTDSQL = '''
WITH ft... | 0 | 2016-06-09T20:51:24Z | [
"python",
"sql",
"postgresql",
"psycopg2"
] |
django forms get value from cookies | 37,735,467 | <p>How to make django forms get value from cookies? I save user previuos input to cookies and if user opens form again I want to show that values.</p>
<p>Now I do forms manually like this:</p>
<pre><code><select name="transmission_type" class="selectpicker">
<option value="" selected>Select value</... | 0 | 2016-06-09T20:23:00Z | 37,738,153 | <p>I solved this by myself. You just need to use django forms initial attribute for your form in views.</p>
<p>Solution example:</p>
<pre><code>if 'something' in request.COOKIES:
something = request.COOKIES['something']
else:
something = ''
form = SomethingForm(initial={'something': something })
</code></pr... | 0 | 2016-06-10T00:20:00Z | [
"python",
"django",
"cookies",
"django-forms"
] |
Python design pattern | 37,735,543 | <p>I have a module that does something one of two ways:</p>
<pre><code>project/
|-- main.py
+-- module.py
</code></pre>
<p><strong>main.py</strong></p>
<pre><code>import module
module.do_something()
module.set_method(module.WAY_2)
module.do_something()
</code></pre>
<p><strong>module.py</strong></p>
<pre><code>WA... | 0 | 2016-06-09T20:28:00Z | 37,735,828 | <p>By default, any assignment in a function creates a function-local variable; it does not update a global by the same name. You need to define it as global explicitly:</p>
<pre><code>def set_method(new_method):
global method
method = new_method
</code></pre>
| 0 | 2016-06-09T20:45:13Z | [
"python"
] |
Python Requests - Why doesn't POST fall back to GET in case of no POST data? | 37,735,679 | <p>Running <code>python</code> version 3.5.1 and <code>requests</code> module version 2.9.1</p>
<p>Old version that worked - <code>python</code> version 2.7.9, unfortunately do not have the <code>requests</code> module version.</p>
<hr>
<p>In previously scenarios there have been cases where I would only need to work... | 1 | 2016-06-09T20:35:58Z | 37,735,858 | <p>You can make the code prettier:</p>
<pre><code>if self.data:
fn = requests.post
else:
fn = requests.get
request = fn(url=self.url, headers=self.headers, data=self.data or None,
timeout=self.timeout, proxies=self.proxies, verify=False)
</code></pre>
<p>(I realize this isn't an answer, but I do... | 3 | 2016-06-09T20:47:24Z | [
"python",
"python-requests"
] |
Python Requests - Why doesn't POST fall back to GET in case of no POST data? | 37,735,679 | <p>Running <code>python</code> version 3.5.1 and <code>requests</code> module version 2.9.1</p>
<p>Old version that worked - <code>python</code> version 2.7.9, unfortunately do not have the <code>requests</code> module version.</p>
<hr>
<p>In previously scenarios there have been cases where I would only need to work... | 1 | 2016-06-09T20:35:58Z | 37,736,008 | <p>You could also just use the <code>request()</code> function instead of the <code>get</code> and <code>post</code> convenience functions.</p>
<pre><code>import requests
response = requests.request('POST' if self.data else 'GET', url=self.url,
headers=self.headers, data=self.data or Non... | 3 | 2016-06-09T20:56:31Z | [
"python",
"python-requests"
] |
Python Pandas - unique combinations of variables in multiple specific columns | 37,735,745 | <p>I am trying to get unique combinations of phone numbers and values, where phone numbers and values are each in two potential columns. </p>
<p>For example:</p>
<pre><code>df = pd.DataFrame({'phone1':[4567890876, 4567890876, 9178889999, 3237800876],
'phone2':[4567890876, 4567890876, 9178889999, 21... | 1 | 2016-06-09T20:39:59Z | 37,735,822 | <p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.melt.html" rel="nofollow"><code>pd.melt</code></a> can coalesce multiple columns into one value column (and one variable column). You could use it once to coalesce the <code>num1</code> and <code>num2</code> columns, and an second time to coalesce... | 1 | 2016-06-09T20:44:42Z | [
"python",
"pandas",
"unique",
"reshape"
] |
AWS S3 + Django: Files stored in S3 accesible by user | 37,735,781 | <p>I have a (django) web application running in my own server. It has users, permissions and all that.</p>
<p>Each user is able to upload files to my platform. A new entry is created in my DB for each file uploaded and the file is then stored in AWS S3.</p>
<p>Currently the bucket is set to public, so this means tha... | 1 | 2016-06-09T20:42:04Z | 37,735,953 | <p>This can be done very easily. Please follow this exact procedure mentioned here in this article.</p>
<p><a href="http://www.gyford.com/phil/writing/2012/09/26/django-s3-temporary.php" rel="nofollow">http://www.gyford.com/phil/writing/2012/09/26/django-s3-temporary.php</a></p>
| 2 | 2016-06-09T20:53:00Z | [
"python",
"django",
"amazon-web-services",
"amazon-s3",
"aws-sdk"
] |
AWS S3 + Django: Files stored in S3 accesible by user | 37,735,781 | <p>I have a (django) web application running in my own server. It has users, permissions and all that.</p>
<p>Each user is able to upload files to my platform. A new entry is created in my DB for each file uploaded and the file is then stored in AWS S3.</p>
<p>Currently the bucket is set to public, so this means tha... | 1 | 2016-06-09T20:42:04Z | 37,739,218 | <p>Apart from what @error2007s suggests,</p>
<ol>
<li>You could disable list permissions on the bucket and make the filename very long (e.g. use a GUID) making it virtually impossible to guess (for instance, images on Facebook's CDN are made private in this manner-- no real access control)</li>
<li>You could use the D... | -1 | 2016-06-10T02:56:11Z | [
"python",
"django",
"amazon-web-services",
"amazon-s3",
"aws-sdk"
] |
Pandas Series Apply Method | 37,735,898 | <p>I've been using pandas apply method for both series and dataframe, but I am obviously still missing something, because I'm stumped on a simple function i'm trying to execute. </p>
<p>This is what I was doing:</p>
<pre><code>def minmax(row):
return (row - row.min())/(row.max() - row.min())
row.apply(minmax)
</... | 0 | 2016-06-09T20:49:22Z | 37,736,161 | <p>When you call <code>row.apply(minmax)</code> on a <code>Series</code> <strong>only the values</strong> are passed to the function. This is called <strong>element-wise</strong>.</p>
<blockquote>
<p>Invoke function on values of Series. Can be ufunc (a NumPy function that applies to the entire Series) or a Python fu... | 0 | 2016-06-09T21:04:59Z | [
"python",
"pandas",
"apply"
] |
How to form a glob that works for a wild char or exact match? | 37,735,917 | <p>Iam using a statement such as :</p>
<pre><code>input_stuff = '1,2,3'
glob(folder+'['+ input_stuff + ']'+'*')
</code></pre>
<p>to list files that begin with 1,2 or 3 while this lists files such as 1-my-file, 2-my-file, 3-my-file .
This doesnt work if exact file names are given </p>
<pre><code>input_stuff = '1-my-... | 0 | 2016-06-09T20:50:30Z | 37,736,174 | <p>You can use the following:</p>
<pre><code>input_stuff = '1,2,3'
glob(folder+'['+input_stuff+']-my-file*')
</code></pre>
<p>EDIT: Since you said in your comment that you can't hardcode "-my-file", you can do something like:</p>
<pre><code>input_stuff = '1,2,3'
name = "-my-file"
print glob.glob(folder+'['+input_stu... | 0 | 2016-06-09T21:05:23Z | [
"python",
"glob"
] |
How to form a glob that works for a wild char or exact match? | 37,735,917 | <p>Iam using a statement such as :</p>
<pre><code>input_stuff = '1,2,3'
glob(folder+'['+ input_stuff + ']'+'*')
</code></pre>
<p>to list files that begin with 1,2 or 3 while this lists files such as 1-my-file, 2-my-file, 3-my-file .
This doesnt work if exact file names are given </p>
<pre><code>input_stuff = '1-my-... | 0 | 2016-06-09T20:50:30Z | 37,736,706 | <p>Glob expression in brackets is a set of characters, not a list of strings.
You first expresion <code>input_stuff = '1,2,3'</code> is equivalent to <code>'123,'</code> and will also match a name starting with comma.<br>
Your second expression contains <code>'-'</code>, which is used to denote character ranges like '<... | 1 | 2016-06-09T21:46:04Z | [
"python",
"glob"
] |
How to repeat the last command on the command-line in the python debugger, PuDB | 37,736,033 | <p>I'm on Linux and expected it to work like pdb, gdb, i.e., press <code>enter</code> to repeat the last command. I understand the debugger has a <code>Variables</code> watch window. </p>
| 1 | 2016-06-09T20:57:43Z | 37,736,539 | <p>Ctrl-n/p - browse command line history</p>
| 1 | 2016-06-09T21:30:43Z | [
"python",
"pudb"
] |
How to properly iterate through a for loop with python | 37,736,039 | <p>I am relatively inexperienced and come from c#. I am attempting to iterate through a string and individually print out each letter using a for loop.</p>
<p>In c# this would (if I remember correctly) be written like so:</p>
<pre><code> string x = test;
foreach(i in x)
{
print(x[i]);
}
</code></pre>
<p>But in ... | 0 | 2016-06-09T20:57:59Z | 37,736,202 | <p>If you really want a loop index for some reason, you can use <code>enumerate</code>:</p>
<pre><code>x = 'test'
for i, c in enumerate(x):
print(i, x[i], c)
</code></pre>
| 0 | 2016-06-09T21:07:43Z | [
"python",
"arrays",
"string",
"for-loop"
] |
How to properly iterate through a for loop with python | 37,736,039 | <p>I am relatively inexperienced and come from c#. I am attempting to iterate through a string and individually print out each letter using a for loop.</p>
<p>In c# this would (if I remember correctly) be written like so:</p>
<pre><code> string x = test;
foreach(i in x)
{
print(x[i]);
}
</code></pre>
<p>But in ... | 0 | 2016-06-09T20:57:59Z | 37,736,481 | <p>This took me a bit to understand as well, but I think I understand the misunderstanding. The i in <code>for i in x</code> already refers to the character, not the index. For example, writing</p>
<p><code>stringx='hello world
for i in stringx:
print stringx[i]
</code>
is the same as writing </p>
<pre><code>print st... | 0 | 2016-06-09T21:27:04Z | [
"python",
"arrays",
"string",
"for-loop"
] |
How to properly iterate through a for loop with python | 37,736,039 | <p>I am relatively inexperienced and come from c#. I am attempting to iterate through a string and individually print out each letter using a for loop.</p>
<p>In c# this would (if I remember correctly) be written like so:</p>
<pre><code> string x = test;
foreach(i in x)
{
print(x[i]);
}
</code></pre>
<p>But in ... | 0 | 2016-06-09T20:57:59Z | 37,736,909 | <p>Your variable <code>x</code> is a string type, therefore, when you type <code>x[i]</code> you are going to get the letter at the position <code>i</code>.</p>
<p>However, in your loop, you have something different:</p>
<pre><code>x = "test"
for i in x:
print(x[i])
</code></pre>
<p>This for loop (<code>for i in... | 1 | 2016-06-09T22:01:22Z | [
"python",
"arrays",
"string",
"for-loop"
] |
Log all requests to file Django | 37,736,077 | <p>When I run the django development server (<code>./manage.py runserver</code>) all requested urls are conveniently logged into process stdout, with the precise time and the response code:</p>
<pre><code>[09/Jun/2016 23:35:53] "GET /api/game/ HTTP/1.1" 404 3185
[09/Jun/2016 23:36:01] "GET /api/game/123/ HTTP/1.1" 404... | 0 | 2016-06-09T21:00:05Z | 37,736,461 | <p>For a standard Apache installation you are going against what is regarded as best practice by trying to mingle both access logs and error logs. Traditionally they have been left separate so that analysis could be done on access logs on server traffic.</p>
<p>That said, have you tried changing the <code>ErrorLog</co... | 1 | 2016-06-09T21:26:18Z | [
"python",
"django",
"apache",
"logging",
"wsgi"
] |
Reading with xlrd in python | 37,736,100 | <p>I wrote this program to read a column from an excel file then write it into a txt file:</p>
<pre><code>import xlrd, sys
text_file = open("Output.txt", "w")
isotope = xlrd.open_workbook(sys.argv[1])
first_sheet=isotope.sheet_by_index(0)
x= []
for rownum in range(first_sheet.nrows):
x.append(first_sheet.cell(row... | 1 | 2016-06-09T21:01:05Z | 38,316,609 | <p>Also, if you want a way to read entire values of a row in one shot:</p>
<p>You can take first_sheet and do:</p>
<pre><code>first_sheet.row_values(index_of_row)
</code></pre>
<p>This will return a list with all the values of the index_of_row.</p>
| 1 | 2016-07-11T21:36:14Z | [
"python",
"excel",
"xlrd"
] |
Python: Parse string objects into python objects from a file | 37,736,125 | <p>I've got a <code>.csv</code> file and I need to get some information from it. If I open the file, I can see two lines in it, that says "data" and "notes", and I need to get the information that these two variables have.</p>
<p>When I open the <code>.csv</code> file, it shows these lines:</p>
<pre><code>data =
[0,... | 0 | 2016-06-09T21:02:35Z | 37,736,556 | <p>You can change the last part of your code to:</p>
<pre><code>for note in eval(rows[3][0].strip("notes = ")):
if note["position"]:
print note["position"]
</code></pre>
<p>If you need the position to be an actual tuple instead of a string, you can change the last line to:</p>
<pre><code>print tuple(note... | 1 | 2016-06-09T21:32:37Z | [
"python",
"csv",
"dictionary"
] |
How to plot multiple lines as histograms per group from a pandas Date Frame | 37,736,247 | <p>I am trying to look at 'time of day' effects on my users on a week over week basis to get a quick visual take on how consistent time of day trends are. So as a first start I've used this:</p>
<pre><code>df[df['week'] < 10][['realLocalTime', 'week']].hist(by = 'week', bins = 24, figsize = (15, 15))
</code></pre>
... | -2 | 2016-06-09T21:10:54Z | 37,736,557 | <p>Maybe you can simply use <code>crosstab</code> to compute the number of element by week and plot it.</p>
<pre><code># Test data
d = {'realLocalTime': ['12','14','14','12','13','17','14', '17'],
'week': ['10','10','10','10','5','5','6', '6']}
df = DataFrame(d)
ax = pd.crosstab(df['realLocalTime'], df['week']).plot... | 0 | 2016-06-09T21:32:46Z | [
"python",
"pandas"
] |
How to plot multiple lines as histograms per group from a pandas Date Frame | 37,736,247 | <p>I am trying to look at 'time of day' effects on my users on a week over week basis to get a quick visual take on how consistent time of day trends are. So as a first start I've used this:</p>
<pre><code>df[df['week'] < 10][['realLocalTime', 'week']].hist(by = 'week', bins = 24, figsize = (15, 15))
</code></pre>
... | -2 | 2016-06-09T21:10:54Z | 37,736,633 | <p>Use groupby and value_counts</p>
<pre><code>df.groupby('week').realLocalTime.value_counts().unstack(0).fillna(0).plot()
</code></pre>
<p><a href="http://i.stack.imgur.com/C4KZH.png" rel="nofollow"><img src="http://i.stack.imgur.com/C4KZH.png" alt="enter image description here"></a></p>
| 0 | 2016-06-09T21:39:18Z | [
"python",
"pandas"
] |
Table extraction with Selenium and PhantomJS never finishes | 37,736,300 | <p>I am trying to extract a table from a site using the following code (courtesy: Padraic). When I execute this code it goes into execution and does not end or return anything unless terminated. </p>
<pre><code>from selenium import webdriver
import pandas as pd
dr = webdriver.PhantomJS(r'C:\Users\Admin\Anaconda3\pha... | 1 | 2016-06-09T21:14:31Z | 37,736,787 | <p>If you add a <code>print(row)</code> in the loop, you can see output like:</p>
<pre><code><selenium.webdriver.remote.webelement.WebElement (session="10676710-2e8c-11e6-b13a-473272d23fd8", element=":wdc:1465509003017")>
<selenium.webdriver.remote.webelement.WebElement (session="10676710-2e8c-11e6-b13a-47327... | 2 | 2016-06-09T21:52:18Z | [
"python",
"selenium-webdriver",
"web-scraping",
"phantomjs"
] |
python - Calling function within same Class | 37,736,384 | <p>Please see the sample code:</p>
<pre><code>a = [1,2,3,4,5] # main list
b = [4,5,6] #variable list nr1
c = [1,2] #variable list nr2
class union(object):
def __init__(self, name):
self.name = name
def common_numbers(self, variable_list):
self.variable_list = variable_list
for ... | 0 | 2016-06-09T21:20:52Z | 37,736,657 | <p>You're getting the error because you never actually define self.variable_list. It's only defined once you call common_numbers(), but you never do that. You can define it when initiating:</p>
<pre><code>class union(object):
def __init__(self, name, variable_list):
self.name = name
self.variable_l... | 2 | 2016-06-09T21:42:04Z | [
"python",
"function",
"class"
] |
How to write items in the same array on the row and for the next array skip a line and write the items on the next row in Python | 37,736,403 | <p>`I currently have a list of names in one CSV that are separated ["last name", "first name"]. If there is no name, the array just has ["1"]. Each name on the current CSV is in its own separate array. I'm trying write the names in a CSV so that one column is all last names (and "1's") and the other column is all first... | 0 | 2016-06-09T21:22:10Z | 37,736,792 | <p>This question has the feel of "I have a hammer, so everything looks like a nail."</p>
<p>You're trying to use the csv module to do something that isn't exactly csv.</p>
<pre><code>with open("/tmp/input") as fdin, open("/tmp/o", "w") as fdout:
for line in fdin: ... | 0 | 2016-06-09T21:52:41Z | [
"python",
"arrays",
"csv"
] |
How to pull the slice of an array in Spark SQL (Dataframes)? | 37,736,409 | <p>I have a column full of arrays containing split http requests. I have them filtered down to one of two possibilities:</p>
<pre><code>|[, courses, 27381...|
|[, courses, 27547...|
|[, api, v1, cours...|
|[, api, v1, cours...|
|[, api, v1, cours...|
|[, api, v1, cours...|
|[, api, v1, cours...|
|[, api, v1, cours...... | 1 | 2016-06-09T21:22:42Z | 37,737,424 | <p>It's very easy just define a <code>UDF</code>, you made a <a href="http://stackoverflow.com/questions/37689878/select-array-element-from-spark-dataframes-split-method-in-same-call">very similar question previously</a> so I won't post the exact answer to let you think and learn (for your own good).</p>
<pre><code>df... | 1 | 2016-06-09T22:49:04Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql"
] |
Rapid compression of multiple lists with value addition | 37,736,434 | <p>I am looking for a pythonic way to iterate through a large number of lists and use the index of repeated values from one list to calculate a total value from the values with the same index in another list.</p>
<p>For example, say I have two lists</p>
<pre><code>a = [ 1, 2, 3, 1, 2, 3, 1, 2, 3]
b = [ 1, 2, 3, 4, 5,... | 0 | 2016-06-09T21:24:25Z | 37,736,505 | <p>Use the <a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow"><code>zip()</code> function</a> and a <a href="https://docs.python.org/3/library/collections.html#collections.defaultdict" rel="nofollow"><code>defaultdict</code> dictionary</a> to collect values per unique value:</p>
<pre><code>f... | 1 | 2016-06-09T21:28:15Z | [
"python",
"list",
"compression",
"indices"
] |
pandas plugin for python in a canopy environment not sorting? | 37,736,562 | <p>I've been working on this for a few hours and am giving up at this point. I have a scientific tool that is slightly glitching and creating a .csv database with datapoints out of order, i.e.</p>
<pre><code>Test_ID Data_Point Test_Time Step_Time etc...
1 1439 1441.044976 1328.572329
1 1440 1442.046983 1... | 1 | 2016-06-09T21:33:10Z | 37,737,107 | <p>You are using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort.html" rel="nofollow"><code>sort_values</code></a> wrongly. The parameters of the argument <code>ascending</code> have to be boolean<code>(True/False)</code> and not binary<code>(1/0)</code> values.</p>
<p>It should be... | 1 | 2016-06-09T22:18:26Z | [
"python",
"csv",
"pandas"
] |
How to control location of drop down menu in Tkinter? | 37,736,612 | <p>I am trying to change the way that the dropdown menu in Tkinter seems to render. I found this code on TutorialsPoint:</p>
<pre><code> from Tkinter import *
def donothing():
filewin = Toplevel(root)
button = Button(filewin, text="Do nothing button")
button.pack()
root = Tk()
... | 1 | 2016-06-09T21:37:33Z | 37,738,003 | <p>I'm guessing this has something to do with the settings on your computer and not tkinter/Python. </p>
<p>It works like TutorialsPoint's on my computer just fine!
<a href="http://i.stack.imgur.com/aMlOq.png" rel="nofollow"><img src="http://i.stack.imgur.com/aMlOq.png" alt="enter image description here"></a></p>
<p>... | 3 | 2016-06-09T23:57:49Z | [
"python",
"python-3.x",
"user-interface",
"tkinter"
] |
Select rows in pandas matching time condition | 37,736,703 | <p>I have a csv with data like this:</p>
<pre><code>[id names timestamp is_valid]
[1 name:surname 2016-06-09 23:29:50.083093 True]
</code></pre>
<p>I need to select rows based on this condition: if is_valid is true and if timestamp has passed 24 hours. So it should be <strong>True... | 1 | 2016-06-09T21:45:28Z | 37,737,041 | <p>try this:</p>
<pre><code>from datetime import datetime, timedelta
import pandas as pd
from dateutil import parser
df = pd.read_csv('acc.csv')
tidx = pd.to_datetime(df['timestamp'].values)
past_24 = (pd.datetime.now() - tidx).total_seconds() > 60 * 60 * 24
user = df[df['is_valid'] & past_24]
</code></pre>
| 0 | 2016-06-09T22:11:22Z | [
"python",
"csv",
"datetime",
"pandas"
] |
Pandas GroupBy Two Text Columns And Return The Max Rows Based On Counts | 37,736,730 | <p>I'm trying to figure out the max <code>(First_Word, Group)</code> pairs </p>
<pre><code>import pandas as pd
df = pd.DataFrame({'First_Word': ['apple', 'apple', 'orange', 'apple', 'pear'],
'Group': ['apple bins', 'apple trees', 'orange juice', 'apple trees', 'pear tree'],
'Text': ['where to bu... | 0 | 2016-06-09T21:47:55Z | 37,736,788 | <p>Given <code>grouped</code>, you now want to group by the <code>First Word</code> index level, and find the index labels of the maximum row for each group (using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.idxmax.html" rel="nofollow"><code>idxmax</code></a>):</p>
<pre><code>In [39... | 2 | 2016-06-09T21:52:25Z | [
"python",
"pandas",
"max"
] |
Wxpython sound on text enter event | 37,736,744 | <p>My question is a short one, however I was unsuccessful at finding the answer.</p>
<p>I am developing a wxpython project, where a method in the frame class is called when enter is pressed in a textctrl box. This works fine, however, there is a sound played when I press enter like a "dling" voice. I don't want this i... | 0 | 2016-06-09T21:48:27Z | 37,752,889 | <p>I suspect that somewhere on your operating system, there is an option for turning on/off button and window sounds or event sounds.<br>
Sorry, I can't tell you where it is on Windows, I use Linux.
It has nothing to do with wxpython.</p>
| 0 | 2016-06-10T16:17:48Z | [
"python",
"widget",
"wxpython"
] |
Install OpenCV via pip on Python 3.5 64-bit | 37,736,760 | <p>I tried to install OpenCV, and I couldn't find any suitable pip packages for it. I decided to look online for official documentation on how to install it, and found <a href="https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-pytho... | 2 | 2016-06-09T21:50:29Z | 37,737,413 | <p>What OS are you on? If it's Windows have a look at</p>
<p><a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv</a></p>
<p>To properly install the available wheels make sure you have pip version 8 installed.</p>
| 2 | 2016-06-09T22:48:12Z | [
"python",
"python-3.x",
"opencv",
"64bit",
"pip"
] |
How to tree-search an html file tag with no specific type | 37,736,771 | <p>I'm new to Python. I wonder how to get the string from an html as following:</p>
<pre><code> <span style="color: blue; font-size: 36px; font-weight: 600;"> string </span>
</code></pre>
<p>I tried </p>
<pre><code> import lxml from html
import requests
page = requests.get("url")
tree =... | 0 | 2016-06-09T21:51:27Z | 37,736,897 | <p>Be careful with tree searching html files because seldomly developers will move things which ends up breaking old projects. I feel its safer to go with string manipulation because if you plan it well, you won't have to reprogram it even if the developers decided to wrap your target in one more containers. </p>
<p>I... | 0 | 2016-06-09T22:00:44Z | [
"python",
"html",
"search",
"tree"
] |
I need to stop my for loop but break won't work | 37,736,775 | <p>I have written some code that finds the position of the word a user enters in a sentence. But after they enter the word I need the code to find the position and print it and then stop there. But it doesn't stop instead it continues onto the else statement which is what happens if they enter a word that isn't in the ... | -2 | 2016-06-09T21:51:41Z | 37,736,962 | <p>You could just get all the indexes first, then do your second function only if there are no matching indexes.</p>
<pre><code>indexes = [i for i, word in enumerate(words) if word == keyword]
if indexes:
for i in indexes:
print('The position is {}'.format(i))
if not indexes:
...
</code></pre>
<p>You... | 1 | 2016-06-09T22:05:33Z | [
"python",
"position"
] |
Python load variables into an array from file | 37,736,816 | <p>I'm making a reddit bot and I've made it store the comment ids in an array so it doesn't reply to the same comment twice, however if I close the program the array is cleared.</p>
<p>I'm looking for a way to keep the array, such as storing it in an external file and reading it, thanks!</p>
<p>Here's my code:</p>
<... | 0 | 2016-06-09T21:54:50Z | 37,736,872 | <p>What you're looking for is called <a href="https://en.wikipedia.org/wiki/Serialization" rel="nofollow"><em>serialization</em></a>. You can use <a href="https://docs.python.org/2/library/json.html" rel="nofollow"><code>json</code></a> or <a href="http://pyyaml.org/wiki/PyYAMLDocumentation" rel="nofollow"><code>yaml<... | 0 | 2016-06-09T21:58:54Z | [
"python",
"arrays",
"reddit",
"praw"
] |
Regular expression to add additional argument to php function in source | 37,736,855 | <p>I want to add an additional argument to my function using regular expressions and Python.</p>
<p>My function looks like this: </p>
<pre><code>mail(arg1, arg2, arg3, arg4);
</code></pre>
<p>Can anyone help with regular expression to get this result:</p>
<pre><code>mail(arg1, arg2, arg3, arg4, arg5);
</code></pre>... | 0 | 2016-06-09T21:57:47Z | 37,737,297 | <p>Assuming you're not doing complex multiline parsing, and that your arguments aren't expressions with whitespace or commas, and that your spaces between arguments are consistent, here is a naive regex:</p>
<pre><code>re.sub(r'(mail\(\S+, \S+, \S+)\);', '\\1, arg4);', src)
</code></pre>
<p>You may wish to surround t... | 0 | 2016-06-09T22:37:21Z | [
"python",
"regex"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.