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
Can't find module that exists
37,970,448
<p>From the cli I enter the python shell via <code>python</code>.</p> <p><strong>I then take a look at my import search path:</strong></p> <pre><code>import sys print '\n'.join(sys.path) /path/to/a/package/foo.bar /other paths... </code></pre> <p>So I know <code>foo.bar</code> is in my python search path.</p> <p><...
0
2016-06-22T14:05:34Z
37,970,619
<ul> <li>Don't have a <code>.</code> in the folder name.</li> <li>Make sure there is an empty <code>__init__.py</code> file in the foo &amp; bar folders. This is required for python to see it as a package</li> <li>Make sure the folder that the foo folder is in, is in <code>sys.path</code></li> </ul>
0
2016-06-22T14:12:02Z
[ "python", "python-2.7", "shell", "path" ]
Can't find module that exists
37,970,448
<p>From the cli I enter the python shell via <code>python</code>.</p> <p><strong>I then take a look at my import search path:</strong></p> <pre><code>import sys print '\n'.join(sys.path) /path/to/a/package/foo.bar /other paths... </code></pre> <p>So I know <code>foo.bar</code> is in my python search path.</p> <p><...
0
2016-06-22T14:05:34Z
37,970,752
<p><code>imp.find_module</code> does not handle names with dots. From the <a href="https://docs.python.org/2/library/imp.html" rel="nofollow">documentation</a>:</p> <blockquote> <p>This function does not handle hierarchical module names (names containing dots). </p> </blockquote> <p>It also points out a solution:</...
1
2016-06-22T14:17:23Z
[ "python", "python-2.7", "shell", "path" ]
importing current package
37,970,564
<p>I'm writing a script and running it with the -i argument in order to keep the repl open after it finishes in order to be able to see info about the objects that I'm using while debugging.</p> <p>In order to avoid having to quit and re-run the script I figured out that I can modify and save the script and then impor...
0
2016-06-22T14:09:51Z
37,970,705
<p><code>import</code>, in any of it's incarnations, only reloads the script once. You are looking for the <a href="https://docs.python.org/3/library/imp.html#imp.reload" rel="nofollow"><code>reload</code></a> function:</p> <pre><code>from importlib import reload import sys def main(): pass def x(): reload(s...
1
2016-06-22T14:15:25Z
[ "python", "python-3.x", "import" ]
importing current package
37,970,564
<p>I'm writing a script and running it with the -i argument in order to keep the repl open after it finishes in order to be able to see info about the objects that I'm using while debugging.</p> <p>In order to avoid having to quit and re-run the script I figured out that I can modify and save the script and then impor...
0
2016-06-22T14:09:51Z
37,971,276
<p>I did it!</p> <pre><code>def x(): # make what I'm doing now at this very moment easier main() print("It works!") def y(): # calls x() after loading most recent version import importlib from imp import reload this = importlib.import_module("".join(sys.argv[0].split(".py"))) # sys.argv gives [module-n...
0
2016-06-22T14:38:38Z
[ "python", "python-3.x", "import" ]
Transforming a column index in Python pandas
37,970,648
<p>I have the following DataFrame:</p> <pre><code> index PUBLICO CLASSIFICACAO_PUBLICO 0 19 143643 1 1 34 111879 2 2 31 50382 3 3 9 49204 4 4 32 37541 5 5 4 36095 6 </code></pre> <p>I need convert the index ...
-1
2016-06-22T14:13:03Z
37,971,035
<p>The method <code>set_index</code> doesn't work inplace. So that you have to reassign your dataframe, or to pass the option <code>inplace = True</code>:</p> <pre><code>df = df.set_index('index') </code></pre> <p>or</p> <pre><code>df.set_index('index',inplace = True) </code></pre> <p>see <a href="http://pandas.pyd...
1
2016-06-22T14:28:20Z
[ "python", "pandas", "indexing" ]
Transforming a column index in Python pandas
37,970,648
<p>I have the following DataFrame:</p> <pre><code> index PUBLICO CLASSIFICACAO_PUBLICO 0 19 143643 1 1 34 111879 2 2 31 50382 3 3 9 49204 4 4 32 37541 5 5 4 36095 6 </code></pre> <p>I need convert the index ...
-1
2016-06-22T14:13:03Z
37,971,462
<p>You can try it this way:</p> <pre><code>df.set_index(df['index'], inplace=True) </code></pre> <p>This will set your <code>index</code> column as the index in your dataframe and your <code>index</code> column will still remain in your dataframe as well. Then, you can just drop that column.</p> <pre><code>df.drop('...
0
2016-06-22T14:46:37Z
[ "python", "pandas", "indexing" ]
Opening txt file, Invalid literal for float()
37,970,670
<p>Just trying to open this data set in txt format.</p> <pre class="lang-none prettyprint-override"><code>400.,41.7693 403.977686150861,42.68129270405837 408.3434392432695,43.86688321933424 412.61217560029104,45.59966935704514 416.4928450157652,48.72324436844505 420.9556148435605,51.64162102143182 423.86611690516617,5...
1
2016-06-22T14:13:49Z
37,970,739
<p>Use <code>row.split(',')</code> to split on commas. <code>.split()</code> without passing arguments will only split on whitespaces.</p>
4
2016-06-22T14:16:56Z
[ "python" ]
Opening txt file, Invalid literal for float()
37,970,670
<p>Just trying to open this data set in txt format.</p> <pre class="lang-none prettyprint-override"><code>400.,41.7693 403.977686150861,42.68129270405837 408.3434392432695,43.86688321933424 412.61217560029104,45.59966935704514 416.4928450157652,48.72324436844505 420.9556148435605,51.64162102143182 423.86611690516617,5...
1
2016-06-22T14:13:49Z
37,970,796
<p>This isn't really doing anything:</p> <pre><code>row.split() </code></pre> <p>Perhaps you meant</p> <pre><code>row.split(',') </code></pre>
0
2016-06-22T14:18:47Z
[ "python" ]
Opening txt file, Invalid literal for float()
37,970,670
<p>Just trying to open this data set in txt format.</p> <pre class="lang-none prettyprint-override"><code>400.,41.7693 403.977686150861,42.68129270405837 408.3434392432695,43.86688321933424 412.61217560029104,45.59966935704514 416.4928450157652,48.72324436844505 420.9556148435605,51.64162102143182 423.86611690516617,5...
1
2016-06-22T14:13:49Z
37,970,856
<p>If you want to read the txt file, you can use the numpy library and the command : np.loadtxt()</p> <p>Then you can make lots of processes because you get a numpy array ;)</p> <pre><code>import numpy as np reading = np.loadtxt("SunData.txt", delimiter=',', usecols=(0, 1), unpack=True) print reading </code></pre> ...
0
2016-06-22T14:20:52Z
[ "python" ]
Opening txt file, Invalid literal for float()
37,970,670
<p>Just trying to open this data set in txt format.</p> <pre class="lang-none prettyprint-override"><code>400.,41.7693 403.977686150861,42.68129270405837 408.3434392432695,43.86688321933424 412.61217560029104,45.59966935704514 416.4928450157652,48.72324436844505 420.9556148435605,51.64162102143182 423.86611690516617,5...
1
2016-06-22T14:13:49Z
37,970,917
<pre><code>for item in data.split('\n'): floats = item.split(',') </code></pre>
0
2016-06-22T14:23:17Z
[ "python" ]
Variable behaviour in python - making more efficient code
37,970,722
<p>Trying to do some optimization here on a class. We're trying not to change too much the class definitions. In essence we are instantiating a <code>ClassA</code> <code>N</code> times but one of the methods has a nasty file read. </p> <pre><code>for x in range(0, N): cl = ClassA() cl.dostuff(x) </code></pre> <p>...
0
2016-06-22T14:16:22Z
37,970,878
<p>You could encapsulate opening the file in a <code>classmethod</code>.</p> <pre><code>class ClassA(): @classmethod def open_nasty_file(cls): cls.nasty_file = open('file_path', 'file_mode') def do_stuff(self): if not hasattr(self, 'nasty_file'): self.open_nasty_file() </code>...
2
2016-06-22T14:21:47Z
[ "python" ]
Variable behaviour in python - making more efficient code
37,970,722
<p>Trying to do some optimization here on a class. We're trying not to change too much the class definitions. In essence we are instantiating a <code>ClassA</code> <code>N</code> times but one of the methods has a nasty file read. </p> <pre><code>for x in range(0, N): cl = ClassA() cl.dostuff(x) </code></pre> <p>...
0
2016-06-22T14:16:22Z
37,970,916
<p>You could have a class method that opens the file when the first instance asks for it. I've wrapped it in a lock so that it is thread safe.</p> <pre><code>import threading class ClassA: _nasty_file = None _nasty_file_lock = threading.Lock() def dostuff(self, x): #open nasty file here nast...
1
2016-06-22T14:23:15Z
[ "python" ]
Variable behaviour in python - making more efficient code
37,970,722
<p>Trying to do some optimization here on a class. We're trying not to change too much the class definitions. In essence we are instantiating a <code>ClassA</code> <code>N</code> times but one of the methods has a nasty file read. </p> <pre><code>for x in range(0, N): cl = ClassA() cl.dostuff(x) </code></pre> <p>...
0
2016-06-22T14:16:22Z
37,971,234
<p>Instances can access and modify class attributes by themselves. So you can just set up an attribute on the class and provide it with a default (None) value, and then check for that value before doing anything in <em>dostuff</em>. Example:</p> <pre><code>class A(): nastyfileinfo=None def dostuff(self,x): ...
1
2016-06-22T14:36:30Z
[ "python" ]
SQL error returned after attempting to create a magento category using xmlrpc in Python
37,970,723
<p>So I am trying to programmatically create a Magento category in Python using the xmlrpc API.<br> I am new to Python, this is my first serious program I am writing in Python.<br> I do not know for sure if this has something to do with my code but I'll give it a try.<br> This is my code:</p> <pre><code>from xmlrpc im...
0
2016-06-22T14:16:24Z
37,970,805
<p>This has NOTHING to do with Python. Your SQL is bad:</p> <pre><code>... WHERE (entity_id ='Cool , Cat', 'Python Category', .. </code></pre> <p>You cannot use an equality test (<code>=</code>) to test MULTIPLE values at the same time. That's a flat-out syntax error.</p> <p>It should be</p> <pre><code>... WHERE en...
0
2016-06-22T14:19:03Z
[ "python", "sql", "magento", "xml-rpc" ]
Look up value from column in table and interpolate in rows (python pandas scipy)
37,970,801
<p>I am having trouble with a program that will first look up a date in another data frame, and then interpolate a certain value along the rows. </p> <p>Problem: Let the original data frames look like this:</p> <pre><code>A = pd.DataFrame({"date":["06/24/2014","06/25/2014","06/26/2014"], "value":[2, 4, 6]}) B = pd.D...
1
2016-06-22T14:18:57Z
37,980,418
<p>I'm assuming it's not a coincidence that the values to be interpolated are the 'missing' values in B. If that's the case, you don't need the <code>A</code> dataframe at all.</p> <pre><code>B = pd.DataFrame({"date":["06/25/2014","06/26/2014","06/24/2014"], "1":[0.1, 0.5, 0.9],"3":[0.2, 0.6, 1.0],...
0
2016-06-23T00:35:23Z
[ "python", "pandas", "scipy" ]
Look up value from column in table and interpolate in rows (python pandas scipy)
37,970,801
<p>I am having trouble with a program that will first look up a date in another data frame, and then interpolate a certain value along the rows. </p> <p>Problem: Let the original data frames look like this:</p> <pre><code>A = pd.DataFrame({"date":["06/24/2014","06/25/2014","06/26/2014"], "value":[2, 4, 6]}) B = pd.D...
1
2016-06-22T14:18:57Z
37,980,933
<p>If you really only want the <em>select</em> values, this will give it to you. Note, I make use of the <code>groupby</code> function so that I only have to create a <code>scipy.interpolate.interp1d</code> call once per <code>date</code></p> <p>The data munging:</p> <pre><code>A = pd.DataFrame({"date":["06/24/2014",...
1
2016-06-23T01:40:25Z
[ "python", "pandas", "scipy" ]
Parse Zabbix output format
37,970,828
<p>I am using <code>pyzabbix</code> to interface with Zabbix and retrieve what I want:</p> <pre><code>#!/usr/bin/env python # import import sys, subprocess, time, datetime, csv, platform from pyzabbix import ZabbixAPI # api/vars url='http://172.18.64.100/zabbix' zh = ZabbixAPI(url) zh.login(user="Admin",password="xx...
0
2016-06-22T14:19:51Z
37,971,579
<p>Thanks, i just loop again I know its ugly, but well, it's fine for now :)</p> <p>I've put another loop inside #print part:</p> <pre><code>for hostid in hosts: # triggers = zh.trigger.get(hostids=[x['hostid'] for x in hosts], active="1", selectHosts="1") print hostid triggers = zh.trigger.get(filter={"h...
0
2016-06-22T14:51:41Z
[ "python" ]
Neural Network converging and accurate in training, but failing in real world
37,970,895
<p>This is my first question on this site. I'm attempting to practice neural networks by having my program predict whether the temperature will go up or down on a given day relative to the previous day. My training data set consists of the previous ten days and whether they went up or down relative to the day before ...
0
2016-06-22T14:22:30Z
37,971,491
<p>What Ashafix says was my first though, you should post your training and test data also the data that you use for 'real world'. Another problem it could be that when you are testing, you are using only previous correct whether data(data you already have), and when you are in practice you are using your predicts and ...
0
2016-06-22T14:47:55Z
[ "python", "neural-network", "prediction" ]
Encoding of measurements exported from photoshop CS4 to read in Python
37,971,107
<p>I exported some measurements (not image files) from Photoshop in CS4. <a href="https://helpx.adobe.com/photoshop/using/measurement.html" rel="nofollow">This page</a> describes the tool in CS6 and up, where the measurements nicely export to a csv with utf-8 encoding. In CS4, it exports as a tab-delimited text, and I ...
0
2016-06-22T14:31:04Z
37,971,108
<p>I was getting close to posting one of these files here to see if someone could figure it out, but before doing so I opened one in Excel. When I did Save As, Excel defaulted to a utf-16 text file. </p> <p>I was able to open these files with csv and <code>encoding = utf-16</code>, and with pandas <code>read_table</co...
0
2016-06-22T14:31:04Z
[ "python", "encoding", "photoshop", "cs4" ]
Communication between python applications
37,971,151
<p>I'm having trouble finding a good solution for a client server system where the clients make requests to the server and the server responds with the result. The server needs to be independent from the clients, i.e. if I create a new python application I want to easily be able to connect to the server and send reques...
0
2016-06-22T14:33:08Z
37,971,406
<p>Check out <a href="http://zeromq.org/bindings:python" rel="nofollow"><strong><code>ZeroMQ</code></strong></a>. It can be used point to point like a super powered socket and looks nice and clean in your code like your example. <a href="http://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/client_serv...
0
2016-06-22T14:44:32Z
[ "python", "multithreading", "server", "client" ]
Communication between python applications
37,971,151
<p>I'm having trouble finding a good solution for a client server system where the clients make requests to the server and the server responds with the result. The server needs to be independent from the clients, i.e. if I create a new python application I want to easily be able to connect to the server and send reques...
0
2016-06-22T14:33:08Z
37,973,448
<p>Once I played with these things (in Python) and here's an example (don't mind the code style, format, efficiency, as they are lame, lots of NO-NOs from programming's PoV, just look at it as it was a starting point):</p> <blockquote> <p>server.py:</p> </blockquote> <pre><code>import sys import select from SocketS...
0
2016-06-22T16:18:57Z
[ "python", "multithreading", "server", "client" ]
How to instruct Heroku NOT to run collectstatic automatically on deploy?
37,971,195
<p>I have a Django-based project on GitHub that I'd like everyone to be able to deploy using the one-click deploy button. It does not use the <code>django.contrib.staticfiles</code> app.</p> <p>I have the following <code>app.json</code> file at the root of the project:</p> <pre><code>{ "name": "Django project", "...
0
2016-06-22T14:35:16Z
37,971,196
<p>Just add <code>"DISABLE_COLLECTSTATIC": { "value": "1" }</code> to your <code>env</code> object in your <code>app.json</code>, like so:</p> <pre><code>"env": { "DISABLE_COLLECTSTATIC": { "description": "Don't run python manage.py collectstatic --noinput on deploy", "value": "1" } } </code></pre> <p>Als...
0
2016-06-22T14:35:16Z
[ "python", "django", "heroku" ]
Python - Parse XML or conver to JSON Alexa API Data
37,971,220
<p>I have some data in xml coming in through alexa. It looks like this: </p> <pre><code>&lt;!-- Need more Alexa data? Find our APIs here: https://aws.amazon.com/alexa/ --&gt; &lt;ALEXA VER="0.9" URL="yahoo.com/" HOME="0" AID="=" IDN="yahoo.com/"&gt; &lt;SD&gt; &lt;POPULARITY URL="yahoo.com/" TEXT="5" SOURCE="panel"...
0
2016-06-22T14:36:02Z
37,971,328
<p>So there is no such thing as a one to one mapping tool which will automatically turn your xml to JSON. The best bet would be to parse XML using Python's built in abilities like <a href="https://docs.python.org/2/library/xml.html" rel="nofollow">https://docs.python.org/2/library/xml.html</a> or you could try to use ...
1
2016-06-22T14:40:43Z
[ "python", "json", "xml" ]
Python - Parse XML or conver to JSON Alexa API Data
37,971,220
<p>I have some data in xml coming in through alexa. It looks like this: </p> <pre><code>&lt;!-- Need more Alexa data? Find our APIs here: https://aws.amazon.com/alexa/ --&gt; &lt;ALEXA VER="0.9" URL="yahoo.com/" HOME="0" AID="=" IDN="yahoo.com/"&gt; &lt;SD&gt; &lt;POPULARITY URL="yahoo.com/" TEXT="5" SOURCE="panel"...
0
2016-06-22T14:36:02Z
37,979,661
<p>If all you want is the <em>RANK</em> attribute from the <em>REACH</em> tag, you can use the builtin <a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow">xml.etree</a>, it is just a matter of finding the REACH tag and extracting the attribute with <code>.get</code>:</p> <pre><code>In...
0
2016-06-22T23:08:07Z
[ "python", "json", "xml" ]
Python scipy not installed
37,971,237
<p>I am trying to install python scipy because I need it to work with some .mat files coming from matlab. To install it, I downloaded Anaconda for Windows 64-bit, for Python 2.7 (my version) and run the file.exe.</p> <p>However, when I type <code>import scipy.io</code> in the python command line, I receive the error: ...
0
2016-06-22T14:36:40Z
38,803,885
<p>$ sudo apt-get install python-scipy</p>
0
2016-08-06T11:40:40Z
[ "python", "windows", "python-2.7", "installation", "scipy" ]
Python multiprocessing - When is a referenced object shared? When is it copied?
37,971,246
<p>I have a data structure <code>L</code> (it could be a list, a dict, ...) and I need multiple processes to read from it. I don't want to use a <code>multiprocessing.Manager</code> because it's slow. </p> <p>Now if <code>L</code> is never modified, the <a href="http://stackoverflow.com/questions/10721915/shared-memor...
1
2016-06-22T14:36:59Z
37,977,569
<p>Python <code>multiprocessing</code> does not share memory between processes and passes objects (including the called function) between processes by pickling them (representing the object as a string). So when you call a function within a pool, the main process must pickle the function, pass the pickled representatio...
0
2016-06-22T20:21:45Z
[ "python", "python-3.x", "python-multiprocessing", "copy-on-write" ]
NLTK POS Tags - Unable to Export CSV
37,971,268
<p>I have this code which I have been using for sometime. I wonder if there is a way to read csv file per line (twitter feeds) and export the output in csv. </p> <p>I am ideally looking to extract Noun terms per line i.e. in my case a twitter feed.</p> <p>Here is the code. I am sorry but I am new to Python.</p> <p><...
0
2016-06-22T14:38:27Z
37,971,762
<p>(csv docs) <a href="https://docs.python.org/2/library/csv.html" rel="nofollow">https://docs.python.org/2/library/csv.html</a></p> <pre><code>import csv all_nouns = [] with open('twitter_feed.csv', 'rb') as csvfile: tweetreader = csv.reader(csvfile, delimiter=',', quotechar='"') for tweet in tweetreader: ...
0
2016-06-22T14:59:55Z
[ "python", "twitter", "nltk" ]
TypeError: not all arguments converted during string formatting. What am I not doing right
37,971,285
<p>I have tried:</p> <pre><code>sql = "INSERT INTO "+ tablenane + " ("+ ",".join(headers) +") VALUES (" + ",".join(["%s"] * len(headers)) + ")" </code></pre> <p>and:</p> <pre><code>sql = "INSERT INTO "+ tablenane + " ("+ ",".join(headers) +") VALUES (" + ",".join(["?"] * len(headers)) + ")" </code></pre> <p>but sti...
0
2016-06-22T14:39:00Z
37,985,119
<p>I read somewhere that MySQL-python does not allow "?". All I was missing was the db.commit()</p> <p>Final query was</p> <p>sql = "INSERT INTO "+ tablenane + " ("+ ",".join(headers) +") VALUES (" + ",".join(['%s'] * len(headers)) + ")"</p> <p>cursor.executemany(sql, dataset)</p> <p>db.commit(). Though not sure wh...
0
2016-06-23T07:39:24Z
[ "python", "mysql" ]
Column Order in Pandas Dataframe from dict of dict
37,971,322
<p>I am creating a pandas dataframe from a dictionary of dict in the following way :</p> <pre><code>df = pd.DataFrame.from_dict(stats).transpose() </code></pre> <p>I want the columns in a particular order but cant seem to figure out how to do so. I have tried this:</p> <pre><code>df = pd.DataFrame(columns=['c1','c2'...
0
2016-06-22T14:40:29Z
37,971,411
<p>You could do:</p> <pre><code>df = pd.DataFrame.from_dict(stats).transpose().loc[:, ['c1','c2','c3']] </code></pre> <p>or just </p> <pre><code>df = pd.DataFrame.from_dict(stats).transpose()[['c1','c2','c3']] </code></pre>
1
2016-06-22T14:44:40Z
[ "python", "dictionary", "pandas", "dataframe" ]
Column Order in Pandas Dataframe from dict of dict
37,971,322
<p>I am creating a pandas dataframe from a dictionary of dict in the following way :</p> <pre><code>df = pd.DataFrame.from_dict(stats).transpose() </code></pre> <p>I want the columns in a particular order but cant seem to figure out how to do so. I have tried this:</p> <pre><code>df = pd.DataFrame(columns=['c1','c2'...
0
2016-06-22T14:40:29Z
37,971,453
<p>If you know the order, you can manually adjust as follows:</p> <pre><code>df = df[['c1','c3','c2']] </code></pre> <p>You can also do it by just creating a list of column names</p> <pre><code>disiredOrder = ['c1','c3','c2'] df = df[disiredOrder] </code></pre>
1
2016-06-22T14:46:19Z
[ "python", "dictionary", "pandas", "dataframe" ]
Deep lowercase inside files inside folders inside a path
37,971,348
<p>Ok, this is the thing, I have been working on a project under Windows (not mine) and finally they decided to have a fully functional fork on Linux, the main problem is that the original programmers coded regarless the cases, opening and calling things using upercase o lowercase at will...crazy...right? Well, I manag...
2
2016-06-22T14:42:13Z
37,971,903
<p>Please decompose your problem.</p> <p>You can either go top-down or bottom-up. I recommend bottom-up.</p> <p>That is, descend to leaf directory, list <strong>all files</strong> (1) there, rename these files. Step out, rename that leaf directory. Step out, ...</p> <p>Code:</p> <pre><code>def descend(path): fo...
1
2016-06-22T15:06:20Z
[ "python", "linux", "file", "folders", "lowercase" ]
Calculating Energy of image frame using DWT in python shows wrong value
37,971,371
<p>I want to find the energy of the image frame. This is how I calculated in Matlab.</p> <pre><code>[~,LH,HL,HH] = dwt2(rgb2gray(maskedImage),'db1'); % applying dwt E = HL.^2 + LH.^2 + HH.^2; % Calculating the energy of each pixel. Eframe = sum(sum(E))/(m*n); % m,n row and columns of image. </code></pre> <p>when...
0
2016-06-22T14:43:03Z
37,973,117
<p>The problem with your analysis is that numpy arrays and MATLAB matrices are in different orders (by default). The first dimension of a 2D numpy array is the row, while the first dimension of a 2D MATLAB matrix is the column. The <code>dwt2</code> function is dependent on this order. So in order to get the same ou...
0
2016-06-22T16:01:39Z
[ "python", "matlab", "dwt" ]
How to create a nested data structure in Python?
37,971,434
<p>Since I recently started a new project, I'm stuck in the "think before you code" phase. I've always done basic coding, but I really think I now need to carefully plan how I should organize the results that are produced by my script.</p> <p>It's essentially quite simple: I have a bunch of satellite data I'm extracti...
0
2016-06-22T14:45:27Z
37,971,691
<ul> <li>Lists: Don't use lists for nested and complex data structures. You're just shooting yourself in the foot- code you write will be specialized to the exact format you are using, and any changes or additions will be brutal to implement.</li> <li>Dictionaries: Aren't bad- they'll nest nicely and you can use a dict...
4
2016-06-22T14:56:26Z
[ "python" ]
How does the indexing of subplots work
37,971,541
<p>I have the following:</p> <pre><code>import matplotlib.pyplot as plt fig = plt.figure() for i in range(10): ax = fig.add_subplot(551 + i) ax.plot([1,2,3,4,5], [10,5,10,5,10], 'r-') </code></pre> <p>I was imagining that the <code>55</code> means that it is creating a grid that is 5 subplots wide and 5 sub...
0
2016-06-22T14:50:30Z
37,971,874
<p>In the convience shorthand notation, the <code>55</code> does mean there are 5 rows and 5 columns. However, the shorthand notation only works for single-digit integers (i.e. for nrows, ncols and plot_number all less than 10). </p> <p>You can expand it to full notation (i.e. use commas: <code>add_subplot(nrows, ncol...
2
2016-06-22T15:04:41Z
[ "python", "matplotlib" ]
How does the indexing of subplots work
37,971,541
<p>I have the following:</p> <pre><code>import matplotlib.pyplot as plt fig = plt.figure() for i in range(10): ax = fig.add_subplot(551 + i) ax.plot([1,2,3,4,5], [10,5,10,5,10], 'r-') </code></pre> <p>I was imagining that the <code>55</code> means that it is creating a grid that is 5 subplots wide and 5 sub...
0
2016-06-22T14:50:30Z
37,973,295
<p>Although tom answered your question, in this sort of situation you should be using <code>fig, axs = plt.subplots(n, m)</code>. This will create a new figure with the <code>n</code> rows and <code>m</code> columns of subplots. <code>fig</code> is the figure created. <code>axs</code> is a 2D numpy array where each ...
1
2016-06-22T16:11:54Z
[ "python", "matplotlib" ]
Comparing field data line by line in python or Shell
37,971,646
<p>I have input file with below data:</p> <pre><code>Mode|Date|Count|timestamp|status HR|06/08/2016|3000|Thu Jun 09 2016|Complete HR|06/08/2016|3010|Thu Jun 09 2016|Complete HR|06/08/2016|2000|Thu Jun 09 2016|Complete HR|06/08/2016|2000|Fri Jun 09 2016|Complete HR|06/08/2016|1000|Thu Jun 09 2016|Complete HR|06/08/2016...
1
2016-06-22T14:54:19Z
37,974,467
<p>You can use awk:</p> <pre><code>awk 'BEGIN{ FS="|" } NR==1 { split($0, h, /\|/) next } NR%2==0 { pr=$0 split($0, a, /\|/) next } { s = "" for(i=1; i&lt;=NF; i++) if ($i != a[i]) s = sprintf("%s%s", s, (!s? "" : " and ") h[i]) print s, "Mismatch:" ORS pr ORS $0 }' file Coun...
1
2016-06-22T17:14:25Z
[ "python", "shell", "unix", "ksh" ]
How to manage chrome local storage
37,971,725
<p>I'm using <code>Selenium</code> + <code>Python</code> + <code>ChromeDriver</code> to test web application. Web application contains tables with data that could be sorted using various embedded filters. The problem is that after first test executed application saves current state (like which table page is opened, whi...
1
2016-06-22T14:57:59Z
37,971,758
<p>You should <em>execute the script</em> instead:</p> <pre><code>driver.execute_script('window.localStorage.clear();') </code></pre>
0
2016-06-22T14:59:45Z
[ "python", "selenium", "local-storage", "selenium-chromedriver" ]
How to sort a list of tuples based on the keys in a list?
37,971,820
<p>I want to sort a list of tuples based on a number of keys. For example, I have this list of tuples:</p> <pre><code>list_t = [(1, 3, 5, 6, 9, 10), (1, 2, 3, 4, 5, 61), (1, 2, 3, 0, 9, 81), (1, 2, 6, 7, 9, 54), (1, 3, 5, 6, 12, 43)] </code></pre> <p>One time I want to sort it by the first, second, third, and fifth e...
2
2016-06-22T15:02:09Z
37,971,894
<p>Here you go. You can read more about <code>operator.itemgetter</code> <a href="https://docs.python.org/3.5/library/operator.html#operator.itemgetter">here in the docs</a>.</p> <pre><code>import operator list_t = [(1, 3, 5, 6, 9, 10), (1, 2, 3, 4, 5, 61), (1, 2, 3, 0, 9, 81), (1, 2, 6, 7, 9, 54), (1, 3, 5, 6, 12, 43...
6
2016-06-22T15:05:53Z
[ "python", "list", "sorting", "tuples", "list-comprehension" ]
How to sort a list of tuples based on the keys in a list?
37,971,820
<p>I want to sort a list of tuples based on a number of keys. For example, I have this list of tuples:</p> <pre><code>list_t = [(1, 3, 5, 6, 9, 10), (1, 2, 3, 4, 5, 61), (1, 2, 3, 0, 9, 81), (1, 2, 6, 7, 9, 54), (1, 3, 5, 6, 12, 43)] </code></pre> <p>One time I want to sort it by the first, second, third, and fifth e...
2
2016-06-22T15:02:09Z
37,972,100
<p>michael_j_ward's answer is a much cleaner solution to your question, but if you want to know what went wrong with your original idea:</p> <p>You are attempting to sort generator objects, which I am guessing has a different way of equating. A way to show this is by showing what you are actually attempting to sort wi...
2
2016-06-22T15:15:21Z
[ "python", "list", "sorting", "tuples", "list-comprehension" ]
Is it possible to Pass values between C# and python and edit them both ways.
37,971,864
<p>I'm learning python for home automation a few months now and want to learn C# for building apps.</p> <p>My python file is turning devices on and off automatically. Now I want to make an app that can read this python file, see if the device is on or off.( lamp=o or lamp=1 ). For this it must read a variable from pyt...
0
2016-06-22T15:04:21Z
37,971,906
<p>I think the easiest way to do this would be to store the data in a shared resource of some kind. Perhaps your python script could store values in a database and your C# application could refer to the database to retrieve the state of your bulbs, switches, etc.</p>
2
2016-06-22T15:06:31Z
[ "c#", "python" ]
How to simplify several functions with the same purpose
37,971,929
<p>Let's say I have several functions that basically do the same thing but on a set of different variables. I think about something like that:</p> <pre><code>def changex(): if x: # do procedure1 with x as variable else: # do procedure2 with x as variable def changey(): if y: # do p...
0
2016-06-22T15:07:23Z
37,971,985
<p>Functions can accept variables as parameters.<br> Something like this:</p> <pre><code>def change(p): if p: # do procedure1 with p as variable else: # do procedure2 with p as variable </code></pre> <p>Then <code>changex()</code> becomes <code>change(x)</code>; <code>changey()</code> become...
3
2016-06-22T15:10:30Z
[ "python", "function", "python-3.x" ]
How to simplify several functions with the same purpose
37,971,929
<p>Let's say I have several functions that basically do the same thing but on a set of different variables. I think about something like that:</p> <pre><code>def changex(): if x: # do procedure1 with x as variable else: # do procedure2 with x as variable def changey(): if y: # do p...
0
2016-06-22T15:07:23Z
37,972,013
<p>Decorators are way too complex for what you are trying to do. Functions can take arguments, so you can pass in the variable you want to do stuff with:</p> <pre><code>def change(var): if var: procedure1(var) else: procedure2(var) </code></pre> <p>Notice that I used <code>if/else</code> inste...
1
2016-06-22T15:11:32Z
[ "python", "function", "python-3.x" ]
Pythons Pandas `from_dict` formating `to_csv`
37,972,018
<p>Ive got a dictionary in the following format <code>key[0],key[1], value</code> im trying to put this dict into a DataFrame and then write this to a csv file. Now trying to work out how to format the DataFrame is causing me pains. Ive read the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Data...
0
2016-06-22T15:11:55Z
37,972,701
<p>You can easily construct a pandas data frame from a list of tuples.</p> <pre><code>d = {(0,1): 'a', (0,2): 'b', (1,2): 'c'} data = [(k1,k2,v) for (k1,k2),v in d.items()] df = pd.DataFrame(data, columns=['key1', 'key2', 'value']) df </code></pre> <p>Outputs:</p> <pre><code> key1 key2 value 0 0 1 a 1 1 ...
2
2016-06-22T15:41:08Z
[ "python", "pandas" ]
Regex to match PEP440 compliant version strings
37,972,029
<p><a href="https://www.python.org/dev/peps/pep-0440" rel="nofollow">PEP 440</a> lays out what is the accepted format for version strings of Python packages.</p> <p>These can be simple, like: <code>0.0.1</code></p> <p>Or complicated, like: <code>2016!1.0-alpha1.dev2</code></p> <p>What is a suitable regex which could...
1
2016-06-22T15:12:08Z
37,972,030
<p>I think this should comply with PEP440:</p> <pre><code>^(\d+!)?(\d+)(\.\d+)+([\.\-\_])?((a(lpha)?|b(eta)?|c|r(c|ev)?|pre(view)?)\d*)?(\.?(post|dev)\d*)?$ </code></pre> <h3>Explained</h3> <p>Epoch, e.g. <code>2016!</code>:</p> <pre><code>(\d+!)? </code></pre> <p>Version parts (major, minor, patch, etc.):</p> <p...
1
2016-06-22T15:12:08Z
[ "python", "regex", "pep" ]
Regex to match PEP440 compliant version strings
37,972,029
<p><a href="https://www.python.org/dev/peps/pep-0440" rel="nofollow">PEP 440</a> lays out what is the accepted format for version strings of Python packages.</p> <p>These can be simple, like: <code>0.0.1</code></p> <p>Or complicated, like: <code>2016!1.0-alpha1.dev2</code></p> <p>What is a suitable regex which could...
1
2016-06-22T15:12:08Z
38,020,327
<p>I had the same question. This is the most thorough regex pattern I could find. PEP440 links to the codebase of the packaging library in it's references section.</p> <pre><code>pip install packaging </code></pre> <p>To access just the pattern string you can use the global</p> <pre><code>from packaging import versi...
3
2016-06-24T18:55:28Z
[ "python", "regex", "pep" ]
Java TCP server not receiving packets until client disconnects
37,972,060
<p>I have a TCP server in Java and a client written in Python. The python client simply sends 10 packets waiting 2 seconds in between each send. However, the java server doesn't seem to recognize the packets until the python script terminates, in which it finally receives all the messages as if they came in at the same...
1
2016-06-22T15:13:47Z
37,972,139
<p>You are trying to read a complete line. But because you never send an newline <code>\n</code> it just waits until the stream is closed. Either send newlines in your client or don't read lines.</p>
0
2016-06-22T15:17:20Z
[ "java", "python", "sockets", "tcp" ]
Java TCP server not receiving packets until client disconnects
37,972,060
<p>I have a TCP server in Java and a client written in Python. The python client simply sends 10 packets waiting 2 seconds in between each send. However, the java server doesn't seem to recognize the packets until the python script terminates, in which it finally receives all the messages as if they came in at the same...
1
2016-06-22T15:13:47Z
37,972,153
<p>You are using <code>BufferedReader.readLine()</code> in the server... but never sending a new line symbol from the client.</p> <p>As such, the server doesn't know whether it is going to receive more data in that line, and so has to wait until it is sure that no more data will be sent on that line: closing the socke...
1
2016-06-22T15:17:56Z
[ "java", "python", "sockets", "tcp" ]
python Search for subdirectories
37,972,065
<p>I'd like to create a list of all sub-directories that contain "HICU-B" in their name. Only directories not files (some files in the parent directory contain this too).</p> <p>I'm wondering if there is a way to combine <code>glob</code> and <code>os.walk()</code> together to accomplish this. Or if there is another w...
0
2016-06-22T15:14:04Z
37,972,553
<p>Append a slash <code>'/'</code> to the end of <code>HICU-B*</code>:</p> <pre><code>dirstext = glob.glob('/data01/HICU-B*/') </code></pre> <p>This would return only directories with names starting with <code>HICU-B*</code> while files will be excluded.</p> <p>If you need to <code>walk</code> through the matching d...
1
2016-06-22T15:35:05Z
[ "python", "linux", "glob", "os.walk" ]
Convert CSV Scrape to mySQL insert
37,972,104
<p>I have a python script that is scraping a website into a csv file. I am trying to convert it to an mySQL insert statement. The code below is inserting NULL values into my table. How can I alter it to work?</p> <p>Note: the commented out lines are removing the CSV scrape that is working.</p> <pre><code>#f = code...
0
2016-06-22T15:15:37Z
37,993,294
<p>I used Drew's suggestion to use load data infile. I ran the script as normal which creates the csv. I then added code that loads the data after the script was created.</p>
0
2016-06-23T13:37:56Z
[ "python", "mysql" ]
How to calculate the mean of a pandas DataFrame with NaN values
37,972,166
<p>I have a DataFrame that looks like as follows (the address key is the index):</p> <p><code>address date1 date2 date3 date4 date5 date6 date7 &lt;email&gt; NaN NaN NaN 1 NaN NaN NaN</code></p> <p>I want to calculate the mean across a row, but when I use <code>...
1
2016-06-22T15:18:29Z
37,972,524
<p>Despite appearances your dtypes are not numeric hence the <code>NaN</code> values, you need to cast the type using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.astype.html#pandas.Series.astype" rel="nofollow"><code>astype</code></a>:</p> <pre><code>df['date4'] = df['date4'].astype(in...
1
2016-06-22T15:33:54Z
[ "python", "pandas", "dataframe", null, "mean" ]
pd.to_datetime() returning incorrect date
37,972,224
<p>I'm trying to extract all of the unique values in a date column. In this case, there is only one value so it's easy to see the error.</p> <p>The code I'm using to see this is:</p> <pre><code>print df['Date'].unique() print pd.to_datetime(df['Date'], format = "%Y-%m-%d").unique()) </code></pre> <p>The two results ...
1
2016-06-22T15:21:07Z
37,973,238
<p>This is just an issue with how <code>numpy</code> is displaying the dates - in version <code>1.11</code> it goes away.</p> <pre><code>In [55]: np.__version__ Out[55]: '1.10.4' In [56]: pd.to_datetime(['2015-05-31']) Out[56]: DatetimeIndex(['2015-05-31'], dtype='datetime64[ns]', freq=None) In [57]: pd.to_datetime(...
1
2016-06-22T16:08:10Z
[ "python", "pandas", "datetime-format" ]
Crop plot 1 according to the shape of plot 2
37,972,256
<p>I'm trying to plot a heatmap with the plt.pcolormesh, and then plot the outline of my figure with the plt.scatter and I would like to crop the result according to the shape of the last plot which is the outline.</p> <p>It doesn't seem that hard to do but still I haven't managed to do it or found anything. Here is m...
1
2016-06-22T15:21:55Z
37,972,639
<p>You can just use plt.xlim() and plt.ylim() and give them the coordinates of the new figure. Here is a modified version of the code:</p> <pre><code>plt.rcParams['figure.figsize'] = (10.0, 10.0) plt.axis('off') plt.pcolormesh(x, y, intens) plt.colorbar() coord = np.genfromtxt('myfile.csv', delimiter=' ') x = coord[:,...
0
2016-06-22T15:38:30Z
[ "python", "matplotlib", "plot", "crop" ]
Python - how to extract the last occurrence meeting a certain condition from a list
37,972,332
<p>For example, I have the following data as a list:</p> <pre><code>l = [['A', 'aa', '1', '300'], ['A', 'ab', '2', '30'], ['A', 'ac', '3', '60'], ['B', 'ba', '5', '50'], ['B', 'bb', '4', '10'], ['C', 'ca', '6', '50']] </code></pre> <p>Now for <code>'A'</code>, <code>'B'</code>, and <code>'C'<...
0
2016-06-22T15:25:28Z
37,972,603
<p>Even though I'm not sure I understood your question, here's what you could do:</p> <pre><code>li = [l[i][0] for i in range(len(l))] [l[j][2] for j in [''.join(li).rfind(i) for i in set(li)]] </code></pre> <p>Note that the output is <code>[3,4,6]</code>, as the last occurrence of <code>A</code> seems to be the thir...
1
2016-06-22T15:36:59Z
[ "python", "list", "data-manipulation" ]
Python - how to extract the last occurrence meeting a certain condition from a list
37,972,332
<p>For example, I have the following data as a list:</p> <pre><code>l = [['A', 'aa', '1', '300'], ['A', 'ab', '2', '30'], ['A', 'ac', '3', '60'], ['B', 'ba', '5', '50'], ['B', 'bb', '4', '10'], ['C', 'ca', '6', '50']] </code></pre> <p>Now for <code>'A'</code>, <code>'B'</code>, and <code>'C'<...
0
2016-06-22T15:25:28Z
37,972,675
<p>A not-very-pythonic approach: (note that Nils' solution is the most pythonic - using list comprehension)</p> <pre><code>def get_last_row(xs,q): for i in range(len(xs)-1,-1,-1): if xs[i][0] == q: return xs[i][2] def get_third_cols(xs): third_cols = [] for q in ["A","B","C"]: ...
0
2016-06-22T15:40:10Z
[ "python", "list", "data-manipulation" ]
Python - how to extract the last occurrence meeting a certain condition from a list
37,972,332
<p>For example, I have the following data as a list:</p> <pre><code>l = [['A', 'aa', '1', '300'], ['A', 'ab', '2', '30'], ['A', 'ac', '3', '60'], ['B', 'ba', '5', '50'], ['B', 'bb', '4', '10'], ['C', 'ca', '6', '50']] </code></pre> <p>Now for <code>'A'</code>, <code>'B'</code>, and <code>'C'<...
0
2016-06-22T15:25:28Z
37,972,729
<p><code>{l[0]: l[2] for l in vals}</code> will get you a mapping of 'A', 'B', and 'C' to their last values</p>
1
2016-06-22T15:42:09Z
[ "python", "list", "data-manipulation" ]
Python - how to extract the last occurrence meeting a certain condition from a list
37,972,332
<p>For example, I have the following data as a list:</p> <pre><code>l = [['A', 'aa', '1', '300'], ['A', 'ab', '2', '30'], ['A', 'ac', '3', '60'], ['B', 'ba', '5', '50'], ['B', 'bb', '4', '10'], ['C', 'ca', '6', '50']] </code></pre> <p>Now for <code>'A'</code>, <code>'B'</code>, and <code>'C'<...
0
2016-06-22T15:25:28Z
37,972,754
<pre><code>l = [['A', 'aa', '1', '300'], ['A', 'ab', '2', '30'], ['A', 'ac', '3', '60'], ['B', 'ba', '5', '50'], ['B', 'bb', '4', '10'], ['C', 'ca', '6', '50']] import itertools for key, group in itertools.groupby(l, lambda x: x[0]): print key, list(group)[-1] </code></pre> <p>With no comment on "effic...
2
2016-06-22T15:43:59Z
[ "python", "list", "data-manipulation" ]
Python - how to extract the last occurrence meeting a certain condition from a list
37,972,332
<p>For example, I have the following data as a list:</p> <pre><code>l = [['A', 'aa', '1', '300'], ['A', 'ab', '2', '30'], ['A', 'ac', '3', '60'], ['B', 'ba', '5', '50'], ['B', 'bb', '4', '10'], ['C', 'ca', '6', '50']] </code></pre> <p>Now for <code>'A'</code>, <code>'B'</code>, and <code>'C'<...
0
2016-06-22T15:25:28Z
37,974,561
<p>This will generalize to any key / value location. note, the output will be in <em>in the order that the first key was observed</em>. It would wouldn't be hard to adjust so that the order of the output is the order that the output value was observed</p> <pre><code>import operator l = [['A', 'aa', '1', '300'], ['A...
0
2016-06-22T17:21:00Z
[ "python", "list", "data-manipulation" ]
Passing copy of a list to a function in python
37,972,334
<p>I'm trying to pass a copy of a list to a function in python so I can pop and append to a new list without losing the information in the old list. But I'm having trouble.</p> <p>here's my code</p> <pre><code>def show_magicians(magicians): for magician in magicians: print (magician.title()) retu...
0
2016-06-22T15:25:30Z
37,972,455
<p>You are returning after the first magician is processed</p> <p>Change the make_great function as follows</p> <pre><code>def make_great(magicians): for magician in magicians: new_magician = magicians.pop() new_magicians.append(new_magician) print (new_magician.title() + ", is a great mag...
2
2016-06-22T15:30:38Z
[ "python", "list", "function", "copy" ]
Passing copy of a list to a function in python
37,972,334
<p>I'm trying to pass a copy of a list to a function in python so I can pop and append to a new list without losing the information in the old list. But I'm having trouble.</p> <p>here's my code</p> <pre><code>def show_magicians(magicians): for magician in magicians: print (magician.title()) retu...
0
2016-06-22T15:25:30Z
37,972,868
<p>The <a href="http://stackoverflow.com/a/37972455/3001761">existing answer</a> solves your immediate problem, but your code is still unnecessarily confusing, which I think contributed to your getting stuck.</p> <p>The <em>"correct"</em> way to do this is to avoid mutating <code>magicians</code> within <code>make_gre...
1
2016-06-22T15:49:49Z
[ "python", "list", "function", "copy" ]
Passing copy of a list to a function in python
37,972,334
<p>I'm trying to pass a copy of a list to a function in python so I can pop and append to a new list without losing the information in the old list. But I'm having trouble.</p> <p>here's my code</p> <pre><code>def show_magicians(magicians): for magician in magicians: print (magician.title()) retu...
0
2016-06-22T15:25:30Z
37,983,301
<p>Ok so first of all thank you all so much. I finally figured out the problem and how to solve it. The exercise I'm working on specifically wants me to use the [:] to make a shallow copy of the list and pass it through a function to create a new list by popping.</p> <p>The problem was I kept the <code>for</code> lo...
0
2016-06-23T05:50:39Z
[ "python", "list", "function", "copy" ]
Pandas reading excel file with simple multicolumn index
37,972,467
<p>I have an excel file which looks like this</p> <p><a href="http://i.stack.imgur.com/3uFJ2.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/3uFJ2.jpg" alt="enter image description here"></a></p> <p>When I read this whith pandas.read_excel pandas returns a df which looks like this:</p> <pre><code> ...
1
2016-06-22T15:31:15Z
37,973,105
<p>You could try:</p> <pre><code>df.columns = df.columns.to_series().str.replace(r'^Unnamed', np.nan).fillna(method='ffill').tolist() </code></pre>
1
2016-06-22T16:00:46Z
[ "python", "excel", "pandas", "dataframe" ]
Pandas reading excel file with simple multicolumn index
37,972,467
<p>I have an excel file which looks like this</p> <p><a href="http://i.stack.imgur.com/3uFJ2.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/3uFJ2.jpg" alt="enter image description here"></a></p> <p>When I read this whith pandas.read_excel pandas returns a df which looks like this:</p> <pre><code> ...
1
2016-06-22T15:31:15Z
37,974,890
<p>You would need to create a new column list &amp; then redefine the column names like below :</p> <pre><code>df.columns = df.columns.astype(str) new_columns = [df.columns[i-1] if df.columns[i].find("Unnamed") &gt;= 0 else df.columns[i] for i in range(len(df.columns))] df.columns = new_columns </code></pre> <p>...
1
2016-06-22T17:41:46Z
[ "python", "excel", "pandas", "dataframe" ]
selenium-webdriver: select not working in Firefox 47
37,972,494
<p>I'm trying to select an option in a select form on a website with Selenium.</p> <p>It used to work fine, but after upgrading Selenium and Firefox and switching to the Marionette Webdriver to make the upgrade work, my code doesn't work anymore.</p> <p>The desired form gets selected and the code doesn't raise an exc...
0
2016-06-22T15:32:41Z
37,976,065
<p>Looking at the <a href="https://github.com/SeleniumHQ/selenium/blob/master/py/CHANGES" rel="nofollow">CHANGELOG</a> on the repo, the new beta drivers seem to support Firefox version 4x. It might behoove of you to check which version you have.</p> <p>Side note: I am running the latest version of selenium with Java, ...
0
2016-06-22T18:49:36Z
[ "python", "selenium", "firefox", "selenium-webdriver" ]
Executing a class method as a Lambda handler
37,972,554
<p>I'm attempting to use a class method as a Lambda handler within AWS. I've followed along with the example setup (creating a virtualenv and zipping it up) but I'm not able to get a working call.</p> <p>My package name is "cloudwatch_metrics" and this is my package init file:</p> <pre><code>from exporter import Exp...
1
2016-06-22T15:35:07Z
37,979,216
<p>I gave up and added some shim scripts that set up imports and called into the correct function. Each class got a unique shim file. As a positive side benefit, that shortened the string name of the handler function and makes it more readable in the AWS Console.</p>
0
2016-06-22T22:22:03Z
[ "python", "aws-lambda" ]
Python 3 Evaluate Variable in String
37,972,607
<p>Self admitted PHP coder turning to the Python side and my head hurts. I'm trying to do what I think would be simple. Read in a file (have that working) and then store each lines input into a variable then evaluate the string variable into an existing string of text.</p> <p>Here's what I have:</p> <pre><code>with o...
0
2016-06-22T15:37:08Z
37,973,273
<p>First, as @acushner suggests, you should <code>strip</code> your line:</p> <pre><code>"/vmrest/users?query=(alias%2520is%2520{})".format(user.strip()) </code></pre> <p>This will remove any leading or trailing whitespace from the <code>user</code> string. Keep in mind that in Python, when you read a file's lines, i...
1
2016-06-22T16:10:21Z
[ "python", "python-3.x" ]
using fixture return value as value in mark.parametrize()
37,972,610
<p>my question is - is it possible to use return value from fixture as a value in parametrize? The problem is - I'd like to dynamically get possible values (for example, available systems on a virtual server) for parametrize. I can access these when a virtual server is created by one of the fixtures. Tests look like th...
0
2016-06-22T15:37:27Z
37,975,718
<p>I think you may be unable to achieve what you want directly. Because <code>@pytest.mark.parametrize</code> is being called during collecting, and fixtures will be called after collection completed.</p> <p>But I have an alternative way to achieve similar result, mainly by extending pytest plugin <code>pytest_generat...
1
2016-06-22T18:29:16Z
[ "python", "py.test" ]
Import Jupyter notebook as a module: path problems
37,972,643
<p>I am trying load some of my Jupyter notebooks as modules. Jupyter has nice instructions on how to do it <a href="http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Importing%20Notebooks.html" rel="nofollow">here</a>. I have copied all the necessary functions and classes in the <code>notebook_import.p...
0
2016-06-22T15:38:38Z
37,985,071
<p><strong>[I add this as an answer because as a comment the formatting is not enough to explain my comment. I'm guessing so maybe it is not a good answer].</strong></p> <p>I suppose you are doing so from other notebook. If you started jupyter on a folder (you are on win10), e.g., inside folder:</p> <pre><code>C:\my_...
1
2016-06-23T07:37:11Z
[ "python", "module", "path", "ipython", "jupyter" ]
Save pandas dataframe to disk work by row
37,972,647
<p>Pandas has <a href="http://pandas.pydata.org/pandas-docs/stable/io.html" rel="nofollow">many output formats</a>. Which of these is best suited for iteratively appending rows to a dataframe and having them written to disk immediately - so that if the program or machine crashes, the last computed row is still saved an...
0
2016-06-22T15:38:44Z
37,972,796
<p>You can use <code>pd.HDFStore.append()</code> or <code>df.to_hdf(path, 'table_name', append=True)</code> - see <a href="http://pandas.pydata.org/pandas-docs/stable/io.html#hdf5-pytables" rel="nofollow">HDF docs</a>, and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.HDFStore.append.html" rel="...
2
2016-06-22T15:46:13Z
[ "python", "pandas" ]
Save pandas dataframe to disk work by row
37,972,647
<p>Pandas has <a href="http://pandas.pydata.org/pandas-docs/stable/io.html" rel="nofollow">many output formats</a>. Which of these is best suited for iteratively appending rows to a dataframe and having them written to disk immediately - so that if the program or machine crashes, the last computed row is still saved an...
0
2016-06-22T15:38:44Z
37,973,014
<p>One solution would be to write a custom generator that writes to disk before yielding to the DataFrame</p> <pre><code>data = [(0,1,'a'), (0,2,'b'), (1,2,'c')] def writeGen(data_tuples): with open('file.csv', 'w') as f: for data in data_tuples: string = ','.join(str(c) for c in data) + '\n' ...
0
2016-06-22T15:56:11Z
[ "python", "pandas" ]
What is a right way of creating apps into django project? (doubts about file location)
37,972,648
<p>I have doubts about a right file location into a django project. </p> <p><strong>Prologue</strong></p> <p>Let's imaging, I'm going to create an ecommerce web app "consumer-to-consumer". One user can sell something and other one can buy it. Even though the app is big, assume that it contains a detail page of the pr...
0
2016-06-22T15:38:45Z
37,973,040
<p>A Django apps is usually a self-contained group of <strong>configurations, classes, views, templates and urls</strong> (all optional, of course), although it always has dependencies. They may be inserted or removed from a project at will.</p> <p>Given that definition, it makes sense to question: Does the next imple...
1
2016-06-22T15:57:54Z
[ "python", "django" ]
Django "update_or_create" API: how to filter objects by created or updated?
37,972,697
<p>So, I'm using the Django update_or_create API to build my form data. It works fine...but, once built, I need a way to check to see what profiles were actually updated or if they were created for the first time?</p> <p>Just an example:</p> <pre><code> for people in peoples: people, updated = People.objec...
0
2016-06-22T15:41:00Z
37,972,852
<p>As you have shown in your question, the <code>update_or_create</code> method returns a tuple <code>(obj, created)</code>, where <code>obj</code> in the object, and <code>created</code> is a boolean showing whether a new object was created.</p> <p>You could check the value of the boolean field, and create a list to ...
1
2016-06-22T15:48:45Z
[ "python", "django", "django-queryset", "django-filter" ]
Django "update_or_create" API: how to filter objects by created or updated?
37,972,697
<p>So, I'm using the Django update_or_create API to build my form data. It works fine...but, once built, I need a way to check to see what profiles were actually updated or if they were created for the first time?</p> <p>Just an example:</p> <pre><code> for people in peoples: people, updated = People.objec...
0
2016-06-22T15:41:00Z
37,972,907
<p>When you call <code>update_or_create</code>:</p> <pre><code>person, created = People.objects.update_or_create(...) </code></pre> <p>the <code>created</code> return value will be <code>True</code> if the record was freshly created, or <code>False</code> if it was an existing record that got updated. If you need to...
1
2016-06-22T15:51:17Z
[ "python", "django", "django-queryset", "django-filter" ]
How to change the encoding of JSON dictionary string value?
37,972,751
<p>I ran into an issue a string encoded with "utf-8" doesn't print as expected. The string contains accented letters (á, é, ü, ñ, etc.), and is part of a JSON dict returned from Wikipedia API. </p> <p>Below is an example with the letter é:</p> <p><strong>== The complete code: ==</strong></p> <pre><code>import u...
1
2016-06-22T15:43:34Z
37,975,625
<p>Your <code>check()</code> routine does some very odd things, including parsing the string representation of a dictionary.</p> <p>Try this instead:</p> <pre><code>def check(wikitext): for value in wikitext.values(): result = re.findall(ur'\[\[.*?\]\]', value) if result: return resul...
0
2016-06-22T18:23:44Z
[ "python", "json", "encoding", "diacritics", "wikipedia-api" ]
Retriving all the rows from a csv file and plotting
37,972,785
<p>I need to retrieve the rows from a csv file generated from the function:</p> <pre><code>def your_func(row): return (row['x-momentum']**2+ row['y-momentum']**2 + row['z-momentum']**2)**0.5 / row['mass'] columns_to_keep = ['#time', 'x-momentum', 'y-momentum', 'z-momentum', 'mass'] dataframe = pd.read_csv("./flas...
0
2016-06-22T15:45:51Z
37,974,740
<p>you can adjust <code>pd.options.display.max_rows</code> option, but it won't affect your plots, so your plots will contain all your data</p> <p>demo:</p> <pre><code>In [25]: df = pd.DataFrame(np.random.randint(0,100,size=(10, 3)), columns=list('ABC')) In [26]: df Out[26]: A B C 0 93 76 5 1 33 70 12...
1
2016-06-22T17:32:30Z
[ "python", "csv", "pandas", "plot" ]
Python project conversion 2.7 to 3.4
37,972,791
<p>I have a python project which is built on 2.7 version. I would like to convert the complete project to be compatible with 3.4 version. Is there a way to convert the entire project at once or should I do it file by file ?</p> <pre><code>2to3 -w pythonfile.py </code></pre>
1
2016-06-22T15:45:59Z
37,972,967
<p>You should be able to convert the entire project at once. I'd recommend putting all of your python's .py project files in the same directory (even though the 2to3 module is supposed to work recursively through directories). </p> <p>Usage Instructions can be found here: <a href="https://docs.python.org/2/library/2to...
1
2016-06-22T15:54:00Z
[ "python" ]
Parsing json.dumps - Python
37,972,798
<p>I have a call to an API that returns the following JSON:</p> <pre><code>{ "trades": [ { "stopLoss": 154.79, "takeProfit": 151.79, "price": 153.784, "side": "sell", "trailingStop": 0, "instrument": "GBP_JPY", "time": "2016-06-21T18:20:24.000000Z", ...
0
2016-06-22T15:46:17Z
37,973,466
<p>You can use <strong>json.loads()</strong> to parse the json.</p> <pre><code>import json response = '{"trades": [{"stopLoss": 154.79, "takeProfit": 151.79, "price": 153.784, "side": "sell", "trailingStop": 0, "instrument": "GBP_JPY", "time": "2016-06-21T18:20:24.000000Z", "units": 25, "id": 10297636517, "trailingAmo...
1
2016-06-22T16:19:36Z
[ "python", "json", "python-2.7", "parsing" ]
Parsing json.dumps - Python
37,972,798
<p>I have a call to an API that returns the following JSON:</p> <pre><code>{ "trades": [ { "stopLoss": 154.79, "takeProfit": 151.79, "price": 153.784, "side": "sell", "trailingStop": 0, "instrument": "GBP_JPY", "time": "2016-06-21T18:20:24.000000Z", ...
0
2016-06-22T15:46:17Z
37,973,664
<p>Figured out the answer. I was trying just <code>['trades']['id']</code> and not <code>['trades'][0]['id']</code>.. thanks</p>
0
2016-06-22T16:29:00Z
[ "python", "json", "python-2.7", "parsing" ]
Multiple dimensions coordinates
37,972,835
<p>I am currently building a tree (using Python) that will support multiple dimensions but, as a start, I am trying to understand the 2D part first. Each node in the 2D tree will contain the coordinates of the square it represents and a data point contained within it. The 2D case represents a QuadTree - <a href="https:...
0
2016-06-22T15:48:09Z
37,973,248
<p>The <strong>itertools</strong> doesn't work the way I think you want: the subrange is valid only for the dimension on which it was computed. To simplify the typing a little, I'm going to consider a square over (0,8) instead of (0,1). On the first split, we get four squares; let's look at (0,4), (4,8). We now want...
1
2016-06-22T16:08:40Z
[ "python", "data-structures", "dimension", "cartesian-coordinates" ]
Python/Django date query: Unsupported lookup 'date' for DateField or join on the field not permitted
37,972,938
<p>I have a simple method. Entries are entries in a time sheet application where employees enter their hours.</p> <pre><code>class Entry(m.Model): """ Represents an entry in a time_sheet. An entry is either for work, sick leave or holiday. """ # type choices WORK = 'w' SICK = 's' VACATION =...
0
2016-06-22T15:52:30Z
37,972,996
<p>There's no such thing as a <code>__date</code> lookup on a DateField; the field is already a date.</p> <p>It's not clear what you are trying to compare this field with. Is the day you are passing into that method an integer, or a date? If it's also a date then you should just compare them directly.</p>
1
2016-06-22T15:55:25Z
[ "python", "django", "date" ]
What do model.predict() and model.fit() do?
37,973,005
<p>I'm going through <a href="http://outlace.com/Reinforcement-Learning-Part-3/" rel="nofollow">this reinforcement learning tutorial</a> and It's been really great so far but could someone please explain what</p> <pre><code>newQ = model.predict(new_state.reshape(1,64), batch_size=1) </code></pre> <p>and </p> <pre><c...
1
2016-06-22T15:55:46Z
37,974,356
<p>First of all it surprises me that you could not find the documentation <a href="http://keras.io/models/model/" rel="nofollow">yourself</a> but I assume you just had bad luck while searching.</p> <p>The documentation states for <a href="http://keras.io/models/model/#fit" rel="nofollow"><code>model.fit</code></a>:</p...
0
2016-06-22T17:07:00Z
[ "python", "deep-learning", "keras", "reinforcement-learning" ]
ctypes, python3.5, OSError: exception: access violation writing 0x00000000
37,973,033
<p>Researching other similar errors, I think that I have an issue with a an illegal operation such as writing to an address that I shouldn't be. I'm not sure how to resolve this. Any help please?</p> <p>Exact error I'm getting:</p> <pre><code>in GetSoftwareVersion() result = f(LCP_Version, FCP_Version) OSError: excep...
1
2016-06-22T15:57:16Z
38,061,327
<p>You're getting the error <code>OSError: exception: access violation writing 0x00000000</code> because of the statement <code>LCP_Version = ct.c_char_p(0)</code>. As suggested by the <a href="https://docs.python.org/3/library/ctypes.html#ctypes.c_char_p" rel="nofollow">ctypes documentation for <code>c_char_p</code><...
1
2016-06-27T18:59:58Z
[ "python", "python-3.x", "ctypes", "python-3.5" ]
numpy.argmin for elements greater than a threshold
37,973,135
<p>I'm interested in getting the location of the minimum value in an 1-d NumPy array that meets a certain condition (in my case, a medium threshold). For example:</p> <pre><code>import numpy as np limit = 3 a = np.array([1, 2, 4, 5, 2, 5, 3, 6, 7, 9, 10]) </code></pre> <p>I'd like to effectively mask all numbers in ...
1
2016-06-22T16:02:31Z
37,973,394
<p>This can simply be accomplished using numpy's <code>MaskedArray</code></p> <pre><code>import numpy as np limit = 3 a = np.array([1, 2, 4, 5, 2, 5, 3, 6, 7, 9, 10]) b = np.ma.MaskedArray(a, a&lt;3) np.ma.argmin(b) # == 6 </code></pre>
2
2016-06-22T16:16:35Z
[ "python", "arrays", "performance", "numpy" ]
numpy.argmin for elements greater than a threshold
37,973,135
<p>I'm interested in getting the location of the minimum value in an 1-d NumPy array that meets a certain condition (in my case, a medium threshold). For example:</p> <pre><code>import numpy as np limit = 3 a = np.array([1, 2, 4, 5, 2, 5, 3, 6, 7, 9, 10]) </code></pre> <p>I'd like to effectively mask all numbers in ...
1
2016-06-22T16:02:31Z
37,973,409
<p>You could store the valid indices and use those for both selecting the valid elements from <code>a</code> and also indexing into with the <code>argmin()</code> among the selected elements to get the final index output. Thus, the implementation would look something like this -</p> <pre><code>valid_idx = np.where(a &...
1
2016-06-22T16:17:12Z
[ "python", "arrays", "performance", "numpy" ]
python/pygame test specific key to be up
37,973,162
<p>So i'm trying to make a topdown game and i'm having problems with player movement. When i press key [W,A,S or D] player moves that way. But i want it to keep moving as long as button is being held down. So i change [<strong>playerMoveLeft</strong>, <strong>playerMoveRight</strong>, <strong>playerMoveDown</strong> ...
-1
2016-06-22T16:03:47Z
37,977,321
<p>Assuming your player can only go in one direction (up/down/left/right) at a time:</p> <pre><code>STANDSTILL = 0 UP = 1 RIGHT = 2 DOWN = 3 LEFT = 4 playermovement = STANDSTILL if event.type == pygame.KEYDOWN: if allowMovement == 1: if event.key == pygame.K_a: playermovement = LEFT i...
0
2016-06-22T20:07:37Z
[ "python", "pygame" ]
pick month start and end data in python
37,973,190
<p>I have stock data downloaded from yahoo finance. I want to pickup data in the row corresponding to monthly start and month end. I am trying to do it with python pandas data frame. But I am not getting correct method to get the starting &amp; ending of the month. will be great full if somebody can help me in solving ...
0
2016-06-22T16:05:12Z
37,973,524
<p>For the first / last day of each month, you can use <code>.resample()</code> with <code>'BMS'</code> and <code>'BM'</code> for <code>Business Month (Start)</code> like so (using <code>pandas 0.18</code> syntax):</p> <pre><code>df.resample('BMS').first() df.resample('BM').last() </code></pre> <p>This assumes that y...
0
2016-06-22T16:22:03Z
[ "python", "pandas" ]
pick month start and end data in python
37,973,190
<p>I have stock data downloaded from yahoo finance. I want to pickup data in the row corresponding to monthly start and month end. I am trying to do it with python pandas data frame. But I am not getting correct method to get the starting &amp; ending of the month. will be great full if somebody can help me in solving ...
0
2016-06-22T16:05:12Z
37,973,606
<p>First, you should convert your date column to datetime format, then group by month, then sort groupby Series by date and take the first/last from it using head/tail methods, like so:</p> <pre><code>In [37]: df Out[37]: 0 1 2 3 4 5 6 0 2016-01-05 222.80 222.80 217...
0
2016-06-22T16:26:07Z
[ "python", "pandas" ]
pick month start and end data in python
37,973,190
<p>I have stock data downloaded from yahoo finance. I want to pickup data in the row corresponding to monthly start and month end. I am trying to do it with python pandas data frame. But I am not getting correct method to get the starting &amp; ending of the month. will be great full if somebody can help me in solving ...
0
2016-06-22T16:05:12Z
37,974,186
<p>Assuming you have downloaded data from Yahoo:</p> <pre><code>&gt; import pandas.io.data as web &gt; import datetime &gt; start = datetime.datetime(2016,1,1) &gt; end = datetime.datetime(2016,5,1) &gt; df = web.DataReader("AAPL", "yahoo", start, end) </code></pre> <p>You simply pick the month end and start ro...
0
2016-06-22T16:56:46Z
[ "python", "pandas" ]
wx Python MessageDialog popping up behind BusyInfo box?
37,973,287
<p>I am working on some software for the company that I work for. I am using wx for the GUI. I basically have this: When the program is busy or loading, I create a wx.BusyInfo object. But, sometimes, while this busy info box is still visible, and I need to print an error message to the user, but that MessageDialog actu...
0
2016-06-22T16:11:17Z
38,064,868
<p>After lots of google searches and research I found out how to solve the issue! First, instead of using wx.BusyInfo I use PyBusyInfo (I found the code here: <a href="https://searchcode.com/codesearch/view/63249201/" rel="nofollow">https://searchcode.com/codesearch/view/63249201/</a>). This is because, wx.BusyInfo is ...
0
2016-06-27T23:41:36Z
[ "python", "wx", "messagedialog" ]
While loop is not iterating over the correct solution in array
37,973,341
<p><strong>My goal:</strong> I am trying to get the user to type in their own query for a troubleshooting system. If the user's input has a keyword that is found in the 'keywords' array, a solution is given from the same index in the 'answers' array. </p> <p><strong>The problem:</strong> There are no syntax errors but...
2
2016-06-22T16:13:34Z
37,973,422
<p>You must remember that in <code>for keyword in keywords:</code>, keyword is a string, and indexing it via <code>i</code> is pulling out individual letters. Instead you want to do something like:</p> <pre><code>for keyword in keywords: if keyword in user_query: # Handle things here </code></pre> <p>or</...
2
2016-06-22T16:17:51Z
[ "python", "arrays", "indexing", "while-loop", "counter" ]
While loop is not iterating over the correct solution in array
37,973,341
<p><strong>My goal:</strong> I am trying to get the user to type in their own query for a troubleshooting system. If the user's input has a keyword that is found in the 'keywords' array, a solution is given from the same index in the 'answers' array. </p> <p><strong>The problem:</strong> There are no syntax errors but...
2
2016-06-22T16:13:34Z
37,973,648
<p>I think this might work a little better:</p> <pre><code>answers = ['dry it out','replace screen','delete any apps that are not needed','restart it'] keywords = ['wet','cracked','download','unresponsive'] responses = {k:v for k,v in zip(keywords,answers)} def getAnswer(query, solutions): for keyword in solution...
0
2016-06-22T16:28:04Z
[ "python", "arrays", "indexing", "while-loop", "counter" ]
While loop is not iterating over the correct solution in array
37,973,341
<p><strong>My goal:</strong> I am trying to get the user to type in their own query for a troubleshooting system. If the user's input has a keyword that is found in the 'keywords' array, a solution is given from the same index in the 'answers' array. </p> <p><strong>The problem:</strong> There are no syntax errors but...
2
2016-06-22T16:13:34Z
37,973,662
<pre><code>answers = ['dry it out','replace screen','delete any apps that are not needed','restart it'] keywords = ['wet','cracked','download','unresponsive'] query = input('What\'s the problem?\n&gt;&gt; ').lower() try: print(answers[keywords.index(query)]) except ValueError: print("Contact the supplier.") <...
2
2016-06-22T16:28:58Z
[ "python", "arrays", "indexing", "while-loop", "counter" ]
Represent a column other than x, y on plot using matplotlib, python 2.7
37,973,589
<p>I want to make a simulation of some data and I want to display my points with different colors for different categories. I have three columns where two columns I am using are x,y and I want to use third column which has two categories to be reflected on my plot.</p> <pre><code>y = np.array(q) x = np.array(p) fig =...
-1
2016-06-22T16:24:59Z
38,010,368
<p>There are lots of ways to do this, here is one using Pandas</p> <pre><code>#generate data df = pd.DataFrame(np.random.random(size=(100,2)), columns=['x','y']) df.loc[:,'cat'] = ['Match' if np.random.randint(0,2)==1 else '-' for i in range(100) ] plt.plot(df.loc[df.cat=='Match','x'],df.loc[df.cat=='Match','y'],'bs'...
1
2016-06-24T09:45:43Z
[ "python", "python-2.7", "matplotlib" ]
Tensorflow converging but bad predictions
37,973,619
<p>I posted a similar question the other day <a href="http://stackoverflow.com/questions/37898795/tensorflow-accuracy-at-99-but-predictions-awful">here</a>, but I have since made edits to bugs that I found, and the problem of bad predictions remains. </p> <p>I have two networks -- one with 3 conv layers and another wi...
0
2016-06-22T16:26:40Z
37,973,844
<p>The concept of deconvolution is to output something of the same size as the input.</p> <p>At the line:</p> <pre><code>conv6 = tf.nn.bias_add(conv6, biases['bdc3']) </code></pre> <p>You have this output of shape <code>[batch_size, 200, 200, 2]</code>, so you <strong>don't need</strong> to add your fully connected ...
1
2016-06-22T16:38:44Z
[ "python", "machine-learning", "neural-network", "artificial-intelligence", "tensorflow" ]
ImportError: libboost_iostreams.so.1.61.0: cannot open shared object file: No such file or directory
37,973,680
<p>I am using Anaconda as my main python distribution (though also have the system's default python installed) so have to compile graph-tool from source to get it to work with Anaconda. </p> <p>I am using Ubuntu 14.04 so also have to compile boost from source to be able to use the full functionality of graph-tool as t...
2
2016-06-22T16:29:30Z
39,873,286
<p>Seems you have wrong <code>boost</code> package version installed by conda</p> <ol> <li>List installed conda boost package in current environment <code>conda list | grep boost</code>, you can see wrong version (not 1.61.0)</li> <li>Search required version <code>anaconda search -t conda boost | grep 1.61.0</code></l...
0
2016-10-05T11:55:42Z
[ "python", "c++", "boost", "graph-tool" ]
Incremental least squares in Python
37,973,693
<p>Numpy has a handy least squares estimate of the form np.linalg.lstsq(X, Y) to estimate beta such that X_i * beta = Y_i, where X_i is an m x n matrix, beta is a length-n row vector, and Y is a length-n column vector.</p> <p>However, what if I want to repeatedly estimate beta as I add rows to X and values to Y? In ot...
0
2016-06-22T16:30:46Z
38,040,313
<p>I ended up writing my own function that re-computes beta for each new (x,y) pair but saves previous computations. </p> <p>Specifically, given X in R^(nxd) as a matrix of n x-observations and y in R^n as a column vector of the corresponding n y-observations, in general we want to estimate beta by </p> <p>beta_hat =...
0
2016-06-26T15:53:41Z
[ "python", "numpy", "regression", "linear" ]
Attribute error while filtering a dataframe based values from certain columns
37,973,728
<p>I have a couple of files of the same format which I need to filter based on certain threshold based on three columns from those data frames.And in the end I need to save them as separate results</p> <p>The example dataframe looks like follows,</p> <pre><code> ID Mean log2FoldChange SE stat pvalue pad...
0
2016-06-22T16:32:40Z
37,975,987
<p>You are attempting to run a data frame level operation on series level method. Do not pass the function in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow">DataFrame.apply</a> (which applies a function on either the rows or columns of a dataframe). Simply cal...
2
2016-06-22T18:44:14Z
[ "python", "pandas", "dataframe" ]
Loop optimization in Python using loc command
37,973,738
<p>I have a section of python code as shown:</p> <pre><code># Main Loop that take values attributed to the row by row basis and sorts # them into correpsonding columns based on matching the 'Name' and the newly # generated column names. listed_names=list(df_cv) #list of column names to reference later. variable=listed...
0
2016-06-22T16:33:01Z
37,973,858
<p>Instead of looping, think of it as a pivot operation. Assuming that Time is a column and not an index (if it is, just use <code>reset_index</code>):</p> <pre><code>In [96]: df Out[96]: Time Name Value 0 1 Color Red 1 2 Age 6 2 3 Temp 25 3 4 Age 1 In [97]: df.pivot(index...
3
2016-06-22T16:39:24Z
[ "python", "for-loop", "pandas", "optimization" ]
How to multiply element by element between Matrices in PYTHON
37,973,772
<p>Let's assume I have 2 matrices which each of them represents vector: </p> <pre><code>X = np.matrix([[1],[2],[3]]) Y = np.matrix([[4],[5],[6]]) </code></pre> <p>I want the output to be the result of multiplying it element by element, which means it should be: </p> <pre><code>[[4],[10],[18]] </code></pre> <p>Notic...
1
2016-06-22T16:35:28Z
37,973,906
<p>so remember that NumPy matrix is a subclass of NumPy array, and array operations are element-wise.</p> <p>therefore, you can convert your matrices to NumPy arrays, then multiply them with the "*" operator, which will be element-wise:</p> <pre><code>&gt;&gt;&gt; import numpy as NP &gt;&gt;&gt; X = NP.matrix([[1],[2...
0
2016-06-22T16:42:02Z
[ "python", "numpy", "matrix" ]
How to multiply element by element between Matrices in PYTHON
37,973,772
<p>Let's assume I have 2 matrices which each of them represents vector: </p> <pre><code>X = np.matrix([[1],[2],[3]]) Y = np.matrix([[4],[5],[6]]) </code></pre> <p>I want the output to be the result of multiplying it element by element, which means it should be: </p> <pre><code>[[4],[10],[18]] </code></pre> <p>Notic...
1
2016-06-22T16:35:28Z
37,973,913
<p>Tested <strong>np.multiply()</strong> on ipython and it worked like a charm</p> <pre><code>In [41]: X = np.matrix([[1],[2],[3]]) In [42]: Y = np.matrix([[4],[5],[6]]) In [43]: np.multiply(X, Y) Out[43]: matrix([[ 4], [10], [18]]) </code></pre>
2
2016-06-22T16:42:31Z
[ "python", "numpy", "matrix" ]
Getting a form in Django DetailView
37,973,779
<p>I am currently trying to show a custom form where I alter the form in the corresponding view</p> <p>in the .html</p> <pre><code>&lt;form action="{% url 'systems_system_update' system.id %}" id="system_update_form" method="post" class="form"&gt; {% csrf_token %} {% buttons %} &lt;button ty...
1
2016-06-22T16:35:53Z
37,973,895
<p><strong><a href="https://docs.djangoproject.com/en/1.9/ref/class-based-views/generic-display/#django.views.generic.detail.DetailView" rel="nofollow"><code>DetailView</code></a></strong> does not have a <code>get_form()</code> method as it <strong>does not uses a form, thereby your <code>get_form()</code> method is n...
2
2016-06-22T16:41:35Z
[ "python", "django", "forms", "django-generic-views", "detailview" ]