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
python loadtxt with exotic format of table
39,621,800
<p>I have a file from simulation which reads like :</p> <pre><code>5.2000 -0.01047 -0.02721 0.823400 -0.56669 1.086e-5 2.109e-5 -1.57e-5 -3.12e-5 0.823400 -0.56669 -0.02166 -0.01949 -2.28e-5 -2.66e-5 1.435e-5 1.875e-5 1.086e-5 2.109e-5 -2.28e-5 -2.66e-5 -0.01878 -0.01836 0.820753 -0.57065 -1.57e-5...
2
2016-09-21T16:23:30Z
39,625,890
<p><code>genfromtxt</code> is generally much more versatile a module than <code>loadtxt</code></p> <p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html" rel="nofollow">genfromtxt documentation</a> </p>
0
2016-09-21T20:20:37Z
[ "python", "numpy" ]
How to have python functions and classes available system-wide with an easy `import` statement
39,621,831
<h1>Introduction</h1> <p>I thought I'd try my hand at making a python module to make some of my libraries and functions available system-wide. Google and StackExchange provide ample "solutions" and how-toos. But for some reason none of them seem to work for me. Obviously, I'm doing something wrong. But after days of t...
-1
2016-09-21T16:24:55Z
39,622,187
<p>You completely misread the sources you were working off of. If you want to be able to import <code>SmartDisk</code> directly from the <code>mausy5043libs</code> package, then <code>mausy5043libs/__init__.py</code> needs to import <code>SmartDisk</code>:</p> <pre><code># in mausy5043libs/__init__.py from .libsmart3 ...
1
2016-09-21T16:44:53Z
[ "python", "python-3.x", "python-import" ]
Import data from xml file into two tables w/ foreign key at MySQL database
39,621,860
<p>I need to load file of the following format into MySQL database.</p> <pre><code>&lt;item value="{$\emptyset $}"&gt; &lt;subitem value="(empty language)"&gt;&lt;/subitem&gt; &lt;subitem value="(empty set)"&gt;&lt;/subitem&gt; &lt;/item&gt; &lt;item value="{$\subseteq$ (subset)}"&gt; &lt;/item&gt; &lt;item valu...
1
2016-09-21T16:26:08Z
39,630,669
<p>I was able to do it by reading xml with python and then inserting it into MySQL database. First one need to install needed software:</p> <pre><code>sudo apt install mysql-server sudo apt-get install python-mysqldb </code></pre> <p>Then this py-file will do the job:</p> <pre><code>import xml.etree.ElementTree impo...
0
2016-09-22T05:06:33Z
[ "python", "mysql" ]
Using a DLL exported from D
39,621,900
<p>I've created a simple encryption program in D, and I had the idea to make a DLL from it and try to import it to, for example, Python.</p> <p>I've could simply call my <code>main</code> function, becouse it dosn't need any params. But when I get to my encrytion method, <strong>it uses dynamic-lenght <code>ubyte[]</c...
6
2016-09-21T16:28:32Z
39,625,571
<p>Well tbh. there's no real elegant way other than wrapping a pointer with a length or wrapping to C arrays and then to D.</p> <p>However you can make a somewhat elegant purpose with the first way using a struct that has a pointer, a length and a property that converts it to a D array.</p> <p>Then the function you e...
1
2016-09-21T20:01:53Z
[ "python", "dll", "d" ]
pd.read_csv ignores columns that don't have headers
39,621,914
<p>I have a .csv file that is generated by a third-party program. The data in the file is in the following format:</p> <pre><code>%m/%d/%Y 49.78 85 6 15 03/01/1984 6.63368 82 7 9.8 34.29056405 2.79984079 2.110346498 0.014652412 2.304545521 0.004732732 03/02/1984 6.53368 68 0 0.2 ...
2
2016-09-21T16:29:27Z
39,622,282
<p>You could do it as shown:</p> <pre><code>col_name = list('ABCDEFGHIJK') data = 'path.csv' pd.read_csv(data, delim_whitespace=True, header=None, names=col_name, usecols=col_name[5:]) </code></pre> <p><a href="http://i.stack.imgur.com/QqBJJ.png" rel="nofollow"><img src="http://i.stack.imgur.com/QqBJJ.png" alt="Image...
1
2016-09-21T16:50:17Z
[ "python", "csv", "pandas" ]
pd.read_csv ignores columns that don't have headers
39,621,914
<p>I have a .csv file that is generated by a third-party program. The data in the file is in the following format:</p> <pre><code>%m/%d/%Y 49.78 85 6 15 03/01/1984 6.63368 82 7 9.8 34.29056405 2.79984079 2.110346498 0.014652412 2.304545521 0.004732732 03/02/1984 6.53368 68 0 0.2 ...
2
2016-09-21T16:29:27Z
39,622,485
<p>There are a couple of parameters that can be passed to <code>pd.read_csv()</code>:</p> <pre><code>import pandas as pd colnames = list('ABCDEFGHIKL') df = pd.read_csv('test.csv', sep='\t', names=colnames) </code></pre> <p>With this, I can actually import your data quite fine (and it is accessible via eg <code>df['K...
1
2016-09-21T17:02:00Z
[ "python", "csv", "pandas" ]
np reshape within pandas apply
39,621,965
<p>Arise Exception: Data must be 1-dimensional.</p> <p>I'll present the problem with a toy example to be clear.</p> <pre><code>import pandas as pd import numpy as np </code></pre> <p>Initial dataframe:</p> <pre><code>df = pd.DataFrame({"A": [[10,15,12,14],[20,30,10,43]], "R":[2,2] ,"C":[2,2]}) &gt;&gt;df A ...
2
2016-09-21T16:32:03Z
39,622,513
<p>Using <code>apply</code> directly doesn't work - the return value is a <code>numpy</code> 2d array, and placing it back in the DataFrame confuses Pandas, for some reason. </p> <p>This seems to work, though:</p> <pre><code>df['reshaped'] = pd.Series([a.reshape((c, r)) for (a, c, r) in zip(df.A, df.C, df.R)]) &gt;&...
2
2016-09-21T17:03:46Z
[ "python", "pandas", "numpy", "reshape" ]
TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
39,622,005
<p>For my course in Python, I am creating a program that calculates the distance between two cities bases on their coordinates. It has worked and suddenly I got the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;pyshell#13&gt;", line 1, in &lt;module&gt; distance(+1, 52, 22, +1, 4, ...
-2
2016-09-21T16:34:29Z
39,622,313
<p>There is no return statement in the <code>conversion</code> function. At the moment, the radians value is calculated then forgotten when the function finishes. If you want the value of <code>total_radians</code> to be accessed from outside the function, add </p> <pre><code> return total_radians </code></pre> <p...
0
2016-09-21T16:52:34Z
[ "python", "typeerror" ]
Problems with pickling data
39,622,014
<pre><code>import random import pickle, shelve import os #import RPi.GPIO as GPIO | Raspberry pi only import tkinter import sys import time class Operator(object): global list_name def __init__(self): print("Welcome to Python OS 1.0") print("type 'help' to access help...") # ADD CODE OS.REMOVE...
0
2016-09-21T16:35:16Z
39,628,530
<p>You have a while loop that will execute forever because you are not assigning your user variable to anything. while user != data[0]: user = input("please enter your username...") print( 'Welcome Back To Python OS, '+ data[0])</p>
0
2016-09-22T00:40:09Z
[ "python", "python-3.x", "pickle" ]
How do I see/get the Number of subreddits I downloaded using reddits API
39,622,022
<pre><code>&gt;&gt;&gt; import requests &gt;&gt;&gt; from pprint import pprint &gt;&gt;&gt; r = requests.get('http://www.reddit.com/reddits.json', headers= {'User-Agent': 'me'}) &gt;&gt;&gt; data = r.json() &gt;&gt;&gt; pprint(data.keys()) </code></pre> <p>This prints subreddits &amp; im trying to figure out how muc...
1
2016-09-21T16:35:31Z
39,622,248
<pre><code>import requests r = requests.get('http://www.reddit.com/reddits.json', headers= {'User-Agent': 'me'}) data = r.json() print(len(data['data']['children'])) </code></pre> <p>The structure of the JSON is complicated, so I'm not entirely sure what you are trying to count, but <code>['data']['children']</code>...
0
2016-09-21T16:48:31Z
[ "python", "json", "api", "reddit-api" ]
Slice numpy array to make it desired shaped
39,622,059
<p>Surprisingly, couldn't find the answer across the internet. I have an n-dimensional numpy array. E.g.: 2-D np array:</p> <pre><code>array([['34.5500000', '36.9000000', '37.3200000', '37.6700000'], ['41.7900000', '44.8000000', '48.2600000', '46.1800000'], ['36.1200000', '37.1500000', '39.3100000', '38....
3
2016-09-21T16:37:45Z
39,622,690
<p>This is not a 2d array. It is a 1d array, whose elements are objects, in this case some 4 element lists and one 5 element one. And this lists contain strings.</p> <pre><code>In [577]: np.array([['34.5500000', '36.9000000', '37.3200000', '37.6700000'], ...: ['41.7900000', '44.8000000', '48.2600000', '4...
2
2016-09-21T17:13:30Z
[ "python", "arrays", "numpy" ]
Slice numpy array to make it desired shaped
39,622,059
<p>Surprisingly, couldn't find the answer across the internet. I have an n-dimensional numpy array. E.g.: 2-D np array:</p> <pre><code>array([['34.5500000', '36.9000000', '37.3200000', '37.6700000'], ['41.7900000', '44.8000000', '48.2600000', '46.1800000'], ['36.1200000', '37.1500000', '39.3100000', '38....
3
2016-09-21T16:37:45Z
39,622,939
<p>Here's an almost* vectorized approach -</p> <pre><code>def slice_2Dobject_arr(arr,out_shape): lens = np.array(map(len,arr)) id_arr = np.ones(lens.sum(),dtype=int) id_arr[lens[:-1].cumsum()] = -lens[:-1]+1 mask = id_arr.cumsum()&lt;=out_shape[1] vals = np.concatenate(arr) return vals[mask].re...
1
2016-09-21T17:25:59Z
[ "python", "arrays", "numpy" ]
Pandas Dataframe automatic typecasting
39,622,081
<p>I am working with a pandas dataframe and need several columns (x &amp; y in the example below) to be an integer and one column to be a float (l). It appears that assigning a new row with a float in it recasts the whole dataframe as a float. Why is this and how do I prevent it?</p> <pre><code>data = pd.DataFrame(d...
3
2016-09-21T16:39:06Z
39,622,269
<p>You can recast all of the other columns after each addition using:</p> <pre><code>data['y'] = data['y'].astype(int) </code></pre> <p>Not the most efficient solution if you need to add a lot of columns on the fly. Alternatively you could create the entire data frame using Series in advance and type the whole thing ...
1
2016-09-21T16:49:37Z
[ "python", "pandas", "dataframe", "casting" ]
How to load a pre-trained Word2vec MODEL File?
39,622,106
<p>I'm going to use a pre-trained <code>word2vec</code> model, but I don't know how to load it in python.</p> <p>This file is a MODEL file (703 MB). <a href="http://devmount.github.io/GermanWordEmbeddings/" rel="nofollow">http://devmount.github.io/GermanWordEmbeddings/</a></p>
1
2016-09-21T16:40:18Z
39,622,188
<p>You can use <code>gensim</code> like this:</p> <pre><code>import gensim # Load pre-trained Word2Vec model. model = gensim.models.Word2Vec.load("filename.model") </code></pre> <p>More info <a href="http://mccormickml.com/2016/04/12/googles-pretrained-word2vec-model-in-python/" rel="nofollow">here</a></p>
1
2016-09-21T16:44:53Z
[ "python", "model", "word2vec" ]
How do you store an entire array into another array
39,622,176
<p>How do you store an entire array into another array</p> <p>suppose I have an array </p> <pre><code>data = np.array([], dtype=float, ndmin=2) a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) </code></pre> <p>How do you store the values such that</p> <pre><code>data = [ [1,2,3], [4,5,6] ] </code></pre> <p...
1
2016-09-21T16:44:16Z
39,622,294
<p>You mean like:</p> <pre><code>&gt;&gt;&gt; data = np.array([a,b]) &gt;&gt;&gt; data array([[1, 2, 3], [4, 5, 6]]) </code></pre> <p>If you want to do it stepwise, you <em>can</em> use append, but you need to make sure all your arguments are rank 2 (or wrapped in a list). Right now, <code>a</code> and <code>b...
1
2016-09-21T16:51:07Z
[ "python", "arrays", "numpy" ]
How do you store an entire array into another array
39,622,176
<p>How do you store an entire array into another array</p> <p>suppose I have an array </p> <pre><code>data = np.array([], dtype=float, ndmin=2) a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) </code></pre> <p>How do you store the values such that</p> <pre><code>data = [ [1,2,3], [4,5,6] ] </code></pre> <p...
1
2016-09-21T16:44:16Z
39,622,336
<p>So you are looking for <code>np.vstack</code>:</p> <pre><code>a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) data = np.vstack([a,b]) </code></pre>
2
2016-09-21T16:53:24Z
[ "python", "arrays", "numpy" ]
How to convert dictionary list values uniformly in Python 3?
39,622,263
<p>I have a yaml file with a couple of fields that are lists.</p> <p>It looks kind of like this:</p> <pre><code>key0: "value0" key1: ["value1-0", "value1-1", "value1-2"] key2: ["value2-0", "value2-1", "value2-2"] key3: "value3" </code></pre> <p>This is naturally converted to a Python dictionary with the PyYAML libra...
1
2016-09-21T16:49:14Z
39,622,440
<p>If you already have something that converts what you've got into a dictionary, then this should do what you want</p> <pre><code>d = {'key1' : 'value1', 'key2' : 'value2'} stringFinal = '' tempString = '' for k, v in d.items(): tempString = str(k) + ' ' + str(v) stringFinal ='--' + tempString + ' ' + string...
0
2016-09-21T16:59:17Z
[ "python", "python-3.x", "refactoring" ]
How to convert dictionary list values uniformly in Python 3?
39,622,263
<p>I have a yaml file with a couple of fields that are lists.</p> <p>It looks kind of like this:</p> <pre><code>key0: "value0" key1: ["value1-0", "value1-1", "value1-2"] key2: ["value2-0", "value2-1", "value2-2"] key3: "value3" </code></pre> <p>This is naturally converted to a Python dictionary with the PyYAML libra...
1
2016-09-21T16:49:14Z
39,622,847
<p>You can iterate through the dictionary to build a string. if the item is a list, you have to iterate through its elements.</p> <p>NOTE: since dictionary is an unordered collection, the output may vary.</p> <pre><code>dict={"key0": "value0", "key1": ["value1-0", "value1-1", "value1-2"], "key2": ["value2-0", "value2...
0
2016-09-21T17:21:11Z
[ "python", "python-3.x", "refactoring" ]
capture one frame from a video file after every 10 seconds
39,622,281
<p>I want to capture from a video file one frame after every 10 seconds, So if anyone can help me for that i will be very thankful. my python code is like that:</p> <pre><code>import cv2 print(cv2.__version__) vidcap = cv2.VideoCapture('Standoff.avi') vidcap.set(cv2.CAP_PROP_POS_MSEC,96000) success,image = vidcap....
1
2016-09-21T16:50:15Z
39,658,034
<p>If you can get the framerate of the video from the file the following should work (You may need to check the syntax as I have not tested it):</p> <pre class="lang-js prettyprint-override"><code>import numpy as np import cv2 cap = cv2.VideoCapture('Standoff.avi') framerate = cap.get(cv2.cv.CV_CAP_PROP_FPS) framecou...
0
2016-09-23T10:04:01Z
[ "python", "video", "video-capture" ]
Why exhausted generators raise StopIteration more than once?
39,622,288
<p>Why is it that when an exhausted generator is called several times, <code>StopIteration</code> is raised every time, rather than just on the first attempt? Aren't subsequent calls meaningless, and indicate a likely bug in the caller's code?</p> <pre><code>def gen_func(): yield 1 yield 2 gen = gen_func() nex...
3
2016-09-21T16:50:42Z
39,622,498
<blockquote> <p>Perhaps there's an important use case for calling exhausted generators multiple times and getting <code>StopIteration</code>?</p> </blockquote> <p>There is, specifically, when you want to perform multiple loops on the same iterator. Here's an example from the <a href="https://docs.python.org/3/librar...
2
2016-09-21T17:03:09Z
[ "python", "python-3.x", "generator" ]
Why exhausted generators raise StopIteration more than once?
39,622,288
<p>Why is it that when an exhausted generator is called several times, <code>StopIteration</code> is raised every time, rather than just on the first attempt? Aren't subsequent calls meaningless, and indicate a likely bug in the caller's code?</p> <pre><code>def gen_func(): yield 1 yield 2 gen = gen_func() nex...
3
2016-09-21T16:50:42Z
39,622,585
<p>It is a part of the iteration protocol:</p> <blockquote> <p>Once an iterator’s <code>__next__()</code> method raises StopIteration, it must continue to do so on subsequent calls. Implementations that do not obey this property are deemed broken.</p> </blockquote> <p>Source: <a href="https://docs.python.org/...
3
2016-09-21T17:07:34Z
[ "python", "python-3.x", "generator" ]
Barrier after spawned mpi4py process
39,622,415
<p>I have a piece of code that uses mpi4py to spawn several instances of an mpi exectuable. I want the code to halt while these processes complete, and then call a second group of the same executable.</p> <p>The problem is that all calls to the mpi executable get spawned immediately.</p> <p>It seems like there is no ...
0
2016-09-21T16:57:55Z
39,636,470
<p>You must use the <em>intercommunicator</em> returned by <code>Spawn</code>:</p> <pre><code>child_comm = MPI.COMM_WORLD.Spawn("./spawnchild.py", args=None, maxprocs=2) child_comm.Barrier() </code></pre> <p>For the child, get the parent <em>intercommunicator</em> (similarly in Fortran):</p> <pre><code>parent = MPI....
1
2016-09-22T10:21:54Z
[ "python", "parallel-processing", "mpi", "mpi4py" ]
Cumulative Set in PANDAS
39,622,487
<p>I have a dataframe of tweets and I'm looking to group the dataframe by date and generate a column that contains a cumulative list of all the unique users who have posted up to that date. None of the existing functions (e.g., cumsum) would appear to work for this. Here's a sample of the original tweet dataframe, wher...
0
2016-09-21T17:02:06Z
39,623,235
<p>You cannot add sets, but can add lists! So build a list of users, then take the cumulative sum and finally apply the set constructor to get rid of duplicates.</p> <pre><code>cum_names = (df['screen_name'].groupby(df.index.date) .agg(lambda x: list(x)) .cum...
3
2016-09-21T17:43:40Z
[ "python", "pandas" ]
Python 3.5.2 internet explorer control
39,622,496
<p>how do i open a download link like <a href="http://ops.epo.org/3.1/rest-services/published-data/images/EP/1000000/A1/thumbnail?Range=1" rel="nofollow">http://ops.epo.org/3.1/rest-services/published-data/images/EP/1000000/A1/thumbnail?Range=1</a> in the Internet Explorer and save it without pushing 'save' in a file l...
0
2016-09-21T17:03:09Z
39,731,291
<p>It looks like its a PDF file. This could be achieved using basic request example</p> <pre><code>import requests url='http://ops.epo.org/3.1/rest-services/published-data/images/EP/1000000/A1/thumbnail?Range=1' r = requests.get(url) with open('1.pdf', 'wb') as fh: fh.write(r.content) </code></pre>
0
2016-09-27T17:53:31Z
[ "python", "image", "download" ]
Python 3.2+ converting int to bytes
39,622,527
<p>I'm having a problem converting int to bytes in Python. </p> <p>This works - </p> <pre><code>&gt;&gt;&gt; (1024).to_bytes(2, 'big') b'\x04\x00' </code></pre> <p>However this does not work as I would expect - </p> <pre><code>&gt;&gt;&gt; (33).to_bytes(2, 'big') b'\x00!' </code></pre> <p>What am I not understa...
1
2016-09-21T17:04:30Z
39,622,597
<p><code>!</code> has the decimal value 33 by ascii standarts, so that python-shell can show it without escape codes, and so it does.</p> <pre><code>&gt;&gt;&gt; x = b'\x00\x21' &gt;&gt;&gt; x b'\x00!' </code></pre>
5
2016-09-21T17:08:25Z
[ "python", "python-3.2" ]
Python 3.2+ converting int to bytes
39,622,527
<p>I'm having a problem converting int to bytes in Python. </p> <p>This works - </p> <pre><code>&gt;&gt;&gt; (1024).to_bytes(2, 'big') b'\x04\x00' </code></pre> <p>However this does not work as I would expect - </p> <pre><code>&gt;&gt;&gt; (33).to_bytes(2, 'big') b'\x00!' </code></pre> <p>What am I not understa...
1
2016-09-21T17:04:30Z
39,622,602
<p>You're not understanding that <code>!</code> is ASCII character 33, equivalent to <code>\x21</code>. This bytestring is exactly the bytestring you asked for; it just isn't displayed the way you were expecting.</p>
1
2016-09-21T17:08:33Z
[ "python", "python-3.2" ]
Python 3.2+ converting int to bytes
39,622,527
<p>I'm having a problem converting int to bytes in Python. </p> <p>This works - </p> <pre><code>&gt;&gt;&gt; (1024).to_bytes(2, 'big') b'\x04\x00' </code></pre> <p>However this does not work as I would expect - </p> <pre><code>&gt;&gt;&gt; (33).to_bytes(2, 'big') b'\x00!' </code></pre> <p>What am I not understa...
1
2016-09-21T17:04:30Z
39,622,731
<p>According to documentation -> <a href="https://docs.python.org/3.3/library/stdtypes.html" rel="nofollow">https://docs.python.org/3.3/library/stdtypes.html</a></p> <pre><code> &gt;&gt;&gt; (1024).to_bytes(2, byteorder='big') b'\x04\x00' &gt;&gt;&gt; (1024).to_bytes(10, byteorder='big') b'\x00\x00\x00\x00\x00\x00\...
0
2016-09-21T17:15:15Z
[ "python", "python-3.2" ]
numpy array as datatype in a structured array?
39,622,533
<p>I was wondering if it is possible to have a numpy.array as a datatype in a structured array. This is the idea:</p> <pre><code>import numpy raw_data = [(1, numpy.array([1,2,3])), (2, numpy.array([4,5,6])), (3, numpy.array([7,8,9]))] data = numpy.array(raw_data, dtype=[('num', float), ...
0
2016-09-21T17:04:45Z
39,622,632
<p>Yes, you can create compound fields that look like arrays within the structured array; for example:</p> <pre><code>import numpy as np raw_data = [(1, np.array([1,2,3])), (2, np.array([4,5,6])), (3, np.array([7,8,9]))] tp = np.dtype([('id', int), ('arr', float, (3,))]) x = np.array(raw_da...
1
2016-09-21T17:10:12Z
[ "python", "arrays", "numpy", "structured-array" ]
Python: Document results and figures into tex document
39,622,537
<p>I currently have written a script that produces several figures. I was wondering if there is a way to publish these figures directly into a tex file, say in eps format without including all of the python code verbatim. I also want to include the values of some variables. I looked at the module pweave (<a href="http:...
1
2016-09-21T17:04:54Z
39,623,365
<p>You can use pweave. If you want a code chunk to be executed but not formatted, set the echo property to false. See <a href="http://mpastell.com/pweave/chunks.html#envvar-echo=Trueor(False)" rel="nofollow">http://mpastell.com/pweave/chunks.html#envvar-echo=Trueor(False)</a></p>
0
2016-09-21T17:50:36Z
[ "python", "documentation", "pweave" ]
Interest Calculator looping issue Python
39,622,596
<p>beginner here. I've made an interest calculator program to help me with my loans of different sorts. I'm having two issues to finalize my program. Here's the program. I tried looking up the problems but I wasn't sure how to word it so I thought I'd just ask a question in total.</p> <pre><code>x=1 while x==1: im...
0
2016-09-21T17:08:22Z
39,622,893
<p>On both of your examples, I believe your looking for Python's <code>continue</code> <a href="https://docs.python.org/3/reference/simple_stmts.html#continue" rel="nofollow">statement</a>. From the Python Docs:</p> <p>(emphasis mine)</p> <blockquote> <p>continue may only occur syntactically nested in a for or whil...
0
2016-09-21T17:23:31Z
[ "python" ]
Interest Calculator looping issue Python
39,622,596
<p>beginner here. I've made an interest calculator program to help me with my loans of different sorts. I'm having two issues to finalize my program. Here's the program. I tried looking up the problems but I wasn't sure how to word it so I thought I'd just ask a question in total.</p> <pre><code>x=1 while x==1: im...
0
2016-09-21T17:08:22Z
39,622,900
<p>You make an infinite loop, that you <code>break</code> out of when all is well. Simplified:</p> <pre><code>while True: x_as_string = input("Value") try: x = float(x_as_string) except ValueError: print("I can't convert", x_as_string) else: break </code></pre> <p>It is easi...
1
2016-09-21T17:23:56Z
[ "python" ]
Interest Calculator looping issue Python
39,622,596
<p>beginner here. I've made an interest calculator program to help me with my loans of different sorts. I'm having two issues to finalize my program. Here's the program. I tried looking up the problems but I wasn't sure how to word it so I thought I'd just ask a question in total.</p> <pre><code>x=1 while x==1: im...
0
2016-09-21T17:08:22Z
39,623,048
<p>Your problem is straightforward. You have to use <a href="https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops" rel="nofollow"><code>continue</code></a> or <a href="https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clause...
0
2016-09-21T17:33:42Z
[ "python" ]
BeautifulSoup4 is not working even though I have successfully installed it using pip Linux Mint Sarah
39,622,609
<p>I am a brand new linux user using linux mint sarah and I just installed python 3.5 as well as BeautifulSoup to do some web scraping.</p> <p>However, when I type in the following command I receive a traceback error:</p> <p>from bs4 import BeautifulSoup</p> <p>The error tells me that there is no module bs4.</p> <p...
0
2016-09-21T17:08:51Z
39,622,872
<p>You need to install <strong>BeautifulSoup4</strong> for <strong>Python 3.5</strong>.</p> <p><strong>Option 1:</strong></p> <ul> <li>Download <a href="https://bootstrap.pypa.io/get-pip.py" rel="nofollow">https://bootstrap.pypa.io/get-pip.py</a> file to server.</li> <li>Run <code>python3 get-pip.py</code></li> <li>R...
0
2016-09-21T17:22:42Z
[ "python", "linux", "bs4" ]
How to break numpy array into smaller chunks/batches, then iterate through them
39,622,639
<p>Suppose i have this numpy array</p> <pre><code>[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] </code></pre> <p>And i want to split it in 2 batches and then iterate:</p> <pre><code>[[1, 2, 3], Batch 1 [4, 5, 6]] [[7, 8, 9], Batch 2 [10, 11, 12]] </code></pre> <p>What is the simplest way to do it?</p> ...
2
2016-09-21T17:10:32Z
39,622,748
<p>do like this:</p> <pre><code>a = [[1, 2, 3],[4, 5, 6], [7, 8, 9],[10, 11, 12]] b = a[0:2] c = a[2:4] </code></pre>
0
2016-09-21T17:15:59Z
[ "python", "pandas", "numpy" ]
How to break numpy array into smaller chunks/batches, then iterate through them
39,622,639
<p>Suppose i have this numpy array</p> <pre><code>[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] </code></pre> <p>And i want to split it in 2 batches and then iterate:</p> <pre><code>[[1, 2, 3], Batch 1 [4, 5, 6]] [[7, 8, 9], Batch 2 [10, 11, 12]] </code></pre> <p>What is the simplest way to do it?</p> ...
2
2016-09-21T17:10:32Z
39,622,821
<p>consider array <code>a</code></p> <pre><code>a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) </code></pre> <p><strong><em>Option 1</em></strong><br> use <code>reshape</code> and <code>//</code></p> <pre><code>a.reshape(a.shape[0] // 2, -1, a.shape[1]) array...
3
2016-09-21T17:19:43Z
[ "python", "pandas", "numpy" ]
How to break numpy array into smaller chunks/batches, then iterate through them
39,622,639
<p>Suppose i have this numpy array</p> <pre><code>[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] </code></pre> <p>And i want to split it in 2 batches and then iterate:</p> <pre><code>[[1, 2, 3], Batch 1 [4, 5, 6]] [[7, 8, 9], Batch 2 [10, 11, 12]] </code></pre> <p>What is the simplest way to do it?</p> ...
2
2016-09-21T17:10:32Z
39,623,292
<p>You can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.split.html" rel="nofollow"><code>numpy.split</code></a> to split along the first axis <code>n</code> times, where <code>n</code> is the number of desired batches. Thus, the implementation would look like this -</p> <pre><code>np.split(ar...
3
2016-09-21T17:46:35Z
[ "python", "pandas", "numpy" ]
AES / RSA implementation from Python to C#
39,622,646
<p>I want to migrate following python code into c#. The entry point is the method encrypted_request</p> <p>I have no real clue about aes/rsa in python or in c#. Maybe someone could explain the different code sections and if possible give me a hint how to implement that in c#. Especially the magic numbers used here an...
0
2016-09-21T17:11:01Z
39,640,476
<p>Here are a couple of things I see right off the bat, but the question is a bit too open-ended:</p> <ul> <li>In <code>aesEncryptBase64</code> you are manually applying padding. The AES implementation in .NET does that for you. If you prefer to do it yourself you need to set <code>aes.Padding = PaddingMode.None</cod...
0
2016-09-22T13:30:50Z
[ "c#", "python", "encryption", "aes", "rsa" ]
How to make spawnSync and fs.readFile to execute one after other?
39,622,647
<p>I have a python script which returns a <code>JSON</code> file as output by taking a FILE as input.</p> <p>I have 10 files, I am using <strong>spawnSync</strong> inside <strong>for loop</strong> and inside loop I have <strong>fs.readFile</strong> for reading JSON file which is coming from the python script. </p> <p...
0
2016-09-21T17:11:02Z
39,623,150
<p>If you are rely to use third party module then I recommend to use <a href="http://caolan.github.io/async/docs.html#.eachSeries" rel="nofollow">async.eachSeries</a> the method of the <a href="https://github.com/caolan/async" rel="nofollow">async</a> module to resolve this issue</p> <pre><code>var filename = ['first....
1
2016-09-21T17:39:21Z
[ "javascript", "python", "json", "node.js", "express" ]
String variable just refuses to be turned into an integer
39,622,738
<p>I am writing a python GUI application which takes an entry from the user, converts it into an integer, and then uses that integer with the datetime module. However I have run into a problem which hopefully you can help with.</p> <p>I am using Tkinter to construct a GUI with 3 elements, an entry box, a "GO!" button,...
1
2016-09-21T17:15:41Z
39,622,794
<p>The conversion happens, but nobody was listening. You have to rebind the name to the return value:</p> <pre><code>numberdate = int(numberdate) </code></pre>
5
2016-09-21T17:18:28Z
[ "python", "python-3.x", "tkinter" ]
Flush to zero and/or significant digits in python floats
39,622,871
<p>I'm trying to conduct an ICA application using audio files (.wavs). When using scipy wavfile, I have noticed from using cprofile, that my load_wav function performs very poorly. It takes 30 minutes to process a 44100 stereo .wav file at a CPU speed of 4.5 Ghz. Bear in mind, the .wav file is only 10 seconds in durati...
0
2016-09-21T17:22:35Z
39,625,702
<p>As AndyG already commented, <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.resample.html#scipy.signal.resample" rel="nofollow">the documentation for <code>scipy.signal.resample</code></a> warns you that</p> <blockquote> <p>... resample uses FFT transformations, which can be very slow if...
1
2016-09-21T20:09:16Z
[ "python", "c++", "audio", "scipy", "signal-processing" ]
Simple if/elif statement + raw_input why dosen't work
39,622,882
<p>I have a problem with simple if statement. I want user to press a key '1','2' or '3' to choose any option then program will do something. For a test it just prints text for example "Wybrano 2" after pressing '2'.</p> <p>Here is my code:</p> <pre><code>if raw_input() == '1': print "Wybrano 1" elif raw_inp...
0
2016-09-21T17:23:02Z
39,623,647
<p><strong>When i press 2 or 3 program does not nothing</strong> is wrong. It is waiting for you for next input.</p> <p>Let me tell you how this is working.</p> <ul> <li><code>raw_input</code> is python function for accepting user input.(I know you are aware of this :) )</li> <li>When you execute code, first it will ...
3
2016-09-21T18:07:42Z
[ "python", "python-2.7" ]
Pandas groupby over list
39,622,884
<p>I have a pandas data frame in the following format:</p> <pre><code>Arrival Departure Park Station Count 8 10 5 [1,2] 1 5 12 6 [3,4] 1 8 10 5 [1,2] 1 </code></pre> <p>I want to groupby this data frame by arrival, departure, park and station but sinc...
1
2016-09-21T17:23:14Z
39,623,134
<p>The problem is that a <a href="http://stackoverflow.com/questions/19371358/python-typeerror-unhashable-type-list">Python <code>list</code> is a mutable type, and hence unhashable</a>. In the place you'd put in the <code>groupby</code> criterion <code>df.Station</code>, put instead <code>df.Station.apply(tuple)</code...
3
2016-09-21T17:38:28Z
[ "python", "list", "pandas", "dataframe" ]
Pandas groupby over list
39,622,884
<p>I have a pandas data frame in the following format:</p> <pre><code>Arrival Departure Park Station Count 8 10 5 [1,2] 1 5 12 6 [3,4] 1 8 10 5 [1,2] 1 </code></pre> <p>I want to groupby this data frame by arrival, departure, park and station but sinc...
1
2016-09-21T17:23:14Z
39,623,209
<pre><code>import pandas as pd df = pd.DataFrame({'arrival':[8,5,8], 'departure':[10,12,10], \ 'park':[5,6,5], 'station':[[1,2], [3,4], [1,2]]}) df['arrival_station'] = df.station.apply(lambda x: x[0]) df['departure_station'] = df.station.apply(lambda x: x[1]) print df arrival departure park station arrival_sta...
1
2016-09-21T17:42:11Z
[ "python", "list", "pandas", "dataframe" ]
Django - problems with URLS mapping and dispatcher
39,622,971
<p>I'm learning Django and I would like to build an application with the calendar and tasks, where every task has a separate link via <code>get_absolute_url</code>. I've created a list of activities and url link to each of them, but when I pick one of them there is no reaction, not even an error message. </p> <p>Pleas...
1
2016-09-21T17:28:01Z
39,624,465
<p>You need to terminate your activity_list URL:</p> <pre><code>url(r'^$', views.activity_list, name='activity_list'), </code></pre> <p>Otherwise this will simply match all paths, including those that are supposed to point to your activities.</p>
0
2016-09-21T18:57:28Z
[ "python", "django", "url" ]
How to plot (or update) a matplot figure and continue python code immediately (don't wait for the plot)?
39,622,994
<p>I am trying to write python code that continuously gets data from machine and plots these data in a figure window. I am using matplotlib with interactive plotting enabled / ion().</p> <p>There is quite a bit of data, so plotting may take a while. Since the python code does not continue until the plot is updated, da...
0
2016-09-21T17:29:54Z
39,623,353
<p>You can use threading which will make it to run independently, see <a href="https://docs.python.org/3/library/threading.html" rel="nofollow">https://docs.python.org/3/library/threading.html</a> for more details</p>
0
2016-09-21T17:50:06Z
[ "python", "asynchronous", "matplotlib", "background", "blocking" ]
How can I read 10-bit Raw image? which contain RGB-IR data
39,623,001
<p>I want to know how extract the rgb image from my 10-bit raw (it has rgb-ir imagedata) data?</p> <p>How can I read in Python or MATLAB?</p> <p>The camera resolution at the time of capture were 1280x720: indoor photo <a href="https://drive.google.com/file/d/0B0givAGTBMIweWMzbWFzd0xSQ2M/view?usp=sharing" rel="nofollo...
0
2016-09-21T17:30:17Z
39,627,104
<p>I used the following image processing stages: </p> <ul> <li>Bayer mosaic color channel separation.</li> <li>Linear stretching each color channel.</li> <li>Simple white balance.</li> <li>Replace IR color channel with green (convert image to standard Bayer format).</li> <li>Restore Bayer mosaic.</li> <li>Simple gamm...
5
2016-09-21T21:48:38Z
[ "python", "matlab", "numpy", "image-processing" ]
Skipping falsifying examples in Hypothesis
39,623,023
<p><strong>The Story:</strong></p> <p>I'm currently in the process of unit-testing a function using <a href="http://hypothesis.readthedocs.io/en/latest/" rel="nofollow"><code>hypothesis</code></a> and a <a href="http://stackoverflow.com/q/39561310/771848">custom generation strategy</a> trying to find a specific input ...
1
2016-09-21T17:31:51Z
39,623,466
<p>There's at present no way to get Hypothesis to keep trying after it finds a failure (it might happen at some point, but it's not really clear what the right behaviour for this should be and it hasn't been a priority), but you can get it to ignore specific classes of failure using the <a href="https://hypothesis.read...
1
2016-09-21T17:56:50Z
[ "python", "unit-testing", "testing", "property-based-testing", "python-hypothesis" ]
Error Embedding Pyqtgraph into PyQt4 GraphicsView
39,623,076
<p>I am attempting to embed a pyqtgraph into a PyQt4 GraphicsView widget. I am getting an error with the following code:. What am I doing wrong?</p> <pre><code>#imports from PyQt4 import QtGui from PyQt4 import QtCore import ui_test #Gui File import sys import pyqtgraph as pg class Gui(QtGui.QMainWindow, ui_test.Ui...
0
2016-09-21T17:35:41Z
40,061,003
<p>The two things that need to be fixed with this code: (1) Remove pg from base class list, you don't inherit from the whole pyqtgraph library:</p> <pre><code>class Gui(QtGui.QMainWindow, ui_test.Ui_MainWindow, pg): </code></pre> <p>to</p> <pre><code>class Gui(QtGui.QMainWindow, ui_test.Ui_MainWindow): </code></pre>...
1
2016-10-15T15:40:31Z
[ "python", "pyqt4", "qgraphicsview", "pyqtgraph" ]
Copying a file to multiple paths at the same time
39,623,222
<p>I am transferring a 150-200mb file to many locations (shared drives located across the world) daily. The issue is that each transfer (using shutil) takes probably 100-700 seconds and each one has to complete in order for the next one to begin. It now takes like a full hour to transfer some files if I do it that way....
0
2016-09-21T17:43:04Z
39,624,270
<p>Here's a working example that does what you want. Note that it may not be any faster than one-at-a-time if the bottleneck is network bandwidth.</p> <pre><code>from concurrent.futures import ThreadPoolExecutor import os import shutil import time from threading import Lock src_dir = './test_src' src_files = 'src1.tx...
1
2016-09-21T18:43:44Z
[ "python", "python-3.x", "shutil" ]
SECRET_KEY errors with enviroment variables
39,623,443
<p>I am working through <a href="http://www.marinamele.com/taskbuster-django-tutorial/create-home-page-with-tdd-staticfiles-templates-settings" rel="nofollow">the TaskBuster Django</a> tutorial whose goal is to help in the process of setting up a good development setup for a project.</p> <p>When I run the command echo...
1
2016-09-21T17:55:27Z
39,623,714
<p>You don't have an environment variable named SECRET_KEY. You need to set it before you run your program. </p> <p>On Unix</p> <pre><code>export SECRET_KEY="password" </code></pre> <p>On Windows </p> <pre><code>set SECRET_KEY="password" </code></pre> <p>It's worth noting that the variable will disappear when you...
1
2016-09-21T18:12:25Z
[ "python", "django", "testing", "virtualenv" ]
What is IF-MIB: snimpy.mib.SMIException: unable to find b'IF-MIB' (check the path)?
39,623,454
<p>I followed <a href="https://snimpy.readthedocs.io/en/latest/usage.html#regular-python-module" rel="nofollow">the doc</a> but got the following error:</p> <pre><code>&gt;&gt;&gt; from snimpy.manager import Manager as M from snimpy.manager import load load("IF-MIB") m = M("localhost") print(m.ifDescr[0]) Traceback (...
0
2016-09-21T17:55:57Z
39,624,108
<p>As provided by <a href="https://github.com/vincentbernat/snimpy/issues/57#issuecomment-248692852" rel="nofollow">snimpy developer</a>:</p> <blockquote> <p>If you are on Ubuntu, you need to </p> <pre><code>apt-get install snmp-mibs-downloader </code></pre> </blockquote>
0
2016-09-21T18:34:29Z
[ "python", "snmp", "mib", "snimpy" ]
Using local Python modules from python -c '...'
39,623,499
<p>I'm having trouble getting the Python 3.5 CLI to run commands with the <code>-c</code> switch.</p> <p>If I try <code>python3 -c "print(5 + 9)"</code> in the shell, the output is <code>14</code> as expected.</p> <p>However, I have a file in the current working directory called <code>gcd.py</code> that looks like th...
0
2016-09-21T17:58:47Z
39,623,531
<p>You can't use <code>-m</code> and <code>-c</code> together; either one or the other controls execution. Specifying them both makes Python ignore them.</p> <p>Use an <code>import</code> statement in <code>-c</code> instead:</p> <pre><code>python3 -c "from gcd import gcd; print(gcd(48, 18))" </code></pre> <p>Note t...
4
2016-09-21T18:00:54Z
[ "python", "shell" ]
How do I find a value relative to where a list occurs within my list in Python?
39,623,506
<p>I have a list of numbers:</p> <pre><code>Data = [0,2,0,1,2,1,0,2,0,2,0,1,2,0,2,1,1,...] </code></pre> <p>And I have a list of tuples of two, which is all possible combinations of the individual numbers above:</p> <pre><code>Combinations = [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)] </code></pre> <p>I...
2
2016-09-21T17:59:24Z
39,623,756
<pre><code>sum([all(x) for x in (Data[i:i+len(CurrentTuple)] == CurrentTuple for i in xrange (len(Data)-len(CurrentTuple)+1))]) </code></pre> <p>What you did return a generator that produce the following list:</p> <pre><code>[array([False, True], dtype=bool), array([ True, False], dtype=bool), array([False, True]...
0
2016-09-21T18:14:47Z
[ "python", "list", "tuples", "markov-chains" ]
How do I find a value relative to where a list occurs within my list in Python?
39,623,506
<p>I have a list of numbers:</p> <pre><code>Data = [0,2,0,1,2,1,0,2,0,2,0,1,2,0,2,1,1,...] </code></pre> <p>And I have a list of tuples of two, which is all possible combinations of the individual numbers above:</p> <pre><code>Combinations = [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)] </code></pre> <p>I...
2
2016-09-21T17:59:24Z
39,623,911
<p>You can use a dict to group the data to see where/if any comb lands in the original list zipping up pairs:</p> <pre><code>it1, it2 = iter(Data), iter(Data) next(it2) Combinations = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)] d = {c: [] for c in Combinations} ind = 2 for i, j in zip(it...
0
2016-09-21T18:24:44Z
[ "python", "list", "tuples", "markov-chains" ]
need help pivoting pandas table
39,623,521
<pre><code>print df output_time position 0 2016-01-01 08:00:01 start 1 2016-01-01 08:07:53 end 2 2016-01-01 08:07:54 start 3 2016-01-01 08:09:23 end 4 2016-01-01 08:09:24 start 5 2016-01-01 08:32:51 end </code></pre> <p>I need the output as such (wit...
0
2016-09-21T18:00:27Z
39,623,713
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pivot.html" rel="nofollow"><code>pivot</code></a> instead of <code>pivot_table</code>:</p> <pre><code># Perform the pivot. df = df.pivot(index=df.index//2, columns='position') # Format the columns. df.columns = df.columns.droplevel...
2
2016-09-21T18:12:25Z
[ "python", "pandas", "numpy" ]
need help pivoting pandas table
39,623,521
<pre><code>print df output_time position 0 2016-01-01 08:00:01 start 1 2016-01-01 08:07:53 end 2 2016-01-01 08:07:54 start 3 2016-01-01 08:09:23 end 4 2016-01-01 08:09:24 start 5 2016-01-01 08:32:51 end </code></pre> <p>I need the output as such (wit...
0
2016-09-21T18:00:27Z
39,623,755
<p>Another solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.cumcount.html" rel="nofollow"><code>cumcount</code></a> for creating new <code>index</code> values with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.unstack.html" rel="nofo...
0
2016-09-21T18:14:43Z
[ "python", "pandas", "numpy" ]
need help pivoting pandas table
39,623,521
<pre><code>print df output_time position 0 2016-01-01 08:00:01 start 1 2016-01-01 08:07:53 end 2 2016-01-01 08:07:54 start 3 2016-01-01 08:09:23 end 4 2016-01-01 08:09:24 start 5 2016-01-01 08:32:51 end </code></pre> <p>I need the output as such (wit...
0
2016-09-21T18:00:27Z
39,624,264
<p>This seems to be really quick though <code>pivot_table</code> was actually asked:</p> <pre><code>data = df.T.unstack().ravel() pd.DataFrame(data={data[1]:data[0::4], data[3]:data[2::4]}) </code></pre> <p><a href="http://i.stack.imgur.com/yD8xc.png" rel="nofollow"><img src="http://i.stack.imgur.com/yD8xc.png" alt="...
0
2016-09-21T18:43:30Z
[ "python", "pandas", "numpy" ]
Solving an ordinary differential equation on a fixed grid (preferably in python)
39,623,613
<p>I have a differential equation of the form </p> <p><code>dy(x)/dx = f(y,x)</code></p> <p>that I would like to solve for <code>y</code>. </p> <p>I have an array <code>xs</code> containing all of the values of <code>x</code> for which I need <code>ys</code>. </p> <p>For only those values of <code>x</code>, I can e...
2
2016-09-21T18:05:32Z
39,623,781
<p>Assuming you can use something simple like Forward Euler...</p> <p>Numerical solutions will rely on approximate solutions at previous times. So if you want a solution at <code>t = 1</code> it is likely you will need the approximate solution at <code>t&lt;1</code>.</p> <p>My advice is to figure out what step size ...
0
2016-09-21T18:16:10Z
[ "python", "math", "mathematical-optimization", "numerical-methods", "differential-equations" ]
Solving an ordinary differential equation on a fixed grid (preferably in python)
39,623,613
<p>I have a differential equation of the form </p> <p><code>dy(x)/dx = f(y,x)</code></p> <p>that I would like to solve for <code>y</code>. </p> <p>I have an array <code>xs</code> containing all of the values of <code>x</code> for which I need <code>ys</code>. </p> <p>For only those values of <code>x</code>, I can e...
2
2016-09-21T18:05:32Z
39,624,481
<p>I think you should first solve ODE on a regular grid, and then interpolate solution on your fixed grid. The approximate code for your problem</p> <pre><code>import numpy as np from scipy.integrate import odeint from scipy import interpolate xs = np.array([0.15, 0.383, 0.99, 1.0001]) # dy/dx = f(x,y) def dy_dx(y, ...
0
2016-09-21T18:58:23Z
[ "python", "math", "mathematical-optimization", "numerical-methods", "differential-equations" ]
Prevent PyPI from publishing a new version until all wheels are uploaded?
39,623,682
<p>We have a Python package which we distribute via PyPI. We create wheels for Win x64, Win x86, and Mac.</p> <p>We use AppVeyor for the Windows builds and Travis for the Mac build.</p> <p>The problem we have is that all the wheels don't finish at the same time, but as soon as the first wheel is uploaded to PyPI, the...
1
2016-09-21T18:10:20Z
39,624,118
<p>What I just did was I downloaded all wheels manually from CI after they're all built (OK, using <a href="https://github.com/MacPython/terryfy" rel="nofollow">https://github.com/MacPython/terryfy</a>, but that is a detail) and then uploaded them all in one go manually. Not exacty <em>elegant</em>, I know. But that do...
1
2016-09-21T18:35:18Z
[ "python", "pypi" ]
How to export Bokeh view to Matplotlib?
39,623,694
<p><p> I have a Flask web app that uses Bokeh to deliver interactive charts. My end goal is to export whatever the current Bokeh view is to Matplotlib (so that I can create a printable pdf file after that). This would include how the current axes look like after the user zooms and pans. Is there a way to export that da...
0
2016-09-21T18:11:26Z
39,625,002
<p>No, currently there is no way to export bokeh to matplotlib. Actually you can do it otherway. You can create matplotlib plot, save, and after that you can <a href="http://bokeh.pydata.org/en/latest/docs/user_guide/compat.html#bokeh.mpl.to_bokeh" rel="nofollow">export matplotlib to bokeh</a>. I think this is the bes...
0
2016-09-21T19:26:16Z
[ "python", "matplotlib", "flask", "pdf-generation", "bokeh" ]
TensorFlow Multi-Layer Perceptron
39,623,747
<p>I am learning TensorFlow, and my goal is to implement MultiPerceptron for my needs. I checked the <a href="https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/multilayer_perceptron.py" rel="nofollow">MNIST tutorial with MultiPerceptron implementation</a> and everything was cle...
0
2016-09-21T18:14:22Z
39,623,857
<blockquote> <p>They feed whole bathces(which are packs of data points and labels)!</p> </blockquote> <p>Yes, this is how neural networks are usually trained (due to some nice mathematical properties of having best of two worlds - better gradient approximation than in SGD on one hand and much faster convergence than...
1
2016-09-21T18:20:57Z
[ "python", "machine-learning", "tensorflow" ]
How to authenticate in Jenkins while remotely accessing its JSON API?
39,623,786
<p>I need to access the Jenkins JSON API from a Python script. The problem is that our Jenkins installation is secured so to log in users have to select a certificate. Sadly, in Jenkins <a href="https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API" rel="nofollow">Remote Access Documentation</a> they don't ment...
1
2016-09-21T18:16:30Z
39,625,595
<p>I finally found out how to authenticate to Jenkins using certs and wget. I had to convert my pfx certificates into pem ones with cert and keys in separate files <a href="http://stackoverflow.com/questions/15144046/need-help-converting-p12-certificate-into-pem-using-openssl">For more info about that come here</a>. In...
0
2016-09-21T20:03:11Z
[ "python", "authentication", "jenkins" ]
How to authenticate in Jenkins while remotely accessing its JSON API?
39,623,786
<p>I need to access the Jenkins JSON API from a Python script. The problem is that our Jenkins installation is secured so to log in users have to select a certificate. Sadly, in Jenkins <a href="https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API" rel="nofollow">Remote Access Documentation</a> they don't ment...
1
2016-09-21T18:16:30Z
39,626,190
<p>You have to authenticate to the JSON API using HTTP Basic Auth. </p> <blockquote> <p>To make scripted clients (such as wget) invoke operations that require authorization (such as scheduling a build), use HTTP BASIC authentication to specify the user name and the API token. This is often more convenient than emula...
1
2016-09-21T20:39:34Z
[ "python", "authentication", "jenkins" ]
Search XML Tags for Name Attribute: Python elementTree module
39,623,852
<p>I'm trying to parse an XML doc in Python using the <code>ElementTree</code> module. I'm trying to look for <code>Elements</code> that have an xml tag of <code>entry</code> and a <code>name</code> attribute within that tag that equals a certain <code>ipAddress</code>. Below is my code so far:</p> <pre><code>tree = E...
0
2016-09-21T18:20:40Z
39,623,925
<pre><code>import xml.etree.ElementTree as ET tree = ET.parse(your_xml) root = tree.getroot() for child in root: if child.tag=='entry': for node in child: if node.attrib["name"]=='certain_ip': print("found") </code></pre>
0
2016-09-21T18:25:29Z
[ "python", "xml", "elementtree" ]
Search XML Tags for Name Attribute: Python elementTree module
39,623,852
<p>I'm trying to parse an XML doc in Python using the <code>ElementTree</code> module. I'm trying to look for <code>Elements</code> that have an xml tag of <code>entry</code> and a <code>name</code> attribute within that tag that equals a certain <code>ipAddress</code>. Below is my code so far:</p> <pre><code>tree = E...
0
2016-09-21T18:20:40Z
39,626,880
<pre><code>tree = ET.parse(fi2) root = tree.getroot() for child in root.iter('entry'): #looks through child elements for tag=entry #look for elements that have an attribute(name)='string' if ipAddress in child.get('name'): #condition is met. Execute some code. Do your thang </code></pre>
0
2016-09-21T21:30:14Z
[ "python", "xml", "elementtree" ]
Creating a Pandas DataFrame with HDFS file in .csv format
39,623,858
<p>Im trying to create a Spark workflow from fetching .csv data from a hadoop cluster and putting it into Pandas DataFrame. I'm able to pull the Data from HDFS and put it in an RDD, but unable to process it into the Pandas Dataframe. The following is my code:</p> <pre><code>import pandas as pd import numpy as nm A=s...
0
2016-09-21T18:21:00Z
39,625,656
<p>I would recommend to load the csv into a Spark DataFrame and convert it to a Pandas DataFrame.</p> <pre><code>csvDf = sqlContext.read.format("csv").option("header", "true").option("inferschema", "true").option("mode", "DROPMALFORMED").load("hdfs://localhost:9000/sales_ord_univ.csv") B = csvDf.toPandas() </code></p...
0
2016-09-21T20:06:32Z
[ "python", "csv", "hadoop", "pandas", "pyspark" ]
Adjusting matplotlib colormap to show simulation
39,623,883
<p>I'm building a little simulation based on this experiment: <a href="https://www.youtube.com/watch?v=plVk4NVIUh8" rel="nofollow">https://www.youtube.com/watch?v=plVk4NVIUh8</a> , which shows the evolution of a bacteria over time.</p> <p>I have initialized some bacteria with random resistance at the edge of a petri d...
0
2016-09-21T18:22:34Z
39,624,288
<p>You could get a <a href="http://matplotlib.org/users/colormaps.html" rel="nofollow">colormap</a> with a dark color for low values, such as 'magma' and define, as Andreas suggested a 'vmin' value. e.g.</p> <pre><code>import matplotlib.pyplot as plt from scipy import rand a = rand(10, 20) + 0.5 a[0, 0] = 0 cmap = pl...
1
2016-09-21T18:45:10Z
[ "python", "numpy", "matplotlib", "simulation" ]
Adjusting matplotlib colormap to show simulation
39,623,883
<p>I'm building a little simulation based on this experiment: <a href="https://www.youtube.com/watch?v=plVk4NVIUh8" rel="nofollow">https://www.youtube.com/watch?v=plVk4NVIUh8</a> , which shows the evolution of a bacteria over time.</p> <p>I have initialized some bacteria with random resistance at the edge of a petri d...
0
2016-09-21T18:22:34Z
39,677,557
<p>I was able to make the visulaization better, using logaritmic normalization: Let's say my bacteriaMap has really different resistancevalues:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl size=10 a = rand(size, size) * 0.2 b = rand(size, size) * 2 c = rand(size, size) * ...
0
2016-09-24T14:39:45Z
[ "python", "numpy", "matplotlib", "simulation" ]
Is there any way to print **kwargs in Python
39,623,889
<p>I am just curious about <code>**kwargs</code>. I am just started learning it, So while going through all the question on stackoverflow and video tutorials I notice we can do like this </p> <pre><code>def print_dict(**kwargs): print(kwargs) print_dict(x=1,y=2,z=3) </code></pre> <p>Which gives output as :<code...
2
2016-09-21T18:23:04Z
39,623,935
<p>You have to build your own formatting for dictionaries (nothing else are <code>**kwargs</code>):</p> <pre><code>print(','.join('{0}={1!r}'.format(k,v) for k,v in this.items())) </code></pre>
4
2016-09-21T18:26:07Z
[ "python" ]
Is there any way to print **kwargs in Python
39,623,889
<p>I am just curious about <code>**kwargs</code>. I am just started learning it, So while going through all the question on stackoverflow and video tutorials I notice we can do like this </p> <pre><code>def print_dict(**kwargs): print(kwargs) print_dict(x=1,y=2,z=3) </code></pre> <p>Which gives output as :<code...
2
2016-09-21T18:23:04Z
39,623,954
<p>The syntax <code>callable(**dictionary)</code> <em>applies</em> the dictionary as if you used separate keyword arguments.</p> <p>So your example:</p> <pre><code>mydict = {'x':1,'y':2,'z':3} print(**mydict) </code></pre> <p>Is internally translated to:</p> <pre><code>print(x=1, y=2, z=3) </code></pre> <p>where t...
7
2016-09-21T18:26:44Z
[ "python" ]
cycle "for" in Python
39,623,953
<p>I have to create a three new lists of items using two different lists.</p> <pre><code>list_one = ['one', 'two','three', 'four','five'] list_two = ['blue', 'green', 'white'] </code></pre> <p>So, <code>len(list_one) != len(list_two)</code></p> <p>Now I should create an algorithm(a cycle) which can do this: <code>[...
-2
2016-09-21T18:26:43Z
39,624,005
<p>I think you might be looking for <a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow">itertools.product</a>:</p> <pre><code>&gt;&gt;&gt; [b + a for a,b in itertools.product(list_two, list_one)] ['oneblue', 'twoblue', 'threeblue', 'fourblue', 'fiveblue', 'onegreen', 'twog...
2
2016-09-21T18:29:04Z
[ "python" ]
cycle "for" in Python
39,623,953
<p>I have to create a three new lists of items using two different lists.</p> <pre><code>list_one = ['one', 'two','three', 'four','five'] list_two = ['blue', 'green', 'white'] </code></pre> <p>So, <code>len(list_one) != len(list_two)</code></p> <p>Now I should create an algorithm(a cycle) which can do this: <code>[...
-2
2016-09-21T18:26:43Z
39,624,047
<ul> <li>return should be out of for loop.</li> <li>No need to initialize <code>i</code> and increment it, since you are using range.</li> <li>Also, since both list can be of variable length, don't use range. Iterate over the list elements directly.</li> <li><code>def mix():</code> should be like <code>def mix(l_one,l_...
0
2016-09-21T18:31:09Z
[ "python" ]
cycle "for" in Python
39,623,953
<p>I have to create a three new lists of items using two different lists.</p> <pre><code>list_one = ['one', 'two','three', 'four','five'] list_two = ['blue', 'green', 'white'] </code></pre> <p>So, <code>len(list_one) != len(list_two)</code></p> <p>Now I should create an algorithm(a cycle) which can do this: <code>[...
-2
2016-09-21T18:26:43Z
39,624,084
<p>You should do this</p> <pre><code>def cycle(list_one,list_two): newList = [] for el1 in list_two: for el2 in list_one: newList.append(el2+el1) return newList </code></pre>
0
2016-09-21T18:33:20Z
[ "python" ]
cycle "for" in Python
39,623,953
<p>I have to create a three new lists of items using two different lists.</p> <pre><code>list_one = ['one', 'two','three', 'four','five'] list_two = ['blue', 'green', 'white'] </code></pre> <p>So, <code>len(list_one) != len(list_two)</code></p> <p>Now I should create an algorithm(a cycle) which can do this: <code>[...
-2
2016-09-21T18:26:43Z
39,624,148
<p>There are a few problems with your code:</p> <ol> <li><p>When you do a for loop <code>for i in ...:</code>, you do not need to initialize <code>i</code> (<code>i = 0</code>) and you should not increment it (<code>i = i + 1</code>) since Python knows that <code>i</code> will take all values specified in the for loop...
0
2016-09-21T18:36:58Z
[ "python" ]
cycle "for" in Python
39,623,953
<p>I have to create a three new lists of items using two different lists.</p> <pre><code>list_one = ['one', 'two','three', 'four','five'] list_two = ['blue', 'green', 'white'] </code></pre> <p>So, <code>len(list_one) != len(list_two)</code></p> <p>Now I should create an algorithm(a cycle) which can do this: <code>[...
-2
2016-09-21T18:26:43Z
39,624,394
<p>Another way to achieve this using <code>map()</code>. Just mentioning as the option:</p> <pre><code>&gt;&gt;&gt; from itertools import product &gt;&gt;&gt; map(lambda x: ''.join(x), product(list_one, list_two)) ['oneblue', 'onegreen', 'onewhite', 'twoblue', 'twogreen', 'twowhite', 'threeblue', 'threegreen', 'threew...
0
2016-09-21T18:52:23Z
[ "python" ]
In pandas dataframe, generate third column data based on results in two other columns
39,623,977
<p>I'm a newbie to dataframes. I have columns <code>A</code>, <code>B</code> and <code>C</code> and want to use the data in A and B to create a value in C. For example, if <code>A = 1</code> and/or <code>B = 1</code>, then I want to place a <code>1</code> in column <code>C</code> and do this logic for all rows in the...
2
2016-09-21T18:27:45Z
39,624,056
<pre><code>def f(x): if (x.B==1) and (x.A !=1): #Or whatever logic you like return 1 else: return 0 df['C'] = df.apply(lambda x: f(x), axis = 1) </code></pre>
0
2016-09-21T18:31:34Z
[ "python", "pandas", "dataframe", "boolean", "condition" ]
In pandas dataframe, generate third column data based on results in two other columns
39,623,977
<p>I'm a newbie to dataframes. I have columns <code>A</code>, <code>B</code> and <code>C</code> and want to use the data in A and B to create a value in C. For example, if <code>A = 1</code> and/or <code>B = 1</code>, then I want to place a <code>1</code> in column <code>C</code> and do this logic for all rows in the...
2
2016-09-21T18:27:45Z
39,624,075
<p>Given a starting DF of:</p> <pre><code>df = pd.DataFrame({'A': [1, 0, 1, 0], 'B': [0, 1, 1, 0]}) </code></pre> <p>Then you can create column <code>C</code> as such:</p> <pre><code>df['C'] = (df == 1).any(axis=1).astype(int) </code></pre> <p>Then leaves <code>df</code> as:</p> <pre><code> A B C 0 1 0 1 1 ...
2
2016-09-21T18:32:44Z
[ "python", "pandas", "dataframe", "boolean", "condition" ]
In pandas dataframe, generate third column data based on results in two other columns
39,623,977
<p>I'm a newbie to dataframes. I have columns <code>A</code>, <code>B</code> and <code>C</code> and want to use the data in A and B to create a value in C. For example, if <code>A = 1</code> and/or <code>B = 1</code>, then I want to place a <code>1</code> in column <code>C</code> and do this logic for all rows in the...
2
2016-09-21T18:27:45Z
39,624,091
<p>Use <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.where.html" rel="nofollow"><code>numpy.where</code></a>:</p> <pre><code>df['C'] = np.where(df.A | df.B, 1, 0) print (df) A B C 0 0 0 0 1 0 1 1 2 1 0 1 3 1 1 1 df['C'] = np.where((df.A == 0) &amp; (df.B == 0), 0, 1) print...
2
2016-09-21T18:33:36Z
[ "python", "pandas", "dataframe", "boolean", "condition" ]
In pandas dataframe, generate third column data based on results in two other columns
39,623,977
<p>I'm a newbie to dataframes. I have columns <code>A</code>, <code>B</code> and <code>C</code> and want to use the data in A and B to create a value in C. For example, if <code>A = 1</code> and/or <code>B = 1</code>, then I want to place a <code>1</code> in column <code>C</code> and do this logic for all rows in the...
2
2016-09-21T18:27:45Z
39,624,158
<p>You can use the logical functions of numpy <code>logical_and</code> and <code>logical_or</code></p> <pre><code>import numpy as np df['C'] = np.logical_and(df['A'], df['B']).astype(int) </code></pre>
0
2016-09-21T18:37:34Z
[ "python", "pandas", "dataframe", "boolean", "condition" ]
In pandas dataframe, generate third column data based on results in two other columns
39,623,977
<p>I'm a newbie to dataframes. I have columns <code>A</code>, <code>B</code> and <code>C</code> and want to use the data in A and B to create a value in C. For example, if <code>A = 1</code> and/or <code>B = 1</code>, then I want to place a <code>1</code> in column <code>C</code> and do this logic for all rows in the...
2
2016-09-21T18:27:45Z
39,624,164
<p>Other solution using a <code>list comprehesion</code> and <code>zip</code></p> <pre><code>df['C'] = [(1 if i or j == 1 else 0) for i,j in zip(df['A'], df['B'])] </code></pre> <p>it returns:</p> <pre><code> A B C 0 1 0 1 1 0 1 1 2 1 1 1 3 0 0 0 </code></pre> <p>Change the condition if <code>'A'</c...
0
2016-09-21T18:37:50Z
[ "python", "pandas", "dataframe", "boolean", "condition" ]
WEIRD Django AuthenticationForm Behaviour
39,623,998
<p>I have, all day, tried to figure this out but I can't really see where the problem is coming from.</p> <p>I have a <strong>Django</strong> <code>AuthenticationForm</code> that seems to be submitting data somehow but not getting validated.</p> <p><strong>forms.py</strong>:</p> <pre><code>class LoginForm(Authentica...
1
2016-09-21T18:28:59Z
39,624,185
<p>Try making the following change:</p> <pre><code>reg = LoginForm(data=request.POST) </code></pre> <p><code>AuthenticationForm</code> is slightly different in that it needs the <code>data</code> argument.</p> <p>Also note that you should test it with actually valid username and password combinations (that correspon...
1
2016-09-21T18:39:18Z
[ "python", "django", "python-2.7", "django-forms" ]
Is it possible to cast dtype of scipy CSR matrix to NPY_FLOAT?
39,624,043
<p>I have a scipy CSR matrix that was constructed from a COO matrix as follows:</p> <pre><code>coord_mat = coo_matrix((data, (row, col)), dtype=np.float64) </code></pre> <p>It is being used as an input to a library with an underlying C implementation, and I believe that the dtype of my matrix is <code>double(np.float...
0
2016-09-21T18:30:56Z
39,625,960
<p>I'm not sure about the <code>C</code> interface, I'll try to explain the <code>coo_matrix</code> part.</p> <p>Since you are using the tuple input it splits that into 3 variables</p> <pre><code>obj, (row, col) = arg1 </code></pre> <p>then it assigns those to attributes</p> <pre><code>self.row = np.array(row, copy...
0
2016-09-21T20:24:27Z
[ "python", "numpy", "scipy", "python-c-api" ]
Extract data from &quote under title tag using BeautifulSoup?
39,624,126
<p>I want to extract title of a link after getting its HTML via <code>BeautifulSoup</code> library in python. Basically, the whole title tag is </p> <pre><code> &lt;title&gt;Imaan Z Hazir on Twitter: &amp;quot;Guantanamo and Abu Ghraib, financial and military support to dictators in Latin America during the cold war. ...
1
2016-09-21T18:36:01Z
39,624,609
<p>Once you have parsed the html:</p> <pre><code>data = BeautifulSoup(h,"html.parser") </code></pre> <p>Find the title this way:</p> <pre><code>title = data.find("title").string # this is without &lt;title&gt; tag </code></pre> <p>Now find two quotes (<code>"</code>) in the string. There are many ways to do that. ...
0
2016-09-21T19:05:06Z
[ "python", "css-selectors", "beautifulsoup", "html-parser" ]
Extract data from &quote under title tag using BeautifulSoup?
39,624,126
<p>I want to extract title of a link after getting its HTML via <code>BeautifulSoup</code> library in python. Basically, the whole title tag is </p> <pre><code> &lt;title&gt;Imaan Z Hazir on Twitter: &amp;quot;Guantanamo and Abu Ghraib, financial and military support to dictators in Latin America during the cold war. ...
1
2016-09-21T18:36:01Z
39,626,388
<p>Here is a simple complete example using regex to extract the text within quotes:</p> <pre><code>import urllib import re from bs4 import BeautifulSoup link = "https://twitter.com/ImaanZHazir/status/778560899061780481" r = urllib.request.urlopen(link) soup = BeautifulSoup(r, "html.parser") title = soup.title.string...
0
2016-09-21T20:52:21Z
[ "python", "css-selectors", "beautifulsoup", "html-parser" ]
Extract data from &quote under title tag using BeautifulSoup?
39,624,126
<p>I want to extract title of a link after getting its HTML via <code>BeautifulSoup</code> library in python. Basically, the whole title tag is </p> <pre><code> &lt;title&gt;Imaan Z Hazir on Twitter: &amp;quot;Guantanamo and Abu Ghraib, financial and military support to dictators in Latin America during the cold war. ...
1
2016-09-21T18:36:01Z
39,627,577
<p>Just split the text on the colon:</p> <pre><code>In [1]: h = """&lt;title&gt;Imaan Z Hazir on Twitter: &amp;quot;Guantanamo and Abu Ghraib, financial and military support to dictators in Latin America during the cold war. REALLY, AMERICA? (3)&amp;quot;&lt;/title&gt;""" In [2]: from bs4 import BeautifulSoup In [3...
0
2016-09-21T22:37:16Z
[ "python", "css-selectors", "beautifulsoup", "html-parser" ]
Clojure equivalent of python int.from_bytes(byteorder='big')
39,624,132
<p>The Python built in method <code>int.from_bytes()</code> returns the integer represented by the given array of bytes. I wanted know the Clojure equivalent of such method or similar methods in Clojure.</p>
0
2016-09-21T18:36:16Z
39,624,791
<p>You could use java's <a href="https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#BigInteger(byte[])" rel="nofollow">java's BigInteger</a> directly:</p> <pre><code>(BigInteger. (byte-array [1 2 3])) =&gt; 66051 </code></pre> <p>Since clojure natively supports big numbers, you could use it seamless...
2
2016-09-21T19:14:29Z
[ "python", "clojure" ]
Python Unit Test subtle bug
39,624,159
<p>I'm new to Python and I've read the unit test documentation for python and I'm doing something different from the examples provided. I'm comparing sets. I don't know why my code keeps getting a failure. It seems like the code is written correctly. Can someone take a gander and see if they can resolve the problem? I ...
1
2016-09-21T18:37:35Z
39,624,213
<p>You're simply missing a parentheses at the end of </p> <pre><code>self.assertSetEqual(results['intersection'], set(["a"]) </code></pre> <p>This confuses the interpreter. Change it to</p> <pre><code>self.assertSetEqual(results['intersection'], set(["a"])) </code></pre> <p>In general, you might try to find an edit...
2
2016-09-21T18:40:44Z
[ "python", "unit-testing" ]
Linked List Type Error
39,624,170
<p>I am a beginner and I started learning python programming and I am stuck with an error. I get a type error</p> <pre><code>class Node: def __init__(self): self.data = None self.next = Node def setData(self,data) self.data = data def getData(self): return self.data ...
0
2016-09-21T18:38:20Z
39,624,269
<p>Looks like you've got a typo right here:</p> <pre><code>class Node: def __init__(self): self.data = None self.next = Node </code></pre> <p>That should be <code>self.next = None</code>.</p> <p>The reason you're getting <code>getNext() missing 1 required positional argument</code> is because ev...
0
2016-09-21T18:43:43Z
[ "python", "linked-list", "typeerror" ]
Linked List Type Error
39,624,170
<p>I am a beginner and I started learning python programming and I am stuck with an error. I get a type error</p> <pre><code>class Node: def __init__(self): self.data = None self.next = Node def setData(self,data) self.data = data def getData(self): return self.data ...
0
2016-09-21T18:38:20Z
39,624,291
<p><code>while currentNode.hasNext</code> is always true, because it is a method.</p> <p>On the other hand, <code>while currentNode.hasNext()</code> might be false at some point.</p> <hr> <p><code>self.next = Node</code> means the class is next.</p> <p>On the other hand, <code>self.next = Node()</code> would make a...
0
2016-09-21T18:45:32Z
[ "python", "linked-list", "typeerror" ]
Linked List Type Error
39,624,170
<p>I am a beginner and I started learning python programming and I am stuck with an error. I get a type error</p> <pre><code>class Node: def __init__(self): self.data = None self.next = Node def setData(self,data) self.data = data def getData(self): return self.data ...
0
2016-09-21T18:38:20Z
39,624,553
<p>You have made mistakes in your code:</p> <p>In <code>Node</code> class:</p> <pre><code>self.next = Node </code></pre> <p>Why do you make this statement? Assign class itself to next is unreasonable. it should be:</p> <pre><code>self.next = None </code></pre> <p>Another thing, I would like to suggest is you'd bet...
0
2016-09-21T19:02:15Z
[ "python", "linked-list", "typeerror" ]
How to kill celery worker process for process restart
39,624,223
<p>I have a celery worker process that creates one socket to an external server in <code>celery.signals.worker_process_init</code>. If the connection can't be established and an exception is raised the celery worker fails to start, which is the intended behaviour.</p> <p>That socket class also sends occasional heartbe...
3
2016-09-21T18:41:20Z
39,688,990
<p>I had similar problem. I ended up creating a separate script to manage workers. </p> <p>Create an infinite while loop, sleep for required time and then create/kill worker process.</p> <pre><code>while True: time.sleep(5) # create workers if possible # kill stale workers if not required. </code></pre>
0
2016-09-25T16:08:30Z
[ "python", "multithreading", "sockets", "celery", "python-multiprocessing" ]
Authentication Popup using Selenium Webdriver Python
39,624,225
<p>I'm able to send keys to handle the authentication popup of a site using Selenium and win32com.client. It is working fine when I run the code manually (running a Jupyter Notebook).</p> <p>The error occurs when I convert .ipynb to .py and schedule it to run automatically using Windows Task Scheduler. It get stuck in...
0
2016-09-21T18:41:25Z
39,667,751
<p>Works well with .ipynb and py while in active desktop session updates: added codes to minimize the Console Window Class</p> <pre><code>app = Application().Connect(title ='path' + 'python.exe', class_name = 'ConsoleWindowClass') cwc = app.ConsoleWindowClass cwc.Minimize() app = Application().Connect(title ='page',...
0
2016-09-23T18:55:43Z
[ "python", "selenium-webdriver", "scheduled-tasks", "win32com", "pywinauto" ]
Python: Json Data into Class Instance varaibles
39,624,240
<p>I am trying to create a class called Movie. I have declared the instance variables. I am calling the OMDB API and I would like to store assign the variables to that. But that doesn't seem to be working. Even when I print json_Data, it doesn't print anything. Can anyone point me in the right direction. I know I can s...
0
2016-09-21T18:42:04Z
39,624,320
<pre><code>class Movie(object): """ Class provides a structure to store Movie information """ def __init__(self, imdb_id, title = None, release_year = None, rating = None, run_time = None, genre = None, director = None, actors = None, plot = None, awards = None, poster_image = None, imdb_votes = None, youtube_traile...
1
2016-09-21T18:47:15Z
[ "python", "python-2.7" ]
Loop over Colums in Pandas Dataframe to create multiple plots with one x variable and mulitple y (colum values)
39,624,252
<p>I have a single pandas dataframe and want to plot colums 2 though n against colum 1. I would like to create a for loop to do this. I am using matplotlib.</p>
-2
2016-09-21T18:42:55Z
39,625,783
<p>The <a href="https://stanford.edu/~mwaskom/software/seaborn/index.html" rel="nofollow">Seaborn</a> visualization library is based on matplotlib and provides out of the box plot for statistical analysis. I think the <code>pairplot</code> function is what your are looking for. See the documentation <a href="https://st...
0
2016-09-21T20:13:41Z
[ "python", "pandas", "matplotlib" ]
Passing bash variable to python command within a shell script
39,624,434
<p>Needing to extract two variables per line from a JSON file and use each of these 2 variables in separate follow up commands.</p> <p>My script is so far:</p> <pre><code>#!/bin/bash VCTRL_OUT='/tmp/workingfile.json' old_IFS=$IFS # save the field separator IFS=$'\n' # new field separator, the end of line ...
0
2016-09-21T18:54:58Z
39,626,537
<p>Python wouldn't be my first choice for this kind of one-liner, but you might try</p> <pre><code>#!/bin/bash VCTRL_OUT='/tmp/workingfile.json' parse_json () { python -c $'import json,fileinput,operator\nfor line in fileinput.input(): print "%s %s"%operator.itemgetter("ip_range","description")(json.loads(line))...
3
2016-09-21T21:02:04Z
[ "python", "json", "bash" ]
How to do power curve fitting in Python?
39,624,462
<p>There is a question about exponential curve fitting, but I didn't find any materials on how to create a power curve fitting, like this:</p> <pre><code>y = a*x^b </code></pre> <p>There is a way to do this in Excel, but is it possible in Python?</p>
0
2016-09-21T18:57:17Z
39,624,517
<p>If you do an easy transformation you can apply the usual least squares regression.</p> <p>Instead of this equation: </p> <pre><code>y = a*x^b </code></pre> <p>Take the natural log of both sides:</p> <pre><code>ln(y) = ln(a*x^b) = ln(a) + ln(x^b) = ln(a) + b*ln(x) </code></pre> <p>This is a linear equation in <c...
1
2016-09-21T19:00:15Z
[ "python", "scikit-learn", "regression" ]
How to do power curve fitting in Python?
39,624,462
<p>There is a question about exponential curve fitting, but I didn't find any materials on how to create a power curve fitting, like this:</p> <pre><code>y = a*x^b </code></pre> <p>There is a way to do this in Excel, but is it possible in Python?</p>
0
2016-09-21T18:57:17Z
39,624,545
<p>Just take logarithms:</p> <pre><code>y = ax^b log(y) = log(a) + b*log(x) </code></pre> <p>and use a linear fit for the pair <code>log(x)</code> and <code>log(y)</code>. It will result on a line with slope <code>b</code> and intercept <code>log(a)</code>, just take exponential to obtain the parameter <code>a</code>...
1
2016-09-21T19:01:50Z
[ "python", "scikit-learn", "regression" ]
Python Selenium webdriver working with iframes
39,624,736
<p>Good day. Im trying to learn how to use the Selenium IDE on firefox together with Python by exporting whatever test i did to Python 2.7.</p> <p>During my test i ran into a few problems, one of them is that it isn't recognizing 2 text fields, which are inside iframes. Ive found some other answers right here on stack...
0
2016-09-21T19:11:34Z
39,630,177
<p>If you want to switch to iframe</p> <pre><code>driver.switch_to_frame(driver.find_element_by_xpath("//iframe[@id='tinymce ']")) </code></pre> <p>If you want to switch to window -1 seems default active window</p> <pre><code>driver.switch_to_window(driver.window_handles[-1]) </code></pre> <p>Don't forgot to switch...
0
2016-09-22T04:17:37Z
[ "python", "selenium", "iframe" ]
Iterate only one dict list from multi list dict
39,624,778
<p>I have a dict of lists like so:</p> <pre><code>edu_options = { 'Completed Graduate School' : ['medical','litigation','specialist'...], 'Completed College' : ['linguistic','lpn','liberal','chicano'... ], 'Attended College' : ['general','inprogress','courseworktowards','continu'...], </code></...
0
2016-09-21T19:13:58Z
39,624,873
<p>How about this:</p> <pre><code>for key, val_list in edu_options.items(): if key == "Completed Graduate School": if cleaned_string in val_list: #do something #Similarly for remaining key types </code></pre> <p>This way, you are restricting the checks specifically to the key types. </p>
1
2016-09-21T19:18:55Z
[ "python", "list", "dictionary" ]