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
Pyspark RDD .filter() with wildcard
39,256,520
<p>I have an Pyspark RDD with a text column that I want to use as a a filter, so I have the following code:</p> <pre><code>table2 = table1.filter(lambda x: x[12] == "*TEXT*") </code></pre> <p>To problem is... As you see I'm using the <code>*</code> to try to tell him to interpret that as a wildcard, but no success. ...
0
2016-08-31T18:23:31Z
39,256,540
<pre><code>table2 = table1.filter(lambda x: "TEXT" in x[12]) </code></pre>
0
2016-08-31T18:24:58Z
[ "python", "apache-spark", "rdd" ]
formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
39,256,529
<h1>TL;DR</h1> <p>How can you...</p> <ul> <li><p>Force the <code>LogFormatter</code> to use scientific notation for every label? Now it uses it for values smaller than <code>0</code> or larger than <code>1000</code>. It does not seem to expose any <code>set_powerlimit</code> method that I can find, either. Is there a...
2
2016-08-31T18:24:06Z
39,256,959
<p>Change the formatter in the function to <a href="http://matplotlib.org/api/ticker_api.html#matplotlib.ticker.LogFormatterMathtext" rel="nofollow"><code>LogFormatterMathtext</code></a>: </p> <pre><code>cb=plt.colorbar(ticks=tick_locations, format=ticker.LogFormatterMathtext()) </code></pre> <p>The formatters obviou...
1
2016-08-31T18:50:03Z
[ "python", "matplotlib" ]
os.environ doesn't show all environmental variables in Jupyter notebook
39,256,559
<p>I am finding that the following code prints out my expected environmental variable when I execute the script in a shell:</p> <pre><code>import os print(os.environ['STUFF']) </code></pre> <p>However, when I run this same code in Jupyter Notebook, I get a key error. I have tried restarting the Jupyter server. What e...
0
2016-08-31T18:26:38Z
39,256,671
<p>You can query all the dictionary keys to confirm the one you have is not there.</p> <pre><code>import os print(os.environ.keys()) </code></pre> <p>Or better you can test for the presence of the specific key.</p> <pre><code>print(os.environ.has_key('STUFF')) </code></pre>
0
2016-08-31T18:33:08Z
[ "python", "environment-variables" ]
Add confirmation step to custom Django management/manage.py command
39,256,578
<p>I created the following custom management command following <a href="https://docs.djangoproject.com/en/1.10/howto/custom-management-commands/" rel="nofollow">this tutorial</a>.</p> <pre><code>from django.core.management.base import BaseCommand, CommandError from django.contrib.auth.models import User from topspots...
0
2016-08-31T18:27:43Z
39,257,511
<p>You can use Python's <code>raw_input</code>/<code>input</code> function. Here's an example method from Django's <a href="https://github.com/django/django/blob/59afe61a970dd60df388e7cda9041ef3c0e770cb/django/db/migrations/questioner.py#L87" rel="nofollow">source code</a>:</p> <pre><code>from django.utils.six.moves i...
1
2016-08-31T19:24:30Z
[ "python", "django", "django-manage.py", "django-management-command" ]
Python: Dedup a dictionary
39,256,611
<p>Good afternoon,</p> <p>I reading in a pcap and am basically trying to get a dedup'd list of BSSID's &amp; ESSID's. I am still getting duplicates with this code and cannot for the life of me figure out what I am doing wrong:</p> <pre><code>if not (t[0] in ssid_pairs and ssid_pairs[t[0]] == t[1]): ssid_pairs[t[...
0
2016-08-31T18:29:52Z
39,256,829
<p>Dictionaries <em>can't</em> have duplicates:</p> <pre><code>some_data = [('foo', 'bar'), ('bang', 'quux'), ('foo', 'bar'), ('zappo', 'whoo'), ] mydict = {} for data in some_data: mydict[data[0]] = data[1] import pprint; print(mydict) </code></pre> <p>The on...
1
2016-08-31T18:42:16Z
[ "python", "scapy" ]
Python: Dedup a dictionary
39,256,611
<p>Good afternoon,</p> <p>I reading in a pcap and am basically trying to get a dedup'd list of BSSID's &amp; ESSID's. I am still getting duplicates with this code and cannot for the life of me figure out what I am doing wrong:</p> <pre><code>if not (t[0] in ssid_pairs and ssid_pairs[t[0]] == t[1]): ssid_pairs[t[...
0
2016-08-31T18:29:52Z
39,256,844
<p>Let's say you get:</p> <pre><code>t[0] = 'foo' t[1] = 'bar' </code></pre> <p>Then we hit your code above:</p> <pre><code>if not (t[0] in ssid_pairs and ssid_pairs[t[0]] == t[1]): ssid_pairs[t[0]] = t[1] of.write(t[0] + ',' + t[1] + ((',' + f + '\n') if verbose else '\n')) </code></pre> <p>The condition p...
1
2016-08-31T18:43:20Z
[ "python", "scapy" ]
Load a .csv file into a numpy array as a column vector
39,256,672
<p>I've got a .csv file that I'm trying to load into a numpy array as a column vector. When using </p> <pre><code>temp = np.genfromtxt(location, delimiter=',') </code></pre> <p>the data is a <code>numpy array</code> where the entries are represented as follows:</p> <pre><code>[ 0. ... 0. 1. 0. ... 0.], [ 0. .....
0
2016-08-31T18:33:13Z
39,257,012
<p>Add a new axis to <code>temp</code>, and cast sublists to <em>np arrays</em>:</p> <pre><code>temp = np.genfromtxt(location, delimiter=',') my_data = map(np.array, temp[:, :, np.newaxis]) </code></pre> <hr> <p>For Python 3, call <code>list</code> on the above result or use a list comprehension:</p> <pre><code>my_...
1
2016-08-31T18:54:28Z
[ "python", "arrays", "csv", "numpy" ]
python apply function to df pandas - atribute error
39,256,717
<p>I have a data frame "b" with numbers stored as text like '12.5%'. One column is:</p> <pre><code>1 NaN 2 NaN 3 1.2% 4 0.6% 5 NaN 6 1.4% 7 0.1% 8 NaN 9 5.1% 10 2.5% 11 89.1% 12 NaN Name: Idaho, dtype: object </code></pre> <p>I've wrote a function to apply...
0
2016-08-31T18:35:46Z
39,256,993
<p>Your original method didn't work because NaN was not a string, but the float value <code>np.NaN</code> </p> <p>Try this... </p> <pre><code>np.NaN.replace('%', '') </code></pre> <p>and you will get the same error.</p> <pre><code>AttributeError: 'float' object has no attribute 'replace' </code></pre> <p>You could...
2
2016-08-31T18:53:03Z
[ "python", "function", "pandas", "attributes", "apply" ]
lxml XPath - extracting text from multi p nodes
39,256,973
<h2>Please have a look at <a href="http://stackoverflow.com/questions/39242154/lxml-xpath-position-does-not-work">lxml XPath position() does not work</a> first.</h2> <p>Since XPath does not support to extract text from multi nodes, I decided to write for loop to get 30 stuffs.</p> <pre><code>for i in range(1,31): ...
0
2016-08-31T18:51:21Z
39,257,015
<p>In Python3, <code>print</code> is a <em>function</em> which prints to the screen <em>and returns</em> <code>None</code>. (In Python2, <code>print</code> is a <em>statement</em> and the code would have raised an error since you can't put a statement in the middle of an expression.) Instead, to build a string use the ...
1
2016-08-31T18:54:33Z
[ "python", "python-3.x", "xpath", "lxml" ]
lxml XPath - extracting text from multi p nodes
39,256,973
<h2>Please have a look at <a href="http://stackoverflow.com/questions/39242154/lxml-xpath-position-does-not-work">lxml XPath position() does not work</a> first.</h2> <p>Since XPath does not support to extract text from multi nodes, I decided to write for loop to get 30 stuffs.</p> <pre><code>for i in range(1,31): ...
0
2016-08-31T18:51:21Z
39,257,018
<p>The trailing <code>/.</code> in your xpath is invalid. </p> <p>Try: </p> <pre><code>content = "string(//div[@id='article']/p[" + (print(i)) + "])" </code></pre> <p>Full example:</p> <pre class="lang-py prettyprint-override"><code>import lxml.html html = """&lt;tag1&gt; &lt;tag2&gt; &lt;div id="article"&gt; &lt;...
1
2016-08-31T18:54:44Z
[ "python", "python-3.x", "xpath", "lxml" ]
Call a Python function in a file with command-line argument
39,256,977
<p>I'm trying to pass arguments from Node.js to Python with <code>child_process</code> spawn. I also want to invoke the specific Python function with one of the argument that I specified in the Node.js array.</p> <p><code>test.js</code></p> <pre><code>'use strict'; const path = require('path'); const spawn = require...
1
2016-08-31T18:51:36Z
39,257,140
<p>I'd recommend using <a href="https://docs.python.org/3/library/argparse.html" rel="nofollow">argparse</a> to parse the command line arguments. Then you can use <a href="https://docs.python.org/3.5/library/functions.html#eval" rel="nofollow">eval</a> to get the actual function from the input.</p> <pre><code>import a...
2
2016-08-31T19:01:46Z
[ "python", "arguments", "command-line-arguments", "sys" ]
how to use for loop to iterating url index to collect the data
39,256,983
<p>I am a newbie in python. I want to write a for loop to iterate the index in order to pull the data. </p> <p>Here is my code:</p> <pre><code>url90=[] for i in range(-90,0): url90.append('http://staging.foglogic.com/api/v1/index.php/accounts/34/reports/bcjobs?cmd=json&amp;datestr=today&amp;**index=i**&amp;filter={}...
2
2016-08-31T18:52:11Z
39,257,156
<p>If you think that <code>i</code> variable will automatically be used in the string used to populate the list, you are wrong. It does not work that way. Use <code>.format</code>:</p> <pre><code>url90=[] for i in range(-90,0): url90.append('http://staging.foglogic.com/api/v1/index.php/accounts/34/reports/bcjobs?c...
1
2016-08-31T19:02:21Z
[ "python", "string", "for-loop" ]
sort a list by prefered order
39,257,017
<p>is it possible to sort through a list and do something depending on your preferred order or pre determined choice?</p> <p>so i have a list of files containing definitions, if i re.search the string and return a match, i would like to only print the string + highest definition</p> <p>i started to explore the below ...
2
2016-08-31T18:54:38Z
39,257,112
<p>If you want only a single result (the highest) and considering that your list is ordered highest to lowest, you can simply return after the first result was found:</p> <pre><code>import re definitions = ['1080p', '720p', 'SD'] # order (highest to lowest) some_files = ['movie_a_1080p.mp4', 'movie_b_720p.mp4', 'movie...
1
2016-08-31T19:00:30Z
[ "python", "python-2.7", "python-3.x" ]
sort a list by prefered order
39,257,017
<p>is it possible to sort through a list and do something depending on your preferred order or pre determined choice?</p> <p>so i have a list of files containing definitions, if i re.search the string and return a match, i would like to only print the string + highest definition</p> <p>i started to explore the below ...
2
2016-08-31T18:54:38Z
39,257,183
<p>If I understand what you're trying to do, this should work:</p> <pre><code>def best(some_files): for definition in ('1080p', '720p', 'SD'): match = next((file for file in some_files if definition in file), None) if match is not None: return match print(best(['movie_a_1080p.mp4', 'mo...
1
2016-08-31T19:03:37Z
[ "python", "python-2.7", "python-3.x" ]
sort a list by prefered order
39,257,017
<p>is it possible to sort through a list and do something depending on your preferred order or pre determined choice?</p> <p>so i have a list of files containing definitions, if i re.search the string and return a match, i would like to only print the string + highest definition</p> <p>i started to explore the below ...
2
2016-08-31T18:54:38Z
39,257,613
<p>Since your <code>definitions</code> is in order, you can just traverse the lists, and return the file when a match is found. </p> <pre><code>def best_quality(l): definitions = ['1080p', '720p', 'SD'] # order (highest to lowest) for definition in definitions: for file in some_files: if ...
3
2016-08-31T19:30:44Z
[ "python", "python-2.7", "python-3.x" ]
Theano crashing using cuDNN in linux
39,257,060
<p>I am a non-root user on a cluster computer running Scientific Linux release 6.6 (Carbon). </p> <p>I am experiencing some theano crashes when running code on a GPU with CUDA 7.5 and cuDNN 5. I am using Python 2.7, Theano 0.9, Keras 1.0.7 and Lasange 0.1.</p> <p>The following crash occurs ONLY when I run the program...
0
2016-08-31T18:57:23Z
39,265,420
<p>Not sure if this can be the issues but: export LIBRARY_PATH=/home/t/tj/tjb32/cuda/lib64:$<strong>LD_</strong>LIBRARY_PATH should be? export LIBRARY_PATH=/home/t/tj/tjb32/cuda/lib64:$LIBRARY_PATH</p>
0
2016-09-01T07:34:43Z
[ "python", "linux", "theano", "theano-cuda", "cudnn" ]
flask: get session time remaining via AJAX
39,257,102
<p>I am using Flask, with the flask-session plugin for server-side sessions stored in a Redis backend. I have flask set up to use persistent sessions, with a session timeout. How can I make an AJAX request to get the time remaining on the session without resetting the timeout?</p> <p>The idea is for the client to chec...
1
2016-08-31T19:00:08Z
39,259,673
<p>The following works, though it is rather hacky:</p> <p>In the application <code>__init__.py</code>, or wherever you call <code>Session(app)</code> or <code>init_app(app)</code>:</p> <pre><code>#set up the session Session(app) # Save a reference to the original save_session function so we can call it original_save...
0
2016-08-31T22:01:22Z
[ "python", "ajax", "session", "flask" ]
WxPython, How to fill ListBox with class attributes
39,257,126
<p>I am building a wxpython project, I have a list of elements that are a class instances. Each of this elements has an attribute <code>title</code>. In a ListBox I want to display only the titles, and when the title selected, after we GetSelection from listbox, the instance should be returned and not just the title. I...
0
2016-08-31T19:01:07Z
39,257,327
<ul> <li>Put your instances in a list</li> <li>Use <code>GetSelection</code> to retrieve the index of the item you selected from the listbox</li> <li>Get the corresponding instance from that index in the list</li> </ul>
1
2016-08-31T19:12:41Z
[ "python", "listbox", "wxpython" ]
How to fix <Response [400]> while make a POST in Python?
39,257,168
<p>I kept getting <code>&lt;Response [400]&gt;</code> in my terminal while running the script.</p> <p>I have tried </p> <pre><code>import requests import json url = 'http://172.19.242.32:1234/vse/account' data = '{ "account_id": 1008, "email_address": "bhills_4984@mailinator.com", "password": "qqq", "accou...
0
2016-08-31T19:02:54Z
39,257,227
<p>Change </p> <pre><code>r = requests.post(url, data=json.dumps(data), headers=headers) </code></pre> <p>to</p> <pre><code>r = requests.post(url, data=data, headers=headers) </code></pre> <p>because data is not a dict that must be transformed to json but is already json.</p>
4
2016-08-31T19:05:57Z
[ "python", "request", "http-status-code-400" ]
Python interpreter PATH oddity. Can't use django
39,257,191
<p>I have three Python environments across two different interpreters. The first is the basic Python27 in my c:. The second is an Anaconda interpreter with its own environment and another environment in it's \envs\ directory. I have directed my PYTHONPATH variable to point to the Anaconda interpreter not in the \envs\ ...
0
2016-08-31T19:04:02Z
39,257,356
<p>Because python 2.7 path is set in the system environment variable PATH. You are editing your user variables (which are bizarrely configured because they contain duplicate stuff only found in system path like <code>C:\windows\system32</code> for instance)</p> <p>if you type <code>where python</code> you'll probably...
1
2016-08-31T19:14:16Z
[ "python", "django", "environment-variables", "windows-10" ]
How can i insert a scrollbar in my Tk window?
39,257,319
<p>I wrote this for my school project, but I can't figure out how to add a scroll bar.</p> <pre><code>from Tkinter import* #import Tk main_s= Tk() #forming a Tk window fundo = PhotoImage(file="d.gif") class Welcome: def __init__(self): def proceed(): main_s.update() ...
-1
2016-08-31T19:12:02Z
39,318,073
<p>Here is your standard vetical scrollbar. Nice project by the way, at our school the most complicated thing we do is text based programs XD</p> <p>I see you're new to stack overflow, what you wanna do is press that nice big green tick next to my answer :)</p> <pre><code>from Tkinter import* #import Tk main_s= Tk()...
0
2016-09-04T14:39:43Z
[ "python", "tkinter", "tk" ]
Django custom command - Not Implemented Error
39,257,379
<p>I'm trying to set up a cronjob on my Ubuntu server to run a django <code>.py</code> file - but I'm having trouble running the script first.</p> <p>I'm using the command <code>python3 /opt/mydir/manage.py updatefm</code> </p> <p>which produces the error:</p> <pre><code>File "/opt/mydir/manage.py", line 15, in &lt;...
0
2016-08-31T19:15:58Z
39,257,651
<p>Check <code>__init__.py</code> inside <code>commands</code> folder. Then you have to use <code>handle</code> method</p> <pre><code>class Command(BaseCommand): args = '' help = 'Help Test' def handle(self, *args, **options): hi = 'test </code></pre> <p>For more info <a href="https://docs.djangop...
1
2016-08-31T19:33:52Z
[ "python", "django", "python-3.x" ]
Django custom command - Not Implemented Error
39,257,379
<p>I'm trying to set up a cronjob on my Ubuntu server to run a django <code>.py</code> file - but I'm having trouble running the script first.</p> <p>I'm using the command <code>python3 /opt/mydir/manage.py updatefm</code> </p> <p>which produces the error:</p> <pre><code>File "/opt/mydir/manage.py", line 15, in &lt;...
0
2016-08-31T19:15:58Z
39,257,714
<p>Classes inheriting from <code>BaseCommand</code> must implement the method <code>handle</code>. </p> <p>In your case, you should change </p> <p><code>def update_auto(self, *args, **options):</code></p> <p>to </p> <p><code>def handle(self, *args, **options):</code></p>
1
2016-08-31T19:38:51Z
[ "python", "django", "python-3.x" ]
Combining Pandas Dataframe with indexed value as column name
39,257,459
<p>Given the following two pandas DataFrames:</p> <pre><code>main_table = pd.DataFrame([[1, 'A'], [2, 'B'], [3,'C']], columns=['id', 'label']) extras_table = pd.DataFrame([[1, 'e1', 'e1_Val'], [1, 'e2', 'e2_...
1
2016-08-31T19:20:27Z
39,257,573
<pre><code>xdf = extras_table.set_index(['main_id', 'col_label']) \ .unstack().value.reset_index('main_id') main_table.merge(xdf, left_on='id', right_on='main_id').drop('main_id', axis=1) </code></pre> <p><a href="http://i.stack.imgur.com/uPy0S.png" rel="nofollow"><img src="http://i.stack.imgur.com/uPy0S.png" alt...
3
2016-08-31T19:28:28Z
[ "python", "pandas", "dataframe" ]
Import Selenium IDE script as unittest.TestCase and Modify Dynamically
39,257,481
<p>I am writing a program in python that will generate more robust data and reports from Selenium tests. I want to be able to export a test case from Selenium IDE from Firefox, and without modifying that specific exported python file, inject it into my script and allow my script to make modifications such as changing t...
3
2016-08-31T19:21:59Z
39,437,390
<p>Hi my friend i have been searchin something like this for few days. I found this question in stackoverflow</p> <p><a href="http://stackoverflow.com/questions/11380413/python-unittest-passing-arguments">Python unittest passing arguments</a></p> <p>so you code should be like this:</p> <pre><code>import sys import u...
1
2016-09-11T14:59:13Z
[ "python", "unit-testing", "selenium", "phantomjs" ]
Access JSON Key in Python
39,257,547
<p>I'm trying to print out all the <code>cpe_mac</code> fields of my JSON data.</p> <h1>I have</h1> <pre><code># Last updated : BH | 8/31/2016 import requests import json ssc_ip = raw_input("What is your SSC Host (Ex. http://172.19.242.32:1234/ ) ? : ") if not ssc_ip: ssc_ip = 'http://172.19.242.32:1234/' cpe_...
-2
2016-08-31T19:26:39Z
39,257,610
<p>That's not how to access a dictionary item. The dictionaries of interest are contained in a list (accessible via key <code>data</code>) inside the parent dictionary <code>json_data</code>. </p> <p>You should do:</p> <pre><code>for x in json_data['data']: print x['cpe_mac'] </code></pre>
1
2016-08-31T19:30:36Z
[ "python" ]
Access JSON Key in Python
39,257,547
<p>I'm trying to print out all the <code>cpe_mac</code> fields of my JSON data.</p> <h1>I have</h1> <pre><code># Last updated : BH | 8/31/2016 import requests import json ssc_ip = raw_input("What is your SSC Host (Ex. http://172.19.242.32:1234/ ) ? : ") if not ssc_ip: ssc_ip = 'http://172.19.242.32:1234/' cpe_...
-2
2016-08-31T19:26:39Z
39,257,636
<p>You have a nested dictionary, it should be:</p> <pre><code>for x in json_data['data']: print x['cpe_mac'] </code></pre>
3
2016-08-31T19:32:51Z
[ "python" ]
Add a clip_analysis to a buffer_analysis
39,257,575
<p>I'm trying to add a clip_analysis to the buffer_analysis I just completed. </p> <p>The script that I'm using is:</p> <pre><code>for i in range(len(cities)): arcpy.Buffer_analysis(sites[i]+'.shp', sites[i]+'_Buffer3000.shp','3000') print 'site buffered to',i,'buffer 3000' arcpy.Clip_analysis(openSpace,[i]+'.shp', [...
0
2016-08-31T19:28:36Z
39,258,041
<p>In the line:</p> <pre><code>arcpy.Clip_analysis(openSpace,[i]+'.shp', [i]+'_OpenSpace.shp') </code></pre> <p>you're trying to append together the list <code>[i]</code> to the string <code>.shp</code></p> <p>...did you mean to write:</p> <pre><code>arcpy.Clip_analysis(openSpace,sites[i]+'.shp', [i]+'_OpenSpace.sh...
0
2016-08-31T19:59:08Z
[ "python" ]
How to iterate through this nested json array with python
39,257,576
<p>So I made an API call to JIRA to get the list of all the issues. It returns something like this: </p> <pre><code>{ issues: [ { fields: { description: summary: creator: reporter: priority: } } ] </code></pre> <p>and I'm trying to get to what's ins...
0
2016-08-31T19:28:36Z
39,257,639
<p>if you look at your json it's an array to a hash or list to dict. To get fields you'd just call the first array element and the key.</p> <p><code>response[issues][0][fields]</code></p>
1
2016-08-31T19:33:01Z
[ "python", "json", "api", "jira", "jira-rest-api" ]
Pyspark: Prevent removal of terminal ansi-escape characters in logging while using pyspark
39,257,608
<p>I have put together a custom formatter for a logger and I am using pyspark, but it looks like all of my color is removed on the command-line. I can confirm that the escape sequences are present within the record of each emitted value, but it appears that they're stripped when sent to the terminal. </p> <p>Why?</p...
-1
2016-08-31T19:30:27Z
39,358,454
<p>I spent some time digging into this, and I found that the terminal escape sequences are different when loading under pyspark. The way I fixed it is by using pygments to run over the terminal output I created (see function: <code>fix_for_spark</code>).</p> <pre><code># -*- coding: utf-8 -*- import datetime import ...
0
2016-09-06T21:58:09Z
[ "python", "logging", "pyspark", "ansi-escape" ]
From string library, template function doesnt work with int value?
39,257,631
<p>I am trying to use Template from string. I have a directory with 100 csv files with data pertaining to each year.</p> <p>For ex.:</p> <pre><code>yob1881.txt yob1882.txt yob1883.txt yob1884.txt yob1885.txt </code></pre> <p>Now i want to use template so that i can loop over all files. So i am using a range function...
-2
2016-08-31T19:32:23Z
39,257,841
<p>You should pass the parameter as a named argument:</p> <pre><code>for year in range(1880, 2011): template = Template('/name/year$year') t = template.substitute(year=year) </code></pre>
0
2016-08-31T19:47:45Z
[ "python", "string", "python-3.x", "templates" ]
From string library, template function doesnt work with int value?
39,257,631
<p>I am trying to use Template from string. I have a directory with 100 csv files with data pertaining to each year.</p> <p>For ex.:</p> <pre><code>yob1881.txt yob1882.txt yob1883.txt yob1884.txt yob1885.txt </code></pre> <p>Now i want to use template so that i can loop over all files. So i am using a range function...
-2
2016-08-31T19:32:23Z
39,257,853
<p>Your issue is that you're not assigning the substitution when calling <code>template.substitute(year)</code>. You need to format this like:</p> <pre><code>template.substitute(year=year) </code></pre> <p>Also, <code>substitute()</code> returns a new string, so you should either reassign this template or assign it t...
0
2016-08-31T19:48:14Z
[ "python", "string", "python-3.x", "templates" ]
Python: rolling an array multiple times and saving each iteration as an image
39,257,652
<p>I have multiple images that I am taking in with a for loop. I want to obtain 5 pseudo-layers for each image by rolling the initial by one pixel in both x and y and saving the rolled image each time. </p> <p>I'm practicing with one image making sure I can get five layers out of it but no joy.</p> <p>My code is belo...
0
2016-08-31T19:34:10Z
39,257,689
<p>You save all 5 images in the same output file, which means that you get only one image, <code>im4</code></p> <pre><code>im0.save('pl_{}.tif'.format(index)) im1 = Image.fromarray(imary1xy) im1.save('pl_{}.tif'.format(index)) im2 = Image.fromarray(imary2xy) im2.save('pl_{}.tif'.format(index)) im3 = Image.fromarray(im...
1
2016-08-31T19:37:01Z
[ "python", "numpy", "pillow" ]
Python: rolling an array multiple times and saving each iteration as an image
39,257,652
<p>I have multiple images that I am taking in with a for loop. I want to obtain 5 pseudo-layers for each image by rolling the initial by one pixel in both x and y and saving the rolled image each time. </p> <p>I'm practicing with one image making sure I can get five layers out of it but no joy.</p> <p>My code is belo...
0
2016-08-31T19:34:10Z
39,257,994
<p>Untested, but I think this should do what you're aiming for:</p> <p>Addition of a <code>number_of_shifts</code> variable, and then using that to iterate. Then the calls to np.roll are nested, which I think should work</p> <pre><code>list_frames = glob.glob('*.gif') for index1, fname in enumerate(list_frames): ...
1
2016-08-31T19:56:54Z
[ "python", "numpy", "pillow" ]
How to display x axis label for each matplotlib subplot
39,257,712
<p>I want to add an x axis label below each subplot. I use this code to create the charts:</p> <pre><code>fig = plt.figure(figsize=(16,8)) ax1 = fig.add_subplot(1,3,1) ax1.set_xlim([min(df1["Age"]),max(df1["Age"])]) ax1.set_xlabel("All Age Freq") ax1 = df1["Age"].hist(color="cornflowerblue") ax2 = fig.add_subplot(1,3...
0
2016-08-31T19:38:33Z
39,257,779
<p>You can add a title above each plot using:</p> <pre><code>ax.set_title('your title') </code></pre>
0
2016-08-31T19:44:18Z
[ "python", "matplotlib", "histogram" ]
How to display x axis label for each matplotlib subplot
39,257,712
<p>I want to add an x axis label below each subplot. I use this code to create the charts:</p> <pre><code>fig = plt.figure(figsize=(16,8)) ax1 = fig.add_subplot(1,3,1) ax1.set_xlim([min(df1["Age"]),max(df1["Age"])]) ax1.set_xlabel("All Age Freq") ax1 = df1["Age"].hist(color="cornflowerblue") ax2 = fig.add_subplot(1,3...
0
2016-08-31T19:38:33Z
39,257,797
<p>That's easy, just use <a href="http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_title" rel="nofollow">matplotlib.axes.Axes.set_title</a>, here's a little example out of your code:</p> <pre><code>from matplotlib import pyplot as plt import pandas as pd df1 = pd.DataFrame({ "Age":[1,2,3,4] }) df...
0
2016-08-31T19:45:03Z
[ "python", "matplotlib", "histogram" ]
How to display x axis label for each matplotlib subplot
39,257,712
<p>I want to add an x axis label below each subplot. I use this code to create the charts:</p> <pre><code>fig = plt.figure(figsize=(16,8)) ax1 = fig.add_subplot(1,3,1) ax1.set_xlim([min(df1["Age"]),max(df1["Age"])]) ax1.set_xlabel("All Age Freq") ax1 = df1["Age"].hist(color="cornflowerblue") ax2 = fig.add_subplot(1,3...
0
2016-08-31T19:38:33Z
39,257,803
<p>You are using <code>ax.set_xlabel</code> wrong, which is a <strong>function</strong> (first call is correct, the others are not):</p> <pre><code>fig = plt.figure(figsize=(16,8)) ax1 = fig.add_subplot(1,3,1) ax1.set_xlim([min(df1["Age"]),max(df1["Age"])]) ax1.set_xlabel("All Age Freq") # CORRECT USAGE ax1 = df1["Ag...
2
2016-08-31T19:45:19Z
[ "python", "matplotlib", "histogram" ]
How to calculate the number of matched groups of rows in pandas dataframe?
39,257,713
<p>Having been banging my head against the wall for 2 days now for this one. Got some ideas, tried to implement, but the speed was terribly slow, so wonder whether someone can point out a better way of doing this. Here's what I want:</p> <p>I have a dataframe like this:</p> <p><code>pd.DataFrame({'var1':[1, 1, 4, 4, ...
1
2016-08-31T19:38:41Z
39,258,109
<pre><code>gb = df.groupby(['var1', 'var2', 'var3', 'label']) size = gb.size() size var1 var2 var3 label 1 2 3 a 2 4 5 6 b 2 c 1 7 8 9 d 1 8 8 8 d 1 dtype: int64 </code></pre> <hr> <pre><code>lvls = list(range(siz...
0
2016-08-31T20:04:11Z
[ "python", "pandas" ]
How to calculate the number of matched groups of rows in pandas dataframe?
39,257,713
<p>Having been banging my head against the wall for 2 days now for this one. Got some ideas, tried to implement, but the speed was terribly slow, so wonder whether someone can point out a better way of doing this. Here's what I want:</p> <p>I have a dataframe like this:</p> <p><code>pd.DataFrame({'var1':[1, 1, 4, 4, ...
1
2016-08-31T19:38:41Z
39,258,406
<p>Using a <code>groupby</code> approach:</p> <pre><code>def matched_group(grp): if len(grp) == 1: return np.nan return grp.nunique() == 1 is_matched = df.groupby(['var1', 'var2', 'var3'])['label'].apply(matched_group).dropna() match_pcnt = is_matched.sum()/len(is_matched) </code></pre> <p>The <c...
1
2016-08-31T20:24:20Z
[ "python", "pandas" ]
"IndexError: too many indices" using HDF5 file with 8760 - every hour for the year
39,257,734
<p><strong>Background:</strong> I am trying to pull out the daily max windspeed from an 8760 hdf5 dataset using a kdtree to lat/lons from a point file and then pull it all into a csv. Things go smoothly, until I try to make an empty array to store the max values. I am having a hard time wrapping my head around the logi...
0
2016-08-31T19:40:29Z
39,261,584
<p>First, there was some indentation missing below the <code>with ... a vector:</code>. I added my guess on that. But I'm guessing all of that <code>hdf5</code> stuff is unimportant - at least for your problem.</p> <p>The problem is all at the end - if I read your question right:</p> <pre><code>ws_sites = ws[:, kdt...
0
2016-09-01T01:57:25Z
[ "python", "arrays", "numpy" ]
Regular Expression with letter
39,257,759
<p>I need to match things that format something along the lines of 657432-76, 54678-01, 54364<strong>A</strong>-12</p> <p>I got <code>(r'^\d{6}-\d{2}$')</code> and <code>(r'^\d{5}-\d{2}$')</code> but how do you get the letter?</p> <p>thanks!!</p>
2
2016-08-31T19:42:23Z
39,257,812
<p>If you want a single regex to match the 3rd pattern you can use a regex like this:</p> <pre><code>(?i)(r'^\d{5}[a-z]-\d{2}$') </code></pre> <p><strong><a href="https://regex101.com/r/uA0bK2/1" rel="nofollow">Working demo</a></strong></p> <p>However, if you want to have a single regex for all of them, you might fi...
0
2016-08-31T19:46:01Z
[ "python", "regex", "format", "expression" ]
Regular Expression with letter
39,257,759
<p>I need to match things that format something along the lines of 657432-76, 54678-01, 54364<strong>A</strong>-12</p> <p>I got <code>(r'^\d{6}-\d{2}$')</code> and <code>(r'^\d{5}-\d{2}$')</code> but how do you get the letter?</p> <p>thanks!!</p>
2
2016-08-31T19:42:23Z
39,257,814
<p>For the letter use <code>[a-zA-Z]</code>, and if it's only upper case then <code>[A-Z]</code> is sufficient.</p>
0
2016-08-31T19:46:09Z
[ "python", "regex", "format", "expression" ]
Regular Expression with letter
39,257,759
<p>I need to match things that format something along the lines of 657432-76, 54678-01, 54364<strong>A</strong>-12</p> <p>I got <code>(r'^\d{6}-\d{2}$')</code> and <code>(r'^\d{5}-\d{2}$')</code> but how do you get the letter?</p> <p>thanks!!</p>
2
2016-08-31T19:42:23Z
39,257,845
<p>it seems the pattern generically is 6 characters with possible letter or number at last char max then <code>-</code> then 2 numbers? so then you'd use this pattern</p> <p><code>pattern = r'^d{5}.+-\d{2}$'</code></p>
0
2016-08-31T19:47:51Z
[ "python", "regex", "format", "expression" ]
Regular Expression with letter
39,257,759
<p>I need to match things that format something along the lines of 657432-76, 54678-01, 54364<strong>A</strong>-12</p> <p>I got <code>(r'^\d{6}-\d{2}$')</code> and <code>(r'^\d{5}-\d{2}$')</code> but how do you get the letter?</p> <p>thanks!!</p>
2
2016-08-31T19:42:23Z
39,257,899
<p>How about this expression:</p> <pre><code>&gt;&gt;&gt; re.search(r'^\d+[A-Z]?-\d+$','657432A-76') &lt;_sre.SRE_Match object; span=(0, 10), match='657432A-76'&gt; &gt;&gt;&gt; &gt;&gt;&gt; re.search(r'^\d+[A-Z]?-\d+$','657432-76') &lt;_sre.SRE_Match object; span=(0, 9), match='657432-76'&gt; &gt;&gt;&gt; &gt;&gt;&...
0
2016-08-31T19:50:34Z
[ "python", "regex", "format", "expression" ]
Regular Expression with letter
39,257,759
<p>I need to match things that format something along the lines of 657432-76, 54678-01, 54364<strong>A</strong>-12</p> <p>I got <code>(r'^\d{6}-\d{2}$')</code> and <code>(r'^\d{5}-\d{2}$')</code> but how do you get the letter?</p> <p>thanks!!</p>
2
2016-08-31T19:42:23Z
39,257,925
<p>Here's a possible candidate matching all your samples:</p> <pre><code>import re samples = [ "657432-76", "54678-01", "54364A-12" ] for s in samples: print re.match(r'^(\d+[A-Z]?)-(\d+)$', s).groups() </code></pre>
0
2016-08-31T19:52:48Z
[ "python", "regex", "format", "expression" ]
Performant Spectral Graph Partitioning in Python?
39,257,776
<p>I'm working on partitioning a sparse graph I have, and while I'm happy with the results I've seen, it's currently far too slow. The graph has around 200,000 nodes and scipy.sparse.linalg.eigsh takes on the order of hours. I've tried using shift-invert mode and various initializations, as well as a linear spectral sh...
3
2016-08-31T19:43:57Z
39,297,709
<p>I found scipy.sparse.linalg.lobpcg to give much better results relatively quickly, so if anyone else is trying this in the future I suggest starting there. I also used a <a href="https://en.wikipedia.org/wiki/Preconditioner#Jacobi_.28or_diagonal.29_preconditioner" rel="nofollow">Jacobi diagonal preconditioner</a> ba...
0
2016-09-02T17:17:26Z
[ "python", "algorithm", "performance", "linear-algebra", "linear" ]
I've tried to change my font size and it still has no affect. How do I actually change the font size?
39,257,827
<p>I'm trying to change the font size of my buttons in Tkinter so it's not so small. Does anyone have any idea on what I can do that might have the result that I'm looking for? Why is there so much text required for me to ask a question when I can ask it plainly and simply with less text?! </p> <pre><code>from Tkinter...
0
2016-08-31T19:46:47Z
39,257,870
<p>I'm not familiar with <code>Font</code>, but you can denote it also using a string:</p> <pre><code>customFont = '{arial} 18' </code></pre> <p>For default font uer</p> <pre><code>customFont = '{} 18' </code></pre>
0
2016-08-31T19:49:22Z
[ "python", "tkinter" ]
I've tried to change my font size and it still has no affect. How do I actually change the font size?
39,257,827
<p>I'm trying to change the font size of my buttons in Tkinter so it's not so small. Does anyone have any idea on what I can do that might have the result that I'm looking for? Why is there so much text required for me to ask a question when I can ask it plainly and simply with less text?! </p> <pre><code>from Tkinter...
0
2016-08-31T19:46:47Z
39,257,983
<p>When you create a <code>tk.button</code> object, use the font option, and specify the font style as a string like so: <code>"Arial 10 Bold"</code></p> <p>I used your code as an example and made the font Arial, size 18, bolded.</p> <pre><code>from Tkinter import * from tkFont import * class App: def __init__(...
0
2016-08-31T19:56:24Z
[ "python", "tkinter" ]
I've tried to change my font size and it still has no affect. How do I actually change the font size?
39,257,827
<p>I'm trying to change the font size of my buttons in Tkinter so it's not so small. Does anyone have any idea on what I can do that might have the result that I'm looking for? Why is there so much text required for me to ask a question when I can ask it plainly and simply with less text?! </p> <pre><code>from Tkinter...
0
2016-08-31T19:46:47Z
39,258,050
<p>You can create a new font and then just applying it to your widgets using <code>my_widget['font']=my_font</code>, example out of your code:</p> <pre><code>from Tkinter import * from tkFont import * class App: def __init__(self): guiWindow = Tkinter.Tk() guiWindow.wm_title("FooBar") #...
0
2016-08-31T19:59:32Z
[ "python", "tkinter" ]
CPU cores, treads and optimal number of workers - python threading
39,257,857
<p>I am beginning to appreciate the usefulness of the threading library on python and I was wondering what was the optimal number of threads to keep open in order to maximise the efficiency of the script I am running. </p> <p>Please do keep in mind that my one and only priority is speed, I don't need to multitask /do ...
0
2016-08-31T19:48:29Z
39,257,984
<p>The question is very complex, because on the same CPU there can be an arbitrary number of others threads running, from processes that are not under your control.</p> <p>Instead, you can estimate when a certain piece of code worth to be executed by a separate thread, based on the time needed to create a new thread.<...
1
2016-08-31T19:56:27Z
[ "python", "multithreading", "cpu" ]
python: if (substring X in string Y) only true for last characters?
39,257,884
<p>This code only returns true when the substring is at the end. How do I fix it to consider any substring? Data looks like this:</p> <p>prediction: </p> <ol> <li><p>dog</p></li> <li><p>cat</p></li> </ol> <p>actual: </p> <ol> <li><p>red,dog</p></li> <li><p>cat,blue</p></li> </ol> <p>returns true then returns f...
0
2016-08-31T19:50:01Z
39,257,949
<p><code>readlines</code> gives you each line include the newline at the end of the line. So you're doing comparisons like <code>"cat\n" in "cat,blue\n"</code>. Since there isn't a newline in the right place, the check fails.</p> <p>Try this to strip the newlines off the end of each line:</p> <pre><code>with open("te...
1
2016-08-31T19:54:00Z
[ "python", "python-3.x" ]
python: if (substring X in string Y) only true for last characters?
39,257,884
<p>This code only returns true when the substring is at the end. How do I fix it to consider any substring? Data looks like this:</p> <p>prediction: </p> <ol> <li><p>dog</p></li> <li><p>cat</p></li> </ol> <p>actual: </p> <ol> <li><p>red,dog</p></li> <li><p>cat,blue</p></li> </ol> <p>returns true then returns f...
0
2016-08-31T19:50:01Z
39,257,996
<p><code>'cat' in 'cat,blue'</code> returns True</p> <p>Please make small change to your script</p> <pre><code>if prediction[n].strip() in actual[n] </code></pre>
0
2016-08-31T19:56:59Z
[ "python", "python-3.x" ]
python: if (substring X in string Y) only true for last characters?
39,257,884
<p>This code only returns true when the substring is at the end. How do I fix it to consider any substring? Data looks like this:</p> <p>prediction: </p> <ol> <li><p>dog</p></li> <li><p>cat</p></li> </ol> <p>actual: </p> <ol> <li><p>red,dog</p></li> <li><p>cat,blue</p></li> </ol> <p>returns true then returns f...
0
2016-08-31T19:50:01Z
39,258,002
<p>The items in the list returned by <code>readlines</code> will include the <code>\n</code> at the end of each line, so you are <em>actually</em> testing <code>'dog\n' in 'red,dog\n'</code>, which is fine, and <code>'cat\n' in 'cat,blue\n'</code>, which is not.</p> <p>To fix it, you can use <code>strip()</code> to re...
0
2016-08-31T19:57:18Z
[ "python", "python-3.x" ]
python: if (substring X in string Y) only true for last characters?
39,257,884
<p>This code only returns true when the substring is at the end. How do I fix it to consider any substring? Data looks like this:</p> <p>prediction: </p> <ol> <li><p>dog</p></li> <li><p>cat</p></li> </ol> <p>actual: </p> <ol> <li><p>red,dog</p></li> <li><p>cat,blue</p></li> </ol> <p>returns true then returns f...
0
2016-08-31T19:50:01Z
39,258,064
<p>You just need to <em>rstrip</em> the <em>newline</em> from each line of the first file so you don't compare <code>dog\n</code> with <code>red,dog\n</code>, the newline on the string you are testing is irrelevant. You can also use <em>zip</em> and read the files line by line withput the need for <em>readlines</em> a...
0
2016-08-31T20:01:12Z
[ "python", "python-3.x" ]
Case insensitive dictionary search with enchant
39,257,988
<p>Is there a way to do a case-insensitive search in enchant?</p> <p>I am trying to achieve the following:</p> <pre><code>import enchant d = enchant.DictWithPWL("en_US","mywords.txt") d.check("Alexandria") True d.check("alexandria") False </code></pre> <p>Both cases should return True</p>
0
2016-08-30T05:29:24Z
39,257,989
<p>As per you example, it should return <code>True</code>.</p> <pre><code>import enchant d = enchant.DictWithPWL("en_US","/home/user/yourscript.py") a=d.check("import") print(a) a=d.check("Import") print(a) </code></pre> <p>Output:</p> <pre><code>True True </code></pre> <p>You can try following link, you may get s...
0
2016-08-30T06:07:22Z
[ "python" ]
Python Remove List of Strings from List of Strings
39,257,990
<p>I'm trying to remove several strings from a list of URLs. I have more than 300k URLs, and I'm trying to find which are variations of the original. Here's a toy example that I've been working with.</p> <pre><code>URLs = ['example.com/page.html', 'www.example.com/in/page.html', 'example.com/ca/fr/page...
0
2016-08-31T19:56:46Z
39,258,130
<p>You have to assign the result of <code>replace</code> to <code>item</code> again:</p> <pre><code>clean = [] for item in URLs: for loc in locs: item = item.replace(loc, '') clean.append(item) </code></pre> <p>or in short:</p> <pre><code>clean = [ reduce(lambda item,loc: item.replace(loc,''), [i...
4
2016-08-31T20:05:22Z
[ "python", "list" ]
Python Remove List of Strings from List of Strings
39,257,990
<p>I'm trying to remove several strings from a list of URLs. I have more than 300k URLs, and I'm trying to find which are variations of the original. Here's a toy example that I've been working with.</p> <pre><code>URLs = ['example.com/page.html', 'www.example.com/in/page.html', 'example.com/ca/fr/page...
0
2016-08-31T19:56:46Z
39,258,191
<p>The biggest problem you have is that you don't save the return value. </p> <pre><code>urls = ['example.com/page.html', 'www.example.com/in/page.html', 'example.com/ca/fr/page.html', 'm.example.com/de/page.html', 'example.com/fr/page.html'] locs = ['/in', '/ca', '/de', '/fr', 'm.', '...
3
2016-08-31T20:08:43Z
[ "python", "list" ]
Python Remove List of Strings from List of Strings
39,257,990
<p>I'm trying to remove several strings from a list of URLs. I have more than 300k URLs, and I'm trying to find which are variations of the original. Here's a toy example that I've been working with.</p> <pre><code>URLs = ['example.com/page.html', 'www.example.com/in/page.html', 'example.com/ca/fr/page...
0
2016-08-31T19:56:46Z
39,258,215
<p>You could first abstract the removing part into a function and then use a list comprehension:</p> <pre><code>def remove(target, strings): for s in strings: target = target.replace(s,'') return target URLs = ['example.com/page.html', 'www.example.com/in/page.html', 'example.com/ca/fr...
2
2016-08-31T20:10:26Z
[ "python", "list" ]
The most efficient way to iterate over a list of elements. Python 2.7
39,258,038
<p>I am trying to iterate over a list of elements, however the list can be massive and takes too long to execute. I am using newspaper api. The for loop I constructed is:</p> <pre><code>for article in list_articles: </code></pre> <p>Each article in the list_articles are an object in the format of:</p> <pre><code>&lt...
-2
2016-08-31T19:59:06Z
39,258,199
<p>Here's a little benchmark to make the question a little bit more interesting:</p> <pre><code>import timeit import random N = 1000000 class Foo: def __init__(self): self.n = random.randint(0, 1000) bar = [Foo() for r in xrange(N)] def f1(lst): return [v for v in lst] def f2(lst): return ...
-1
2016-08-31T20:09:09Z
[ "python", "list", "python-2.7", "loops", "cpython" ]
The most efficient way to iterate over a list of elements. Python 2.7
39,258,038
<p>I am trying to iterate over a list of elements, however the list can be massive and takes too long to execute. I am using newspaper api. The for loop I constructed is:</p> <pre><code>for article in list_articles: </code></pre> <p>Each article in the list_articles are an object in the format of:</p> <pre><code>&lt...
-2
2016-08-31T19:59:06Z
39,258,211
<p>The best way is to use built in functions, when possible, such as functions to split strings, join strings, group things, etc...</p> <p>The there is the list comprehension or <code>map</code> when possible. If you need to construct one list from another by manipulating each element, then this is it.</p> <p>The th...
1
2016-08-31T20:10:11Z
[ "python", "list", "python-2.7", "loops", "cpython" ]
Python - BeautifulSoup scrape non-standard web table
39,258,047
<p>I am attempting to scrape data from several webpages in order to create a CSV of the data. The data is just nutritional information of products. I have generated code to access the website, but I can't quite get the code to iterate out properly. The problem is, the website uses DIV tags for the product name, and ins...
2
2016-08-31T19:59:23Z
39,258,264
<p>Find the tables, then extract the text from the previous strong and take the second <em>td</em> from each <em>tr</em> splitting the text once to remove the <code>(g)</code> etc..:</p> <pre><code>from bs4 import BeautifulSoup soup = BeautifulSoup(html) for table in soup.find_all("table"): name = [table.find_p...
1
2016-08-31T20:13:52Z
[ "python", "html", "web-scraping", "beautifulsoup" ]
Initial and final check when running pytest test suite
39,258,076
<p>I have productive code which creates config files in my <code>$HOME</code> folder and to run my tests in an isolated environment I patch <code>$HOME</code> in <code>conftest.py</code>. Still I'm not sure if this works in general and maybe unthoughtful written test functions might break out.</p> <p>To ensure the val...
8
2016-08-31T20:02:15Z
39,515,114
<p>Have you considered writing a session-scoped pytest fixture? Something like:</p> <pre><code>@pytest.fixture(scope="session") def global_check(request): assert initial_condition def final_check(request): assert final_condition request.addfinalizer(final_check) return request </code></pre> ...
0
2016-09-15T15:36:47Z
[ "python", "py.test" ]
Datetime does not work in my index series
39,258,290
<p>I have a hf5 filled with some data. </p> <p>when I open it in python I have this output</p> <pre><code>hf['SB'].head() 0_1 price cng 2015-07-15 07:30:00.087 12.61 4 2015-07-15 07:30:00.087 12.61 1 2015-07-15 07:30:00.087 12.61 1 2015-07-15 07:30:00.087 12.61 2 2015-07-15 07:30:0...
0
2016-08-31T20:16:06Z
39,258,610
<p>I believe, that you are truing to get value for a key which is not present in index at all. <code>hf['SB']['2015-08-20']</code> will give you all records for that particular date. See example below:</p> <pre><code>&gt;&gt;&gt; rng = pd.date_range('1/1/2016', periods=10, freq='S') &gt;&gt;&gt; ts = pd.Series(np.rand...
1
2016-08-31T20:39:26Z
[ "python", "datetime", "pandas" ]
Sorting all the sub Dictionary using values of one of the sub dictionary
39,258,329
<p>I have data structure like the below and would like to sort the all the sub dictionaries to be sorted based on the values of the 'order' column.</p> <p>Input:</p> <pre><code>to_sort = [ ('Fruits', { 'size': {1:[4, 2, 7,9]}, 'name': {1:['Orange', 'Apple', 'Kiwi', 'Mango']}, 'color': {1:['Orange',...
4
2016-08-31T20:18:18Z
39,258,731
<p>Assuming you are okay with modifying your data structure as mentioned in the comments, this will work for you. This is adapted from this other question: <a href="http://stackoverflow.com/q/6618515/3901060">Sorting list based on values from another list?</a></p> <pre><code>to_sort = [('Fruits', { 'size': [4, 2, ...
1
2016-08-31T20:47:21Z
[ "python", "python-3.x" ]
Sorting all the sub Dictionary using values of one of the sub dictionary
39,258,329
<p>I have data structure like the below and would like to sort the all the sub dictionaries to be sorted based on the values of the 'order' column.</p> <p>Input:</p> <pre><code>to_sort = [ ('Fruits', { 'size': {1:[4, 2, 7,9]}, 'name': {1:['Orange', 'Apple', 'Kiwi', 'Mango']}, 'color': {1:['Orange',...
4
2016-08-31T20:18:18Z
39,258,851
<h2> How to deal with what you've got</h2> <p>Your existing data structure is a bit crazy, but here is how I would handle it (<strong>edit</strong> suppose the key for the color list was <code>123</code>):</p> <pre><code>&gt;&gt;&gt; to_sort = [ ... ('Fruits', ... { ... 'size': {1:[4, 2, 7,9]}, ... 'nam...
1
2016-08-31T20:55:27Z
[ "python", "python-3.x" ]
How to check Ubuntu program coredump in either bash or python?
39,258,362
<p>I have a binary foo, and i will give a file input to foo which may potentially trigger coredump in Ubuntu. I write a loop to do so and I change the file content in every iteration. But I would like to terminate the loop whenever a coredump appears. Here is the bash code:</p> <pre><code>while true do change_file f...
1
2016-08-31T20:20:42Z
39,258,460
<p>If the return code is greater than 127, then the program exited due to a signal. Core dumps only happen as the result of this sort of exit.</p> <pre><code>./foo file_new if (($? &gt; 127)); then echo foo crashed break fi </code></pre>
1
2016-08-31T20:28:12Z
[ "python", "bash", "ubuntu", "coredump" ]
How to identify the values of indexes around a specific array coordinate?
39,258,576
<p>If I had a 2-D array, representing a world, that looked something like: </p> <pre><code>. . . . . . . . . . . . . . . . P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . t . . . . . . . . . . . . . . t . . . . . . . . . . . . . . . t . . . . . . . . . . . . . . . t . . . . . . . . . . . . . . t t ...
0
2016-08-31T20:36:23Z
39,258,755
<p>Since you got the x and y and the original array, you should be able to iterate through this points with code like:</p> <pre><code>tiles_to_move = [] for i in range(x-1, x+2): for j in range(y-1, y+2): if i != x or j != y: if array[i][j] != 'm': # depends on how you manage your array ...
0
2016-08-31T20:49:24Z
[ "python", "arrays", "python-2.7", "multidimensional-array" ]
How to identify the values of indexes around a specific array coordinate?
39,258,576
<p>If I had a 2-D array, representing a world, that looked something like: </p> <pre><code>. . . . . . . . . . . . . . . . P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . t . . . . . . . . . . . . . . t . . . . . . . . . . . . . . . t . . . . . . . . . . . . . . . t . . . . . . . . . . . . . . t t ...
0
2016-08-31T20:36:23Z
39,258,927
<p>I think a better solution would be to have a method which tries to move the player in the desired direction and have that method be outside the player class since the player class shouldn't know about the map (code not tested):</p> <pre><code>def try_to_move_player(direction,map,player): desired_x = player.x ...
0
2016-08-31T21:00:39Z
[ "python", "arrays", "python-2.7", "multidimensional-array" ]
How to identify the values of indexes around a specific array coordinate?
39,258,576
<p>If I had a 2-D array, representing a world, that looked something like: </p> <pre><code>. . . . . . . . . . . . . . . . P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . t . . . . . . . . . . . . . . t . . . . . . . . . . . . . . . t . . . . . . . . . . . . . . . t . . . . . . . . . . . . . . t t ...
0
2016-08-31T20:36:23Z
39,259,197
<p>You can add a method to your <code>Player</code> class which will move a given number of steps vertically and/or horizontally. It could achieve this by calculating what the new coordinates of the <code>Player</code> object would be and checking the matrix at that index to make sure it's not a mountain (I'm also assu...
0
2016-08-31T21:21:00Z
[ "python", "arrays", "python-2.7", "multidimensional-array" ]
iPyWidget with date slider?
39,258,580
<p>I am wondering if there's an easy way to build an iPyWidget with a datetime slider. Right now it is easy to slide over integer or floating point ranges (e.g. numbers 1-10, decimals 0.01, 0.02, ...). </p> <p>I imagine you could convert dates to floats or integers, build some sort of slider using these, and then conv...
0
2016-08-31T20:36:41Z
39,268,222
<p>I had the same issue recently. I had to write my own class to do a daterange picker. Here is my code:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import ipywidgets as widgets from IPython.display import display class DateRangePicker(object): def __init__(self,start,end,freq='D',fmt=...
1
2016-09-01T09:49:22Z
[ "python", "jupyter", "ipywidgets" ]
running two process simultaneously
39,258,616
<p>I'm trying to run 2 processes simultaneously, but only the first one runs </p> <pre><code>def add(): while True: print (1) time.sleep(3) def sud(): while True: print(0) time.sleep(3) p1 = multiprocessing.Process(target=add) p1.run() p = multiprocessing.Process(target=sud)...
-1
2016-08-31T20:39:53Z
39,258,674
<p>The method you're looking for is <code>start</code>, not <code>run</code>. <code>start</code> starts the process and calls <code>run</code> to perform the work in the new process; if you call <code>run</code>, you run the work in the calling process instead of a new process.</p>
2
2016-08-31T20:43:31Z
[ "python", "multiprocessing" ]
running two process simultaneously
39,258,616
<p>I'm trying to run 2 processes simultaneously, but only the first one runs </p> <pre><code>def add(): while True: print (1) time.sleep(3) def sud(): while True: print(0) time.sleep(3) p1 = multiprocessing.Process(target=add) p1.run() p = multiprocessing.Process(target=sud)...
-1
2016-08-31T20:39:53Z
39,260,326
<p>Below will work for sure but try to run this as a module.Don't try in console or Jupiter notebook as notebook will never satisfy the condition "if <strong>name</strong> == '<strong>main</strong>'". Save the entire code in a file say process.py and run it from command prompt. Edit - It's working fine. Just now I tri...
-1
2016-08-31T23:03:19Z
[ "python", "multiprocessing" ]
Finding global matches inside a pattern
39,258,669
<p>If I have a pattern like this: (<a href="https://regex101.com/r/cR0aG8/12" rel="nofollow">https://regex101.com/r/cR0aG8/12</a>)</p> <pre><code>Product:.*?(.*?),.*?ReqID: </code></pre> <p>I assume(d) that</p> <pre><code>Product.*?(.*?),.*?ReqID: </code></pre> <p>would find <code>Toys</code>, <code>Books</code>, <...
-1
2016-08-31T20:43:21Z
39,258,784
<p>You need to create separate groups:</p> <pre><code>Product: (.*?), (.*?), (.*?), (.*?) ReqID: </code></pre> <p>To match these words. You don't even need <code>?</code> for this pattern.</p> <p>This is a sed for multiple patterns:</p> <pre><code>$ cat t1 Product: Toys, Books, Clothes, Radios ReqID: Product: Toys,...
0
2016-08-31T20:51:45Z
[ "python", "regex" ]
Finding global matches inside a pattern
39,258,669
<p>If I have a pattern like this: (<a href="https://regex101.com/r/cR0aG8/12" rel="nofollow">https://regex101.com/r/cR0aG8/12</a>)</p> <pre><code>Product:.*?(.*?),.*?ReqID: </code></pre> <p>I assume(d) that</p> <pre><code>Product.*?(.*?),.*?ReqID: </code></pre> <p>would find <code>Toys</code>, <code>Books</code>, <...
-1
2016-08-31T20:43:21Z
39,258,802
<p>If you are using PCRE engine (like your demo is made on it) or any of .NET, Java, Ruby or Perl regex flavors then use start match from end of previous one token <code>\G</code>:</p> <pre><code>(?:Product:|(?!\A)\G)(\s+\w+), </code></pre> <p><a href="https://regex101.com/r/hG6gP8/3" rel="nofollow">Live demo</a></p>...
0
2016-08-31T20:52:38Z
[ "python", "regex" ]
Modification of Future Value
39,258,769
<p>For this you have to add the annual contribution to the beginning of the year (the principal total) before computing interest for that year.</p> <p>I am stuck and need help. This is what I have so far:</p> <pre><code>def main(): print("Future Value Program - Version 2") print() principal = eval(inpu...
0
2016-08-31T20:50:43Z
39,259,382
<p>Here's a working example that produces the expected output:</p> <pre><code>def main(): print("Future Value Program - Version 2") print() principal = float(input("Enter Initial Principal: ")) contribution = float(input("Enter Annual Contribution: ")) apr = float(input("Enter Annual Percentage Ra...
0
2016-08-31T21:35:18Z
[ "python", "python-3.x" ]
Python pull values from nested dictionary for args in function call
39,258,783
<p>So I'm writing a bit of Python code to read in JSON data containing object types and parameters. I essentially need to run through this data and call one of a few functions that, using those parameters, creates a new, unique object each time to be used later. The JSON data looks like this:</p> <pre><code> { "objec...
1
2016-08-31T20:51:43Z
39,258,987
<p>This will add all of the <code>Shapes</code> to a list. </p> <pre><code>data ={ "objects" : { "1" : { "type" : "sphere", "radius" : "100", "centerx" : "30", "centery" : "40", "centerz" : "50" }, "2" : { "type" : "box", "lengthx" : "30", "lengthy" : "40", "lengthz" : "50", ...
2
2016-08-31T21:04:36Z
[ "python", "json", "dictionary" ]
Using Python to Post json contact list to Qualtrics API, error with Content-Type
39,258,853
<p>I'm trying to import contacts into a contact list in Qualtrics. I am using python to do this. </p> <pre><code>Token = 'MyToken' #when running the code I put in my actual token and id ContactsID = 'MyContactsID' data = open('contacts.json', 'rb') headers = {'X-API-TOKEN': Token, 'Content-Type':'application/json',} ...
2
2016-08-31T20:55:36Z
39,259,011
<p>You need to use <code>files = ..</code> for a <a href="http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file" rel="nofollow">multipart</a> request:</p> <pre><code>Token = 'MyToken' #when running the code I put in my actual token and id ContactsID = 'MyContactsID' data = open('con...
1
2016-08-31T21:06:34Z
[ "python", "json", "content-type", "qualtrics" ]
Using Python to Post json contact list to Qualtrics API, error with Content-Type
39,258,853
<p>I'm trying to import contacts into a contact list in Qualtrics. I am using python to do this. </p> <pre><code>Token = 'MyToken' #when running the code I put in my actual token and id ContactsID = 'MyContactsID' data = open('contacts.json', 'rb') headers = {'X-API-TOKEN': Token, 'Content-Type':'application/json',} ...
2
2016-08-31T20:55:36Z
39,296,146
<p>With the help of Qualtrics Support, I was eventually able to get the following code to work:</p> <pre><code>Token = 'MyToken' #when running the code I put in my actual token and id ContactsID = 'MyContactsID' url = "https://az1.qualtrics.com/API/v3/mailinglists/" + ContactsID + "/contactimports/" headers = { 'c...
1
2016-09-02T15:38:16Z
[ "python", "json", "content-type", "qualtrics" ]
Jenkins Master/Slave Windows
39,258,953
<p>Just want a clarification of the following. I am currently in the process of transferring a Bamboo plan into a Jenkins one and everything was working fine up until the point I ran a Python script on my CentOS Virtual Machine. The reason being that Python wants to import a library called <strong>winreg</strong> which...
0
2016-08-31T21:02:32Z
39,284,421
<p>Yes, it will. This is usual Jenkins using - see <a href="https://wiki.jenkins-ci.org/display/JENKINS/Distributed+builds" rel="nofollow">documentation</a>.</p>
0
2016-09-02T04:38:45Z
[ "python", "jenkins", "centos" ]
Open file with Adobe Captivate from command line
39,258,993
<p>I am attempting to open an XML file with Adobe Captivate in my script using <code>os.system()</code>. Here is my code:</p> <p><code>os.system("open /Applications/Adobe\ Captivate\ 9/Adobe\ Captivate.app/ \"flashcards_template_changed.xml\"")</code></p> <p>It works fine the issue is with the opening screen on Adobe...
2
2016-08-31T21:05:23Z
39,259,124
<p>If Adobe Captivate is registered as the default application for handling XML files, then you can leave out the application name altogether:</p> <pre><code>os.system("open flashcards_template_changed.xml") </code></pre> <p>Otherwise, specify the application with the <code>-a</code> flag:</p> <pre><code>os.system("...
0
2016-08-31T21:15:08Z
[ "python", "xml", "operating-system", "adobe" ]
fmin_ncg not returning an optimized result
39,259,026
<p>I am trying to use fmin_ncg for minimizing my cost function. But, the results that I get back are not minimized. I get the same result I would get without advanced optimization. I know for a fact that it can further be minimized. </p> <p>PS. I am trying to code assignment 2 of the <a href="https://www.coursera.org/...
0
2016-08-31T21:07:48Z
39,260,249
<p>First of all your gradient is invalid</p> <pre><code>def grad(theta, X, y, m, lam): h = sigmoid(X.dot(initial_theta)) theta0 = initial_theta gg = 1 / m * ((X.T.dot(h-y)) + (lam * theta0)) return gg.flatten() </code></pre> <p>this function <strong>never uses theta</strong>, you put <code>initial_the...
1
2016-08-31T22:53:20Z
[ "python", "machine-learning", "octave", "jupyter", "logistic-regression" ]
Django model with a list
39,259,046
<p>How to implement a list in a Django model?</p> <p>Lets say I have a <code>UserProfile</code> model, and each user can have a list of mortgages (undefined quantity) defined by <code>MortgageModel</code>.</p> <pre><code>class MortgageModel(models.Model): bank_name = models.CharField(max_length=128) sum = model...
0
2016-08-31T21:09:21Z
39,259,118
<p>You'll have to assign a <code>ForeignKey</code> to <code>User</code> , so that each <code>Mortgate</code> 'belongs' to a user. That is how a <strong><em>One-To-Many relationship</em></strong> is done. Then, if you want to get the list of Mortgages a user have, you'd filter them out like <code>MortgageModel.objects....
3
2016-08-31T21:14:55Z
[ "python", "django" ]
Group by column and get mean of the the group pandas
39,259,089
<p>I have a dataframe like below </p> <pre><code>Mode Time Air 2 Sea 4 Air 5 Sea 6 </code></pre> <p>So I want to have the output as </p> <pre><code>Mode Time Air 3.5 Sea 5 </code></pre> <p>The output should contain two columns Mode and the Time.</p> <p>With my Code I dont see the columns com...
0
2016-08-31T21:12:50Z
39,259,324
<p>Don't select the column:</p> <pre><code>&gt;&gt;&gt; df1.groupby('Mode').mean() Time Mode Air 3.5 Sea 5.0 &gt;&gt;&gt; </code></pre> <h2>Edit in response to comment</h2> <pre><code>&gt;&gt;&gt; df1.groupby('Mode').mean().reset_index() Mode Time 0 Air 3.5 1 Sea 5.0 &gt;&gt;&gt; </code><...
2
2016-08-31T21:31:31Z
[ "python", "pandas", "dataframe" ]
Python: moving file to a newly created directory
39,259,136
<p>I've got my script creating a bunch of files (size varies depending on inputs) and I want to be certain files in certain folders based on the filenames.</p> <p>So far I've got the following but although directories are being created no files are being moved, I'm not sure if the logic in the final for loop makes any...
1
2016-08-31T21:16:09Z
39,259,245
<p>A simple fix would be to check if '*_01.png' is in the file name <code>i</code> and change the <code>shutil.move</code> to include <code>i</code>, the filename. (It's also worth mentioning that <code>i</code>is not a good name for a filepath</p> <pre><code>list_of_sub_frames = glob.glob('*.png') for i in list_of_su...
1
2016-08-31T21:25:35Z
[ "python", "filesystems", "shutil" ]
Python: moving file to a newly created directory
39,259,136
<p>I've got my script creating a bunch of files (size varies depending on inputs) and I want to be certain files in certain folders based on the filenames.</p> <p>So far I've got the following but although directories are being created no files are being moved, I'm not sure if the logic in the final for loop makes any...
1
2016-08-31T21:16:09Z
39,259,472
<p>As you said, the logic of the final loop does not make sense.</p> <pre><code>if i == '*_01.ng' </code></pre> <p>It would evaluate something like <code>'image_01.png' == '*_01.png'</code> and be always false.</p> <p>Regexp should be the way to go, but for this simple case you just can slice the number from the fil...
2
2016-08-31T21:42:46Z
[ "python", "filesystems", "shutil" ]
Python: moving file to a newly created directory
39,259,136
<p>I've got my script creating a bunch of files (size varies depending on inputs) and I want to be certain files in certain folders based on the filenames.</p> <p>So far I've got the following but although directories are being created no files are being moved, I'm not sure if the logic in the final for loop makes any...
1
2016-08-31T21:16:09Z
39,259,512
<p>Here is a complete example using regular expressions. This also implements the incrementing of file names/destination folders</p> <pre><code>import os import glob import shutil import re num_sub_frames = 3 # No need to enumerate range list without start or step for index in range(num_sub_frames+10): path = os....
1
2016-08-31T21:46:38Z
[ "python", "filesystems", "shutil" ]
How to draw a circular heatmap within a rectangle in Python
39,259,225
<p>Say I have an image and I have a bounding box on a part of the image. How can I draw a circular heatmap within this rectangle?</p>
0
2016-08-31T21:23:51Z
39,259,969
<p>You need to create a new <code>Axes</code> in the desired position, and use a polar <code>pcolor</code> plot to construct a "heatmap":</p> <pre><code>import matplotlib.pyplot as plt import numpy as np fig,ax1 = plt.subplots() # plot dummy image ax1.imshow(np.random.rand(200,200),cmap='viridis') # create new Axes,...
1
2016-08-31T22:27:39Z
[ "python", "matplotlib", "heatmap" ]
Is there an option to edit the padding inside of a Tkinter EntryBox?
39,259,264
<p>Is there an option to edit the padding inside of a Tkinter EntryBox? So that the text that the user inputs starts e.g. 10px from the left border.</p>
3
2016-08-31T21:26:40Z
39,509,532
<p>Technically, yes if you are using <code>.grid()</code>. </p> <p>Using:</p> <pre><code>grid(ipadx=HORIZONTAL-PADDING, ipady=VERTICAL-PADDING) </code></pre> <p>Is what the documentation says, however it doesn't seem to dictate how the text bbehaves. I can only get it to work for <code>ipady</code>. <code>ipadx</cod...
0
2016-09-15T11:06:21Z
[ "python", "tkinter" ]
Unicode python Error
39,259,290
<p>i'm trying to print : Pokémon GO Việt Nam</p> <pre><code>print u"Pokémon GO Việt Nam" </code></pre> <p>and i'm getting :</p> <pre><code>print u"PokÚmon GO Vi?t Nam" SyntaxError: (unicode error) 'utf8' codec can't decode byte 0xe9 in position 0: unexpected end of data </code></pre> <p>i've tried : </p> <p...
1
2016-08-31T21:28:17Z
39,259,334
<pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- print "Pokémon GO Việt Nam" </code></pre> <p>You can find <a href="https://www.python.org/dev/peps/pep-0263/" rel="nofollow">here</a> more info</p> <p>For PyCharm settings, go to the menu: PyCharm --> Preference then use the search to look up "encoding", you sh...
4
2016-08-31T21:32:09Z
[ "python", "unicode" ]
Unicode python Error
39,259,290
<p>i'm trying to print : Pokémon GO Việt Nam</p> <pre><code>print u"Pokémon GO Việt Nam" </code></pre> <p>and i'm getting :</p> <pre><code>print u"PokÚmon GO Vi?t Nam" SyntaxError: (unicode error) 'utf8' codec can't decode byte 0xe9 in position 0: unexpected end of data </code></pre> <p>i've tried : </p> <p...
1
2016-08-31T21:28:17Z
39,259,349
<p>Specify the encoding</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- </code></pre> <p>in the top of the program</p>
1
2016-08-31T21:33:07Z
[ "python", "unicode" ]
Unicode python Error
39,259,290
<p>i'm trying to print : Pokémon GO Việt Nam</p> <pre><code>print u"Pokémon GO Việt Nam" </code></pre> <p>and i'm getting :</p> <pre><code>print u"PokÚmon GO Vi?t Nam" SyntaxError: (unicode error) 'utf8' codec can't decode byte 0xe9 in position 0: unexpected end of data </code></pre> <p>i've tried : </p> <p...
1
2016-08-31T21:28:17Z
39,261,872
<p>As an alternative you can encode the unicode string:</p> <pre><code>print u"Pokémon GO Việt Nam".encode('utf-8') </code></pre> <p>The advantage is that the bytes in the resulting string are independent of the encoding of the source file: <code>u"ệ".encode('utf-8')</code> is always the same 3 bytes <code>"\xe1...
0
2016-09-01T02:37:58Z
[ "python", "unicode" ]
Python search for single filename recursively in directory tree. Return false if not found
39,259,318
<p>Using Python, I would like to search a directory tree recursively for a specific file name.</p> <p>**If found, print nothing.</p> <p>**If not found print a message stating it was not found.</p> <p>===== here is what I have so far, no errors, but no message when file not found either=====</p> <pre><code>import os...
0
2016-08-31T21:31:01Z
39,259,384
<p>Return early when you find the file; that way, after your <code>os.walk()</code> loop has completed you know the file was never found:</p> <pre><code>import os def find_file(name, root): for _, _, filenames in os.walk(root): if name in filenames: return # found the file, exit early pri...
1
2016-08-31T21:35:27Z
[ "python", "recursion", "filenames", "os.walk" ]
Python search for single filename recursively in directory tree. Return false if not found
39,259,318
<p>Using Python, I would like to search a directory tree recursively for a specific file name.</p> <p>**If found, print nothing.</p> <p>**If not found print a message stating it was not found.</p> <p>===== here is what I have so far, no errors, but no message when file not found either=====</p> <pre><code>import os...
0
2016-08-31T21:31:01Z
39,259,432
<pre><code>if not any(file_name in filenames for dirpath, dirnames, filenames in os.walk(rootDir)): print file_name, 'not found' </code></pre>
0
2016-08-31T21:39:22Z
[ "python", "recursion", "filenames", "os.walk" ]
Python search for single filename recursively in directory tree. Return false if not found
39,259,318
<p>Using Python, I would like to search a directory tree recursively for a specific file name.</p> <p>**If found, print nothing.</p> <p>**If not found print a message stating it was not found.</p> <p>===== here is what I have so far, no errors, but no message when file not found either=====</p> <pre><code>import os...
0
2016-08-31T21:31:01Z
39,259,505
<p>If you are using Python3.5+ you can use <code>**</code> with the <code>recursive</code> flag:</p> <pre><code>import glob rootDir = 'G:\\some_top_directory\\' file_name = 'fileOFinterest.txt' found_files = glob.glob("{}**\\{}".format(rootDir, file_name), recursive=True) if not found_files: # do whatever you need...
0
2016-08-31T21:46:07Z
[ "python", "recursion", "filenames", "os.walk" ]
PyQt5: Progamically adding QWidget to layout, doesn't show Qwidget when a spacer is added
39,259,367
<p><strong>Edit</strong>: I have tried a few more things. If I move the spacer to a layout below the spacer I am adding to it doesn't exibit the same exact behavior. Its still not optimal, and isn't going to work because my end goal is to have a scrollArea with a spacer inside that i add my widgets to, but this would ...
0
2016-08-31T21:34:26Z
39,283,290
<p>I finally fixed this by trying random things over and over until something worked.</p> <p>It turned out that on my second ui file I did not have a top level layout. (I am not sure if that's what its called.)</p> <p>To fix this I right clicked on the top level widget and choose layout and selected horizontal layout...
0
2016-09-02T02:04:10Z
[ "python", "pyqt5" ]
np.array returning numpy.ndarray with "..."
39,259,371
<p>I created a script to generate a list:</p> <pre><code>import random nota1 = range (5, 11) nota2 = range (5, 11) nota3 = range (5, 11) nota4 = range (0, 2) dados = [] for i in range(1000): dados_dado = [] n1 = random.choice(nota1) n2 = random.choice(nota2) n3 = random.choice(nota3) n4 = rand...
0
2016-08-31T21:34:38Z
39,259,407
<p>Your array is fine. NumPy just suppresses display of the whole array for large arrays by default.</p> <p>(If you actually <em>were</em> expecting your array to be short enough not to trigger this behavior, or if you were actually expecting it to have non-integer entries, you'll have to explain why you expected that...
0
2016-08-31T21:37:16Z
[ "python", "arrays", "numpy" ]
np.array returning numpy.ndarray with "..."
39,259,371
<p>I created a script to generate a list:</p> <pre><code>import random nota1 = range (5, 11) nota2 = range (5, 11) nota3 = range (5, 11) nota4 = range (0, 2) dados = [] for i in range(1000): dados_dado = [] n1 = random.choice(nota1) n2 = random.choice(nota2) n3 = random.choice(nota3) n4 = rand...
0
2016-08-31T21:34:38Z
39,259,428
<pre><code>numpy.set_printoptions(precision=20) </code></pre> <p>Will give you more displayabilty, set precision as you desire.</p>
0
2016-08-31T21:38:57Z
[ "python", "arrays", "numpy" ]
np.array returning numpy.ndarray with "..."
39,259,371
<p>I created a script to generate a list:</p> <pre><code>import random nota1 = range (5, 11) nota2 = range (5, 11) nota3 = range (5, 11) nota4 = range (0, 2) dados = [] for i in range(1000): dados_dado = [] n1 = random.choice(nota1) n2 = random.choice(nota2) n3 = random.choice(nota3) n4 = rand...
0
2016-08-31T21:34:38Z
39,259,861
<p>With your sample:</p> <pre><code>In [574]: dados=[[5.0, 8.0, 10.0, 1.0], [8.0, 9.0, 9.0, 1.0], [7.0, 5.0, 6.0, 1. ...: 0], [5.0, 8.0, 7.0, 0.0], [9.0, 7.0, 10.0, 0.0], [6.0, 7.0, 9.0, 1.0], ...: [6.0, 9.0, 8.0, 1.0]] In [575]: print(dados) [[5.0, 8.0, 10.0, 1.0], [8.0, 9.0, 9.0, 1.0], [7.0, 5.0, 6.0, 1....
1
2016-08-31T22:18:57Z
[ "python", "arrays", "numpy" ]
How do I create a new dict of dicts from a dict with nested dicts in Python
39,259,383
<p>I am starting with a dict received from an api </p> <pre><code>start_dict = { "a": 795, "b": 1337, "c": [ { "d1": 2, "d2": [ { "e1": 4 } ] } ] } </code></pre> <p>I need to create a separat...
0
2016-08-31T21:35:19Z
39,259,446
<p>You can build the output with a recursive function:</p> <pre><code>def transform(ob): if isinstance(ob, list): return [transform(v) for v in ob] elif not isinstance(ob, dict): return ob return [{'element_name': k, 'value': transform(v)} for k, v in ob.items()] values = {'fie...
5
2016-08-31T21:40:52Z
[ "python", "python-2.7", "dictionary" ]
What is the best way to store a list of functions?
39,259,411
<p>I need to store a large numbers of functions rules in Python (around 100000 ), to be used after....</p> <pre><code>def rule1(x,y) :... def rule2(x,y): ... </code></pre> <p>What is the best way to store, manage those function rules instance into Python structure ? </p> <p>What about using Numpy dtype=np.object arr...
0
2016-08-31T21:37:52Z
39,259,467
<p>Functions are first class objects in Python - you can store them just like you'd store any other variable or value:</p> <pre><code>def a(): pass def b(): pass funcs = [a,b] funcs[0]() # calls `a()`. </code></pre>
2
2016-08-31T21:42:05Z
[ "python" ]