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 searching through columns
40,008,998
<p>I have a CSV file that I need to loop through in a specific pattern for specific columns and have the output patterns be stored in new files with the same name + "_pattern" + [1,2,3,etc.] + .csv.</p> <p>This is the search pattern: Loop through column 1 and find the same # and grab them, then loop through column 2 o...
3
2016-10-12T21:53:05Z
40,110,795
<p>As you loop over your files you need to keep a record of which patterns are not eligible for saving. You could use a <code>set</code> for this purpose. To group your entries in each file you could use <code>itertools.groupby</code>. Using your example:</p> <pre class="lang-python prettyprint-override"><code>import ...
0
2016-10-18T14:21:19Z
[ "python", "loops", "csv" ]
Python searching through columns
40,008,998
<p>I have a CSV file that I need to loop through in a specific pattern for specific columns and have the output patterns be stored in new files with the same name + "_pattern" + [1,2,3,etc.] + .csv.</p> <p>This is the search pattern: Loop through column 1 and find the same # and grab them, then loop through column 2 o...
3
2016-10-12T21:53:05Z
40,111,537
<p>The following should do what you need. It reads a csv file in and generates a matching <code>datetime</code> for each of the entries to allow them to be correctly sorted. It creates output csv files based on the pattern number with the entries sorted by date. Column 4 entries already seen are omitted:</p> <pre><cod...
0
2016-10-18T14:52:46Z
[ "python", "loops", "csv" ]
Finding index by iterating over each row of matrix
40,009,008
<p>I have an numpy array 'A' of size <code>5000x10</code>. I also have another number <code>'Num'</code>. I want to apply the following to each row of A:</p> <pre><code>import numpy as np np.max(np.where(Num &gt; A[0,:])) </code></pre> <p>Is there a pythonic way than writing a for loop for above.</p>
1
2016-10-12T21:54:09Z
40,009,044
<p>You could use <code>argmax</code> -</p> <pre><code>A.shape[1] - 1 - (Num &gt; A)[:,::-1].argmax(1) </code></pre> <p>Alternatively with <code>cumsum</code> and <code>argmax</code> -</p> <pre><code>(Num &gt; A).cumsum(1).argmax(1) </code></pre> <p><strong>Explanation :</strong> With <code>np.max(np.where(..)</code...
2
2016-10-12T21:56:59Z
[ "python", "numpy", "vectorization" ]
Ho to use if Function?
40,009,011
<p>I have been making a text-based RPG in python 3.5. I had it fine (or so i thought...) until i tried to say that no I did not want to play. And also when I wanted to make the option to run from Mobs, but instead it combines both if functions, and says the amount of damage AND that you 'Ran away.' I tried to switch ar...
-3
2016-10-12T21:54:16Z
40,009,033
<pre><code> if choice_attack_3 == 'A'or choice_attack_3 == 'a': Demon_attack() elif choice_attack_3 == 'R' or choice_attack_3 == 'r': print('You run away!') time.sleep (2) battle_start() </code></pre> <p>You need to add choice_attac...
0
2016-10-12T21:56:10Z
[ "python" ]
Ho to use if Function?
40,009,011
<p>I have been making a text-based RPG in python 3.5. I had it fine (or so i thought...) until i tried to say that no I did not want to play. And also when I wanted to make the option to run from Mobs, but instead it combines both if functions, and says the amount of damage AND that you 'Ran away.' I tried to switch ar...
-3
2016-10-12T21:54:16Z
40,009,116
<p>This is a very poor question, but is a result of you not understanding boolean logic rather than if statements.</p> <pre><code>If choice == "Y" or "y": </code></pre> <p>is always true. That expands to </p> <pre><code>If choice == "Y" or If "y": </code></pre> <p>you either need to do a case insensitive comparison...
1
2016-10-12T22:03:06Z
[ "python" ]
How is python storing strings so that the 'is' operator works on literals?
40,009,015
<p>In python </p> <pre><code>&gt;&gt;&gt; a = 5 &gt;&gt;&gt; a is 5 True </code></pre> <p>but </p> <pre><code>&gt;&gt;&gt; a = 500 &gt;&gt;&gt; a is 500 False </code></pre> <p>This is because it stores low integers as a single address. But once the numbers begin to be complex, each int gets its own unique address s...
5
2016-10-12T21:54:26Z
40,009,138
<p>It's an optimisation technique called interning. CPython recognises the <a href="https://github.com/python/cpython/blob/c21f17c6e9d3218812b593f6ec5647e91c16896b/Objects/codeobject.c#L59" rel="nofollow">equal values of <strong>string constants</strong></a> and doesn't allocate extra memory for new instances but simpl...
3
2016-10-12T22:04:21Z
[ "python", "string" ]
How is python storing strings so that the 'is' operator works on literals?
40,009,015
<p>In python </p> <pre><code>&gt;&gt;&gt; a = 5 &gt;&gt;&gt; a is 5 True </code></pre> <p>but </p> <pre><code>&gt;&gt;&gt; a = 500 &gt;&gt;&gt; a is 500 False </code></pre> <p>This is because it stores low integers as a single address. But once the numbers begin to be complex, each int gets its own unique address s...
5
2016-10-12T21:54:26Z
40,009,292
<p>It doesn't store an array of all possible strings, instead it has a hash table which point to memory addresses of all currently declared strings, indexed by the hash of the string.</p> <p>For example</p> <p>when you say <code>a = 'foo'</code>, it first hashes the string <code>foo</code> and checks if an entry alre...
0
2016-10-12T22:18:14Z
[ "python", "string" ]
Convert decimal separator
40,009,017
<p>I'm loading a CSV where decimal value separator is <code>,</code> and I would like to replace it by <code>.</code> in order to proceed the analysis.</p> <p>I see the <code>converters</code> option in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">pandas.read_csv<...
1
2016-10-12T21:54:42Z
40,009,079
<p>You don't have to provide all the column names to <code>converter</code>. </p> <p>Give only those columns you want to convert </p> <p>It would be <code>converter = {'col_name':lambda x : str(x).replace(',','.')}</code></p> <p><b>EDIT</b> after rewording question.</p> <p>Is this the best way to do it?</p> <p>I w...
0
2016-10-12T21:59:42Z
[ "python", "python-2.7", "pandas", "dataframe" ]
Convert decimal separator
40,009,017
<p>I'm loading a CSV where decimal value separator is <code>,</code> and I would like to replace it by <code>.</code> in order to proceed the analysis.</p> <p>I see the <code>converters</code> option in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">pandas.read_csv<...
1
2016-10-12T21:54:42Z
40,009,131
<p>there is no need to specify <em>all</em> the column converters, but only the ones you need. Given</p> <pre><code>id;name;value 0;asd;1,2 1;spam;1,5 2;lol;10,5 </code></pre> <p>for example:</p> <pre><code>import pandas as pd df = pd.read_csv('asd', sep=';', converters={'value': lambda x: float(x.replace(',', '.')...
0
2016-10-12T22:03:51Z
[ "python", "python-2.7", "pandas", "dataframe" ]
Convert decimal separator
40,009,017
<p>I'm loading a CSV where decimal value separator is <code>,</code> and I would like to replace it by <code>.</code> in order to proceed the analysis.</p> <p>I see the <code>converters</code> option in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">pandas.read_csv<...
1
2016-10-12T21:54:42Z
40,009,329
<p>You can use the <code>decimal</code> parameter of <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a>:</p> <pre><code>df = pd.read_csv(file.csv, decimal=',') </code></pre>
3
2016-10-12T22:20:48Z
[ "python", "python-2.7", "pandas", "dataframe" ]
extract files inside zip sub folders with python zipfile
40,009,022
<p>i have a zip folder that contains files and child zip folders. I am able to read the files placed in the parent folder but how can i get to the files inside the child zip folders? here is my code to get the files inside the parent folder</p> <pre><code>from io import BytesIO import pandas as pd import requests impo...
-1
2016-10-12T21:55:04Z
40,009,399
<p>Use another <code>BytesIO</code> object to open the contained zipfile</p> <pre><code>from io import BytesIO import pandas as pd import requests import zipfile # Read outer zip file url1 = 'https://www.someurl.com/abc.zip' r = requests.get(url1) z = zipfile.ZipFile(BytesIO(r.content)) # lets say the archive is: # ...
0
2016-10-12T22:28:19Z
[ "python", "pandas", "zipfile" ]
extract files inside zip sub folders with python zipfile
40,009,022
<p>i have a zip folder that contains files and child zip folders. I am able to read the files placed in the parent folder but how can i get to the files inside the child zip folders? here is my code to get the files inside the parent folder</p> <pre><code>from io import BytesIO import pandas as pd import requests impo...
-1
2016-10-12T21:55:04Z
40,029,280
<p>After trying some permutation-combination, i hatched the problem with this code</p> <pre><code>zz = zipfile.ZipFile(z.namelist()[i]) temp2 = pd.read_csv(zz.open('pqr.csv')) # where i is the index position of the child zip folder in the namelist() list. In this case, the 'xyz.zip' folder # for eg if the 'xyz.zip' ...
0
2016-10-13T19:22:04Z
[ "python", "pandas", "zipfile" ]
Serving Excel 2007 file generated by Python
40,009,088
<p>I am looking to generate an Excel workbook based on the input from users in an HTML form. After the form is submitted, a Python script will generate the file and send it to the user. I am using xlsxwriter to create the spreadsheet. </p> <p>I have been able to create a sample file and then provide a link to it, but ...
1
2016-10-12T22:00:26Z
40,044,389
<p>I continued searching after I posted my question and found the answer <a href="http://stackoverflow.com/questions/2374427/python-2-x-write-binary-output-to-stdout">here</a></p>
1
2016-10-14T13:28:19Z
[ "python", "python-2.7", "mime-types", "xlsxwriter" ]
How to plot two different graphs in python
40,009,106
<p>I want to get two lines in the same graph.</p> <p>This is my code: </p> <pre><code> x=sorted(true_strain) y=sorted(true_stress_1) plt.plot(x,y) plt.title('$Tensile Stress-Strain Curve$') plt.xlabel('True Strain [-]') plt.ylabel('$True Stress (MPa)$') a=(true_stress_2) b=sorted(true_s...
1
2016-10-12T22:01:41Z
40,009,145
<p>you haven't actually called plt.show(), try adding it at the bottom.</p> <pre><code>x=sorted(true_strain) y=sorted(true_stress_1) plt.plot(x,y) plt.title('$Tensile Stress-Strain Curve$') plt.xlabel('True Strain [-]') plt.ylabel('$True Stress (MPa)$') a=(true_stress_2) b=sorted(true_strain) plt.plot(a,b) plt.show() ...
0
2016-10-12T22:04:51Z
[ "python" ]
Error with Speaker Recognition API: "Resource or path can't be found."
40,009,127
<p>I'm trying to run the enroll profile code of speaker recognition API using Jupyter Python.</p> <p>Unfortunately, I am getting an error:</p> <pre><code>{ "error": { "code": "NotFound", "message": "Resource or path can't be found." } } </code></pre> <p>Here is the code:</p> <pre><code>#Loading .wav file w ...
0
2016-10-12T22:03:29Z
40,024,245
<p>identificationProfileId is part of the URL path, not a query parameter. You should do the following instead:</p> <pre><code>params = urllib.urlencode({ # Request parameters 'shortAudio': 'true', }) ... conn.request("POST", "/spid/v1.0/identificationProfiles/{0}/enroll?{1}".format(user1, params)...
0
2016-10-13T14:46:11Z
[ "python", "python-2.7", "microsoft-cognitive" ]
Install SCIP solver on Python3.5 Numberjack (OSX)
40,009,141
<p>I am learning Constraint Programming in Python and, for the solving of the problems, I am supposed to use the SCIP solver. I have installed the Numberjack standard package from Github witch includes Mistral, Mistral2, Toulbar2, MipWrapper, SatWrapper, MiniSat and Walksat solvers.</p> <p>Running my code I got the fo...
0
2016-10-12T22:04:41Z
40,013,421
<p>Why is there a <code>scip-3.2.1</code> directory? The SCIP Opt Suite 3.1.0 contains SCIP 3.1.0. You need to make sure to run all setup and make commands <em>exactly</em> as stated on the <a href="https://github.com/eomahony/Numberjack#scip" rel="nofollow">Numberjack install page</a>.</p>
1
2016-10-13T06:04:02Z
[ "python", "python-3.x", "jupyter-notebook", "solver", "scip" ]
Install SCIP solver on Python3.5 Numberjack (OSX)
40,009,141
<p>I am learning Constraint Programming in Python and, for the solving of the problems, I am supposed to use the SCIP solver. I have installed the Numberjack standard package from Github witch includes Mistral, Mistral2, Toulbar2, MipWrapper, SatWrapper, MiniSat and Walksat solvers.</p> <p>Running my code I got the fo...
0
2016-10-12T22:04:41Z
40,047,557
<p>After talking to the assistant teacher I got the answer for this problem.</p> <p>The folder where Numberjack/SCIP was being installed was not the one it was supposed to be, therefore it was not really included in the solver list. After completing the <code>python setup.py build</code> and <code>python setup.py inst...
0
2016-10-14T16:04:49Z
[ "python", "python-3.x", "jupyter-notebook", "solver", "scip" ]
How to Catch a 503 Error and retry request
40,009,167
<p>I'm using <code>grequests</code> to make about 10,000 calls, but some of these calls return as <code>503</code>. This problem goes away if I don't queue all 10,000 calls at once. Breaking it into groups of 1000 seems to do the trick. However I was wondering if there's a way to catch this <code>503</code> error and j...
1
2016-10-12T22:07:21Z
40,010,389
<p>Maybe you can try using event hooks to catch the error and re-launch the requests <a href="http://docs.python-requests.org/en/master/user/advanced/#event-hooks" rel="nofollow">http://docs.python-requests.org/en/master/user/advanced/#event-hooks</a></p> <pre><code> import grequests def response_handler(response): ...
1
2016-10-13T00:22:35Z
[ "python", "python-requests", "grequests" ]
Python threading with strange output errors
40,009,172
<p>I am new to threading in general and have been playing around with different ideas to get my feet under me. However, I came across something I am not sure how to explain. Here is the code:</p> <pre><code>import threading, datetime class ThreadClass(threading.Thread): def run(self): for _ in range(3): ...
2
2016-10-12T22:07:45Z
40,009,259
<p>You're looking for the <a href="https://docs.python.org/2/library/logging.html" rel="nofollow">logging</a> module:</p> <blockquote> <p>15.7.9. Thread Safety</p> <p>The logging module is intended to be thread-safe without any special work needing to be done by its clients. It achieves this though using thread...
1
2016-10-12T22:16:02Z
[ "python", "multithreading" ]
Python threading with strange output errors
40,009,172
<p>I am new to threading in general and have been playing around with different ideas to get my feet under me. However, I came across something I am not sure how to explain. Here is the code:</p> <pre><code>import threading, datetime class ThreadClass(threading.Thread): def run(self): for _ in range(3): ...
2
2016-10-12T22:07:45Z
40,009,378
<p>Complement to Joseph's reply, you can use Semaphore</p> <pre><code>from threading import Semaphore writeLock = Semaphore(value = 1) </code></pre> <p>...</p> <p>When you are about to print in the thread:</p> <pre><code>writeLock.acquire() print ("%s: %s" %(self.getName(), now)) writeLock.release() </code></pre> ...
2
2016-10-12T22:25:33Z
[ "python", "multithreading" ]
Python threading with strange output errors
40,009,172
<p>I am new to threading in general and have been playing around with different ideas to get my feet under me. However, I came across something I am not sure how to explain. Here is the code:</p> <pre><code>import threading, datetime class ThreadClass(threading.Thread): def run(self): for _ in range(3): ...
2
2016-10-12T22:07:45Z
40,009,737
<p>Part of your question is <strong>why</strong> is this occurring? And its a good question as you'll notice in your output there is a completely spurious space that <em>neither of the threads actually tried to print</em></p> <pre><code>Thread-1: 2016-10-12 17:34:23.012802 Thread-2: 2016-10-12 17:34:23.013025 ^ </co...
1
2016-10-12T23:03:13Z
[ "python", "multithreading" ]
Error importing cv2 in python3, Anaconda
40,009,184
<p>I get the following error when importing opencv in python:</p> <pre><code>&gt; python &gt;&gt;&gt; import cv2 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ImportError: /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0: undefined symbol: hb_buffer_set_cluster_level </code></pre> ...
1
2016-10-12T22:09:07Z
40,012,908
<p>Try again by installing </p> <p><code>conda install -c https//conda.binstar.org/menpo opencv3</code></p>
1
2016-10-13T05:25:28Z
[ "python", "python-3.x", "opencv", "anaconda", "opencv3.0" ]
Error importing cv2 in python3, Anaconda
40,009,184
<p>I get the following error when importing opencv in python:</p> <pre><code>&gt; python &gt;&gt;&gt; import cv2 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ImportError: /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0: undefined symbol: hb_buffer_set_cluster_level </code></pre> ...
1
2016-10-12T22:09:07Z
40,077,448
<p>i also had the same issue. I found an answer that may work for you. Try</p> <pre><code>source activate envPython3 conda install -c asmeurer pango python &gt;&gt;&gt; import cv2 </code></pre> <p>Please see this <a href="https://github.com/ContinuumIO/anaconda-issues/issues/368" rel="nofollow">github link</a></p>
0
2016-10-17T01:51:51Z
[ "python", "python-3.x", "opencv", "anaconda", "opencv3.0" ]
python - to extract a specific string
40,009,212
<p>I have a string like : </p> <pre><code> string="(tag, index: develop-AB123-2s), (index: develop-CD123-2s)" </code></pre> <p>I want to extract only "develop-CD123-2s", i.e. the string that comes after "(index:" and not the one with tag. How do I do in python? Thanks!</p>
1
2016-10-12T22:11:46Z
40,009,267
<pre><code>&gt;&gt;&gt; string.split("), (")[1].split(":")[1].split(")")[0].strip() 'develop-CD123-2s' &gt;&gt;&gt; </code></pre> <p>The first split separates each tuple, then split on : and take the second result</p>
1
2016-10-12T22:16:27Z
[ "python" ]
python - to extract a specific string
40,009,212
<p>I have a string like : </p> <pre><code> string="(tag, index: develop-AB123-2s), (index: develop-CD123-2s)" </code></pre> <p>I want to extract only "develop-CD123-2s", i.e. the string that comes after "(index:" and not the one with tag. How do I do in python? Thanks!</p>
1
2016-10-12T22:11:46Z
40,009,287
<p>You could do it like this:</p> <pre><code>string = "(tag, index: develop-AB123-2s), (index: develop-CD123-2s)" string = string.split('(index:') string = string[1].strip(')') print(string) </code></pre> <p>split the string on <code>(index:</code> and strip off the closing curly bracket</p>
1
2016-10-12T22:17:37Z
[ "python" ]
python - to extract a specific string
40,009,212
<p>I have a string like : </p> <pre><code> string="(tag, index: develop-AB123-2s), (index: develop-CD123-2s)" </code></pre> <p>I want to extract only "develop-CD123-2s", i.e. the string that comes after "(index:" and not the one with tag. How do I do in python? Thanks!</p>
1
2016-10-12T22:11:46Z
40,009,289
<p><sup>Warning: I'm not the best at regex</sup></p> <pre><code>import re s='(tag, index: develop-AB123-2s), (index: develop-CD123-2s)' print re.findall("\\(.*?index: ([^)]+)", s)[1] # 'develop-CD123-2s' </code></pre> <p><a href="https://regex101.com/r/zF786N/1" rel="nofollow">Regex Demo</a></p> <p>Alternative rege...
2
2016-10-12T22:18:08Z
[ "python" ]
python - to extract a specific string
40,009,212
<p>I have a string like : </p> <pre><code> string="(tag, index: develop-AB123-2s), (index: develop-CD123-2s)" </code></pre> <p>I want to extract only "develop-CD123-2s", i.e. the string that comes after "(index:" and not the one with tag. How do I do in python? Thanks!</p>
1
2016-10-12T22:11:46Z
40,009,848
<p>One way is using python regex - <a href="https://docs.python.org/2/library/re.html" rel="nofollow">positive lookbehind assertion</a></p> <pre><code>import re string = "(tag, index: develop-AB123-2s), (index: develop-CD123-2s)" re.findall(r"(?&lt;=\(index:) ([^)]+)", string) </code></pre> <p>This pattern only match...
1
2016-10-12T23:16:46Z
[ "python" ]
connecting to a remote server and downloading and extracting binary tar file using python
40,009,230
<p>I would like to connect to a remote server, download and extract binary tar file into a specific directory on that host. I am using python 2.6.8</p> <ol> <li>What would be a simple way to ssh to that server?</li> <li><p>I see the below errors on my script to download the tar file and extract it</p> <p>Traceback (m...
1
2016-10-12T22:14:02Z
40,014,207
<p>There are 2 errors here:</p> <ul> <li><code>urllib.urlretrieve</code> (or <code>urllib.requests.urlretrieve</code> in Python 3) returns a <code>tuple</code>: filename, httprequest. You have to unpack the result in 2 values (or in the original <code>fullfilename</code>)</li> <li>download is OK but the <code>tarfile<...
0
2016-10-13T06:53:34Z
[ "python", "remote-server" ]
Python Higher-Lower program (not higher-lower game)
40,009,358
<p>I'm a 1st year CS student been struggling over the past few days on this lab task I received for python(2.7):</p> <hr> <p>Write a Python script named higher-lower.py which: first reads exactly one integer from standard input (10, in the example below), then reads exactly five more integers from standard input and ...
-3
2016-10-12T22:23:21Z
40,009,674
<p>Given your description, I suspect that the validation program wants to see a single result after each additional input. Have you tried that?</p> <pre><code>while s &lt;= 5: curr = input() if prev &lt; curr: print "higher" elif curr &lt; prev: print "lower" else: print "equal" s =...
0
2016-10-12T22:55:43Z
[ "python" ]
acos getting error math domain error
40,009,384
<p>Trying to figure out why I am getting an error. My numbers are between -1 and 1, but still errors. </p> <blockquote> <p>ValueError: math domain error</p> </blockquote> <p>Any ideas?</p> <p>Thanks</p> <pre><code>from math import sqrt, acos, pi from decimal import Decimal, getcontext getcontext().prec = 30 ...
0
2016-10-12T22:26:27Z
40,009,442
<p>Could it be that <code>u1.dot(u2)</code> equals <code>-1.00000000000000018058942747512</code></p> <pre><code>print(u2) print(u1.dot(u2)) angle_in_radians = acos(u1.dot(u2)) </code></pre> <p>This is around line 60</p> <p>Update, with further tests:</p> <pre><code>getcontext().prec = 16 ...... def dot(self, v): ...
2
2016-10-12T22:32:03Z
[ "python", "math", "vector" ]
What's the closest implementation of scala's '@transient lazy val' in Python?
40,009,409
<p>According to this post:</p> <p><a href="http://stackoverflow.com/questions/3012421/python-memoising-deferred-lookup-property-decorator">Python memoising/deferred lookup property decorator</a></p> <p>A mnemonic decorator can be used to declare a lazy property in a class. There is even an 'official' package that can...
1
2016-10-12T22:29:10Z
40,009,646
<p>Unaware of scala implementation details, but the easiest solution comes to my mind, if you're satisfied with other aspects of the 'lazy property' library you've found, would be implementing <code>__getstate__</code> and <code>__setstate__</code> object methods, as described in <a href="https://docs.python.org/2/libr...
1
2016-10-12T22:53:02Z
[ "python", "serialization", "pickle", "lazy-evaluation" ]
removing elements from a list of genes
40,009,437
<p>I have a list like this:</p> <pre><code>['&gt;ENST00000262144 cds:known chromosome:GRCh37:16:74907468:75019046:-1 gene:ENSG00000103091 gene_biotype:protein_coding transcript_biotype:protein_coding', '&gt;ENST00000446813 cds:known chromosome:GRCh37:7:72349936:72419009:1 gene:ENSG00000196313 gene_biotype:protein_co...
-3
2016-10-12T22:31:45Z
40,009,497
<pre><code>For each string in the list: Split the string on spaces (Python **split** command) Find the element starting with "gene:" Keep the rest of the string (grab the slice [5:] of that element) </code></pre> <p>Do you have enough basic Python knowledge to take it from there? If not, I suggest that yo...
0
2016-10-12T22:36:46Z
[ "python" ]
removing elements from a list of genes
40,009,437
<p>I have a list like this:</p> <pre><code>['&gt;ENST00000262144 cds:known chromosome:GRCh37:16:74907468:75019046:-1 gene:ENSG00000103091 gene_biotype:protein_coding transcript_biotype:protein_coding', '&gt;ENST00000446813 cds:known chromosome:GRCh37:7:72349936:72419009:1 gene:ENSG00000196313 gene_biotype:protein_co...
-3
2016-10-12T22:31:45Z
40,009,587
<p>This is by no means the most Pythonic way to achieve this but it should do what you want.</p> <pre><code>l = [ '&gt;ENST00000262144 cds:known chromosome:GRCh37:16:74907468:75019046:-1 gene:ENSG00000103091 gene_biotype:protein_coding transcript_biotype:protein_coding', '&gt;ENST00000446813 cds:known chromoso...
0
2016-10-12T22:48:21Z
[ "python" ]
removing elements from a list of genes
40,009,437
<p>I have a list like this:</p> <pre><code>['&gt;ENST00000262144 cds:known chromosome:GRCh37:16:74907468:75019046:-1 gene:ENSG00000103091 gene_biotype:protein_coding transcript_biotype:protein_coding', '&gt;ENST00000446813 cds:known chromosome:GRCh37:7:72349936:72419009:1 gene:ENSG00000196313 gene_biotype:protein_co...
-3
2016-10-12T22:31:45Z
40,009,605
<p>Just use some basic list comprehension:</p> <pre><code>lst = ['&gt;ENST00000262144 cds:known chromosome:GRCh37:16:74907468:75019046:-1 gene:ENSG00000103091 gene_biotype:protein_coding transcript_biotype:protein_coding', '&gt;ENST00000446813 cds:known chromosome:GRCh37:7:72349936:72419009:1 gene:ENSG00000196313 gene...
1
2016-10-12T22:49:58Z
[ "python" ]
html table header locked to the top of the page even when scrolling down
40,009,461
<p>I've used both <code>to_html()</code> and <code>style.render()</code> of Pandas DataFrame to generate html page from CSV data. It's cool!</p> <p>But when I scroll the page down I lose sight of the column names, that's the problem.</p> <p>Is there some way of hanging it up on the top of the page?</p>
1
2016-10-12T22:33:38Z
40,009,594
<p>Is this what you need?</p> <pre><code>#NAME HERE{ position: fixed; { </code></pre> <p>You can also do the width ect with this code...</p> <pre><code> #NAME HERE{ position: fixed; bottom:0px; right: 0; width: 0px; height: 0px; } </code></pre> <p>Also, if you want the width to span across the page jus...
1
2016-10-12T22:48:53Z
[ "python", "html", "python-2.7", "pandas", "dataframe" ]
requests - Gateway Timeout
40,009,499
<p>this is a test script to request data from <code>Rovi API</code>, provided by the <code>API</code> itself.</p> <p><strong>test.py</strong></p> <pre><code>import requests import time import hashlib import urllib class AllMusicGuide(object): api_url = 'http://api.rovicorp.com/data/v1.1/descriptor/musicmoods' ...
0
2016-10-12T22:37:09Z
40,009,792
<p>"504, try once more. 502, it went through."</p> <p>Your code is fine, this is a network issue. "Gateway Timeout" is a 504. The intermediate host handling your request was unable to complete it. It made its own request to another server on your behalf in order to handle yours, but this request took too long and time...
0
2016-10-12T23:09:36Z
[ "python", "api", "python-requests" ]
find indices of lat lon point on a grid using python
40,009,528
<p>I am new to python, and I can't figure out how to find the minimum distance from a given lat/lon point (which is not given from the grid, but selected by me) to a find the closest indices of a lat/lon point on a grid.</p> <p>Basically , I am reading in an ncfile that contains 2D coordinates:</p> <pre><code>coords ...
0
2016-10-12T22:40:42Z
40,010,836
<p>I think I found an answer, but it is a workaround that avoids calculating distance between the chosen lat/lon and the lat/lons on the grid. This doesn't seem completely accurate because I am never calculating distances, just the closest difference between lat/lon values themselves.</p> <p>I used the answer to the ...
1
2016-10-13T01:24:43Z
[ "python", "coordinates", "netcdf" ]
find indices of lat lon point on a grid using python
40,009,528
<p>I am new to python, and I can't figure out how to find the minimum distance from a given lat/lon point (which is not given from the grid, but selected by me) to a find the closest indices of a lat/lon point on a grid.</p> <p>Basically , I am reading in an ncfile that contains 2D coordinates:</p> <pre><code>coords ...
0
2016-10-12T22:40:42Z
40,044,540
<p>Checkout the <a href="http://pyresample.readthedocs.io" rel="nofollow">pyresample</a> package. It provides spatial nearest neighbour search using a fast kdtree approach:</p> <pre><code>import pyresample import numpy as np # Define lat-lon grid lon = np.linspace(30, 40, 100) lat = np.linspace(10, 20, 100) lon_grid,...
0
2016-10-14T13:35:54Z
[ "python", "coordinates", "netcdf" ]
In pandas, set a new column and update existing column
40,009,553
<p>In a <code>pandas</code> dataframe, I have a last name field that looks like</p> <pre><code>df = pd.DataFrame(['Jones Jr', 'Smith'], columns=['LastName']) </code></pre> <p>I am trying to set a new column named 'Generation', while stripping out the Generation for the last name, so the outcome would look like this:<...
1
2016-10-12T22:44:56Z
40,009,647
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.extract.html" rel="nofollow">.str.extract()</a> method:</p> <pre><code>In [19]: df2 = df.LastName.str.extract(r'(?P&lt;LastName&gt;\w+)\s?(?P&lt;Generation&gt;Jr|Sr)?', expand=True) In [20]: df2 Out[20]: LastName Generat...
3
2016-10-12T22:53:05Z
[ "python", "pandas", "dataframe" ]
Google service account access token request: "Required parameter is missing: grant_type"
40,009,577
<p><strong>UPDATE:</strong> Solved. I was indeed making a basic mistake, among other things. My usage of the <code>session.headers.update</code> function was incorrect; instead of <code>session.headers.update = {foo:bar}</code>, I needed to be doing <code>session.headers.update({foo:bar})</code>. Additionally, I change...
0
2016-10-12T22:47:04Z
40,027,453
<p>Try "grant_type": "authorization_code". And add grant type as header.</p> <p>Also, check this link - <a href="http://stackoverflow.com/questions/32919099/accessing-google-oauth-giving-invalid-grant-type-bad-request?rq=1">Accessing Google oAuth giving invalid grant_type (Bad request)</a></p>
0
2016-10-13T17:32:39Z
[ "python", "google-api", "python-requests", "google-oauth", "google-oauth2" ]
Pandas Dataframe VWAP calculation for custom duration
40,009,591
<p>I have a slightly unique problem to solve using Pandas Dataframe. I have following two dataframes:</p> <pre><code>df1 time, Date, Stock, StartTime, EndTime 2016-10-11 12:00:00 2016-10-11 ABC 12:00:00.243 13:06:34.232 2016-10-11 12:01:00 2016-10-11 ABC 12:02:00.2...
0
2016-10-12T22:48:32Z
40,010,083
<p>A merge, groupby, and apply weighted average function.</p> <p>Migrated your data to code so easy for people to load.</p> <pre><code>df1 = pd.DataFrame({'Date': {0: '2016-10-11', 1: '2016-10-11', 2: '2016-10-11'}, 'Stock': {0: 'ABC', 1: 'ABC', 2: 'XYZ'}, 'EndTime': {0: '13:06:34.232', 1: '13:04:34.232', 2: '11:24:2...
0
2016-10-12T23:44:20Z
[ "python", "pandas" ]
Importing modules fails in Codeship
40,009,619
<p>I have a repository with the following directory structure:</p> <pre><code>repo_folder\ ----src\ ----__init__.py ----src1.py ----src2.py ----src3.py ----testing\ ----specific_test.py ----requirements.txt </code></pre> <hr> <p><code>specific_test.py</code> has on it's first lines:</p> <pre><co...
0
2016-10-12T22:50:55Z
40,010,121
<p>This seems to be a pathing issue. What seems to be happening on your local machine is you insert into your path your CWD, which is most likely returning as <code>repo_folder\</code>. from there, you can import your src files via <code>src.src1</code> because src is containe. On your codeship account, the cwd (curr...
0
2016-10-12T23:49:03Z
[ "python", "continuous-integration", "python-import", "importerror", "codeship" ]
Python syntax checkers that test edge cases
40,009,629
<p>Are there syntax checkers able to detect broken code based on edge cases. An example:</p> <pre><code>def run(): for j in [0, 1]: if j == 0: yield j else: yield None for i in run(): print i * 2 </code></pre> <p>This code is broken because <code>None * 2</code> does ...
-1
2016-10-12T22:51:54Z
40,009,755
<p>You're looking for a type checker, not a syntax checker. Here's one attempt to make one: <a href="http://mypy-lang.org/" rel="nofollow">http://mypy-lang.org/</a></p>
2
2016-10-12T23:05:14Z
[ "python", "syntax-checking" ]
Python syntax checkers that test edge cases
40,009,629
<p>Are there syntax checkers able to detect broken code based on edge cases. An example:</p> <pre><code>def run(): for j in [0, 1]: if j == 0: yield j else: yield None for i in run(): print i * 2 </code></pre> <p>This code is broken because <code>None * 2</code> does ...
-1
2016-10-12T22:51:54Z
40,010,163
<p>You need a type checker, not a syntax checker. <a href="https://github.com/python/mypy" rel="nofollow">github.com/python/mypy</a></p>
1
2016-10-12T23:55:01Z
[ "python", "syntax-checking" ]
Using python Basemap.pcolormesh with non-monotonic longitude jumps
40,009,652
<p>I have satellite sweep data that I am attempting to plot on a basemap using pcolormesh.</p> <p>The data is organized as a 2d matrix, (bTemp), with two corresponding 2D arrays lat and lon, that give the corresponding latitude and longitude at each point. So my plotting code looks like</p> <pre><code>m = Basemap() m...
1
2016-10-12T22:53:35Z
40,009,718
<p>You could try using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.unwrap.html" rel="nofollow"><code>numpy.unwrap</code></a> to unwrap your data. It was designed exactly for this: to unwrap angular jumps (in radians) that are artifacts due to the way how we use single-valued functions.</p> <p>Yo...
0
2016-10-12T23:00:32Z
[ "python", "matplotlib-basemap" ]
pandas panel data update
40,009,667
<p>I am using panel datastructure in pandas for storing a 3d panel. </p> <pre><code>T=pd.Panel(data=np.zeros((n1,n2,n3)),items=n1_label, major_axis=n2_label, minor_axis=n3_label) </code></pre> <p>Later on, I am trying to update (increment) the values stored at individual locations inside a loop. Currently I am doing:...
2
2016-10-12T22:54:21Z
40,010,287
<p><strong><em>TL;DR</em></strong> </p> <pre><code>T.update(T.loc[[n1_loop], [n2_loop], [n3_loop]].add(1)) </code></pre> <hr> <p>The analogous exercise for a DataFrame would be to assign with <code>loc</code></p> <pre><code>df = pd.DataFrame(np.zeros((5, 5)), list('abcde'), list('ABCDE'), int) df.loc['b':'d', list...
1
2016-10-13T00:09:09Z
[ "python", "panel-data", "pandas" ]
OSError: .pynative/... : file too short
40,009,710
<p>When I try to apply OCRopus (a python-based OCR tool) to a TIFF image, I get the following python error:</p> <pre><code> Traceback (most recent call last): File "/usr/local/bin/ocropus-nlbin", line 10, in &lt;module&gt; import ocrolib File "/usr/local/lib/python2.7/dist-packages/ocrolib/__init__.py", lin...
1
2016-10-12T22:59:54Z
40,031,518
<p>Problem solved. I saw other people having trouble (on diverse matters) with: </p> <blockquote> <p>OSError:<strong>[X]</strong>... : file too short</p> </blockquote> <p>My suggestion is: whatever you are doing, check for hidden directories named [X] in the current directory and delete them.</p>
0
2016-10-13T21:44:31Z
[ "python" ]
Maya python. parentConstraint by distance
40,009,763
<p>I have two sets of skeletons (A and B), and trying to parent constraint A set of joints to B joints.</p> <p>What I did was put A selection into A array and B selection to B array. but how can I proceed parent constraint A to B by distance, which the distance is 0 basically so the toe joint doesn't hook up with fing...
0
2016-10-12T23:06:28Z
40,017,021
<p>Here's an example of how you can constrain objects from one list to another by their world positions. There may be smarter ways of doing it, like adding the values to a <code>dict</code> then sorting it, but this feels more readable.</p> <pre><code>import math # Add code here to get your two selection lists # Loo...
0
2016-10-13T09:21:30Z
[ "python", "maya" ]
Coloring cells of a grid overlaid on top of a polygon with different colors
40,009,795
<p>There is a grid which has been overlaid on top of a polygon. To make the discussion concrete, assume the following picture:</p> <p><a href="https://i.stack.imgur.com/tLIHQ.png" rel="nofollow"><img src="https://i.stack.imgur.com/tLIHQ.png" alt="enter image description here"></a></p> <p>I had the yellow polygon and ...
2
2016-10-12T23:09:54Z
40,015,703
<p>You can consider using <code>fill</code> command, but try to avoid it and use <a href="http://www.mathworks.com/help/matlab/ref/patch.html" rel="nofollow"><code>patch</code></a> if you can. The problem with <code>fill</code> is that you will face serious performance issues when the number of lattice points increases...
0
2016-10-13T08:16:32Z
[ "python", "matlab" ]
How to delete the contents of a file before writing into it in a python script?
40,009,858
<p>I have a file called fName.txt in a directory. Running the following python snippet (coming from a simulation) would add 6 numbers into 3 rows and 2 columns into the text file through executing the loop (containing the snippet) three times. However, I would like to empty the file completely before writing new data i...
2
2016-10-12T23:18:21Z
40,009,972
<p>You are using 'append' mode (<code>'a'</code>) to open your file. When this mode is specified, new text is appended to the existing file content. You're looking for the 'write' mode, that is <code>open(filename, 'w')</code>. This will override the file contents every time you <strong>open</strong> it.</p>
2
2016-10-12T23:30:26Z
[ "python", "python-3.x", "file-io", "seek" ]
How to delete the contents of a file before writing into it in a python script?
40,009,858
<p>I have a file called fName.txt in a directory. Running the following python snippet (coming from a simulation) would add 6 numbers into 3 rows and 2 columns into the text file through executing the loop (containing the snippet) three times. However, I would like to empty the file completely before writing new data i...
2
2016-10-12T23:18:21Z
40,073,770
<p>Using mode 'w' is able to delete the content of the file and overwrite the file but prevents the loop containing the above snippet from printing two more times to produce two more rows of data. In other words, using 'w' mode is not compatible with the code I have given the fact that it is supposed to print into the ...
0
2016-10-16T18:18:20Z
[ "python", "python-3.x", "file-io", "seek" ]
List/Conditional Comprehension in Python
40,009,897
<p>I was wondering how to make the following into a comprehension:</p> <pre><code>for g in a: for f in g[::3]: if f == clf.best_params_: print g </code></pre> <p>I tried this:</p> <pre><code>p = [[print g for g in a] if f==clf.best_params for f in [g[::3] for g in a]] p </code></pre> <p>but ...
0
2016-10-12T23:22:55Z
40,009,941
<p>The correct way to translate those loops would be</p> <pre><code>[print g for g in a for f in g[::3] if f == clf.best_params_] </code></pre> <p>However, in Python 2 <code>print g</code> is a statement, and that's why you get a SyntaxError. The Python 3 counterpart (i.e. with <code>print(g)</code>) would work, but ...
2
2016-10-12T23:27:20Z
[ "python", "list", "scikit-learn", "conditional", "list-comprehension" ]
List/Conditional Comprehension in Python
40,009,897
<p>I was wondering how to make the following into a comprehension:</p> <pre><code>for g in a: for f in g[::3]: if f == clf.best_params_: print g </code></pre> <p>I tried this:</p> <pre><code>p = [[print g for g in a] if f==clf.best_params for f in [g[::3] for g in a]] p </code></pre> <p>but ...
0
2016-10-12T23:22:55Z
40,009,947
<p>I think you've confused the construct: it's a <strong>list</strong> comprehension, not a macro of some sort.</p> <p>You don't get this sort of side effect; the purpose of a list comprehension is to construct a list.</p>
1
2016-10-12T23:27:47Z
[ "python", "list", "scikit-learn", "conditional", "list-comprehension" ]
List/Conditional Comprehension in Python
40,009,897
<p>I was wondering how to make the following into a comprehension:</p> <pre><code>for g in a: for f in g[::3]: if f == clf.best_params_: print g </code></pre> <p>I tried this:</p> <pre><code>p = [[print g for g in a] if f==clf.best_params for f in [g[::3] for g in a]] p </code></pre> <p>but ...
0
2016-10-12T23:22:55Z
40,009,950
<p><strong>Rule 1</strong> - Keep the order of the <code>for</code> and <code>if</code> parts the same. The only part that changes order is the last part, <code>print g</code>: that moves to the front.</p> <pre><code>[print g for g in a for f in g[::3] if f == clf.best_params_] </code></pre> <p><strong>Rule 2</strong...
1
2016-10-12T23:27:59Z
[ "python", "list", "scikit-learn", "conditional", "list-comprehension" ]
django-pipeline throwing ValueError: the file could not be found
40,010,040
<p>When running <code>python manage.py collectstatic --noinput</code> I'm getting the following error:</p> <pre><code>Post-processing 'jquery-ui-dist/jquery-ui.css' failed! Traceback (most recent call last): File "manage_local.py", line 10, in &lt;module&gt; execute_from_command_line(sys.argv) File "/Users/michaelbate...
0
2016-10-12T23:39:52Z
40,142,068
<p>Your problem is related to <a href="https://code.djangoproject.com/ticket/21080" rel="nofollow">this bug</a> on the Django project.</p> <p>In short, django-pipeline is post-processing the <code>url()</code> calls with Django's <code>CachedStaticFilesStorage</code> to append the md5 checksum to the filename (<a href...
1
2016-10-19T21:47:59Z
[ "python", "django", "asset-pipeline", "django-pipeline" ]
Counting number of vowels in a merged string
40,010,066
<p>I am trying to figure out how to calculate the score of two merged lists of names. I need to give one point for each character (including spaces between first and last name) plus one point for each vowel in the name. I can currently calculate score for the the lengths of the names but cannot figure out how to includ...
3
2016-10-12T23:42:14Z
40,010,101
<p>The reason you're not calculating the vowels is because the score variable is not getting incremented. To increment it, you have to set the variable score to previous score + 1.</p> <p>This should work:</p> <pre><code>for letter in name: if letter in vowel: score+=1 </code></pre> <p>Edit: It's worth w...
2
2016-10-12T23:46:15Z
[ "python", "list" ]
Counting number of vowels in a merged string
40,010,066
<p>I am trying to figure out how to calculate the score of two merged lists of names. I need to give one point for each character (including spaces between first and last name) plus one point for each vowel in the name. I can currently calculate score for the the lengths of the names but cannot figure out how to includ...
3
2016-10-12T23:42:14Z
40,010,535
<pre><code>a = ["John", "Kate", "Oli"] b = ["Green", "Fletcher", "Nelson"] vowel = {"a", "e", "i", "o", "u"} names = (first + ' ' + last for first in a for last in b) for name in names: score = len(name) + sum(c in vowel for c in name.lower()) print "Full Name: {name} Score: {score}".format(name=name, score=sc...
1
2016-10-13T00:40:29Z
[ "python", "list" ]
Maya PySide Window - Remember position and size
40,010,166
<p>I am working in Pyside. Every time I re-open the window it pops back to the middle of the screen. How can I get either Maya or Windows to remember the position and size?</p> <p>Here is some basic code I am working with:</p> <pre><code>import traceback from PySide import QtCore from PySide import QtGui from shibo...
0
2016-10-12T23:55:20Z
40,017,712
<p>One option you can use is <code>QWidget.saveGeometry()</code> and <code>QWidget.restoreGeometry()</code>. With this you can save your window's position and size when your tool closes, then restore it back when it initializes. </p> <p>Normally for stuff like this where it's saving a state of the tool, I'll store the...
0
2016-10-13T09:50:56Z
[ "python", "window", "pyside", "maya" ]
Summation of elements of dictionary that are list of lists
40,010,175
<pre><code>d = { 'a': [[1, 2, 3], [1, 2, 3]], 'b': [[2, 4, 1], [1, 6, 1]], } def add_element(lst): ad = [sum(i) for i in zip(*lst)] return ad def csv_reducer2(dicty): return {k: list(map(add_element, v)) for k, v in dicty.items()} csv_reducer2(d) </code></pre> <p>required output:</p> <pre><code>{'b...
6
2016-10-12T23:56:33Z
40,010,243
<pre><code>&gt;&gt;&gt; d = {'a': [[1, 2, 3], [1, 2, 3]], 'b': [[2, 4, 1], [1, 6, 1]]} &gt;&gt;&gt; {k: map(sum, zip(*v)) for k, v in d.items()} {'a': [2, 4, 6], 'b': [3, 10, 2]} </code></pre>
6
2016-10-13T00:04:23Z
[ "python", "list", "dictionary" ]
Summation of elements of dictionary that are list of lists
40,010,175
<pre><code>d = { 'a': [[1, 2, 3], [1, 2, 3]], 'b': [[2, 4, 1], [1, 6, 1]], } def add_element(lst): ad = [sum(i) for i in zip(*lst)] return ad def csv_reducer2(dicty): return {k: list(map(add_element, v)) for k, v in dicty.items()} csv_reducer2(d) </code></pre> <p>required output:</p> <pre><code>{'b...
6
2016-10-12T23:56:33Z
40,010,268
<p>The following will work on Python 2 or 3:</p> <pre><code>&gt;&gt;&gt; {k: [a + b for a, b in zip(*v)] for k, v in d.items()} {'a': [2, 4, 6], 'b': [3, 10, 2]} </code></pre> <p>The issue with your code is you are mapping <code>add_element</code> to every individual element in <code>v</code> inside your dictionary c...
4
2016-10-13T00:06:46Z
[ "python", "list", "dictionary" ]
Summation of elements of dictionary that are list of lists
40,010,175
<pre><code>d = { 'a': [[1, 2, 3], [1, 2, 3]], 'b': [[2, 4, 1], [1, 6, 1]], } def add_element(lst): ad = [sum(i) for i in zip(*lst)] return ad def csv_reducer2(dicty): return {k: list(map(add_element, v)) for k, v in dicty.items()} csv_reducer2(d) </code></pre> <p>required output:</p> <pre><code>{'b...
6
2016-10-12T23:56:33Z
40,010,367
<p>To fix your original code, the only change you need to make is:</p> <pre><code>return {k: list(map(add_element, v)) for k, v in dicty.items()} </code></pre> <p>-></p> <pre><code>return {k: add_element(v) for k, v in dicty.items()} </code></pre> <p>Because <code>zip(*lst)</code> is trying to transpose multiple ro...
4
2016-10-13T00:18:42Z
[ "python", "list", "dictionary" ]
Numpy: Read csv, deal with undefined values
40,010,178
<p>What is the best way to read data from a csv file into a numpy array when some of the values are labelled as 'undefined' as follows:</p> <pre><code>0.231620,0.00001,444.157 0.225370,--undefined--,1914.637 0.237870,0.0003,--undefined-- </code></pre> <p>I have a lot of these files that I will have to loop over, and ...
1
2016-10-12T23:56:37Z
40,010,319
<p>I'd suggest you to try to cast each value you read to float, then catch typecast ValueError exception and assign it to zero in exception handler.</p> <p>This will be the most pythonic way</p> <p>Assuming your CSV contains float values, you should end with something like:</p> <pre><code>with open('data.csv', 'r') ...
0
2016-10-13T00:12:30Z
[ "python", "csv", "numpy" ]
Numpy: Read csv, deal with undefined values
40,010,178
<p>What is the best way to read data from a csv file into a numpy array when some of the values are labelled as 'undefined' as follows:</p> <pre><code>0.231620,0.00001,444.157 0.225370,--undefined--,1914.637 0.237870,0.0003,--undefined-- </code></pre> <p>I have a lot of these files that I will have to loop over, and ...
1
2016-10-12T23:56:37Z
40,010,512
<p>To read CSV files and replace the values the best way I think it is using Pandas which uses numpy as well</p> <pre><code>import pandas as pd df = pd.read_csv('foo.csv', header=None) df.replace("--undefined--",0.0, inplace=True) df 0 1 2 0 0.23162 0.00001 444.157 1 0.22537 0 19...
1
2016-10-13T00:37:43Z
[ "python", "csv", "numpy" ]
Numpy: Read csv, deal with undefined values
40,010,178
<p>What is the best way to read data from a csv file into a numpy array when some of the values are labelled as 'undefined' as follows:</p> <pre><code>0.231620,0.00001,444.157 0.225370,--undefined--,1914.637 0.237870,0.0003,--undefined-- </code></pre> <p>I have a lot of these files that I will have to loop over, and ...
1
2016-10-12T23:56:37Z
40,014,406
<p>No need for Pandas, just use Numpy.</p> <pre><code>import numpy as np x = np.genfromtxt('data.csv', dtype=np.float, delimiter=',', missing_values='--undefined--', filling_values=0.0, ) </code></pre>
0
2016-10-13T07:05:27Z
[ "python", "csv", "numpy" ]
Python plot base64 string as image
40,010,237
<p>I am attempting to convert a jpg, which is encoded as a base64 string that I receive over the server into an RGB image that I can use with numpy, but also plot with matplot lib. I am unable to find docs on how to take a raw base64 string and plot that using python.</p> <p>I also have the option to receive as a png...
1
2016-10-13T00:03:34Z
40,014,667
<pre><code>image = '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAA2AGADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUF...
0
2016-10-13T07:20:08Z
[ "python", "numpy", "image-processing" ]
Native Android mobile app test automaton navigation with multiple class elements
40,010,238
<p><a href="https://i.stack.imgur.com/Jbt8l.png" rel="nofollow"><img src="https://i.stack.imgur.com/Jbt8l.png" alt="enter image description here"></a></p> <p>How do you enter text (password), when there is no <code>text</code>, <code>resource-id</code>, <code>content-desc</code> and there is more than one class? i.e. ...
1
2016-10-13T00:03:44Z
40,011,008
<p>Did you try looking by a class name? You can try the following:</p> <pre><code>element = driver.find_element_by_class_name('android.widget.EditText') </code></pre> <p>If you have more than one element with similar class, find all of them:</p> <pre><code>elements = driver.find_elements_by_class_name('android.widge...
2
2016-10-13T01:49:40Z
[ "android", "python", "automation", "appium", "uiautomator" ]
django-background-tasks indefinite run
40,010,257
<p>The docs says,</p> <p>In Django Background Task, all tasks are implemented as functions (or any other callable).</p> <p>There are two parts to using background tasks:</p> <pre><code>creating the task functions and registering them with the scheduler setup a cron task (or long running process) to execute the tasks...
1
2016-10-13T00:05:28Z
40,012,554
<p>If I am understood correctly then You want to execute your tasks periodically without using cron.</p> <p>You can do using django celery(<a href="https://github.com/celery/django-celery" rel="nofollow">https://github.com/celery/django-celery</a>) or Task Master (<a href="https://github.com/dcramer/taskmaster" rel="n...
0
2016-10-13T04:53:33Z
[ "python", "django", "django-views" ]
While reading multiple files with Python, how can I search for the recurrence of an error string?
40,010,266
<p>I've just started to play with Python and I'm trying to do some tests on my environment ... the idea is trying to create a simple script to find the recurrence of errors in a given period of time.</p> <p>Basically I want to count the number of times a server fails on my daily logs, if the failure happens more than ...
0
2016-10-13T00:06:37Z
40,010,425
<p>I'd better handle such with shell utilities (i.e uniq), but, as long as you prefer to use python:</p> <p>With minimal effor, you can handle it creating appropriate <code>dict</code> object with stings (like 'file_2016_Oct_01.txt@hostname@YES') being the keys. Iterating over log, you'd check corresponding key exists...
0
2016-10-13T00:26:28Z
[ "python", "scripting", "string-iteration" ]
Python Plotting Pandas SQL Dataframe with Seaborn
40,010,317
<p>I am new to data visualization and attempting to make a simple time series plot using an SQL output and seaborn. I am having difficulty inserting the data retrieved from the SQL query into Seaborn. Is there some direction you can give me on how to visualize this dataframe using Seaborn?</p> <p>My Python Code:</p> ...
1
2016-10-13T00:12:21Z
40,010,584
<p>Instead of <code>sns.kdeplot</code> try the following:</p> <pre><code># make time the index (this will help with plot ticks) df.set_index('DATETIME', inplace=True) # make figure and axis objects fig, ax = sns.plt.subplots(1, 1, figsize=(6,4)) df.plot(y='COUNTS', ax=ax, color='red', alpha=.6) fig.savefig('test.pdf'...
2
2016-10-13T00:49:41Z
[ "python", "pandas", "matplotlib", "sqlplus", "seaborn" ]
Getting a Generator Object returned when I want the data
40,010,322
<p>I am very very new to Python 3, so please be nice.</p> <p>I have looked at all the documentation I could find regarding this - there does seem to be a lot, it's just I still cannot figure out what to do.</p> <p>This is my code:</p> <pre><code>poly = [[36606.0,53223.0],[37332.0,52224.0],[39043.0,53223.0], [41603.0...
1
2016-10-13T00:12:36Z
40,010,409
<p>Wrapping an <code>item for item in iterable</code> construct in parentheses makes it a lazy generator expression, which has the appearance you see. Now, the reason it does this instead of giving you an error that you would get from trying to send a non-iterable to <code>sum()</code> is because it doesn't evaluate an...
1
2016-10-13T00:25:20Z
[ "python", "python-3.x", "generator" ]
Getting a Generator Object returned when I want the data
40,010,322
<p>I am very very new to Python 3, so please be nice.</p> <p>I have looked at all the documentation I could find regarding this - there does seem to be a lot, it's just I still cannot figure out what to do.</p> <p>This is my code:</p> <pre><code>poly = [[36606.0,53223.0],[37332.0,52224.0],[39043.0,53223.0], [41603.0...
1
2016-10-13T00:12:36Z
40,010,467
<p>I would try something a bit more explicit like this, this matches your expected answer</p> <pre><code>import itertools def calculate_length(x0, x1, y0, y1): return ((x1 - x0)**2+(y1 - y0)**2)**.5 def make_point_pairs(poly): pairs = zip(poly, poly[1:]) # Close the shape chain = itertools.chain(pair...
0
2016-10-13T00:32:07Z
[ "python", "python-3.x", "generator" ]
Getting a Generator Object returned when I want the data
40,010,322
<p>I am very very new to Python 3, so please be nice.</p> <p>I have looked at all the documentation I could find regarding this - there does seem to be a lot, it's just I still cannot figure out what to do.</p> <p>This is my code:</p> <pre><code>poly = [[36606.0,53223.0],[37332.0,52224.0],[39043.0,53223.0], [41603.0...
1
2016-10-13T00:12:36Z
40,010,529
<p>The first problem is that you have your parentheses in the wrong places. You want to call <code>sum()</code> on a generator expression, but instead you have written a generator expression using <code>sum()</code>. So you might try this:</p> <pre><code>def perimeter(): return sum(((x1 - x0) ** 2) + ((y1 - y0) **...
1
2016-10-13T00:39:38Z
[ "python", "python-3.x", "generator" ]
Getting a Generator Object returned when I want the data
40,010,322
<p>I am very very new to Python 3, so please be nice.</p> <p>I have looked at all the documentation I could find regarding this - there does seem to be a lot, it's just I still cannot figure out what to do.</p> <p>This is my code:</p> <pre><code>poly = [[36606.0,53223.0],[37332.0,52224.0],[39043.0,53223.0], [41603.0...
1
2016-10-13T00:12:36Z
40,010,552
<p>Your code has two problems. One is due to parentheses as @TigerhawkT3 pointed out, and the other is you're not iterating through the points properly. The code below addresses both these issues.</p> <pre><code>poly = [[36606.0,53223.0],[37332.0,52224.0],[39043.0,53223.0], [41603.0,53223.0],[42657.0,53278.0],...
1
2016-10-13T00:43:51Z
[ "python", "python-3.x", "generator" ]
Getting a Generator Object returned when I want the data
40,010,322
<p>I am very very new to Python 3, so please be nice.</p> <p>I have looked at all the documentation I could find regarding this - there does seem to be a lot, it's just I still cannot figure out what to do.</p> <p>This is my code:</p> <pre><code>poly = [[36606.0,53223.0],[37332.0,52224.0],[39043.0,53223.0], [41603.0...
1
2016-10-13T00:12:36Z
40,010,750
<p>I am also a little confused about your question, it seems that you are not intentionally using the generator and just wants to get the perimeter? I think it would be better to clean up the function <code>perimeter()</code> a little bit and not use a generator there, and simply iterate through the list <code>poly</co...
0
2016-10-13T01:12:13Z
[ "python", "python-3.x", "generator" ]
Two Y axis Bar plot: custom xticks
40,010,524
<p>I am trying to add custom xticks to a relatively complicated bar graph plot and I am stuck.</p> <p>I am plotting from two data frames, <code>merged_90</code> and <code>merged_15</code>:</p> <pre><code>merged_15 Volume y_err_x Area_2D y_err_y TripDate ...
0
2016-10-13T00:38:55Z
40,010,901
<p>Have you considered dropping the second axis and plotting them as follows:</p> <pre><code>ind = np.array([0,0.3]) width = 0.1 fig, ax = plt.subplots() Rects1 = ax.bar(ind, [merged_90.Volume.values, merged_15.Volume.values], color=['orange', 'red'] ,width=width) Rects2 = ax.bar(ind + width, [merged_90.Area_2D.values...
0
2016-10-13T01:34:47Z
[ "python", "pandas", "matplotlib", "bar-chart" ]
How to execute a repeated command in pygame?
40,010,562
<p>I've been struggling to get my code to work. I want my image to move continuously while pressing W,A,S, or D instead of having to repeatedly tap the key, but my code keeps having problems. Right now, it says that the video system is not initialized. I don't understand why this is popping up - I already have pygame.i...
0
2016-10-13T00:45:56Z
40,036,184
<p>I've had a bit of a muck around with your code and have fixed some of your little errors... Hopefully you can read through my comments some of the reasoning of why I've changed a few things. Also, your code was getting the video error because of a few reasons I believe: 1. You were constantly calling <code>pygame.qu...
0
2016-10-14T06:15:44Z
[ "python" ]
elif statement not working as expected
40,010,630
<p>I'm trying to look through multiple sources to see which one has a specific entry.</p> <p>My input looks like:</p> <pre><code>json_str2 = urllib2.urlopen(URL2).read() u = json.loads(json_str2) #load all five results One = u['flightStatuses'][0] Two = u['flightStatuses'][1] Three = u['flightStatuses'][2] Four = u['...
0
2016-10-13T00:55:53Z
40,010,662
<p>You should write this as a loop over the five flight statuses instead of using five variables and five conditions.</p> <pre><code>results = json.loads(urllib2.urlopen(URL2).read())['flightStstuses'] for result in results: if result['flightNumber'] == str(FlEnd): fnumber = result['flightId'] brea...
3
2016-10-13T01:00:30Z
[ "python", "if-statement", "comparison" ]
Script for sorting lines
40,010,631
<p>I have a file that has content as below</p> <pre><code>hi hello 123 cat dog 456 boy 456 Ind us 90 Can 67 </code></pre> <p>I am trying to sort lines in this file to something like this</p> <pre><code> boy 456 Can 67 hi hello 123 cat dog 456 Ind us 90 </code></pre>...
-1
2016-10-13T00:55:56Z
40,010,857
<p>File content</p> <pre><code>hi hello 123 cat dog 456 boy 456 Ind us 90 Can 67 </code></pre> <p>Basically, use the <code>key</code> of the <code>sorted</code> function to sort based upon the length of the split string. </p> <pre><code>with open("filename") as f: lines = f.read().splitlin...
1
2016-10-13T01:28:35Z
[ "python", "python-3.x", "sorting" ]
How to carry a digit when doing binary addition?
40,010,655
<p>Code:</p> <pre><code>def add_bitwise(b1, b2): '''Adds two binary numbers.''' if b1 == '': return b2 elif b2 == '': return b1 else: sum_rest = add_bitwise(b1[:-1],b2[:-1]) if b1[-1] == '0' and b2[-1] == '0': return sum_rest + '0' elif b1[-1] == '1' ...
1
2016-10-13T00:59:59Z
40,010,869
<p>Your overflow recursions must sum up <code>'1'</code> against <code>sum_rest</code>, not <code>b2[:-1]</code>. Overflow is carried over to the higher-valued digits.</p> <p>Here's a slightly shorter implementation:</p> <pre><code>def ab(b1, b2): if not (b1 and b2): # b1 or b2 is empty return b1 + b2 ...
2
2016-10-13T01:29:53Z
[ "python", "recursion", "binary", "addition" ]
Apache2 server run script as specific user
40,010,657
<p>I am using Ubuntu server 12.04 to run Apache2 web server.</p> <p>I am hosting several webpages, and most are working fine.</p> <p>One page is running a cgi script which mostly works (I have the python code working outside Apache building the html code nicely.)</p> <p>However, I am calling a home automation progra...
0
2016-10-13T01:00:17Z
40,065,573
<p>It looks like I could use suEXEC.</p> <p>It is an Apache module that is not installed at default because they really don't want you to use it. It can be installed using the apt-get scheme.</p> <p>That said, I found the real answer to my issue, heyu uses the serial ports to do it's work. I needed to add www-data to...
0
2016-10-16T00:24:26Z
[ "php", "python", "apache" ]
Apache2 server run script as specific user
40,010,657
<p>I am using Ubuntu server 12.04 to run Apache2 web server.</p> <p>I am hosting several webpages, and most are working fine.</p> <p>One page is running a cgi script which mostly works (I have the python code working outside Apache building the html code nicely.)</p> <p>However, I am calling a home automation progra...
0
2016-10-13T01:00:17Z
40,076,879
<p>Seeing as you are using python, you can use the following to extract the user that the python script as running as;</p> <pre><code>from getpass import getuser print getuser() </code></pre> <p>When you hit the page, you'll get the username that the script ran as - and you can from there adjust the permissions of th...
0
2016-10-17T00:11:57Z
[ "php", "python", "apache" ]
Checking if the value for the key is the same as before
40,010,727
<p>I have been working on this code and I cannot find a answer.</p> <ol> <li><p>I have 2 lists</p> <pre><code>point_values = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10] letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', ...
-3
2016-10-13T01:08:44Z
40,010,740
<pre><code>point_letters = dict(zip(letters, point_values)) </code></pre> <p><code>zip</code> makes a list of pairs of corresponding elements; <code>dict</code> converts the list of pairs to a dictionary.</p> <p>EDIT: changed the dict name. Also in response to comments, and the posted code:</p> <blockquote> <p>Thi...
4
2016-10-13T01:11:05Z
[ "python", "dictionary" ]
Basic unittest TestCase
40,010,819
<p>I have written the below code to test a basic unittest case for learning. When I execute the below code. I do not get any output. Could someone let me know what could be issue.</p> <pre><code>import unittest class test123(unittest.TestCase): def test1(self): print "test1" if __name__ == "main": x=te...
0
2016-10-13T01:22:05Z
40,010,973
<p>your code should look like this:</p> <pre><code>import unittest class test123(unittest.TestCase): def test1(self): print "test1" if __name__ == "__main__": unittest.main() </code></pre> <p>hence it is name and main with two underscores at the start and end, when you change it and run it with you...
2
2016-10-13T01:43:43Z
[ "python", "python-unittest" ]
Basic unittest TestCase
40,010,819
<p>I have written the below code to test a basic unittest case for learning. When I execute the below code. I do not get any output. Could someone let me know what could be issue.</p> <pre><code>import unittest class test123(unittest.TestCase): def test1(self): print "test1" if __name__ == "main": x=te...
0
2016-10-13T01:22:05Z
40,011,908
<p>In your test you need two things:</p> <ol> <li>Define your test function with 'test'</li> <li>You need a expected result</li> </ol> <p>test.py</p> <pre><code>import unittest class TestHello(unittest.TestCase): def test_hello(self): # Your test function usually need define her name with test str_hel...
1
2016-10-13T03:38:31Z
[ "python", "python-unittest" ]
How to extract exif data into a csv file?
40,010,954
<pre><code>import pyexiv2 import os print "Enter the full path to the directory that your images are conatined in." print "-------------------------------------------" newFileObj = open('C:\\users\\wilson\\desktop\\Metadata.csv', 'w') targ_dir = raw_input('Path: ') targ_files = os.listdir(targ_dir) def getEXIFdata (...
0
2016-10-13T01:41:34Z
40,019,272
<p>If you want to get data of exif, use <code>.value</code> to get value of data. Here is an example.</p> <pre><code># -*-coding:utf-8-*- import sys import csv import os import argparse import pyexiv2 def main(): parser = argparse.ArgumentParser(description="Change the txt file to csv.") parser.add_argument("...
0
2016-10-13T11:05:16Z
[ "python", "csv", "metadata", "exif", "pyexiv2" ]
How to output array in hive python UDF
40,011,104
<p>I used python to do UDF in hive. Is there some method to output array/map such structured data from UDF? I am tried to return a python list in UDF, but it can't be convert to a hive array.</p>
0
2016-10-13T02:03:37Z
40,016,073
<p>When you are trying to return a python list in UDF, I suggest that you split the list and process each data step by step. Here is an example.Use 'TRANSFORM' in hive wisely.</p> <pre><code>#!/usr/bin/env python #-*- coding:utf-8 -*- # demo.py import sys import datetime import time #Turn the timestamp into string d...
0
2016-10-13T08:35:50Z
[ "python", "hive", "udf" ]
tracking all child process spawned by a root process
40,011,209
<p>I'm inspecting a certain make system that runs compilers. I want to track all child processes ever spawned by such a "root" process.</p> <p>I'm aware there's the <code>ps</code> command and as I'm a Python user, the <code>psutil</code> package. But I'm not sure if I'll miss some short lived processes between the ca...
1
2016-10-13T02:14:57Z
40,011,910
<p><code>sttace</code> can provide that info. But you may have to parse the output to get just the info you are interested in.</p> <pre><code>strace -f -e trace=process &lt;executable&gt; </code></pre> <p>That will trace all child processes of <code>&lt;executable&gt;</code> and will trace only the process related sy...
1
2016-10-13T03:38:46Z
[ "python", "linux", "process" ]
How to ensure repeated characters are accounted for in a for loop in python
40,011,226
<p>I'm working through the exercises in a textbook and I'm asked to create a numerology program that takes a name, assigns each letter a value based on ascending order in the alphabet and returns the sum of the letters. </p> <p>The code I've written works fine for any name that doesn't repeat a letter. For example if ...
1
2016-10-13T02:18:10Z
40,011,272
<p>Since you are working through a textbook, and I presume don't just want the answer, here is a hint. You are iterating (looping) over the wrong thing. You should be looping over <code>user_name</code>, not <code>alphabet</code>.</p> <p><strong>Update</strong>. If you want a nice "Pythonic" solution to your proble...
1
2016-10-13T02:23:02Z
[ "python", "for-loop" ]
How to ensure repeated characters are accounted for in a for loop in python
40,011,226
<p>I'm working through the exercises in a textbook and I'm asked to create a numerology program that takes a name, assigns each letter a value based on ascending order in the alphabet and returns the sum of the letters. </p> <p>The code I've written works fine for any name that doesn't repeat a letter. For example if ...
1
2016-10-13T02:18:10Z
40,011,408
<p>The <code>in</code> function only verifies if an element is present in a list. You can resolve the problem in a lot of ways but I think a good approach to learn is to create a dictionary to store letter, value pairs and then iterate over the name characters to sum the values:</p> <pre><code>def main(): alphabet ...
1
2016-10-13T02:40:45Z
[ "python", "for-loop" ]
How to ensure repeated characters are accounted for in a for loop in python
40,011,226
<p>I'm working through the exercises in a textbook and I'm asked to create a numerology program that takes a name, assigns each letter a value based on ascending order in the alphabet and returns the sum of the letters. </p> <p>The code I've written works fine for any name that doesn't repeat a letter. For example if ...
1
2016-10-13T02:18:10Z
40,011,669
<p>A very simple way using list comprehension and the built-in <code>sum</code> function:</p> <pre><code> alphabet = 'abcdefghijklmnopqrstuvwxyxz' user_name = raw_input('Please enter your name ') user_name = user_name.lower().strip() value = sum([alphabet.index(c)+1 for c in user_name]) print(value) </co...
0
2016-10-13T03:10:58Z
[ "python", "for-loop" ]
If Statement - Nested Conditional Using Modulus Operator in Python
40,011,264
<p>I need to create a program in Python that asks the user for a number, then tells the user if that number is even or if it's divisible by 5. If neither is true, do not print anything. For example: </p> <pre><code>Please enter a number: 5 This number is divisible by 5! Please enter a number: 7 Please enter a n...
0
2016-10-13T02:21:56Z
40,011,350
<p>The start of each Python block should end with a colon <code>:</code>. Also take note of the indentation.</p> <pre><code>Num1 = input("Please enter a number") Num_1 = int(Num1) if Num_1 % 2 == 0: print ("This number is even!") if Num_1 % 5 == 0: print ("This number is divisible by 5!") </code></pre...
2
2016-10-13T02:31:39Z
[ "python", "if-statement", "int", "modulus" ]
'B': "{:0<4.0f}" | How should I read this?
40,011,269
<p>While studying <a href="http://pandas.pydata.org/pandas-docs/stable/style.html" rel="nofollow">Pandas Style</a>, I got to the following:</p> <pre><code>df.style.format("{:.2%}") </code></pre> <p>Which I understand means, turn every value to 2 decimal places and add a <code>%</code> in the end.</p> <p>Just after t...
0
2016-10-13T02:22:50Z
40,011,358
<p>As according to the <a href="http://pandas.pydata.org/pandas-docs/stable/style.html#Finer-Control:-Display-Values" rel="nofollow">Pandas Style documentation</a> you linked to, it's a python <a href="https://docs.python.org/3/library/string.html#format-specification-mini-language" rel="nofollow">format specification ...
0
2016-10-13T02:32:48Z
[ "python", "python-2.7", "pandas" ]
'B': "{:0<4.0f}" | How should I read this?
40,011,269
<p>While studying <a href="http://pandas.pydata.org/pandas-docs/stable/style.html" rel="nofollow">Pandas Style</a>, I got to the following:</p> <pre><code>df.style.format("{:.2%}") </code></pre> <p>Which I understand means, turn every value to 2 decimal places and add a <code>%</code> in the end.</p> <p>Just after t...
0
2016-10-13T02:22:50Z
40,011,362
<p>This is the "new" formatting string syntax, explained in <a href="https://docs.python.org/2/library/string.html#format-specification-mini-language" rel="nofollow">https://docs.python.org/2/library/string.html#format-specification-mini-language</a>.</p> <ul> <li>The first <code>0</code> means pad with "0"</li> <li>T...
1
2016-10-13T02:33:26Z
[ "python", "python-2.7", "pandas" ]
'B': "{:0<4.0f}" | How should I read this?
40,011,269
<p>While studying <a href="http://pandas.pydata.org/pandas-docs/stable/style.html" rel="nofollow">Pandas Style</a>, I got to the following:</p> <pre><code>df.style.format("{:.2%}") </code></pre> <p>Which I understand means, turn every value to 2 decimal places and add a <code>%</code> in the end.</p> <p>Just after t...
0
2016-10-13T02:22:50Z
40,011,367
<p>The <a href="https://docs.python.org/3/library/string.html#format-specification-mini-language" rel="nofollow" title="format specification mini language">Python documentation for format strings</a> explains what this means.</p> <p>In the case of <code>0&lt;4.0f</code>, it means:</p> <pre><code>0 0-filled &lt; ...
1
2016-10-13T02:33:56Z
[ "python", "python-2.7", "pandas" ]
Installing python 3 for a specific environment
40,011,373
<p>I have <code>python 2.7.10</code> installed on my <code>mac</code>.</p> <p>but I happen to need <code>Python 3</code> to use a <code>python wrapper</code> for a given <code>API</code>.</p> <p>this is my folder structure:</p> <pre><code>apps/ myapp/ app.py gracenote/ pygn.py...
0
2016-10-13T02:34:29Z
40,011,419
<p>You'll need to install both versions of python at the same time</p> <pre><code>$ which python3 # copy the output of this command $ mkvirtualenv --python=/path/to/python3 ~/.virtualenvs/{your env name} $ workon {your env name} </code></pre>
0
2016-10-13T02:42:25Z
[ "python", "python-2.7", "python-3.x", "development-environment" ]
in Pandas, when using read_csv(), how to assign a NaN to a value that's not the dtype intended?
40,011,531
<p><strong>Note:</strong> Please excuse my very low skilled English, feel free to modify the question's title, or the following text to be more understandable</p> <p>I have this line in my code:</p> <pre><code>moto = pd.read_csv('reporte.csv') </code></pre> <p>It sends a <strong><code>DtypeWarning: Columns (2,3,4,5,...
2
2016-10-13T02:55:06Z
40,011,736
<p>I tried creating a csv to replicate this feedback but couldn't on pandas 0.18, so I can only recommend two methods to handle this:</p> <p><strong>First</strong></p> <p>If you know that your missing values are all marked by a string 'none', then do this:</p> <pre><code>moto = pd.read_csv("test.csv", na_values=['no...
2
2016-10-13T03:19:46Z
[ "python", "pandas" ]
How to find the non-repeating string from the list of string
40,011,539
<p>There is given a list of strings out which we have to print the unique strings. Unique string is a string which is not repeated in the list of string.</p> <pre><code>Ex li = [ram,raj,ram,dev,dev] unique string = raj. </code></pre> <p>I thought of one algorithm. </p> <p>First sort the String array, then check the...
-2
2016-10-13T02:55:44Z
40,011,825
<p>You could try below</p> <pre><code> List&lt;String&gt; names = Arrays.asList("ram", "raj", "ram", "dev", "dev"); Map&lt;String, Long&gt; nameCount = names.stream().collect(Collectors.groupingBy(s -&gt; s, Collectors.counting())); List&lt;String&gt; unique = nameCount.entrySet().stream().filter(e -&gt; e....
0
2016-10-13T03:28:15Z
[ "java", "python", "c++", "string", "algorithm" ]
How to find the non-repeating string from the list of string
40,011,539
<p>There is given a list of strings out which we have to print the unique strings. Unique string is a string which is not repeated in the list of string.</p> <pre><code>Ex li = [ram,raj,ram,dev,dev] unique string = raj. </code></pre> <p>I thought of one algorithm. </p> <p>First sort the String array, then check the...
-2
2016-10-13T02:55:44Z
40,011,886
<h2>Solution 1</h2> <p>You can solve your problem in O(n) complexity.</p> <p>just create a <a href="https://en.wikipedia.org/wiki/Hash_table" rel="nofollow">hash table</a> to store the word counters, and than access just the words with <code>count == 1</code></p> <h2>Solution 2</h2> <p>This solution is not Liniar t...
0
2016-10-13T03:35:35Z
[ "java", "python", "c++", "string", "algorithm" ]
How to find the non-repeating string from the list of string
40,011,539
<p>There is given a list of strings out which we have to print the unique strings. Unique string is a string which is not repeated in the list of string.</p> <pre><code>Ex li = [ram,raj,ram,dev,dev] unique string = raj. </code></pre> <p>I thought of one algorithm. </p> <p>First sort the String array, then check the...
-2
2016-10-13T02:55:44Z
40,012,806
<p>You can try out this simple python implementation, which is based on the concept of using a <strong>HashMap</strong>:</p> <pre><code>li = ['ram','raj','ram','dev','dev'] hash = dict() for item in li: if item in hash: hash[item] += 1 else: hash[item] = 1 print "unique string(s):", for key, ...
0
2016-10-13T05:15:45Z
[ "java", "python", "c++", "string", "algorithm" ]
How to select all values from one threshold to another?
40,011,617
<p>I have an ordered tuple of data:</p> <pre><code>my_data = (1,2,3,2,4,2,3,3,5,7,5,3,6,8,7) </code></pre> <p>How can I subset the tuple items such that all items including and after the first instance of 3 are kept until the first value == 7? For example, the result should be:</p> <pre><code>desired_output = (3,2,4...
-1
2016-10-13T03:04:14Z
40,011,676
<p>I am not sure what you mean by threshold (value == 7, or any value >= 7), but here is a solution:</p> <pre><code>my_data = (1,2,3,2,4,2,3,3,5,7,5,3,6,8,7) index1 = my_data.index(3) index2 = my_data.index(7) desired_output = my_data[index1:index2+1] print desired_output </code></pre>
4
2016-10-13T03:12:00Z
[ "python", "tuples" ]