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
compare an array with two other arrays in python
38,609,502
<p>i have a set of 3 arrays which i would compare to eachother. array a contain a set of values and the values of array b and c should be partly the same.</p> <p>it is so that if let say <code>a[0] == b[0]</code> than is <code>c[0]</code> always a wrong value</p> <p>for better explanation i try to show what i mean.</...
2
2016-07-27T09:50:02Z
38,610,395
<blockquote> <p>Actually all() function Return True if all elements of the iterable are true (or if the iterable is empty). And in programming language 0 is considered as false and any other integer is considered as true. So here in your array a,b,c every element is non zero and a.all(), b.all() and c.all() they ...
-1
2016-07-27T10:28:29Z
[ "python", "arrays", "python-3.x", "numpy" ]
PIL attribute error: Shape when creating an array
38,609,557
<p>I'm trying to warp two images of different sizes using PIL; specifically, by setting the shape (size) for future warped target image as a numpy array and I'm encountering AttributeError:</p> <p>File "C:\Anaconda2\lib\site-packages\PIL\Image.py", line 632, in <strong>getattr</strong> raise AttributeError(name) A...
1
2016-07-27T09:52:37Z
38,609,730
<p>I think Image objects have <em>size</em> attributes and arrays have <em>shape</em> attributes. Try renaming it in your code. (See : <a href="http://effbot.org/imagingbook/image.htm" rel="nofollow">http://effbot.org/imagingbook/image.htm</a>)</p>
1
2016-07-27T09:59:25Z
[ "python", "numpy", "scipy", "python-imaging-library" ]
Anaconda3 install PATH issue
38,609,561
<p>ISSUE FIXED: Restart fixed the issue.</p> <p>I've just finished installing Anaconda3 on Ubuntu 16.04. It automatically added the following line to .bashrc.</p> <blockquote> <p>export PATH="/home/username/anaconda3/bin:$PATH"</p> </blockquote> <p>However when I run python I still get the default python 2 version...
0
2016-07-27T09:52:48Z
38,609,999
<p>Fixed the issue with a simple restart. Still not sure where the original PATH without the 3 in it came from as I hadn't restarted before.</p>
0
2016-07-27T10:11:43Z
[ "python", "ubuntu", "path", "anaconda" ]
Python: TypeError: Only 2-D and 3-D images supported with scikit-image regionprops
38,609,599
<p>Given a <code>numpy.ndarray</code> of the kind</p> <pre><code>myarray= array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
0
2016-07-27T09:54:54Z
38,611,636
<p>I tried this code and I got no errors:</p> <pre><code>import numpy as np from skimage.measure import label, regionprops myarray = np.random.randint(1, 4, (11,11), dtype=np.int64) labelled = label(myarray) props = regionprops(labelled) </code></pre> <p>Sample output:</p> <pre><code>In [714]: myarray Out[714]: ar...
2
2016-07-27T11:25:40Z
[ "python", "numpy", "image-processing", "2d", "scikit-image" ]
How to move color scale labels to middle of colored fields in matplotlib/xarray?
38,609,648
<p>I have a heatmap with discrete values (=categories/factors), created as follows:</p> <pre><code>import xarray dats = xarray.DataArray([[2,4,3,5,1],[8,4,5,3,2], [9,3,4,4,1]]) dats.plot(levels=range(0, 11, 1), cmap='Blues') </code></pre> <p><a href="http://i.stack.imgur.com/lwGxI.png" rel="nofollow"><img src="http:...
1
2016-07-27T09:56:39Z
38,610,350
<p>For this purpose you have to use matplotlib directly:</p> <pre><code>import xarray import matplotlib.pylab as plt dats = xarray.DataArray([[2,4,3,5,1],[8,4,5,3,2], [9,3,4,4,1]]) qm = dats.plot(levels=range(0, 11, 1), cmap='Blues', add_colorbar = False) cbar = plt.colorbar(qm) cbar.ax.get_yaxis().set_ticks([]) for...
2
2016-07-27T10:26:31Z
[ "python", "matplotlib", "colorbar", "categorical-data", "python-xarray" ]
Being told I have an infinite loop, but I'm unsure how to fix it. (Python Coding Course)
38,609,669
<p>I'm currently in a python coding class and this is an assignment. I apparently have an infinite loop somewhere in my code, yet I can't seem to find it.</p> <pre><code>num = int(input("Enter a number: ")) factorial = 1 # check if the number is negative, positive or zero if num &lt; 0: print("Sorry, factorial does ...
0
2016-07-27T09:57:18Z
38,609,811
<p>First, you already know what a loop is and how it works. You should review the loop in your code and make sure any variable used is defined. Since this is an assignment, this is the best I can do for you, to be honest your problem is already solved.</p> <p>Maybe try enclosing your code in a function with arguments/...
0
2016-07-27T10:03:07Z
[ "python" ]
Being told I have an infinite loop, but I'm unsure how to fix it. (Python Coding Course)
38,609,669
<p>I'm currently in a python coding class and this is an assignment. I apparently have an infinite loop somewhere in my code, yet I can't seem to find it.</p> <pre><code>num = int(input("Enter a number: ")) factorial = 1 # check if the number is negative, positive or zero if num &lt; 0: print("Sorry, factorial does ...
0
2016-07-27T09:57:18Z
38,610,188
<p>There is no infinite loop in your code, both loops will finish in finite time. What is happening is that your teacher, without looking at your code, has discovered that the finite time is very, very long and mistaken this for an infinite loop.</p> <p>The reason it's taking so long is that you have misunderstood the...
2
2016-07-27T10:19:54Z
[ "python" ]
Create numpy array (contour) to be used with opencv functions
38,609,676
<p>I'm new to python and I don't know how to create numpy array that may be used in opencv functions. I've got two vectors defined as follows:</p> <pre><code>X=np.array(x_list) Y=np.array(y_list) </code></pre> <p>and the result is:</p> <pre><code>[ 250.78 250.23 249.67 ..., 251.89 251.34 250.78] [ 251.89 251....
2
2016-07-27T09:57:48Z
38,610,116
<p>Here's some example code, that first checks the dimensions of a contour calculated from a test image, and makes a test array and has success with that as well. I hope this help you!</p> <pre><code>import cv2 import numpy as np img = cv2.imread('output6.png',0) #read in a test image ret,thresh = cv2.threshold(img,1...
0
2016-07-27T10:16:35Z
[ "python", "opencv" ]
Multiple new columns dependent on other column value
38,609,684
<p>I have a dataframe that looks like this:</p> <p><code>Node Node1 Length Spaces Dist T 1 2 600 30 300 100 1 3 400 20 200 100 2 1 600 30 300 100 2 6 500 25 250 400 3 1 400 20 200 100 3 4 400 20 200 200 3 12 400 20 200 200 4 3 400 20 200 200 4 5 200 10 100 500 4 11 600 30...
0
2016-07-27T09:58:09Z
38,612,696
<p>The code below should work (col 'A' is your 'NoSpaces'):</p> <pre><code>import numpy as np import pandas as pd df = pd.DataFrame(np.random.randint(0,10,size=(100, 4)), columns=list('ABCD')) max_val = df['A'].max() for itr in range(max_val): colname = 'A%d' % itr df[colname] = (df['A'] &gt;=itr).astype('...
0
2016-07-27T12:15:51Z
[ "python", "pandas" ]
Copy space delimited string columns to list
38,609,794
<p>I am trying to copy the content of a space delimited .txt file into separate lists corresponding to the columns, but I could not find a way to solve this.</p> <p>A sample of a .txt file is this:</p> <pre><code>Product 6153990c-14fa-47d2-81cf-a253f9294f96 - Date: 2016-06-29T09:47:27Z, Instrument: MSI, Mode: , Satel...
0
2016-07-27T10:02:21Z
38,610,051
<p>Your <code>reader</code> variable does not have the shape you think, see : <a href="https://docs.python.org/2/library/csv.html#csv.reader" rel="nofollow">https://docs.python.org/2/library/csv.html#csv.reader</a> "Each row read from the csv file is returned as a list of strings."</p> <p>So you should probably try fo...
1
2016-07-27T10:13:42Z
[ "python", "list" ]
Copy space delimited string columns to list
38,609,794
<p>I am trying to copy the content of a space delimited .txt file into separate lists corresponding to the columns, but I could not find a way to solve this.</p> <p>A sample of a .txt file is this:</p> <pre><code>Product 6153990c-14fa-47d2-81cf-a253f9294f96 - Date: 2016-06-29T09:47:27Z, Instrument: MSI, Mode: , Satel...
0
2016-07-27T10:02:21Z
38,610,085
<p>You can implement this with basic <code>split</code> like this.</p> <pre><code>file_pointer = open('a.txt') text = file_pointer.read() major_list = [] filtered_list = [i for i in text.split('\n') if i] for item in filtered_list: major_list.append(item.split()) first_row = [item[0] for item in major_list] second...
1
2016-07-27T10:15:18Z
[ "python", "list" ]
Python - How to avoid discrepancy of base y**log base y of x, in gmpy2
38,609,934
<p>The Following code examples my problem which does not occur between 10 power 10 and 10 power 11, but does for the example given in code and above it. </p> <p>I can't see where in my code I am not properly handling the retrieval of the original value. May be I have just missed something simple.</p> <p>I need to be...
0
2016-07-27T10:08:42Z
38,614,637
<p>As long as you set the decimal module accuracy, the usual suggestion is to use Decimal datatype</p> <pre><code>from decimal import Decimal, getcontext getcontext().prec = 1000 # Just a different method to get the random number: x = Decimal(round(10**20 * (1 + 9 * random.random()))) x10 = Decimal.log10(x) e10 = ...
1
2016-07-27T13:40:00Z
[ "python", "logarithm", "gmpy" ]
Python - How to avoid discrepancy of base y**log base y of x, in gmpy2
38,609,934
<p>The Following code examples my problem which does not occur between 10 power 10 and 10 power 11, but does for the example given in code and above it. </p> <p>I can't see where in my code I am not properly handling the retrieval of the original value. May be I have just missed something simple.</p> <p>I need to be...
0
2016-07-27T10:08:42Z
38,630,610
<p>Aguy solved my problem, as acknowledged. I had not taken account of needing more than 15 digits of precision. This answer to another question covers that ground. <a href="http://stackoverflow.com/questions/33059198/gmpy2-log2-not-accurate-after-16-digits">gmpy2 log2 not accurate after 16 digits</a></p>
0
2016-07-28T08:10:37Z
[ "python", "logarithm", "gmpy" ]
Python - How to avoid discrepancy of base y**log base y of x, in gmpy2
38,609,934
<p>The Following code examples my problem which does not occur between 10 power 10 and 10 power 11, but does for the example given in code and above it. </p> <p>I can't see where in my code I am not properly handling the retrieval of the original value. May be I have just missed something simple.</p> <p>I need to be...
0
2016-07-27T10:08:42Z
38,651,311
<p><em>Note: I maintain the <code>gmpy2</code> library.</em></p> <p>In your example, you are using <code>getcontext()</code> from the <code>decimal</code> module. You are not changing the precision used by <code>gmpy2</code>. Since the default precision of <code>gmpy2</code> is 53 bits and your value of x requires 69 ...
1
2016-07-29T05:46:23Z
[ "python", "logarithm", "gmpy" ]
Flatten Pandas DataFrame from nested json list
38,609,971
<p>perhaps somebody could help me. I tried to flat the following ist into a pandas dataframe: </p> <pre><code>[{u'_id': u'2', u'_index': u'list', u'_score': 1.4142135, u'_source': {u'name': u'name3'}, u'_type': u'doc'}, {u'_id': u'5', u'_index': u'list', u'_score': 1.4142135, u'_source': {u'dat': u'2016...
1
2016-07-27T10:10:14Z
38,610,160
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.io.json.json_normalize.html" rel="nofollow"><code>json_normalize</code></a>:</p> <pre><code>from pandas.io.json import json_normalize df = json_normalize(data) print (df) _id _index _score _source.dat _source.name _type 0 2 list ...
1
2016-07-27T10:18:48Z
[ "python", "json", "pandas", "dataframe", "nested" ]
Python beautifulsoup remove self closing tag
38,609,977
<p>I'm trying to remove the <code>br</code> tag from an html code by using beautifulsoup.</p> <p>html eg:</p> <pre><code>&lt;span class="qualification" style="font-size:14px; font-family: Helvetica, sans-serif;"&gt; Doctor of Philosophy ( Software Engineering ), Universiti Teknologi Petronas &lt;br&gt; Master of Scie...
0
2016-07-27T10:10:38Z
38,610,230
<p>Because none of those <code>&lt;br&gt;</code>s have closing counterparts, Beautiful Soup adds them automatically thus producing the following HTML:</p> <pre><code>In [23]: soup = BeautifulSoup(html) In [24]: soup.br Out[24]: &lt;br&gt; Master of Science (Computer Science), Government College University Lahore &lt...
1
2016-07-27T10:21:30Z
[ "python", "beautifulsoup" ]
Python beautifulsoup remove self closing tag
38,609,977
<p>I'm trying to remove the <code>br</code> tag from an html code by using beautifulsoup.</p> <p>html eg:</p> <pre><code>&lt;span class="qualification" style="font-size:14px; font-family: Helvetica, sans-serif;"&gt; Doctor of Philosophy ( Software Engineering ), Universiti Teknologi Petronas &lt;br&gt; Master of Scie...
0
2016-07-27T10:10:38Z
38,610,239
<p>using unwrap should work</p> <pre><code>soup = BeautifulSoup(html) for match in soup.findAll('br'): match.unwrap() </code></pre>
0
2016-07-27T10:22:04Z
[ "python", "beautifulsoup" ]
Python beautifulsoup remove self closing tag
38,609,977
<p>I'm trying to remove the <code>br</code> tag from an html code by using beautifulsoup.</p> <p>html eg:</p> <pre><code>&lt;span class="qualification" style="font-size:14px; font-family: Helvetica, sans-serif;"&gt; Doctor of Philosophy ( Software Engineering ), Universiti Teknologi Petronas &lt;br&gt; Master of Scie...
0
2016-07-27T10:10:38Z
38,610,588
<p>Here's a way to do it:</p> <pre><code>for link2 in soup.findAll('span',{'class':'qualification'}): for s in link2.stripped_strings: print(s) </code></pre> <p>It's not necessary to remove the <code>&lt;br&gt;</code> tags, unless you require them removed for later processing. Here <code>link2.stripped_st...
0
2016-07-27T10:37:38Z
[ "python", "beautifulsoup" ]
Pandas compare columns of list
38,610,042
<p>I have columns in my DataFrame storing <code>lists</code> and I would like to compare each element in the column with a <code>lists</code>.</p> <p>All the methods I have tried fails:</p> <pre><code>df.list_col == ['3', '4'] df.list_col.isin([['3', '4']]) df.list_col.equals(['3', '4']) </code></pre> <p>Is there a ...
1
2016-07-27T10:13:27Z
38,610,111
<p>You can use <code>apply</code> with <code>in</code>:</p> <pre><code>df = pd.DataFrame({'A':[[1,2],[2,4],[3,1]], 'B':[4,5,6]}) print (df) A B 0 [1, 2] 4 1 [2, 4] 5 2 [3, 1] 6 print (df.A.apply(lambda x: 2 in x)) 0 True 1 True 2 False Name: A, dtype: bool </code></pre>
2
2016-07-27T10:16:17Z
[ "python", "list", "pandas", "dataframe", "comparison" ]
How do I get the text decoding of the Chinese?
38,610,329
<p>Python in the Chinese part of the result of requests.get (url) is </p> <p>"æ ?? ¯ä¸? ǧ? Å? ¯ä» ¥ è ?? ªç? ± å? ¼å? ¸ç? ??? Æ ???? è§? ï¼ "</p> <p>came out in this way.</p> <p>How it is necessary to decode Can you print Chinese characters?</p> <p>In the following method, source and other...
-2
2016-07-27T10:25:27Z
38,649,228
<p>The problem has been resolved.</p> <p>Set the encoding option in requests, we were able to obtain the required value.</p> <p>Thank you very much.</p> <pre><code>sub_result = requests.get(sub_url) sub_result.encoding = 'utf-8' sub_soup = BeautifulSoup(sub_result.text, 'lxml') </code></pre>
0
2016-07-29T01:40:46Z
[ "python", "encoding", "utf-8", "python-requests" ]
How to convert a dash separated range to several entries with "X" when difference is 9 in Python
38,610,354
<p>let me try to explain what I´m trying to do:</p> <p>I have a range like this: <code>20934-21021</code></p> <p>I´m trying to figure out a way to get an output like:</p> <pre><code>20934,20935,20936,20937,20938,20939,2094X,2095X,2096X,2097X,2098X,2099X,2100X,2101X,21020,21021 </code></pre> <p>Currently I´m just...
-1
2016-07-27T10:26:44Z
38,610,524
<p>The <code>range</code> function can do this for you. In Python 2 it returns a list, in Python 3 it's a generator, but these differences don't matter for the code you need.</p> <pre><code>text = "20934-21021" start, end = text.split("-") start = int(start) # needs error checks end = int(end) # as does this resul...
-1
2016-07-27T10:34:18Z
[ "python", "regex" ]
How to convert a dash separated range to several entries with "X" when difference is 9 in Python
38,610,354
<p>let me try to explain what I´m trying to do:</p> <p>I have a range like this: <code>20934-21021</code></p> <p>I´m trying to figure out a way to get an output like:</p> <pre><code>20934,20935,20936,20937,20938,20939,2094X,2095X,2096X,2097X,2098X,2099X,2100X,2101X,21020,21021 </code></pre> <p>Currently I´m just...
-1
2016-07-27T10:26:44Z
38,611,655
<p>Here is my proposed solution:</p> <pre><code>&gt;&gt;&gt; def range_x(s): start, end = s.split('-') result = '' if start[-1] == '0': string1 = start[:-1]+'X' else: r1 = range(int(start[-1]), 10) string1 = ','.join(map(lambda i:start[:-1]+str(i), r1...
1
2016-07-27T11:26:47Z
[ "python", "regex" ]
How to convert a dash separated range to several entries with "X" when difference is 9 in Python
38,610,354
<p>let me try to explain what I´m trying to do:</p> <p>I have a range like this: <code>20934-21021</code></p> <p>I´m trying to figure out a way to get an output like:</p> <pre><code>20934,20935,20936,20937,20938,20939,2094X,2095X,2096X,2097X,2098X,2099X,2100X,2101X,21020,21021 </code></pre> <p>Currently I´m just...
-1
2016-07-27T10:26:44Z
38,611,766
<p>Here is my solution. </p> <p>There are places for optimization, but I tried to make it easy and straight forward. </p> <pre><code>a,b = map(int, '20934-21021'.split('-')) output_str = '' l = (a/10 + 1) * 10 u= (b/10) * 10 output_str += ','.join(map(str, range(a,l))) output_str += ',' lower = a/10 + 1 upper ...
1
2016-07-27T11:32:21Z
[ "python", "regex" ]
Reading a complex text file in Python
38,610,526
<p>I'm a newbie in Python and I've a problem.</p> <p>I've to compare the values between two files, one is an Excel file (and I don't have any problem with it), the other one is a text file formatted with spaces and "blocks" of lines.</p> <p>The text file is like this:</p> <pre><code>LISON Kontoauszug...
1
2016-07-27T10:34:26Z
38,611,043
<p>One approach would be to read the file in a line at a time and use a regular expression to decide if it is one of the data lines. If it is, append to a list. You will also need to keep a note of the LT line and append it to any following data lines as follows:</p> <pre><code>import re data = [] lt = 'unknown' wit...
1
2016-07-27T10:57:33Z
[ "python", "parsing", "text-files", "python-3.5" ]
Convert spark DataFrame column to python list
38,610,559
<p>I work on a dataframe with two column, mvv and count.</p> <pre><code>+---+-----+ |mvv|count| +---+-----+ | 1 | 5 | | 2 | 9 | | 3 | 3 | | 4 | 1 | </code></pre> <p>i would like to obtain two list containing mvv values and count value. Something like</p> <pre><code>mvv = [1,2,3,4] count = [5,9,3,1] </code></...
0
2016-07-27T10:36:18Z
38,611,657
<p>See, why this way that you are doing is not working. First, you are trying to get integer from a Row Type, the output of your collect is like this:</p> <pre><code>&gt;&gt;&gt; mvv_list = mvv_count_df.select('mvv').collect() &gt;&gt;&gt; mvv_list[0] Out: Row(mvv=1) </code></pre> <p>If you take something like this:<...
3
2016-07-27T11:26:50Z
[ "python", "apache-spark", "pyspark", "spark-dataframe" ]
Find indices of duplicated rows in python ndarray
38,610,634
<p>I coded the for loop to enumerate a multidimensional ndarray containing n rows of 28x28 pixel values.</p> <p>I am looking for the index of each row that is duplicated and the indices of the duplicates without redundancies.</p> <p>I found this code <a href="http://stackoverflow.com/questions/15787582/find-index-of-...
2
2016-07-27T10:39:47Z
38,613,404
<p>The <a href="https://github.com/EelcoHoogendoorn/Numpy_arraysetops_EP" rel="nofollow">numpy_indexed</a> package has a lot of functionality to solve these type of problems efficiently.</p> <p>For instance, (unlike numpy's builtin unique) this will find your unique images:</p> <pre><code>import numpy_indexed as npi ...
1
2016-07-27T12:46:05Z
[ "python", "numpy", "multidimensional-array", "data-science" ]
Python 3.x: Multiprocess cannot serialize 'ExFileObject' object
38,610,709
<p>I try to read txt file from the archive(tar) and process file with function. I have a lot of files and decided to use multiprocessing lib to speed up calculations. But I got error "cannot serialize 'ExFileObject' object". Below is an example of my code. How to serialize 'ExFileObject' object or how to speed up my c...
0
2016-07-27T10:42:49Z
38,612,701
<p>Your example code works fine for me. I would only add a <code>NoneType</code> check because <code>NoneType</code> has no <code>readlines</code> attribute and <code>tar.extractfile(file)</code> might return a <code>NoneType</code> value.</p> <pre><code>import tarfile from multiprocessing import Process, Manager def...
0
2016-07-27T12:16:05Z
[ "python", "multithreading", "multiprocessing" ]
Pandas - Creating Dataframe from Generator object using read_csv
38,610,717
<p>I have a propitiatory cursor (arcpy.da.SearchCursor) object that I need to load into a pandas dataframe.</p> <p>It implements next(), reset() as you would expect for a generator object in Python.</p> <p>Using another post in <a href="http://stackoverflow.com/questions/18915941/create-a-pandas-dataframe-from-genera...
1
2016-07-27T10:43:13Z
38,620,505
<p>Try the following <code>read</code> function:</p> <pre><code>def read(self, n=0): if n == 0: try: return next(self.g) except StopIteration: return '' else: vals = [] try: for x in range(n): vals.append(next(self.g)) ...
0
2016-07-27T18:22:58Z
[ "python", "python-2.7", "pandas" ]
pandas insert dataframe into database
38,610,723
<p>I'm using <code>sqlalchemy</code> in pandas to query postgres database and then insert results of a transformation to another table on the same database. But when I do <code>df.to_sql('db_table2', engine)</code> I get this error message: <code>ValueError: Table 'db_table2' already exists.</code> I noticed it want t...
0
2016-07-27T10:43:23Z
38,610,751
<p>make use of <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html" rel="nofollow">if_exists</a> parameter:</p> <pre><code>df.to_sql('db_table2', engine, if_exists='replace') </code></pre> <p>or</p> <pre><code>df.to_sql('db_table2', engine, if_exists='append') </code></pre> <...
0
2016-07-27T10:44:45Z
[ "python", "pandas" ]
Why Python can not execute the cmd command 'tskill'?
38,610,730
<p>In general, we can use Python to execute Windows's cmd command, for example:</p> <pre><code> os.system('ipconfig') </code></pre> <p>but I find that <code>tskill</code> can not be executed by Python, if I use:</p> <pre><code>os.system('tskill 8684') </code></pre> <p>to kill a process by its pid, Python will show ...
1
2016-07-27T10:43:34Z
38,615,461
<p>Use taskkill, which can do pretty much everything as tskill</p> <p>But if you want to stick to tskill.exe in your scripts/code. Please run the scripts from elevated command prompts. (Right click on cmd.exe and run it as administrator)</p> <pre><code>os.system('c:\windows\system32\tskill.exe 8684') </code></pre>
0
2016-07-27T14:12:30Z
[ "python" ]
Why Python can not execute the cmd command 'tskill'?
38,610,730
<p>In general, we can use Python to execute Windows's cmd command, for example:</p> <pre><code> os.system('ipconfig') </code></pre> <p>but I find that <code>tskill</code> can not be executed by Python, if I use:</p> <pre><code>os.system('tskill 8684') </code></pre> <p>to kill a process by its pid, Python will show ...
1
2016-07-27T10:43:34Z
38,649,148
<p>I have found the root reason:</p> <p>My Python is 32-bit, while My PC is Windows7 64-bit, so Python's <code>os.system</code> can not run <code>tskill</code>. If I use Python 64-bit instead, everything is OK.</p>
1
2016-07-29T01:27:57Z
[ "python" ]
How to create generic 2d array in python
38,610,924
<p>In Java you would do it like this: <code>Node[][] nodes;</code> where Node.java is a custom class. How do I do it in python where Node.py:</p> <pre><code>class Node(object): def __init__(self): self.memory = [] self.temporal_groups = [] </code></pre> <p>I have imported <code>numpy</code> and created an...
1
2016-07-27T10:52:26Z
38,612,912
<p>You can try it this way, inside your node class create a function that will return the generic array: </p> <pre><code>def genArray(a, b): return [[0 for y in range(a)] for x in range(b)] </code></pre> <p>then you can assign them the way you want. Maybe you might change the 0 to your node object. Let me know if...
1
2016-07-27T12:25:19Z
[ "python", "numpy", "generics" ]
How to create generic 2d array in python
38,610,924
<p>In Java you would do it like this: <code>Node[][] nodes;</code> where Node.java is a custom class. How do I do it in python where Node.py:</p> <pre><code>class Node(object): def __init__(self): self.memory = [] self.temporal_groups = [] </code></pre> <p>I have imported <code>numpy</code> and created an...
1
2016-07-27T10:52:26Z
38,617,230
<p>You have two easy options: use <code>numpy</code> or declare a nested list. The latter approach is more conceptually similar to <code>Node[][]</code> since it allows for ragged lists, as does Java, but the former approach will probably make processing faster.</p> <p><strong>numpy arrays</strong></p> <p>To make an ...
0
2016-07-27T15:23:45Z
[ "python", "numpy", "generics" ]
unittest - assertRaises return an error instead of passing
38,610,943
<p>I've written a piece of code that uses a config file (in JSON-format) </p> <pre><code>def test_read_config_file(self): self.assertRaises(ValueError, self.read_config_file('no_json.txt') </code></pre> <p>The original function looks like this:</p> <pre><code>def read_config_file(file_name) config_data = None...
1
2016-07-27T10:53:28Z
38,612,082
<p>You are not using the <code>unittest</code> library correctly. When you write this:</p> <pre><code>def test_read_config_file(self): self.assertRaises(ValueError, self.read_config_file('no_json.txt')) # Btw. there was a missing closing `)` </code></pre> <p>the <code>self.read_config_file()</code> method is ex...
0
2016-07-27T11:46:59Z
[ "python", "python-unittest" ]
unittest - assertRaises return an error instead of passing
38,610,943
<p>I've written a piece of code that uses a config file (in JSON-format) </p> <pre><code>def test_read_config_file(self): self.assertRaises(ValueError, self.read_config_file('no_json.txt') </code></pre> <p>The original function looks like this:</p> <pre><code>def read_config_file(file_name) config_data = None...
1
2016-07-27T10:53:28Z
38,612,195
<p>The problem is that your function catches the <code>ValueError</code> exception that <code>json.load</code> raises, performs the logging, then simply goes on to return the value of <code>config_data</code>. Your test asserts that the function should raise an exception, but there is no code to ensure that the functio...
0
2016-07-27T11:52:43Z
[ "python", "python-unittest" ]
Dealing with big data to perform random forest classification
38,610,955
<p>I am currently working on my thesis, which involves dealing with quite a sizable dataset: ~4mln observations and ~260ths features. It is a dataset of chess games, where most of the features are player dummies (130k for each colour). </p> <p>As for the hardware and the software, I have around 12GB of RAM on this co...
3
2016-07-27T10:53:57Z
38,612,762
<p>I would suggest you give CloudxLab a try. </p> <p>Though it is not free it is quite affordable ($25 for a month). It provides complete environment to experiment with various tools such as HDFS, Map-Reduce, Hive, Pig, Kafka, Spark, Scala, Sqoop, Oozie, Mahout, MLLib, Zookeeper, R, Scala etc. Many of the popular trai...
4
2016-07-27T12:18:46Z
[ "python", "pandas", "scikit-learn", "bigdata", "sparse-matrix" ]
Django {%trans%} not working, despite django.po being generated
38,610,962
<p>I have a template file <code>templates/admin/base_site.html</code> which includes one <code>trans</code> tag: <code>{% trans "Event List" %}</code>.</p> <p><code>settings.py</code> includes:</p> <pre><code>LANGUAGE_CODE = 'sv' LOCALE_PATHS = ( '/srv/mysite/locale/', ) </code></pre> <p>The Django-admin pages a...
1
2016-07-27T10:54:03Z
38,611,079
<p>Have you restarted the webserver? It won't be serving the newly compiled po files if you haven't. </p> <p><strong>Edit:</strong> and be sure to restart Django server after you do as well.</p>
0
2016-07-27T10:59:01Z
[ "python", "django", "django-i18n" ]
Django {%trans%} not working, despite django.po being generated
38,610,962
<p>I have a template file <code>templates/admin/base_site.html</code> which includes one <code>trans</code> tag: <code>{% trans "Event List" %}</code>.</p> <p><code>settings.py</code> includes:</p> <pre><code>LANGUAGE_CODE = 'sv' LOCALE_PATHS = ( '/srv/mysite/locale/', ) </code></pre> <p>The Django-admin pages a...
1
2016-07-27T10:54:03Z
38,611,365
<p><code>django.po</code> files are only meant for editing purpose. You must compile them to <code>django.mo</code> files so that they are interpreted:</p> <pre><code>python manage.py compilemessages </code></pre> <p>See also <a href="https://docs.djangoproject.com/en/1.9/topics/i18n/translation/#compiling-message-fi...
1
2016-07-27T11:13:25Z
[ "python", "django", "django-i18n" ]
Unable to open the link in proxy
38,610,965
<p>I am actually using a proxy to scrape data from some sites but the problem is sometimes some proy url returns nothing and programmed stopped after a few tries, I need some logic to overcome this issue so that even if IP does not respond program should renew the IP and try to open the page again, I am using TOR as a ...
1
2016-07-27T10:54:14Z
38,611,053
<p>You can simply put your code in while loop and give it certain condition, when that condition becomes TRUE, it means your page is properly opened.</p> <pre><code>mainPage = requests.get("http://proxy_IP/?link=http://example.com/") mainTree = html.fromstring(mainPage.text) mainTree while (mainTree.xpath('boolean(so...
0
2016-07-27T10:57:51Z
[ "python", "proxy" ]
Plot some numbers in x axis
38,610,994
<p>My question is related to the figure format generated using the matplotlib library.</p> <p>So, in the x axis, I have the integers from 1 to 100, but in my code I plot just the data related to some numbers (e.g 1,5,77,86,97).</p> <p>At the end, my code shows me a figure with x axis from 1 to 100.</p> <p>How can I ...
-1
2016-07-27T10:55:28Z
38,611,271
<p>If you have a <code>matplotlib.Axes</code> object you can modify the ticks along the x-axis with <code>set_xticks</code>:</p> <pre><code>import matplotlib.pyplot as plt plt.plot([0,1,5,77,86,97],range(6),'o-') ax = plt.gca() ax.set_xticks([1,5,77,86,97]) </code></pre> <p>with output:</p> <p><a href="http://i.stac...
2
2016-07-27T11:09:02Z
[ "python", "matplotlib" ]
Plot some numbers in x axis
38,610,994
<p>My question is related to the figure format generated using the matplotlib library.</p> <p>So, in the x axis, I have the integers from 1 to 100, but in my code I plot just the data related to some numbers (e.g 1,5,77,86,97).</p> <p>At the end, my code shows me a figure with x axis from 1 to 100.</p> <p>How can I ...
-1
2016-07-27T10:55:28Z
38,611,309
<p>How about masking x with y and then plotting it? like:</p> <pre><code>pylap.plot(x[y != 0], y, 'darkmagenta', # colour linestyle='', # line style linewidth=10, # line width marker = '+', ...
0
2016-07-27T11:10:56Z
[ "python", "matplotlib" ]
Plot some numbers in x axis
38,610,994
<p>My question is related to the figure format generated using the matplotlib library.</p> <p>So, in the x axis, I have the integers from 1 to 100, but in my code I plot just the data related to some numbers (e.g 1,5,77,86,97).</p> <p>At the end, my code shows me a figure with x axis from 1 to 100.</p> <p>How can I ...
-1
2016-07-27T10:55:28Z
38,611,748
<p>That will do:</p> <pre><code>import matplotlib.pyplot as plt x = y = list(range(100)) idx = [1,5,77,86,97] new_y = [y[i] for i in idx] plt.plot(range(len(idx)), new_y, 'o-') plt.xticks(range(len(idx)),idx) plt.show() </code></pre> <p><a href="http://i.stack.imgur.com/xbT2a.png" rel="nofollow"><img src="http://i.st...
2
2016-07-27T11:31:18Z
[ "python", "matplotlib" ]
Pass a variable number of arguments to the map function
38,611,073
<p>Suppose I have a function whose the prototype is:</p> <pre><code>def my_func(fixed_param, *args) </code></pre> <p>I would like to run this function with multiple arguments (not necessary the same number of arguments for each run) such as:</p> <pre><code>res = map(partial(my_func, fixed_param=3), [[1, 2, 3], [1, 2...
3
2016-07-27T10:58:47Z
38,611,262
<p>You can unpack the argument list if you use a list comprehension:</p> <pre><code>res= [my_func(3, *args) for args in [[1, 2, 3], [1, 2, 3, 4]]] </code></pre> <p>But you can't do this with <code>map</code>. If you insist on using <code>map</code>, you'll need a helper function:</p> <pre><code>def unpack(args): ...
3
2016-07-27T11:08:44Z
[ "python" ]
Pass a variable number of arguments to the map function
38,611,073
<p>Suppose I have a function whose the prototype is:</p> <pre><code>def my_func(fixed_param, *args) </code></pre> <p>I would like to run this function with multiple arguments (not necessary the same number of arguments for each run) such as:</p> <pre><code>res = map(partial(my_func, fixed_param=3), [[1, 2, 3], [1, 2...
3
2016-07-27T10:58:47Z
38,611,267
<p>I would not be so sure about <code>map</code> vs list comprehension performance, as oftentimes it's a question of the function you use. Anyway, your options are:</p> <pre><code>map(lambda x: my_func(3, *x), ...) </code></pre> <p>Or </p> <pre><code>from itertools import starmap starmap(partial(my_func, 3), ...) <...
5
2016-07-27T11:08:55Z
[ "python" ]
Pass a variable number of arguments to the map function
38,611,073
<p>Suppose I have a function whose the prototype is:</p> <pre><code>def my_func(fixed_param, *args) </code></pre> <p>I would like to run this function with multiple arguments (not necessary the same number of arguments for each run) such as:</p> <pre><code>res = map(partial(my_func, fixed_param=3), [[1, 2, 3], [1, 2...
3
2016-07-27T10:58:47Z
38,611,555
<p>I think your code will work with a few small changes:</p> <pre><code>def f(l, all_args): print "Variable", all_args print "Fixed", l map(partial(f, 1), [[1, 2, 3], [1, 2, 3, 4]]) &gt;&gt;&gt; Variable [1, 2, 3] &gt;&gt;&gt; Fixed 1 &gt;&gt;&gt; Variable [1, 2, 3, 4] &gt;&gt;&gt; Fixed 1 </code></pre>
2
2016-07-27T11:22:05Z
[ "python" ]
Django forms show cleaned data if validation fails
38,611,278
<p>I have the following function declared in a django form:</p> <pre><code>def clean_name(self): name = self.cleaned_data.get('name') name = re.sub('\s+', ' ', name).strip().title() return name </code></pre> <p>I have an unique constraint on the name field and I would like to have the name trimmed in the ...
1
2016-07-27T11:09:29Z
38,613,064
<p>So I've read some articles, finally i came to this solution, to override the full_clean method:</p> <pre><code>def full_clean(self): cleaned_data = {} for i,v in self.data.items(): if isinstance(v, basestring): cleaned_data[i] = re.sub('\s+', ' ', v).strip() else: cle...
0
2016-07-27T12:31:06Z
[ "python", "django", "django-forms" ]
Parallel execution of 2 seperate python scripts using subprocess from the main Python script
38,611,285
<p>Using python, I want to start two subprocesses in parallel. One will start an HTTP Server, while other will start execution of another program(which is a python script generated by selenium IDE plugin to open firefox, navigate to a website and do some interactions). On the other hand, I want to stop execution of the...
3
2016-07-27T11:09:50Z
38,611,426
<p>Call <code>t2.join()</code> before exiting your program. This waits for the navigation thread to terminate, before execution continues.</p> <p>Edit:</p> <p>Your navigation thread terminates immediately because you are not waiting for the child process to exit. This should solve the issue:</p> <pre><code>process=s...
1
2016-07-27T11:15:45Z
[ "python", "selenium", "python-multithreading" ]
Child dialog doesn't show up in PyQt5
38,611,296
<p><br></p> <p>Hi, I'm trying to make simple GUI application using PyQt5, Python 3.4 and Windows 7.</p> <p>Below code works properly. </p> <pre><code># coding: utf-8 import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QDialog class MainWnd(QMainWindow): def __init__(self): super().__ini...
0
2016-07-27T11:10:30Z
38,611,885
<p>As specified in the <a href="http://doc.qt.io/qt-5.7/qdialog.html" rel="nofollow">documentation</a> calling <code>setParent</code> will just change the ownership of the <code>QDialog</code> widget. If you want the <code>QDialog</code> widget to be centered within it's parent, you need to pass the parent widget insta...
0
2016-07-27T11:38:08Z
[ "python", "pyqt", "pyside" ]
Formulating Linear Integer Programming Constraint
38,611,360
<p>I'm trying to formulate a constraint for an optimization problem that forces the solution (a combination of products, represented by binary numbers to signify if they got picked or not) to have a certain property in order.</p> <p>So let's say products 1, 2 and 5 got selected, that solution is represented by [1, 1, ...
3
2016-07-27T11:13:20Z
38,614,427
<p>The condition you are looking for is</p> <pre><code>return abs( mod( max(locations) - min(locations) +50,100)-50) &lt;=2 </code></pre> <p>or in a general form:</p> <pre><code>abs(mod( distance + range/2,range)-range/2) </code></pre> <p>This gives the minimum distance in a circular space. It is commonly used to c...
0
2016-07-27T13:30:39Z
[ "python", "matlab", "mathematical-optimization", "linear-programming" ]
Formulating Linear Integer Programming Constraint
38,611,360
<p>I'm trying to formulate a constraint for an optimization problem that forces the solution (a combination of products, represented by binary numbers to signify if they got picked or not) to have a certain property in order.</p> <p>So let's say products 1, 2 and 5 got selected, that solution is represented by [1, 1, ...
3
2016-07-27T11:13:20Z
38,678,926
<p>I ended up solving this problem with a meta solution, that a friend of mine came up with.</p> <p>Since choosing the product with position X infers the other allowed choices (namely X+1 and X+2) it makes sense to optimize on groups of products, not on individual products. I've built this and it works beautifully.</p...
1
2016-07-30T22:08:48Z
[ "python", "matlab", "mathematical-optimization", "linear-programming" ]
Classification using SVM
38,611,447
<p>In an attempt to classify text I want to use SVM. I want to classify test data into one of the labels(health/adult) The training &amp; test data are text files</p> <p>I am using python's scikit library. While I was saving the text to txt files I encoded it in <code>utf-8</code> that's why i am decoding them in the ...
0
2016-07-27T11:16:41Z
38,612,882
<p>You have to combine your samples, vectorize them and then fit the classifier. Like this:</p> <pre><code>String = String.decode('utf-8') String2 = String2.decode('utf-8') bigram_vectorizer = CountVectorizer(ngram_range=(1, 2), token_pattern=r'\b\w+\b', min_df=1) X_train = bigram...
2
2016-07-27T12:23:51Z
[ "python", "machine-learning", "classification", "svm", "text-classification" ]
Django - Export ASCII CSV
38,611,456
<p>I want to export a CSV-file encoded in ASCII but the default is UTF-8 if I encode the strings i get the bytecode written in the csv (b'String')</p> <pre><code> response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="datev_export.csv"' writer = csv.writer(response,...
0
2016-07-27T11:16:59Z
38,612,747
<p>You can use the encode method of strings like</p> <pre><code>"asdf".encode("ascii") </code></pre> <p>for bytes there is the decode method for getting things back like</p> <pre><code>b"asdf".decode("ascii") </code></pre>
0
2016-07-27T12:18:06Z
[ "python", "django", "export-to-csv" ]
Python: get every possible combination of weights for a portfolio
38,611,467
<p>I think this problem can be solved using either itertools or cartesian, but I'm fairly new to Python and am struggling to use these:</p> <p>I have a portfolio of 5 stocks, where each stock can have a weighting of -0.4, -0.2, 0, 0.2 or 0.4, with weightings adding up to 0. How do I create a function that produces a l...
6
2016-07-27T11:17:23Z
38,611,682
<p>Is this what you are looking for: if <code>L = [-0.4, 0.2, 0, 0.2, 0]</code></p> <pre><code>AllCombi = itertools.permutations(L) for each in AllCombi: print each </code></pre>
-3
2016-07-27T11:27:56Z
[ "python", "list", "itertools", "cartesian-product" ]
Python: get every possible combination of weights for a portfolio
38,611,467
<p>I think this problem can be solved using either itertools or cartesian, but I'm fairly new to Python and am struggling to use these:</p> <p>I have a portfolio of 5 stocks, where each stock can have a weighting of -0.4, -0.2, 0, 0.2 or 0.4, with weightings adding up to 0. How do I create a function that produces a l...
6
2016-07-27T11:17:23Z
38,611,752
<p>If you just want a list of all the combinations, use <a class='doc-link' href="http://stackoverflow.com/documentation/python/1564/itertools-module/9828/itertools-combinations#t=201607271138098681664"><code>itertools.combinations</code></a>:</p> <pre><code>w = [-0.4, -0.2, 0, 0.2, 0.4] l = len(w) if __name__ == '__...
-1
2016-07-27T11:31:39Z
[ "python", "list", "itertools", "cartesian-product" ]
Python: get every possible combination of weights for a portfolio
38,611,467
<p>I think this problem can be solved using either itertools or cartesian, but I'm fairly new to Python and am struggling to use these:</p> <p>I have a portfolio of 5 stocks, where each stock can have a weighting of -0.4, -0.2, 0, 0.2 or 0.4, with weightings adding up to 0. How do I create a function that produces a l...
6
2016-07-27T11:17:23Z
38,612,134
<p>I like using the <code>filter</code> function:</p> <pre><code>from itertools import permutations w = [-0.4, -0.2, 0, 0.2, 0.4] def foo(w): perms = list(permutations(w)) sum0 = filter(lambda x: sum(x)==0, perms) return sum0 print foo(w) </code></pre>
0
2016-07-27T11:48:50Z
[ "python", "list", "itertools", "cartesian-product" ]
Python: get every possible combination of weights for a portfolio
38,611,467
<p>I think this problem can be solved using either itertools or cartesian, but I'm fairly new to Python and am struggling to use these:</p> <p>I have a portfolio of 5 stocks, where each stock can have a weighting of -0.4, -0.2, 0, 0.2 or 0.4, with weightings adding up to 0. How do I create a function that produces a l...
6
2016-07-27T11:17:23Z
38,612,748
<p>I understand the values can repeat, but all have to sum to zero, therefore the solution might be:</p> <pre><code>&gt;&gt;&gt; from itertools import permutations &gt;&gt;&gt; weights = [-0.4, -0.2, 0, 0.2, 0.4] &gt;&gt;&gt; result = (com for com in permutations(weights) if sum(com)==0) &gt;&gt;&gt; for i in result: ...
1
2016-07-27T12:18:08Z
[ "python", "list", "itertools", "cartesian-product" ]
Python: get every possible combination of weights for a portfolio
38,611,467
<p>I think this problem can be solved using either itertools or cartesian, but I'm fairly new to Python and am struggling to use these:</p> <p>I have a portfolio of 5 stocks, where each stock can have a weighting of -0.4, -0.2, 0, 0.2 or 0.4, with weightings adding up to 0. How do I create a function that produces a l...
6
2016-07-27T11:17:23Z
38,613,816
<p>Something like this, although it's not really efficient.</p> <pre><code>from decimal import Decimal import itertools # possible optimization: use integers rather than Decimal weights = [Decimal("-0.4"), Decimal("-0.2"), Decimal(0), Decimal("0.2"), Decimal("0.4")] def possible_weightings(n = 5, target = 0): fo...
3
2016-07-27T13:04:36Z
[ "python", "list", "itertools", "cartesian-product" ]
Python: get every possible combination of weights for a portfolio
38,611,467
<p>I think this problem can be solved using either itertools or cartesian, but I'm fairly new to Python and am struggling to use these:</p> <p>I have a portfolio of 5 stocks, where each stock can have a weighting of -0.4, -0.2, 0, 0.2 or 0.4, with weightings adding up to 0. How do I create a function that produces a l...
6
2016-07-27T11:17:23Z
38,618,914
<p>Different approach. </p> <h1>1 Figure out all sequences of the weights that add up to zero, in order.</h1> <p>for example, these are some possibilities (using whole numbers to type less):<br> [0, 0, 0, 0, 0]<br> [-4, 0, 0, +2, +2]<br> [-4, 0, 0, 0, +4]</p> <p>[-4, +4, 0, 0, 0] is incorrect because weights are n...
0
2016-07-27T16:48:40Z
[ "python", "list", "itertools", "cartesian-product" ]
How to model "family and others" thing?
38,611,528
<p>I need to model family, parents, children and ordinary people entities. How can I do that? Obviously, I could create 4 or even 5 different classess: family, 2 for both parents, one for a children and one for people. But I think there's redundancy in this approach. On the other hand, if I introduce a field "type" be...
0
2016-07-27T11:20:33Z
38,611,607
<p>In this case I think it would make sense to simply have two classes, for example</p> <pre><code>class Person: def __init__(self, name): self.name = name class Family: def __init__(self): self.children = [] self.parents = [] </code></pre> <p>Then <code>Family.children</code> and <co...
2
2016-07-27T11:24:17Z
[ "python", "django", "oop" ]
I need to figure out how to make my program repeat. (Python coding class)
38,611,900
<p>I am a beginner student in a python coding class. I have the majority of the done and the program itself works, however I need to figure out a way to make the program ask if wants a subtraction or an adding problem, and if the user would like another question. I asked my teacher for assistance and he hasn't gotten b...
0
2016-07-27T11:38:55Z
38,612,003
<p>If you want the possibility to have another question asked use a while loop and ask the user for an input. If you want the user to input whether (s)he want an addition or substraction you already used the tools to ask for such an input. Just ask the user for a string.</p>
0
2016-07-27T11:43:30Z
[ "python" ]
I need to figure out how to make my program repeat. (Python coding class)
38,611,900
<p>I am a beginner student in a python coding class. I have the majority of the done and the program itself works, however I need to figure out a way to make the program ask if wants a subtraction or an adding problem, and if the user would like another question. I asked my teacher for assistance and he hasn't gotten b...
0
2016-07-27T11:38:55Z
38,612,057
<p>You'll want to do something like this:</p> <pre><code>def foo(): print("Doing good work...") while True: foo() if input("Want to do more good work? [y/n] ").strip().lower() == 'n': break </code></pre> <p>I've seen this construct (i.e., using a <code>break</code>) used more often than using a <...
4
2016-07-27T11:45:55Z
[ "python" ]
I need to figure out how to make my program repeat. (Python coding class)
38,611,900
<p>I am a beginner student in a python coding class. I have the majority of the done and the program itself works, however I need to figure out a way to make the program ask if wants a subtraction or an adding problem, and if the user would like another question. I asked my teacher for assistance and he hasn't gotten b...
0
2016-07-27T11:38:55Z
38,612,876
<p>Asking users for input is straightforward, you just need to use the python built-in input() function. You then compare the stored answer to some possible outcomes. In your case this would work fine:</p> <pre><code>print('Would you like to test your adding or subtracting skills?') user_choice = input('Answer A for a...
1
2016-07-27T12:23:38Z
[ "python" ]
how to enable serial port(ttyAMA0) communication using "pi serial" in pi3?
38,611,986
<p>i want to enable serial port communication in pi 3 using pi serial. but when i try to open a port like this</p> <p>test=serial.Serial("/dev/ttyAMA0", 115200) </p> <p>it gives me the error "<strong>port already open</strong>".</p> <p>how can i solve it?</p>
1
2016-07-27T11:42:57Z
38,611,987
<p><strong>finally this got work for my pi3 (os: debian jessie)</strong></p> <p>please follow these 6 steps carefully.</p> <p><strong>Step 1</strong> - Install Raspbian Jessie onto a SD card and boot the Pi when connected to a network Login via terminal or desktop and shell Configure the system with:</p> <pre><...
1
2016-07-27T11:42:57Z
[ "python", "serial-port", "serial-communication", "raspberry-pi3" ]
Eve: Endpoint representing currently logged-in user
38,612,038
<p>I am using the auth feature in combination with oauth. I would like to have an endpoint like: <code>/api/v1/user/current</code> representing the currently logged-in user. Is there a way to do that?</p>
1
2016-07-27T11:45:11Z
38,639,692
<p>You could use regular Flask routing to achieve that. Remember Eve is a Flask subclass, so whatever works with Flask generally work with Eve too, enabling custom endpoints included:</p> <pre><code>from eve import Eve app = Eve() @app.route('/user/current') def current_user(): # perform your magic here user...
0
2016-07-28T14:43:46Z
[ "python", "eve" ]
Pandas Flatten a dataframe to a single column
38,612,154
<p>I have dataset in the following format:</p> <pre><code>df = pd.DataFrame({'x':[1,2,3], 'y':[10,20,30], 'v1':[3,2,3] , 'v2':[13,25,31] }) &gt;&gt; v1 v2 x y 3 13 1 10 2 25 2 20 3 31 3 30 </code></pre> <p>Setting the index column with x, I want to flatten the data combining v1 and v2 (V), The ...
1
2016-07-27T11:50:21Z
38,612,189
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.stack.html" rel="nofollow"><code>stack</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a>. Last <a href="http://pandas.pyd...
2
2016-07-27T11:52:24Z
[ "python", "python-3.x", "pandas" ]
Pandas Flatten a dataframe to a single column
38,612,154
<p>I have dataset in the following format:</p> <pre><code>df = pd.DataFrame({'x':[1,2,3], 'y':[10,20,30], 'v1':[3,2,3] , 'v2':[13,25,31] }) &gt;&gt; v1 v2 x y 3 13 1 10 2 25 2 20 3 31 3 30 </code></pre> <p>Setting the index column with x, I want to flatten the data combining v1 and v2 (V), The ...
1
2016-07-27T11:50:21Z
38,612,286
<p><code>pd.lreshape</code> can reformat wide data to long format:</p> <pre><code>In [55]: pd.lreshape(df, {'V':['v1', 'v2']}) Out[57]: x y V 0 1 10 3 1 2 20 2 2 3 30 3 3 1 10 13 4 2 20 25 5 3 30 31 </code></pre> <p><code>lreshape</code> is an undocumented "experimental" feature. To learn...
2
2016-07-27T11:57:18Z
[ "python", "python-3.x", "pandas" ]
Create dict with key/value and key/value reversed
38,612,266
<p>Having such list </p> <p><code>example = ['ab', 'cd']</code></p> <p>I need to get <code>{'a': 'b', 'b': 'a', 'c': 'd', 'd': 'c'}</code></p> <p>With regular loop I could do this like:</p> <pre><code>result = {} for i,j in example: result[i] = j result[j] = i </code></pre> <p>Question: How can I do the sa...
3
2016-07-27T11:56:29Z
38,612,430
<p>list comprehension with dictionary updates</p> <pre><code>[result.update({x[0]:x[1],x[1]:x[0]}) for x in example] </code></pre>
0
2016-07-27T12:03:47Z
[ "python", "generator", "list-comprehension" ]
Create dict with key/value and key/value reversed
38,612,266
<p>Having such list </p> <p><code>example = ['ab', 'cd']</code></p> <p>I need to get <code>{'a': 'b', 'b': 'a', 'c': 'd', 'd': 'c'}</code></p> <p>With regular loop I could do this like:</p> <pre><code>result = {} for i,j in example: result[i] = j result[j] = i </code></pre> <p>Question: How can I do the sa...
3
2016-07-27T11:56:29Z
38,612,458
<p>A <a href="https://www.python.org/dev/peps/pep-0274/" rel="nofollow">dict comprehension</a> should do:</p> <pre><code>In [726]: {k: v for (k, v) in map(tuple, example + map(reversed, example))} # Python 2 Out[726]: {'a': 'b', 'b': 'a', 'c': 'd', 'd': 'c'} In [727]: {s[0]: s[1] for s in (example + [x[::-1] for x i...
0
2016-07-27T12:05:14Z
[ "python", "generator", "list-comprehension" ]
Create dict with key/value and key/value reversed
38,612,266
<p>Having such list </p> <p><code>example = ['ab', 'cd']</code></p> <p>I need to get <code>{'a': 'b', 'b': 'a', 'c': 'd', 'd': 'c'}</code></p> <p>With regular loop I could do this like:</p> <pre><code>result = {} for i,j in example: result[i] = j result[j] = i </code></pre> <p>Question: How can I do the sa...
3
2016-07-27T11:56:29Z
38,612,576
<p>Another possible solution:</p> <pre><code>dict(example + [s[::-1] for s in example]) </code></pre> <p><code>[s[::-1] for s in example]</code> <a class='doc-link' href="http://stackoverflow.com/documentation/python/196/comprehensions/737/list-comprehensions">creates a new list with all strings reversed</a>. <code>e...
2
2016-07-27T12:10:56Z
[ "python", "generator", "list-comprehension" ]
Create dict with key/value and key/value reversed
38,612,266
<p>Having such list </p> <p><code>example = ['ab', 'cd']</code></p> <p>I need to get <code>{'a': 'b', 'b': 'a', 'c': 'd', 'd': 'c'}</code></p> <p>With regular loop I could do this like:</p> <pre><code>result = {} for i,j in example: result[i] = j result[j] = i </code></pre> <p>Question: How can I do the sa...
3
2016-07-27T11:56:29Z
38,612,610
<p>You can use <code>;</code> to seperate logical lines</p> <pre><code>result=dict(example); result.update((k,v) for v,k in example) </code></pre> <p>But of course </p> <pre><code>result=dict(example+map(reversed,example)) # only in python 2.x </code></pre> <p>or</p> <pre><code>result=dict([(k,v) for k,v in exampl...
0
2016-07-27T12:12:18Z
[ "python", "generator", "list-comprehension" ]
Create dict with key/value and key/value reversed
38,612,266
<p>Having such list </p> <p><code>example = ['ab', 'cd']</code></p> <p>I need to get <code>{'a': 'b', 'b': 'a', 'c': 'd', 'd': 'c'}</code></p> <p>With regular loop I could do this like:</p> <pre><code>result = {} for i,j in example: result[i] = j result[j] = i </code></pre> <p>Question: How can I do the sa...
3
2016-07-27T11:56:29Z
38,613,093
<pre><code>example = ['ab', 'cd'] res1={x[1]:x[0] for x in example} res2={x[0]:x[1] for x in example} res=res1.update(res2) print res1 </code></pre>
0
2016-07-27T12:32:29Z
[ "python", "generator", "list-comprehension" ]
How to create Temporary Security Credentials on AWS
38,612,442
<p>I'm trying to use <code>Apache Libcloud</code> <a href="https://libcloud.apache.org/index.html" rel="nofollow">(Web)</a> and reading the <a href="http://libcloud.readthedocs.io/en/latest/compute/drivers/ec2.html" rel="nofollow">Documentation</a> of how to use it with Amazon EC2 I'm stuck on a step at the beginning.<...
0
2016-07-27T12:04:22Z
38,620,051
<p>If this code does not run on an EC2 instance I suggest you go with static credentials:</p> <pre><code>ACCESS_ID = 'your access id' SECRET_KEY = 'your secret key' cls = get_driver(Provider.EC2) driver = cls(ACCESS_ID, SECRET_KEY, region="us-west-1") </code></pre> <p>to create access credentials:</p> <ol> <li>Sign...
1
2016-07-27T17:55:49Z
[ "python", "amazon-web-services", "amazon-ec2", "libcloud" ]
Pyplot "cannot connect to X server localhost:10.0" despite ioff() and matplotlib.use('Agg')
38,612,473
<p>I have a piece of code which gets called by a different function, carries out some calculations for me and then plots the output to a file. Seeing as the whole script can take a while to run for larger datasets and since I may want to analyse multiple datasets at a given time I start it in <code>screen</code> then d...
1
2016-07-27T12:06:10Z
38,618,012
<p>The calling function calls other functions too which also use matplotlib. These get called only after this one but during the <code>import</code> statement their dependecies get loaded. Seeing as they were loaded first they disabled the subsequent <code>matplotlib.use('Agg')</code> declaration. Moving that declarati...
0
2016-07-27T16:00:50Z
[ "python", "matplotlib", "x11", "x11-forwarding" ]
Nested Try in While loop
38,612,496
<p>Can someone help me?</p> <p>I've a problem with a nested try statement inside a while statement. The code looks like this:</p> <pre><code>number = raw_input("what is the number? ") if number &lt; 11: Print "that is good!" else: print "your number had to be lower then 11" raw_input("kies een getal: ") whi...
-2
2016-07-27T12:07:21Z
38,612,571
<p><code>raw_input</code> returns a string. You don't want that.</p> <p>Most of your code doesn't make sense. Here's what I <em>assume</em> you want to do:</p> <ul> <li><p>Take input from a user.</p></li> <li><p>If the input can be converted to a number, convert it and continue. Otherwise, keep asking for input.</p><...
3
2016-07-27T12:10:44Z
[ "python", "python-2.7" ]
Nested Try in While loop
38,612,496
<p>Can someone help me?</p> <p>I've a problem with a nested try statement inside a while statement. The code looks like this:</p> <pre><code>number = raw_input("what is the number? ") if number &lt; 11: Print "that is good!" else: print "your number had to be lower then 11" raw_input("kies een getal: ") whi...
-2
2016-07-27T12:07:21Z
38,612,676
<p>What's the purpose of that script? Two of the raw_input commands are not being stored in any variable and the value of 'number' doesn't change within your loop, so it would run forever until you stop it with Ctrl+C.</p> <p>If the loop is not executed, that's because the condition number &lt; 11 is not met in the fi...
0
2016-07-27T12:15:09Z
[ "python", "python-2.7" ]
How to run a Python script without Windows console appearing
38,612,509
<p>Is there any way to run a Python script without a command shell momentarily appearing? Naming my files with the ".pyw" extension doesn't work.</p> <p>EDIT: problem solved with ShellExecute()</p>
0
2016-07-27T12:07:47Z
38,612,596
<p>Try using the Python's <code>pythonw.exe</code> executable to start your script.</p> <p>In Windows OSes, executables that are <em>console applications</em> (<code>python.exe</code> with out the <code>w</code> is a console app) are run showing a console window; in the other hand regular Windows applications do not s...
1
2016-07-27T12:11:47Z
[ "python", "windows" ]
How to run a Python script without Windows console appearing
38,612,509
<p>Is there any way to run a Python script without a command shell momentarily appearing? Naming my files with the ".pyw" extension doesn't work.</p> <p>EDIT: problem solved with ShellExecute()</p>
0
2016-07-27T12:07:47Z
38,612,723
<p>This info from another post may help: <a href="http://stackoverflow.com/a/30313091/6470259">http://stackoverflow.com/a/30313091/6470259</a></p> <ul> <li><p><strong><code>python.exe</code></strong> is a console (terminal) application <strong>for launching CLI-type scripts</strong>.</p> <ul> <li>Unless run from an ...
-1
2016-07-27T12:16:55Z
[ "python", "windows" ]
How to run a Python script without Windows console appearing
38,612,509
<p>Is there any way to run a Python script without a command shell momentarily appearing? Naming my files with the ".pyw" extension doesn't work.</p> <p>EDIT: problem solved with ShellExecute()</p>
0
2016-07-27T12:07:47Z
38,612,907
<p>In all python installs since 2.5 (and possibly earlier), if the install has been done properly, <code>.py</code> files are associated to <code>python.exe</code> and <code>.pyw</code> files are associated to <code>pythonw.exe</code></p> <p>If the associations have been tampered with, or overridden for a particular u...
0
2016-07-27T12:24:55Z
[ "python", "windows" ]
Angular code not playing nice with my python django application
38,612,655
<p>For some reason I can't get my angular code to play nice with my python django application. When I submit the page it saves all null values in my db and my get response isn't working correctly either because nothing is returned. Any help will be greatly appreciated, I also included screen shots for a better picture ...
2
2016-07-27T12:14:21Z
38,613,139
<p>As your network tab screenshot shows, you're sending JSON, not form-encoded data. So in Django you need to use <code>json.loads(request.body)</code> to get the data as a dict, rather than accessing <code>request.POST</code> which will always be empty.</p> <p>Note that if you're doing something like this, you should...
2
2016-07-27T12:34:17Z
[ "python", "angularjs", "django" ]
Suggestions to make website fast by breaking a request in two parts
38,612,836
<p>I am trying to speed up my website. So at the moment, controller fetches data from database, do calculation on data and display on view. what I plan to do is, controller/action fetches half the data and display to the view. Than come back to different controller/action and do calculation on data and display data on...
0
2016-07-27T12:21:53Z
38,612,965
<p>Why don't you use ajax function , post data to the server and when proccess to the server is done display the result to the html page </p>
2
2016-07-27T12:27:31Z
[ "python", "performance", "model-view-controller", "pyramid" ]
Scikit-image: why major axis length is zero with multiple objects?
38,612,909
<p>An image with multiple objects is labelled like this:</p> <pre><code>image= [[ 1 0 0 0 2 2 0 3 3 3 3] [ 3 0 0 0 0 0 0 0 4 4 4] [ 4 0 5 5 0 0 0 0 6 6 6] [ 6 0 0 0 0 0 0 0 0 7 7] [ 7 0 0 0 0 0 0 0 0 8 8] [ 0 0 0 0 0 0 0 9 9 9 9] [ 9 0 0 0 0 0 10 1...
0
2016-07-27T12:25:09Z
38,614,181
<p>One can read in the <a href="http://scikit-image.org/docs/dev/api/skimage.measure.html?highlight=label#skimage.measure.regionprops" rel="nofollow"><code>regionprops</code></a> documentation:</p> <blockquote> <p><strong>Returns:</strong> &nbsp;&nbsp;&nbsp; <strong>properties</strong> : list of RegionProperties<br>...
2
2016-07-27T13:19:44Z
[ "python", "for-loop", "image-processing", "scikit-image" ]
Can not authenticate using Django and ldap
38,612,960
<p>I am using a simple form which takes an username and a password and tries to use a ldap server to authenticate that user. The actual portal of the dashboard is written in php, but I have to rewrite it using django (and pyldap). In my settings.py file, I have the following set up (I modified the URI since is used by ...
1
2016-07-27T12:27:20Z
38,616,462
<p>Finnaly, I manage to do it. I had to set this variable:</p> <pre><code>AUTH_LDAP_USER_DN_TEMPLATE = "%(user)s" </code></pre> <p>and now it's working perfectly. I hope this will maybe help the others. Thanks anyway!</p> <p>Have a good day!</p>
0
2016-07-27T14:52:46Z
[ "php", "python", "django", "authentication", "ldap" ]
start pandas dataframe index from specified number
38,612,968
<p>Rather than having a pandas dataframe index starting at 0, how to start from a specified number i.e. 120. My naive approach uses <code>len(df.index)</code> to get row count, then using that to generate a list of sequential numbers which is then attached to the dataframe and set to index. Any better way to just start...
0
2016-07-27T12:27:42Z
38,613,022
<p>You can construct the dataframe with an index parameter. IE:</p> <pre><code>df = DataFrame(columns=['a','b','c'], index=[1,2,3], data) </code></pre>
0
2016-07-27T12:29:53Z
[ "python", "pandas" ]
start pandas dataframe index from specified number
38,612,968
<p>Rather than having a pandas dataframe index starting at 0, how to start from a specified number i.e. 120. My naive approach uses <code>len(df.index)</code> to get row count, then using that to generate a list of sequential numbers which is then attached to the dataframe and set to index. Any better way to just start...
0
2016-07-27T12:27:42Z
38,613,060
<p>You have to overwrite the <code>IndexArray</code> object directly, you can use <code>np.arange</code> or <code>pd.RangeIndex</code> to do this:</p> <pre><code>In [109]: df = pd.DataFrame(np.random.randn(5,3), columns=list('abc')) df Out[109]: a b c 0 -0.743707 -0.579372 -0.559999 1 0.902...
0
2016-07-27T12:31:03Z
[ "python", "pandas" ]
start pandas dataframe index from specified number
38,612,968
<p>Rather than having a pandas dataframe index starting at 0, how to start from a specified number i.e. 120. My naive approach uses <code>len(df.index)</code> to get row count, then using that to generate a list of sequential numbers which is then attached to the dataframe and set to index. Any better way to just start...
0
2016-07-27T12:27:42Z
38,613,320
<p>this works and its easy :</p> <pre><code> df.index +=120 </code></pre>
1
2016-07-27T12:42:37Z
[ "python", "pandas" ]
Pandas: checking if a string contains at least two words from a list
38,613,043
<p>I am using the fast, vectorized <code>str.contains</code> method in <code>Pandas</code> to check whether each row in my dataframe contains <strong>at least one word</strong> from my <code>list_word</code>. </p> <pre><code>list_words='foo ber haa' df = pd.DataFrame({'A' : ['foo foor', 'bar bar', 'foo hoo', 'bar haa...
1
2016-07-27T12:30:34Z
38,613,324
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a> with <code>list comprehension</code>:</p> <pre><code>#changed ber to bar list_words='foo bar haa' df = pd.DataFrame({'A' : ['foo foor', 'bar bar', 'foo hoo', 'bar haa', ...
2
2016-07-27T12:42:48Z
[ "python", "pandas" ]
Pandas: checking if a string contains at least two words from a list
38,613,043
<p>I am using the fast, vectorized <code>str.contains</code> method in <code>Pandas</code> to check whether each row in my dataframe contains <strong>at least one word</strong> from my <code>list_word</code>. </p> <pre><code>list_words='foo ber haa' df = pd.DataFrame({'A' : ['foo foor', 'bar bar', 'foo hoo', 'bar haa...
1
2016-07-27T12:30:34Z
38,613,931
<p>Assuming that <code>ber</code> should be <code>bar</code>, you can use <code>.apply</code> with sets - note this does <em>whole words</em> - not substrings (eg <code>foo</code> won't be found in <code>foor</code>)...</p> <pre><code>import pandas as pd list_words='foo bar haa' set_words = set(list_words.split()) d...
2
2016-07-27T13:09:05Z
[ "python", "pandas" ]
Pandas: checking if a string contains at least two words from a list
38,613,043
<p>I am using the fast, vectorized <code>str.contains</code> method in <code>Pandas</code> to check whether each row in my dataframe contains <strong>at least one word</strong> from my <code>list_word</code>. </p> <pre><code>list_words='foo ber haa' df = pd.DataFrame({'A' : ['foo foor', 'bar bar', 'foo hoo', 'bar haa...
1
2016-07-27T12:30:34Z
38,614,290
<p>I am a beginner with pandas (and python in general) so wanted to try it as a challenge rather than getting upvotes :). Just used the techniques I know but they significantly slower than those proposed by others.</p> <pre><code>def check(row, string): #tokenize string string_list = string.split() #token...
1
2016-07-27T13:24:54Z
[ "python", "pandas" ]
How to upgrade pip3?
38,613,316
<p>I want to use python3.5 to develop basically,but many times when i install the module for the python3.5,it always failed.And the termimal told me that higher version is available,it did not work when I upgrade it. <img src="http://i.stack.imgur.com/75IDN.png" alt="enter image description here"></p>
0
2016-07-27T12:42:32Z
38,613,503
<p>You are using pip3 to install flask-script which is associated with python 3.5. However, you are trying to upgrade pip associated with the python 2.7, try running <code>pip3 install --upgrade pip</code>.</p> <p>It might be a good idea to take some time and read about virtual environments in Python. It isn't a best ...
0
2016-07-27T12:50:39Z
[ "python", "linux", "python-3.x" ]
Python: Read value from code in a website
38,613,466
<p>I have a problem i first thought many would experience, but i couldn't find any similar questions. The language i'm using is <strong>Python</strong>.</p> <p>I want to read a specific value from a website, which is embedded in another code behind. I first thought <a href="http://stackoverflow.com/questions/19175180/...
-1
2016-07-27T12:49:07Z
38,614,014
<p>The data on the page comes from an XHR loaded json blob, which it is possible to query directly.</p> <pre><code>&gt;&gt;&gt; import requests &gt;&gt;&gt; import pprint &gt;&gt;&gt; r = requests.get('http://ether.price.exchange/update') &gt;&gt;&gt; pprint.pprint(r.json()) {u'AUD': {u'15m': 873.83, u'buy':...
1
2016-07-27T13:12:47Z
[ "python", "html", "url" ]
Python: Read value from code in a website
38,613,466
<p>I have a problem i first thought many would experience, but i couldn't find any similar questions. The language i'm using is <strong>Python</strong>.</p> <p>I want to read a specific value from a website, which is embedded in another code behind. I first thought <a href="http://stackoverflow.com/questions/19175180/...
-1
2016-07-27T12:49:07Z
38,618,148
<p>I was able to get the value from another webpage. The code looks like this:</p> <p><code>def get_current_value(): chrome_path = r"C:\Users\Chris\Desktop\Chrome_driver\chromedriver.exe" driver = webdriver.Chrome(chrome_path) driver.get("https://cryptowatch.de/kraken/etheur") a = driver.find_element_b...
0
2016-07-27T16:06:50Z
[ "python", "html", "url" ]
EXE with MatplotLib Crashes
38,613,476
<p>I'm developing an application using Python 3.4 and PyQt4 with LiClipse as the IDE and have an issue with plotting graphs closing the entire program with no error after I've compiled the program into an executable. I've pin-pointed the problem area and know that calling matplotlib.figure.Figure() is the crash culpri...
0
2016-07-27T12:49:39Z
38,663,420
<p>My troubleshooting found numpy.core to be the culprit of my issue. I re-installed numpy and the executable runs properly now.</p>
0
2016-07-29T16:22:50Z
[ "python", "matplotlib", "py2exe" ]
Prepare Data Frames to be compared. Index manipulation, datetime and beyond
38,613,514
<p>Ok, this is a question in two steps. </p> <p><strong>Step one:</strong> I have a pandas DataFrame like this:</p> <pre><code> date time value 0 20100201 0 12 1 20100201 6 22 2 20100201 12 45 3 20100201 18 13 4 20100202 0 54...
0
2016-07-27T12:50:59Z
38,615,165
<p><strong>Step 1 Answer</strong></p> <pre><code>df['DateTime'] = (df['date'].astype(str) + ' ' + df['time'].astype(str) +':'+'00'+':'+'00').apply(lambda x: pd.to_datetime(str(x))) df.set_index('DateTime', drop=True, append=False, inplace=True, verify_integrity=False) df.drop(['date', 'time'], axis=1, level=None, in...
1
2016-07-27T14:01:12Z
[ "python", "datetime", "pandas" ]
How can I create many columns after a list in pandas?
38,613,517
<p>I have a dataframe, I want to create a lot of new columns after a list and filled with <code>0</code>, how can I do it?</p> <p>For example: </p> <pre><code>df = pd.DataFrame({"a":["computer", "printer"]}) print(df) &gt;&gt;&gt; a &gt;&gt;&gt;0 computer &gt;&gt;&gt;1 printer </code></pre> <p>I have a l...
1
2016-07-27T12:51:10Z
38,613,551
<p>Use fastest solution:</p> <pre><code>for col in myList: df[col] = 0 print(df) a b c d 0 computer 0 0 0 1 printer 0 0 0 </code></pre> <p>Another solution is use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a> with <...
1
2016-07-27T12:52:35Z
[ "python", "pandas", "dataframe", "append", "multiple-columns" ]
How can I create many columns after a list in pandas?
38,613,517
<p>I have a dataframe, I want to create a lot of new columns after a list and filled with <code>0</code>, how can I do it?</p> <p>For example: </p> <pre><code>df = pd.DataFrame({"a":["computer", "printer"]}) print(df) &gt;&gt;&gt; a &gt;&gt;&gt;0 computer &gt;&gt;&gt;1 printer </code></pre> <p>I have a l...
1
2016-07-27T12:51:10Z
38,613,640
<p>It'll be more performant to <code>concat</code> an empty df for large dfs rather than incrementally adding new columns as this will grow the df incrementally rather than just make a single allocation of the final df dimensions:</p> <pre><code>In [116]: myList=["b","c","d"] df = pd.concat([df,pd.DataFrame(columns=my...
1
2016-07-27T12:56:40Z
[ "python", "pandas", "dataframe", "append", "multiple-columns" ]
Send large email via Gmail API in Python
38,613,797
<p>Recently Google disabled their "legacy" upload capability, so I was forced to change our applications to use the Google users().messages().send api.</p> <p>However it doesn't work on anything over 5mb. I've seen one post on the www about how to do it in PHP, but nothing in Python.</p> <p>Here's my existing code:</...
1
2016-07-27T13:03:51Z
38,636,747
<p>I had the same issue <a href="http://stackoverflow.com/questions/24908700/mail-attachment-wrong-media-type-gmail-api/24957873#24957873">two years ago</a>, and I still think the only way to send messages with large attachments is to circumvent the official client library.</p> <p>This is an example using the <a href=...
0
2016-07-28T12:44:20Z
[ "python", "gmail", "gmail-api" ]
Can we include partial css files into a template file?
38,613,812
<p>I intend to create a main page in a modular way. The main page might have a header, a footer, and a main section, I'd like to keep the markup and the css that is specific to each of those sections separate. So that if I need those sections on other pages, I can just include the files.</p> <p>So I need to be able to...
1
2016-07-27T13:04:28Z
38,613,983
<p>You shouldn't define multiple head sections in HTML. But there's no need to; you should use template inheritance and blocks just like you do with any other element. You shouldn't really be using <code>include</code> here at all; inheritance is much more powerful.</p> <p>So, base.html looks like this:</p> <pre><cod...
2
2016-07-27T13:11:12Z
[ "python", "html", "css", "django", "django-templates" ]
Can we include partial css files into a template file?
38,613,812
<p>I intend to create a main page in a modular way. The main page might have a header, a footer, and a main section, I'd like to keep the markup and the css that is specific to each of those sections separate. So that if I need those sections on other pages, I can just include the files.</p> <p>So I need to be able to...
1
2016-07-27T13:04:28Z
38,614,095
<p>The first problem, it not correct to pu <code>head</code> into <code>body</code>. It make so as your <code>main.html</code> is not a separate html file but the part of <code>base.html</code>. The second is it is not such easy to include another file if you need to once in a future.</p> <p>I make such thing in sligh...
0
2016-07-27T13:16:28Z
[ "python", "html", "css", "django", "django-templates" ]
python popen pipe in loop
38,613,964
<p>I'm trying to write a function to create a shell pipeline in a loop that gets its command parameters from a list and pipes the last stdout to the new stdin. At the and of the command list, I want to call the communicate method on the Popen object to get the output.</p> <p>The output is always empty. What am I doing...
0
2016-07-27T13:10:28Z
38,616,831
<p>The problem is with grep %SESSIONNAME%. When you execute same thing on commandline, the %SESSIONNAME% is actually getting replaced by "Console". But when executed in python script, it is not getting replaced. It is trying to find exact %SESSIONNAME% which is not present. That's why output is blank.</p> <p>Below is ...
0
2016-07-27T15:06:57Z
[ "python", "python-2.7", "subprocess", "popen" ]
Download only part of genbank file with biopython
38,614,031
<p>I am new to Biopython and I have a performance issue when parsing genbank files.</p> <p>I have to parse a lot of gb files, from which I have the accession numbers. After parsing, I only want to examine the taxonomy and the organelle of the file. Right now, I have this code:</p> <pre><code>from Bio import SeqIO fro...
1
2016-07-27T13:13:25Z
38,624,674
<p>You can use <a href="http://www.ncbi.nlm.nih.gov/books/NBK25499/" rel="nofollow">seq_start and seq_stop</a> to truncate your sequence and then parse it as before, e.g.</p> <pre><code>gb_acc1 = Entrez.efetch(db='nuccore', id=access1, rettype='gb', retmode='xml', seq_start=1, seq_stop=1) </code></pre> <p>Perhaps you...
1
2016-07-27T23:14:10Z
[ "python", "parsing", "biopython", "genbank" ]