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
what are the rules for iterator invalidation?
38,003,119
<p>Is there a general rule that all modules follow?</p> <p><a href="http://stackoverflow.com/questions/38003030/python-write-xml-without-any-tags-for-empty-deleted-elements">In my case</a>, I'm using <a href="https://docs.python.org/3/library/xml.etree.elementtree.html#reference" rel="nofollow">Python xml.etree librar...
0
2016-06-23T22:46:31Z
38,003,580
<p>There are lots of cases where modifying an iterable while iterating over it cause problems. <a href="http://stackoverflow.com/questions/37702011/removing-an-element-from-a-parsed-xml-tree-disrupts-iteration/37779451#37779451">Here's</a> an example where an XML tree's iteration is messed up when an element is remove...
1
2016-06-23T23:43:52Z
[ "python", "xml", "iterator" ]
django intermediate model with no foreign key error
38,003,151
<p>Building some complex models for my django app and got some help here:</p> <p><a href="http://stackoverflow.com/questions/37979749/using-manytomany-through-correctly-for-complex-model-in-django/37980278?noredirect=1#comment63450091_37980278">Using ManyToMany through correctly for complex model in django</a></p> <p...
0
2016-06-23T22:49:43Z
38,003,360
<blockquote> <p>When you set up the intermediary model, you explicitly specify foreign keys to the models that are involved in the many-to-many relationship. This explicit declaration defines how the two models are related</p> </blockquote> <p><code>Group</code> (not <code>GroupLocations</code>) and <code>Provid...
1
2016-06-23T23:17:25Z
[ "python", "django", "django-models" ]
Is there any reason to use Ipyparallel for common python script (not ipython notebook) over multiprocessing modue?
38,003,213
<p>Is there any reason to use Ipyparallel for common python script (not ipython notebook)?</p>
0
2016-06-23T22:56:58Z
38,015,997
<p>There are a few reasons why you might choose IPython parallel, which may or may not be relevant to you:</p> <ol> <li>There are some things IPython parallel can serialize efficiently (numpy arrays) that multiprocessing doesn't do as well because it pickles everything</li> <li>IPython parallel can distribute work acr...
1
2016-06-24T14:37:46Z
[ "python", "ipython", "ipython-parallel" ]
How to read a csv django http response
38,003,220
<p>In a view, I create a Django HttpResponse object composed entirely of a csv using a simply csv writer:</p> <pre><code>response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="foobar.csv"' writer = csv.writer(response) table_headers = ['Foo', 'Bar'] writer.w...
0
2016-06-23T22:58:03Z
38,003,382
<p><code>response.content</code> provides bytes. You need to decode this to a string:</p> <pre><code>foo = response.content.decode('utf-8') </code></pre> <p>Then pass this string to the csv reader using io.StringIO:</p> <pre><code>import io reader = csv.reader(io.StringIO(foo)) </code></pre>
3
2016-06-23T23:20:05Z
[ "python", "django", "csv" ]
How to read a csv django http response
38,003,220
<p>In a view, I create a Django HttpResponse object composed entirely of a csv using a simply csv writer:</p> <pre><code>response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="foobar.csv"' writer = csv.writer(response) table_headers = ['Foo', 'Bar'] writer.w...
0
2016-06-23T22:58:03Z
38,003,417
<p>You can use <a href="https://docs.python.org/3/library/io.html#io.TextIOWrapper" rel="nofollow"><code>io.TextIOWrapper</code></a> to convert the provided bytestring to a text stream:</p> <pre><code>import io reader = csv.reader(io.TextIOWrapper(io.BytesIO(response.content), encoding='utf-8')) </code></pre> <p>This...
2
2016-06-23T23:23:36Z
[ "python", "django", "csv" ]
Draw trees or graph using python from a relationship table
38,003,326
<p>Is there a way to draw a tree structure or graph using python from some relationship(parent/child) table? The child may have more than one parent. For example, </p> <pre><code>|Parent |Child |none |node 1 |none |node 2 |node 1 |node 3 |node 2 |node 3 |node 2 |node 4 </code></pre> <p>This gives </p> <pr...
0
2016-06-23T23:12:24Z
38,003,492
<p>Coming from other languages that have trees builtin, python may seem a bit strange because it doesn't have one. </p> <p>I would recommend building a parent to child dict, in which the values are actually lists of children:</p> <p><code>{node1:[node3], node2:[node3, node4]}</code></p>
0
2016-06-23T23:33:02Z
[ "python", "graph", "tree" ]
How to convert a nested if statement into a lambda function (python)
38,003,355
<p>For a recent Python homework assignment, we were assigned to create a function that would return words in a list that start with 'd'. Here's the relevant code:</p> <pre><code>def filter_words(word_list, letter): ''' INPUT: list of words, string OUTPUT: list of words Return the words from word_list which start with...
0
2016-06-23T23:17:06Z
38,003,384
<p>In a way, the lambda equivalent of your if condition would be:</p> <pre><code>fn = lambda x: x[0] == 'd' #fn("dog") =&gt; True, fn("test") =&gt; False </code></pre> <p>Further, you can use <code>.startswith(..)</code> instead of comparing <code>[0]</code>. It then becomes something like:</p> <pre><code>letter_li...
5
2016-06-23T23:20:19Z
[ "python", "lambda" ]
How to convert a nested if statement into a lambda function (python)
38,003,355
<p>For a recent Python homework assignment, we were assigned to create a function that would return words in a list that start with 'd'. Here's the relevant code:</p> <pre><code>def filter_words(word_list, letter): ''' INPUT: list of words, string OUTPUT: list of words Return the words from word_list which start with...
0
2016-06-23T23:17:06Z
38,003,392
<p>I'm not sure what you're asking, because changing the <strong>if</strong> into a lambda of some sort doesn't seem to be useful. You neglected to post your failed code so we'd know what you want.</p> <p>However, there is a succinct way to express what you're doing:</p> <pre><code>def filter_words(word_list, letter...
1
2016-06-23T23:20:51Z
[ "python", "lambda" ]
How to define set from circle in Python script
38,003,364
<p>I want to define set to circles in a Python script for abaqus.</p> <pre><code>for j in range (45): x=data[2*j] # Coordinate X of the center of the circle y=data[2*j+1] # Coordinate X of the center of the circle # r = Radius circle print (mdb.models['Model-1'].rootAssembly.instanc...
1
2016-06-23T23:18:11Z
38,005,149
<p>you need to feed <code>findAt</code> a "tuple of tuples" so that it returns a sequence:</p> <pre><code>edges=mdb.models['Model-1'].rootAssembly.instances ['matrix-1'].edges.findAt(((x+r,y,0),),) </code></pre> <p>alternately get the index of the found edge and build your own sequence:</p> <pre><code> assem=m...
0
2016-06-24T03:24:24Z
[ "python", "abaqus" ]
How to request a url from the browser
38,003,388
<p>I would like to receive the address of the site of the active tab in the browser from my application (in Python or Java)</p>
-2
2016-06-23T23:20:26Z
38,003,715
<p>look into a library called selenium you are going to need a headless web browser too.</p>
0
2016-06-23T23:59:43Z
[ "java", "python", "url", "browser" ]
Unicode Error using pandas: read_hdf
38,003,403
<p>After having searched in every forum/page/site, I can´t fix my problem. I am trying to read a .h5 file with pandas and I've got this message: <code>"UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 35120: ordinal not in range(128)"</code>. This message appears when I am trying to read both h5 an...
2
2016-06-23T23:22:01Z
38,016,540
<p>Well, after try differents things, i just ran my code with python 2.7 and it did work. I guess there is a bug with this or there is a different way to do that, but I choose the easy way. Thank you all!</p>
0
2016-06-24T15:06:09Z
[ "python", "pandas" ]
Pandas: Why is default column type for numeric float?
38,003,406
<p>I am using Pandas 0.18.1 with python 2.7.x. I have an empty dataframe that I read first. I see that the types of these columns are <code>object</code> which is OK. When I assign one row of data, the type for numeric values changes to <code>float64</code>. I was expecting <code>int</code> or <code>int64</code>. Why d...
0
2016-06-23T23:22:26Z
38,003,676
<p>The why is almost certainly to do with flexibility and speed. Just because Pandas has only seen an integer in that column so far doesn't mean that you're not going to try to add a float later, which would require Pandas to go back and change the type for all that column. A float is the most robust/flexible numeric ...
2
2016-06-23T23:54:56Z
[ "python", "pandas" ]
Pandas: Why is default column type for numeric float?
38,003,406
<p>I am using Pandas 0.18.1 with python 2.7.x. I have an empty dataframe that I read first. I see that the types of these columns are <code>object</code> which is OK. When I assign one row of data, the type for numeric values changes to <code>float64</code>. I was expecting <code>int</code> or <code>int64</code>. Why d...
0
2016-06-23T23:22:26Z
38,003,758
<p>If you are reading an empty dataframe, you can explicitly cast the types for each column after reading it. </p> <pre><code>dtypes = { 'bbox_id_seqno': object, 'type': object, 'layer': object, 'll_x': int, 'll_y': int, 'ur_x': int, 'ur_y': int, 'polygon_count': int } df = pd.read_c...
1
2016-06-24T00:05:31Z
[ "python", "pandas" ]
Pandas: Why is default column type for numeric float?
38,003,406
<p>I am using Pandas 0.18.1 with python 2.7.x. I have an empty dataframe that I read first. I see that the types of these columns are <code>object</code> which is OK. When I assign one row of data, the type for numeric values changes to <code>float64</code>. I was expecting <code>int</code> or <code>int64</code>. Why d...
0
2016-06-23T23:22:26Z
38,003,951
<p>It's not possible for Pandas to store <code>NaN</code> values in integer columns.</p> <p>This makes <code>float</code> the obvious default choice for data storage, because as soon as missing value arises Pandas would have to change the data type for the entire column. And missing values arise very often in practice...
0
2016-06-24T00:30:39Z
[ "python", "pandas" ]
Two files comparsion
38,003,516
<p>I have a really weird problem. I've got three files, which contain one column of numbers. I need to get ONLY unique values from first file, that are not present at second and third files.</p> <p>I tried Python like:</p> <pre><code>for e in firstfile: if e not in secondfile: resultfile.append(e) return ...
-2
2016-06-23T23:35:52Z
38,003,606
<p>The easiest way would be to read each file into a <code>set</code>, and then use Python's (very efficient) set operations to do the comparison. </p> <pre><code>file1 = set() file2 = set() for element in firstfile: file1.add(element) for element in secondfile: file2.add(element) unique = file1 - file2 </c...
0
2016-06-23T23:46:45Z
[ "python", "list", "shell", "comparison" ]
Two files comparsion
38,003,516
<p>I have a really weird problem. I've got three files, which contain one column of numbers. I need to get ONLY unique values from first file, that are not present at second and third files.</p> <p>I tried Python like:</p> <pre><code>for e in firstfile: if e not in secondfile: resultfile.append(e) return ...
-2
2016-06-23T23:35:52Z
38,003,671
<p><strong>What's wrong</strong></p> <blockquote> <p>And same for third file</p> </blockquote> <p>If you are really doing the same for the third file, i.e. comparing the original contents of the first file with the third, you can introduce duplicates of items that were not in the second file but are in the third. F...
2
2016-06-23T23:54:11Z
[ "python", "list", "shell", "comparison" ]
Two files comparsion
38,003,516
<p>I have a really weird problem. I've got three files, which contain one column of numbers. I need to get ONLY unique values from first file, that are not present at second and third files.</p> <p>I tried Python like:</p> <pre><code>for e in firstfile: if e not in secondfile: resultfile.append(e) return ...
-2
2016-06-23T23:35:52Z
38,003,708
<p>It's likely the issue might be that <code>first.csv</code> is strictly ASCII text, while <code>second.csv</code>, and <code>third.csv</code> are ASCII text, with CRLF line terminators. I would suggest you change them to the same format (ASCII text would probably work best).</p> <pre><code>$ file first.csv first.csv...
0
2016-06-23T23:59:02Z
[ "python", "list", "shell", "comparison" ]
Normalizing values in a curve_fit of Plancks Law from data set *Edit*
38,003,528
<p>I have a large set of data that in terms of Intensity counts and Wavelength that I want fit with Planks Law to determine the guess parameter for Temperature.</p> <p>The Data set is imported as a text file</p> <pre><code>import numpy as np import scipy as sp from scipy.optimize import curve_fit with open('Good_Sol...
0
2016-06-23T23:37:28Z
38,005,725
<p>You have a slightly finicky issue here: depending on your x values (wavelengths), the exponent, <code>1/(lamb*T)</code> can often be too large to be evaluated, and you'll get an overflow. (Or too small, and it will always result in zero.</p> <p>It might be good to try and split your Planck function into three parts...
3
2016-06-24T04:41:40Z
[ "python", "numpy", "scipy", "curve-fitting" ]
How to generate all injective functions with specified domain and range?
38,003,585
<p>I am a (very) beginner programmer, and especially new at Python. </p> <p>I want to take a specified domain and a specific range and generate injective maps. For example, I could have the domain be A = [1, 2] and the range be B = [1, 3] and I would like the output to look something like "(1 -> 1, 2 ->3 ), (1 -> 3, 2...
2
2016-06-23T23:44:23Z
38,003,621
<p>Permute one of the two lists (<code>from itertools import permutations</code>), and for each of the permutations do a one-to-one mapping (<code>zip(..)</code>).</p> <pre><code>&gt;&gt;&gt; from itertools import permutations &gt;&gt;&gt; a = [1,2,3] &gt;&gt;&gt; b = [4,5,6] &gt;&gt;&gt; [zip(a, x) for x in permutati...
3
2016-06-23T23:48:43Z
[ "python" ]
How to increment a variable contained within a class in python from outside of its class?
38,003,590
<p>I have a fairly simple python question, as I am pretty new to the language. I started writing a quick program just for practice, but have now become frustrated because I cannot get it to work.</p> <pre><code>import random import sys class Meta: turncounter = 1 class Enemy: life = 10 wis = 1 str ...
1
2016-06-23T23:45:06Z
38,003,703
<p>Your second while loop never ends if <code>move == 1</code> because the value of the variable <code>turnmeta</code> is never changed and is always 1 and the variable 'move` is always 1.</p> <p>You need to give them a new value in your loops: <code>turnmeta = Meta.turncounter % 2</code> and <code>move = random.randr...
0
2016-06-23T23:58:29Z
[ "python" ]
How to increment a variable contained within a class in python from outside of its class?
38,003,590
<p>I have a fairly simple python question, as I am pretty new to the language. I started writing a quick program just for practice, but have now become frustrated because I cannot get it to work.</p> <pre><code>import random import sys class Meta: turncounter = 1 class Enemy: life = 10 wis = 1 str ...
1
2016-06-23T23:45:06Z
38,003,751
<p>The problem is your while-loop is relying on <code>turnmeta</code>, which doesn't change when you increment <code>Meta.turncounter</code> in your class methods.</p> <p>Notice:</p> <pre><code>&gt;&gt;&gt; class Meta(object): ... turncounter = 0 ... &gt;&gt;&gt; turnmeta = Meta.turncounter &gt;&gt;&gt; turnmeta ...
2
2016-06-24T00:04:44Z
[ "python" ]
How to increment a variable contained within a class in python from outside of its class?
38,003,590
<p>I have a fairly simple python question, as I am pretty new to the language. I started writing a quick program just for practice, but have now become frustrated because I cannot get it to work.</p> <pre><code>import random import sys class Meta: turncounter = 1 class Enemy: life = 10 wis = 1 str ...
1
2016-06-23T23:45:06Z
38,003,754
<p><code>turnmeta</code> is the result of your calculation <code>Meta.turncounter % 2</code>.</p> <p>It doesn't make any reference to your <code>Meta.turncounter</code> anymore.</p> <p>You should reassign the turnmeta after each turns.</p>
0
2016-06-24T00:05:02Z
[ "python" ]
Python update dictionary into dictionary
38,003,607
<p>I am very novice in python, and I am currently learning the language. I found that array of arrays ( associative arrays ) are called as dictionaries in python ({}) I am facing a problem. I need to build a dictionary and update it in a <code>for</code> loop. My codes are below.</p> <pre><code>loc = {} result = { I g...
0
2016-06-23T23:46:46Z
38,003,804
<p>What you say is your desired output:</p> <pre><code>loc = { {'id' : 123 , 'status' : 'available' }, {'id' : 456 , 'status' : 'unavailable'} } </code></pre> <p>would not be a <code>dict</code>. It would be a <a href="https://docs.python.org/2/library/functions.html#func-set" rel="nofollow"><code>set</code><...
1
2016-06-24T00:09:21Z
[ "python", "python-2.7", "dictionary" ]
Python update dictionary into dictionary
38,003,607
<p>I am very novice in python, and I am currently learning the language. I found that array of arrays ( associative arrays ) are called as dictionaries in python ({}) I am facing a problem. I need to build a dictionary and update it in a <code>for</code> loop. My codes are below.</p> <pre><code>loc = {} result = { I g...
0
2016-06-23T23:46:46Z
38,004,254
<p>If <code>id</code> is unique, it seems more likely that what you really want is just a <code>dict</code> mapping <code>id</code> to <code>status</code>.</p> <pre><code>for res in result: loc[res.id] = res.status </code></pre> <p>If you iterate over <code>loc.viewitems()</code> (in Py3, just <code>loc.items()</...
2
2016-06-24T01:15:52Z
[ "python", "python-2.7", "dictionary" ]
Creating a data frame from two dataframes with period indices that overlap but are not identical
38,003,626
<p>I've got two data frames, each one representing an irregular time series.</p> <p>Here is a sample from df1:</p> <pre><code>index 2014-10-30 16:00 118 2014-10-30 19:00 160 2014-10-30 22:00 88 2014-10-31 00:00 128 2014-10-31 03:00 89 2014-10-31 11:00 66 2014-10-31 17:00 84 2014-10-31 20:00 ...
0
2016-06-23T23:49:03Z
38,003,814
<p>Instead of <code>merge</code>, try <code>join</code> in this case, as it will preserve the index:</p> <p><code>df1.join(df2, how='outer')</code></p> <p>It shouldn't need any other configuration in this case. Joining with <code>outer</code> will leave <code>NaN</code> values in place wherever a column lacks a value...
0
2016-06-24T00:10:42Z
[ "python", "pandas" ]
Creating a data frame from two dataframes with period indices that overlap but are not identical
38,003,626
<p>I've got two data frames, each one representing an irregular time series.</p> <p>Here is a sample from df1:</p> <pre><code>index 2014-10-30 16:00 118 2014-10-30 19:00 160 2014-10-30 22:00 88 2014-10-31 00:00 128 2014-10-31 03:00 89 2014-10-31 11:00 66 2014-10-31 17:00 84 2014-10-31 20:00 ...
0
2016-06-23T23:49:03Z
38,004,128
<p>Two other options:</p> <p>1) use <code>merge</code> </p> <pre><code>df = df1.merge(df2, left_index=True, right_index=True, how='outer') </code></pre> <p>2) use <code>append</code> since the two dfs have the exact same columns then drop duplicated rows</p> <pre><code>df = df1.append(df2).drop_duplicates() </co...
0
2016-06-24T00:56:24Z
[ "python", "pandas" ]
Why is subprocess.py throwing a WindowsError?
38,003,701
<p>I'm trying to use the testing.postgresql package to test a few scripts and am running into this error upon instantiating testing.postgresql.Postgresql() or testing.postgresql.PostgresqlFactory():</p> <pre><code>File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "C:\Python27\lib\site-packages\testing\common\databa...
0
2016-06-23T23:57:58Z
38,003,785
<p>Viewing the source, it doesn't appear that this is compatible with Windows. The package expects a UNIX-style environment.</p> <p><a href="https://github.com/tk0miya/testing.postgresql/blob/master/src/testing/postgresql.py" rel="nofollow">testing.postgresql/src/testing/postgresql.py</a></p> <pre><code>def find_prog...
1
2016-06-24T00:07:23Z
[ "python", "windows", "postgresql", "subprocess", "windowserror" ]
Making a new list with enumerate and sorting
38,003,747
<p>I am brand new to python and coding in general. I'm actually a Cinema 4D artist. C4D has a built in python script manager. I will do my best to explain what I'm trying for.</p> <p>I have a sphere. The sphere is broken up into points. I have calculated the distance each point on the sphere is away from a different o...
1
2016-06-24T00:04:13Z
38,003,807
<p>Use <code>enumerate(..)</code>. When called on a list and iterated over, it returns elements of the list as a tuple of <code>(index, element)</code>.</p> <p>For the second half of your question, use <code>sorted(.., key=&lt;func&gt;)</code>. <code>sorted(..)</code> when called with a <code>key=</code> will use the ...
1
2016-06-24T00:09:45Z
[ "python" ]
Making a new list with enumerate and sorting
38,003,747
<p>I am brand new to python and coding in general. I'm actually a Cinema 4D artist. C4D has a built in python script manager. I will do my best to explain what I'm trying for.</p> <p>I have a sphere. The sphere is broken up into points. I have calculated the distance each point on the sphere is away from a different o...
1
2016-06-24T00:04:13Z
38,004,194
<p>To add to <a href="http://stackoverflow.com/a/38003807/3159288">SuperSaiyan's answer</a>, the built-in <a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow"><code>zip</code></a> provides a more robust tool for solving all similar problems. While <code>enumerate</code> simply pairs a list of e...
0
2016-06-24T01:05:52Z
[ "python" ]
Python function returns uncode strings instead of datetime objects
38,003,825
<p>I have a work around for this problem, but I want to know why it is a problem. In the code below the filter function is a list of unicode strings rather than the datetime objects that is_date_string makes</p> <pre><code>import re import requests datestrings = re.compile(r'\d*-\d*-\d* \d*:\d*:\d*') def is_date_str...
1
2016-06-24T00:12:42Z
38,003,864
<p>Filter use the result of the function to do filtering but the return is the subset of the iterable, which is in your case a string. </p> <p>What you want seems something like this</p> <p><code>d = filter(None, map(is_date_string,datestrings.findall(request.text)))</code></p> <p><a href="https://docs.python.org/2/...
5
2016-06-24T00:18:05Z
[ "python", "datetime" ]
Python Mongodb limiting by batch size times out
38,003,846
<p>I'm trying to scrape a huge (5gb) mongo database, so I'm limiting the batch size in order to be manageable. However, I'm still getting a time out error :/</p> <p>My mongo knowledge is admittedly not the best, so if I'm doing something utterly stupid, please let me know! I already searched through the documentation ...
1
2016-06-24T00:15:29Z
38,008,904
<p>To get more than a single document as the result of a query we use the find() method. find() returns a Cursor instance, which allows us to iterate over all matching documents.</p> <p><a href="https://api.mongodb.com/python/current/tutorial.html#querying-for-more-than-one-document" rel="nofollow">About find()</a></p...
1
2016-06-24T08:30:29Z
[ "python", "mongodb", "collections", "timeout", "pymongo" ]
How do I specify dtype with read_csv for data and index independently
38,003,848
<p>I am trying to specify the <code>dtype</code> of the values when loading a pandas dataframe, but only for the values in the dataframe, not the index. Is this possible?</p> <pre><code>from io import StringIO my_csv = StringIO('''b, c\nx, 1, 2\ny, 3, 2''') </code></pre> <p>I would have assumed the following would wo...
0
2016-06-24T00:16:16Z
38,010,441
<p>One method would be to read just the header to get the column names and then <code>zip</code> them with your desired dtype and read the csv again:</p> <pre><code>In [6]: t="""b,c x,1,2 y,3,2""" cols = pd.read_csv(io.StringIO(t), nrows=1).columns dtyp = dict(zip(cols,['int64'] * len(cols))) pd.read_csv(io.StringIO(t...
1
2016-06-24T09:49:22Z
[ "python", "pandas" ]
Can't find a constant-time module in cryptography package used on AWS Lambda
38,003,860
<p><em>[I am new to Python 2.7 and AWS Lambda, any help is appreciated]</em></p> <p>I followed the <a href="https://aws.amazon.com/blogs/compute/scheduling-ssh-jobs-using-aws-lambda/" rel="nofollow">AWS Lambda tutorial</a> and created a virtualenv to include Python libs associated with the use of paramiko to copy a fi...
3
2016-06-24T00:17:33Z
39,496,915
<p>Since lambda runs under the hood on amazon linux instances, you basically need to:</p> <ol> <li>spin up an amazon linux ec2 instance</li> <li>create a virtualenv and <code>pip install</code> all packages you need</li> <li><code>scp</code> the files down to wherever your local deployment package lives</li> </ol> <p...
3
2016-09-14T18:04:24Z
[ "python", "amazon-web-services", "paramiko", "aws-lambda", "pycrypto" ]
pandas DataFrame assign with format
38,003,927
<p>I'm trying to use assign to create a new column in a pandas DataFrame. I need to use something like str.format to have the new column be pieces of existing columns. For instance...</p> <pre><code>import pandas as pd df = pd.DataFrame(np.random.randn(3, 3)) </code></pre> <p>gives me...</p> <pre><code> ...
0
2016-06-24T00:27:02Z
38,004,007
<pre><code>In [131]: df.assign(c="a"+df[0].astype(str)+"b") Out[131]: 0 1 2 c 0 0.833556 -0.106183 -0.910005 a0.833556419295b 1 -1.487825 1.173338 1.650466 a-1.48782514804b 2 -0.836795 -1.192674 -0.212900 a-0.836795026809b </code></pre> <hr> <p><code>'a{}b'.format(d...
0
2016-06-24T00:39:54Z
[ "python", "pandas" ]
pandas DataFrame assign with format
38,003,927
<p>I'm trying to use assign to create a new column in a pandas DataFrame. I need to use something like str.format to have the new column be pieces of existing columns. For instance...</p> <pre><code>import pandas as pd df = pd.DataFrame(np.random.randn(3, 3)) </code></pre> <p>gives me...</p> <pre><code> ...
0
2016-06-24T00:27:02Z
38,004,041
<pre><code>df['c'] = "a" + df[0].astype(str) + 'b' df 0 1 2 c 0 -1.134154 -0.367397 0.906239 a-1.13415403091b 1 0.551997 -0.160217 -0.869291 a0.551996920472b 2 0.490102 -1.151301 0.541888 a0.490101854737b </code></pre>
0
2016-06-24T00:45:13Z
[ "python", "pandas" ]
Returning variables in Python Selenium from Javascript and updating them with selenium
38,004,003
<p>So I am currently using <a href="https://jobs.walmart.com/us/login?jobId=688590-5022" rel="nofollow">walmart's job site</a> and i'm trying to log in using selenium with python. So far I am using the following code:</p> <pre><code>from selenium import webdriver from selenium import webdriver from selenium.common.exc...
1
2016-06-24T00:39:34Z
38,004,417
<p>Unless you have a particular reason to use JS, selenium can do this for you:</p> <pre><code>driver.find_element_by_id('username').send_keys(username_variable) driver.find_element_by_id('password').send_keys(password_variable) driver.find_element_by_id('event-submit').click() </code></pre> <p>Did you have some othe...
2
2016-06-24T01:38:37Z
[ "javascript", "python", "selenium", "javascript-events" ]
Getting the last created item selection
38,004,124
<p>I run a command in which it creates a new camera, however at the end of the said function, there is no selection nor does the function selects the object after it has run its course. So are there any commands in which I could possible query for the last created item?</p> <p>I tried using `cmds.listHistory' but that...
0
2016-06-24T00:55:55Z
38,004,912
<p>Why can't you just stuff the new camera into a variable instead of relying on selection?</p> <pre><code>new_camera, new_camera_shape = cmds.camera() </code></pre> <hr> <p>You're not using the right syntax when formatting with <code>%</code>:</p> <pre><code>"My name is %s" % "Jon Snow" # Works for single "My name...
1
2016-06-24T02:51:04Z
[ "python", "maya" ]
Getting the last created item selection
38,004,124
<p>I run a command in which it creates a new camera, however at the end of the said function, there is no selection nor does the function selects the object after it has run its course. So are there any commands in which I could possible query for the last created item?</p> <p>I tried using `cmds.listHistory' but that...
0
2016-06-24T00:55:55Z
38,011,147
<p>If you want to keep the last created object. You can create a class that contain a variable history where your append in your other script the last object created.</p> <pre><code>class History: idCounter = [] def __init__(self, name): History.idCounter.append(name) print(History.idCounter) ...
0
2016-06-24T10:24:48Z
[ "python", "maya" ]
How to read a file correctly in flask
38,004,179
<p>I would like to pass a list to Jinja that it can iterate over and populate the values of select field. I'm struggling to build the list correctly that be used to populate the select field correctly.</p> <p>Data I have is list of strings that I read from a text file. Data in text file is in following format.</p> <p...
-1
2016-06-24T01:03:54Z
38,004,261
<p><code>data_list</code> is a <code>string</code> so the iterator is going over each character. To get a list, you could run <code>eval(data_list)</code>, though this is potentially unsafe. You should structure your text file in a different way, with some deliminator between values, then you could set <code>data_list<...
0
2016-06-24T01:16:53Z
[ "python", "flask" ]
How to read a file correctly in flask
38,004,179
<p>I would like to pass a list to Jinja that it can iterate over and populate the values of select field. I'm struggling to build the list correctly that be used to populate the select field correctly.</p> <p>Data I have is list of strings that I read from a text file. Data in text file is in following format.</p> <p...
-1
2016-06-24T01:03:54Z
38,004,552
<p>Change the format of your input file to this:</p> <pre><code>Afghanistan Albania Algeria </code></pre> <p>Then your code becomes:</p> <pre><code>with open(filename, 'r') as f: country_list = [line.strip() for line in f] return render_template('signup.html', countryList= country_list) </code></pre> <...
0
2016-06-24T02:00:08Z
[ "python", "flask" ]
How do I join two pandas data frames in pandasql using the index?
38,004,197
<p>I know how to join tables in various ways in pandas - concat, merge, etc. but I would like to know how to do this using pandasql as well. Specifically, I'd like to join two pandas data frames on the index. Is this possible? When I do</p> <pre><code>new_df = pysqldf("SELECT a.*, b.list3 from df1 as a INNER JOIN ...
0
2016-06-24T01:06:57Z
39,540,050
<p>Just name the index <code>df1.index.rename('foo', inplace=True)</code> then you can refer to the index by column named <code>'foo'</code> in the sql query.</p> <p>That's because pandasql will check if the index name is set:</p> <blockquote> <p>From <a href="https://github.com/yhat/pandasql/blob/a6b7ac405ef741400...
0
2016-09-16T21:04:44Z
[ "python", "pandas", "join", "dataframe", "pandasql" ]
Get encoding bug in Jupyter when writing and reading binary file using Python
38,004,235
<p>I executed the following code in Jupyter, trying to deal with a binary file called <strong>bfile</strong>. However, when I opened the file in Jupyter, I got the error message as shown in the picture below. And when I opened the file using Notepad, I got a bunch of messy characters. Anyone call help (please be plain ...
-1
2016-06-24T01:11:52Z
38,004,721
<p>You appear to try and open the binary file you just written (with just the binary values 0 to 255 inclusive) in Jupyter. That's not how Jupyter works: what is it supposed to do with that (random) binary file?</p> <p>Jupyter can open e.g. notebook files. It will likely also open plain text files, or even image files...
0
2016-06-24T02:24:54Z
[ "python", "encoding", "jupyter", "jupyter-notebook" ]
python class objects not drawing graphics window
38,004,451
<p>I don't understand why the following code will not construct a graphics window with the circle. It does construct an object, but not graphically, when I run <code>SomeObject = Tracker()</code></p> <p>Why is that? This is a simple snippet of code, just for me to understand why I'm not getting a graphics window.</p> ...
-1
2016-06-24T01:44:32Z
38,006,731
<p>You cannot see your circle because:</p> <ol> <li>The radius of your circle (0.5) is too small </li> <li>You placed the <em>center</em> of this small circle at (0, 0), which is at the top left corner</li> <li>Your class's initializer was mispelled <strong>inti</strong>, hence the code was not called when you created...
0
2016-06-24T06:16:52Z
[ "python", "graphics" ]
How to plot two data sets with different time interval and have them share axis in Python Matplotlib
38,004,491
<p>I have two data sets, A and B:</p> <p>Set A: <br> <kbd>date time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>data</kbd><br> <kbd>6/21/2016 00:00:01</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1</kbd><br> <kbd>6/21/2016 01:00:00</kbd><kbd>&nbsp;&nbsp;&n...
1
2016-06-24T01:51:37Z
38,006,367
<p>Skipping right to question (c), if it were me, I wouldn't bother filling both datasets with second resolution. Instead I would do a simple <code>pd.merge</code> and plot.</p> <pre><code>df_C = pd.merge(df_A, df_B, how='outer', left_index=True, right_index=True) # forward fill data df_C.ffill(inplace=True) </code></...
2
2016-06-24T05:48:06Z
[ "python", "datetime", "matplotlib" ]
Recursive arbitrary tree height in python
38,004,577
<p>I'm trying to implement a recursive method to determine the tree height of an arbitrary tree, not a binary tree. We are given two inputs one is 'n' the number of vertices. The second line contains n integer numbers from −1 to n − 1 parents of vertices. If the i-th one of them (0 ≤ i ≤ n − 1) is −1, verte...
-2
2016-06-24T02:03:43Z
38,004,657
<p>I believe what you're looking for is <a href="https://en.wikipedia.org/wiki/Memoization" rel="nofollow">memoization</a>:</p> <p>The naive implementation, for each node, looks at the entire path to the root, stores that height, then recomputes it... over and over.</p> <p>With memoization, you keep a memo of calcula...
1
2016-06-24T02:16:12Z
[ "python", "algorithm", "recursion", "tree" ]
Formatting a Two Dimensional Expanding Dictionary
38,004,612
<p>How to write a two dimensional recursive function in python where my input looks something like this:</p> <pre><code>{ 'Tj634f': { 'child': ['Tj256f', 'Tj996f'], 'title': 'FSIT'}, 'Tj227f': {'child': None, 'title': 'MEGP'}, 'Tj727f': {'child': None, 'title': 'MSIG/OF'}, 'Tj738f...
0
2016-06-24T02:09:22Z
38,007,228
<pre><code>dictionary = { 'Tj634f': {'child': ['Tj256f', 'Tj996f'], 'title': 'FSIT'}, 'Tj227f': {'child': None, 'title': 'MEGP'}, 'Tj727f': {'child': None, 'title': 'MSIG/OF'}, 'Tj738f': {'child': None, 'title': 'EDVAN'}, 'Tj279f': {'child': None, 'title': 'L-L3dary'}, 'Tj230f': {'child': None, ...
1
2016-06-24T06:50:20Z
[ "python", "recursion" ]
Django not hitting Class View on Form Get
38,004,615
<p>I have this url defined:</p> <pre><code>url(r'^persons/(?P&lt;id_person&gt;P\.\d+)/forms/(?P&lt;id_form&gt;\w+\.\d+)/$', views.PersonFormView.as_view()) </code></pre> <p>The regex checks out testing with a regex testor: <code>persons/P.1/forms/D.1/</code></p> <p>This is my Class View:</p> <pre><code>class Person...
0
2016-06-24T02:09:44Z
38,004,741
<p>Your regex is not correct for that url.</p> <p>Try this one instead:</p> <pre><code>url(r'^persons/P.(?P&lt;id_person&gt;\d+)/forms/D.(?P&lt;id_form&gt;\d+)/$', some_view), </code></pre> <p><strong>Edit:</strong></p> <p>if second argument is optional it should be declared with an *. Like this (not tested):</p> ...
0
2016-06-24T02:28:14Z
[ "python", "django", "django-class-based-views" ]
django selenium test close browser too early
38,004,632
<p>I am learning django with this book: Test Driven Development with Python.<br> A problem is that my functional test get random result.<br> It passes the test sometimes and it does not most of the time.<br> And while it fails, the error hint is:<br> <code>http.client.RemoteDisconnected: Remote end closed connection wi...
0
2016-06-24T02:13:25Z
38,004,934
<p>The problem is with firefox webdriver.<br> Suggested by @intelis, I switch to chrome driver, and the test becomes stable.<br> By the time of this posting, I am using Selenium 2.53.5, and I switched to chrome driver 2.22 linux-64. </p>
0
2016-06-24T02:53:53Z
[ "python", "django", "selenium" ]
What's the most efficient way to detect duplicates in numpy arrays of images with Python?
38,004,693
<p>I'm trying to detect duplicates and near-duplicates in a numpy array of images in Python. I'm using notMNIST (character image) data from <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/1_notmnist.ipynb" rel="nofollow">this assignment/tutorial</a>.</p> <p>My approach consis...
1
2016-06-24T02:20:32Z
38,007,942
<p>The <a href="https://github.com/EelcoHoogendoorn/Numpy_arraysetops_EP" rel="nofollow">numpy_indexed</a> package (disclaimer: I am its author) will allow you to find exact matches trivially and efficiently.</p> <pre><code>import numpy_indexed as npi unique = npi.unique(train_dataset) duplicate = npi.multiplicity(tra...
1
2016-06-24T07:31:26Z
[ "python", "image", "numpy" ]
Function of semicolon while deleting an item from a list
38,004,854
<p>I have a list like this, I want to delete <code>("poolhouse", 24.5)</code>.</p> <p>When I use semicolon it only deletes the strings. I dont know why. Isn't it supposed to delete what number I mentioned in the brackets?</p> <p>Two strings are deleted <code>[10]</code> and <code>[12]</code>.</p> <p>I want to know t...
1
2016-06-24T02:43:35Z
38,004,979
<p>When you delete the item at index 10, all the items after index 10 get moved up. Either correct this to:</p> <pre><code>del areas[10], areas[11] </code></pre> <p>or use the <code>remove</code> method on your list:</p> <pre><code>for i in ("poolhouse", 24.5): areas.remove(i) </code></pre>
1
2016-06-24T03:01:04Z
[ "python", "list" ]
Function of semicolon while deleting an item from a list
38,004,854
<p>I have a list like this, I want to delete <code>("poolhouse", 24.5)</code>.</p> <p>When I use semicolon it only deletes the strings. I dont know why. Isn't it supposed to delete what number I mentioned in the brackets?</p> <p>Two strings are deleted <code>[10]</code> and <code>[12]</code>.</p> <p>I want to know t...
1
2016-06-24T02:43:35Z
38,005,128
<p>The semicolon is just a way to put two statements on a single line, but generally doesn't change the behavior of your program.</p> <p>As others have pointed out, deleting the element at index <code>[10]</code> causes all the following element's indices to be shifted down by one, so any subsequent operations must ha...
2
2016-06-24T03:22:35Z
[ "python", "list" ]
PyQt5 show a file content in message window
38,004,988
<p>I have a file info.txt, and I want to show content when I click on Info.</p> <pre><code>import sys from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication, QMessageBox from PyQt5.QtGui import QIcon file=open("info.txt","r") data=file.read() class Example(QMainWindow): def showdialog(self...
1
2016-06-24T03:02:26Z
38,008,842
<p>You're defining <code>showdialog</code> as a method of your class <code>Example</code>. This</p> <pre><code>sourceAction.triggered.connect(showdialog) </code></pre> <p>however, looks for <code>showdialog</code> in the local and global namespace - where it isn't defined. Instead, connect the signal to the the metho...
0
2016-06-24T08:26:34Z
[ "python", "pyqt" ]
what`s the meaning of {"item1","item2",...} in python2.7
38,004,999
<p>I was confused about the structure {item1,item2,item3} in python2.7. Is it a set? </p> <p>what i did :</p> <p><img src="http://i.stack.imgur.com/UjDcg.png" alt="python2.7"></p> <p>while</p> <p><img src="http://i.stack.imgur.com/lDWSo.png" alt="python2.3"></p> <p>so,what`s the meaning of {"item1","item2",...} in...
1
2016-06-24T03:04:14Z
38,005,017
<pre><code>type(a) </code></pre> <p>Yes, it is. You can use type().</p>
0
2016-06-24T03:07:12Z
[ "python", "dictionary", "structure" ]
what`s the meaning of {"item1","item2",...} in python2.7
38,004,999
<p>I was confused about the structure {item1,item2,item3} in python2.7. Is it a set? </p> <p>what i did :</p> <p><img src="http://i.stack.imgur.com/UjDcg.png" alt="python2.7"></p> <p>while</p> <p><img src="http://i.stack.imgur.com/lDWSo.png" alt="python2.3"></p> <p>so,what`s the meaning of {"item1","item2",...} in...
1
2016-06-24T03:04:14Z
38,005,071
<p>You can inspect the type an object with the <code>type()</code> function and figure what's going on :)</p> <p>You will discover that in python2.7, <code>a={1, 2, 3}</code> is a <strong>Set</strong>. You might be wondering "Hey, but in python2.3 there was a set data structure as well!"</p> <p>Well, the syntax was s...
4
2016-06-24T03:14:44Z
[ "python", "dictionary", "structure" ]
How to parse empty JSON property/element in Python
38,005,021
<p>I am attempting to parse some JSON that I am receiving from a RESTful API, but I am having trouble accessing the data in Python because it appears that there is an empty property name.</p> <p>A sample of the JSON returned:</p> <pre><code>{ "extractorData" : { "url" : "RetreivedDataURL", "resourceId" : "e38e1a7dd...
0
2016-06-24T03:07:51Z
38,005,342
<p>If you look at json carefully the <code>data</code> key that you are accessing is actually a list, but <code>data['group']</code> is trying to access it as if it were a dictionary, which is raising the TypeError.</p> <p>To minify your json it is something like this</p> <pre><code>{ "extractorData": { "...
1
2016-06-24T03:53:49Z
[ "python", "json", "parsing", null ]
XPath select image links - parent href link of img src only if it exists, else select img src link
38,005,084
<p>I ran into a somewhat complicated XPath problem. Consider this HTML of part of a web page (I used Imgur and replaced some text):</p> <pre><code>&lt;a href="//i.imgur.com/ahreflink.jpg" class="zoom"&gt; &lt;img class="post-image-placeholder" src="//i.imgur.com/imgsrclink.jpg"&gt; &lt;/img&gt; &lt;/a&gt; </co...
4
2016-06-24T03:16:03Z
38,005,195
<p><em>You don't have to do it in a single XPath expression</em>. Here is a Scrapy specific implementation omitting the image extension check (judging by the comments, you've already figured that out):</p> <pre><code>images = response.xpath("//a/img") for image in images: a_link = image.xpath("../@href").extract_f...
3
2016-06-24T03:32:19Z
[ "python", "xpath", "web-scraping", "scrapy" ]
XPath select image links - parent href link of img src only if it exists, else select img src link
38,005,084
<p>I ran into a somewhat complicated XPath problem. Consider this HTML of part of a web page (I used Imgur and replaced some text):</p> <pre><code>&lt;a href="//i.imgur.com/ahreflink.jpg" class="zoom"&gt; &lt;img class="post-image-placeholder" src="//i.imgur.com/imgsrclink.jpg"&gt; &lt;/img&gt; &lt;/a&gt; </co...
4
2016-06-24T03:16:03Z
38,005,238
<p>This is very simple to do in a single xpath expression:</p> <pre><code>//a[not(@href)]/img/@src | //a[img]/@href </code></pre>
3
2016-06-24T03:40:12Z
[ "python", "xpath", "web-scraping", "scrapy" ]
Python interpolate to larger 1D array
38,005,123
<p>I have a 1D temperature array whose length is 109 elements. I would like to compare this array to a longer 1D temperature array whose length is 400 elements. Both arrays vary through space, and I assume that the endpoints of each array is at the same lat/lon. I want to interpolate the shorter array such that it h...
1
2016-06-24T03:22:02Z
38,005,187
<p>I'll use a spline to interpolate. Here is my solution</p> <pre><code>import scipy.interpolate as interp import numpy as np x = np.linspace(0, 399, num=109) x_new = np.linspace(0, 399) y = ARRAY WITH 109 ELEMENTS def f(t): return interp.InterpolatedUnivariateSpline(x, y) new_array = f(x_new) </code></pre>
0
2016-06-24T03:31:35Z
[ "python", "interpolation" ]
How do you extract rows given conditions on two columns using python?
38,005,154
<pre><code>os.chdir("C:\Users\EDAWES01\Desktop\Cookie profiling") data = pandas.read_csv('activity_url.csv', delimiter=';') data_read=np.array(data) quantity = data_read[0:, 2] other_data = data_read[0:, 1] x="http" url_data = data_read[np.logical_and(quantity==1, any(x in other_data)][:,1] #extraction </code></pre> <...
1
2016-06-24T03:24:56Z
38,005,858
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.iloc.html" rel="nofollow"><code>iloc</code></a> for selecting and <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> with <a href="http://pand...
1
2016-06-24T04:57:38Z
[ "python", "pandas", "dataframe", "conditional", "extract" ]
(web crawler) how to get the text of news passages from news website
38,005,176
<p>i m going to get the text from a news website that i have to get around 1k website content </p> <p>the link is on below : <a href="http://www.dcfever.com/news/readnews.php?id=16727" rel="nofollow">http://www.dcfever.com/news/readnews.php?id=16727</a></p> <p>this website post every latest news and the new url is f...
-1
2016-06-24T03:29:34Z
38,006,185
<p>You've tagged it <code>python</code> too. Look at <code>beautifulsoup</code> here: <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">https://www.crummy.com/software/BeautifulSoup/bs4/doc/</a></p>
0
2016-06-24T05:30:12Z
[ "java", "php", "python", "web", "jsoup" ]
(web crawler) how to get the text of news passages from news website
38,005,176
<p>i m going to get the text from a news website that i have to get around 1k website content </p> <p>the link is on below : <a href="http://www.dcfever.com/news/readnews.php?id=16727" rel="nofollow">http://www.dcfever.com/news/readnews.php?id=16727</a></p> <p>this website post every latest news and the new url is f...
-1
2016-06-24T03:29:34Z
38,007,028
<p>Jsoup is a HTML parser which can help you scrape and parse HTML page. If you already know the pattern of site navigation, Jsoup is good. But if you want to crawl all the contents of the website, you better leverage some crawler framework such as <a href="http://scrapy.org/" rel="nofollow">Scrapy</a> or <a href="http...
0
2016-06-24T06:36:59Z
[ "java", "php", "python", "web", "jsoup" ]
(web crawler) how to get the text of news passages from news website
38,005,176
<p>i m going to get the text from a news website that i have to get around 1k website content </p> <p>the link is on below : <a href="http://www.dcfever.com/news/readnews.php?id=16727" rel="nofollow">http://www.dcfever.com/news/readnews.php?id=16727</a></p> <p>this website post every latest news and the new url is f...
-1
2016-06-24T03:29:34Z
38,027,563
<p>Have a look at <a href="http://stormcrawler.net" rel="nofollow">StormCrawler</a>. Implementing what you are describing should be very straightforward and most components are implemented in Java. You could generate the list of URLs incrementally and pass that for instance to a MemorySpout or put them in a file and us...
0
2016-06-25T10:41:57Z
[ "java", "php", "python", "web", "jsoup" ]
Context manager to remove tempfile
38,005,298
<p>I'm trying to write context manager to conditionally cleanup tempfile after processing. Simplified:</p> <pre><code>import os from contextlib import contextmanager from subprocess import Popen from tempfile import NamedTemporaryFile @contextmanager def temp(cleanup=True): tmp = NamedTemporaryFile(delete=False)...
0
2016-06-24T03:47:18Z
38,005,404
<p>Indeed your file is open when you are trying to remove it. You'll have to close the file first before removing it:</p> <pre><code>@contextmanager def temp(cleanup=True): tmp = NamedTemporaryFile(delete=False) try: yield tmp finally: tmp.close() #closes the file, so we can right remove it...
1
2016-06-24T04:01:49Z
[ "python" ]
Dataframe summary of unique pages
38,005,372
<p>Here is my dataframe:</p> <pre><code>import pandas as pd import re !wget https://s3.amazonaws.com/todel162/elastic.csv df=pd.read_csv('elastic.csv') def mysearch(mystring): urls = re.findall('elastic.co/guide(?:[a-zA-Z]|[0-9]|[$-_@.&amp;+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', mystring) return urls ...
1
2016-06-24T03:58:10Z
38,006,273
<p>You can use:</p> <pre><code>import pandas as pd #force column ParentId as string df=pd.read_csv('https://s3.amazonaws.com/todel162/elastic.csv', dtype={'ParentId':str}) #print (df) #find all patterns, create new dataframe pat = 'elastic.co/guide(?:[a-zA-Z]|[0-9]|[$-_@.&amp;+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F])...
1
2016-06-24T05:38:55Z
[ "python", "pandas", "dataframe", "group-by", "unique" ]
How do I pull inters out of a string and determine which inter is the highest?
38,005,445
<p>For example:</p> <p>"Hello I can count to 4, 1 2 3 4." And it would return that the max number in the string is 4.</p> <p>I need to pull the integers out of the string and determine which one is the highest. I've been toying with this for a while, but I can't find a good way to pull the numbers out of the string....
-2
2016-06-24T04:08:04Z
38,005,477
<p>Homework eh?</p> <pre><code>import re for i in re.findall('\d+', "Hello I can count to 4, 1 2 3 4."): one_int = int(i) print(one_int) </code></pre> <p>To do it without regular expressions, you would have to loop over every character in the string, check if its a digit and remember its position. One you fo...
2
2016-06-24T04:11:33Z
[ "python", "python-3.x" ]
How do I pull inters out of a string and determine which inter is the highest?
38,005,445
<p>For example:</p> <p>"Hello I can count to 4, 1 2 3 4." And it would return that the max number in the string is 4.</p> <p>I need to pull the integers out of the string and determine which one is the highest. I've been toying with this for a while, but I can't find a good way to pull the numbers out of the string....
-2
2016-06-24T04:08:04Z
38,005,488
<p>Split the string on possible separators, and try to map the parts to int. Keep only the ones that can be parsed successfully, and find the max.</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; s = "Hello I can count to 4, 1 2 3 4." &gt;&gt;&gt; parts = re.split(r"[ \t,.]", s) &gt;&gt;&gt; ints = [] &gt;&gt;&gt; f...
0
2016-06-24T04:12:34Z
[ "python", "python-3.x" ]
How do I pull inters out of a string and determine which inter is the highest?
38,005,445
<p>For example:</p> <p>"Hello I can count to 4, 1 2 3 4." And it would return that the max number in the string is 4.</p> <p>I need to pull the integers out of the string and determine which one is the highest. I've been toying with this for a while, but I can't find a good way to pull the numbers out of the string....
-2
2016-06-24T04:08:04Z
38,005,493
<p>One line solution will be like:</p> <pre><code>max(map(int, re.findall('[-+]?\d+',s))) </code></pre> <p>Detaching it:</p> <pre><code>re.findall('[-+]?\d+',s) #Regex to find all integers (including negatives) in your string "s" map(int, re.findall('[-+]?\d+',s)) #Converting the found strings to list of integers ma...
1
2016-06-24T04:13:08Z
[ "python", "python-3.x" ]
How do I pull inters out of a string and determine which inter is the highest?
38,005,445
<p>For example:</p> <p>"Hello I can count to 4, 1 2 3 4." And it would return that the max number in the string is 4.</p> <p>I need to pull the integers out of the string and determine which one is the highest. I've been toying with this for a while, but I can't find a good way to pull the numbers out of the string....
-2
2016-06-24T04:08:04Z
38,005,502
<p>You can check if a character is a digit using the <code>isdigit()</code> function. Create a list of all the integers in the string and then grab the max from the list.</p> <pre><code>str = "Hello I can count to 4, 1 2 3 4"&lt;br/&gt; int_list = [int(s) for s in str.split() if s.isdigit()]&lt;br/&gt; print max(int_l...
0
2016-06-24T04:15:06Z
[ "python", "python-3.x" ]
How do I pull inters out of a string and determine which inter is the highest?
38,005,445
<p>For example:</p> <p>"Hello I can count to 4, 1 2 3 4." And it would return that the max number in the string is 4.</p> <p>I need to pull the integers out of the string and determine which one is the highest. I've been toying with this for a while, but I can't find a good way to pull the numbers out of the string....
-2
2016-06-24T04:08:04Z
38,005,742
<p>A simple solution that would be expected from a student:</p> <pre><code>max = None num = list('0','1','2','3','4','5','6','7','8','9') for x in str: if x in num: if int(x) &gt; max: max = int(x) return max </code></pre>
0
2016-06-24T04:43:04Z
[ "python", "python-3.x" ]
How do I pull inters out of a string and determine which inter is the highest?
38,005,445
<p>For example:</p> <p>"Hello I can count to 4, 1 2 3 4." And it would return that the max number in the string is 4.</p> <p>I need to pull the integers out of the string and determine which one is the highest. I've been toying with this for a while, but I can't find a good way to pull the numbers out of the string....
-2
2016-06-24T04:08:04Z
38,006,004
<p>Here's a functional approach to the problem, it also works for numbers greater than 9, but not with negatives:</p> <pre><code>def split_space(string): return string.split(" ") def is_decimal(string): return string.isdecimal() def number_or_none_from_string(string): maybe_number = "" for character...
0
2016-06-24T05:12:42Z
[ "python", "python-3.x" ]
Printing 6 numbers on the same line with a for /range loop
38,005,613
<p>I am having an issue printing random numbers to the same line, then printing the total of the 6 random numbers on the second print statement. Here is what i have so far.</p> <pre><code>import random def main(): randnums() def randnums(): for num in range(0, 6): num1 = random.randint(1,9) ...
-3
2016-06-24T04:29:06Z
38,005,637
<p>You will have better luck if you indent your code correctly.</p> <pre><code>def randnums(): for num in range(0, 6): num1 = random.randint(1,9) print(str(num1), end=" ") print() print(" The total is: ") </code></pre> <p>And to you need to actually accumulate the total in a variable whic...
0
2016-06-24T04:31:36Z
[ "python" ]
Printing 6 numbers on the same line with a for /range loop
38,005,613
<p>I am having an issue printing random numbers to the same line, then printing the total of the 6 random numbers on the second print statement. Here is what i have so far.</p> <pre><code>import random def main(): randnums() def randnums(): for num in range(0, 6): num1 = random.randint(1,9) ...
-3
2016-06-24T04:29:06Z
38,005,694
<p>The correct code is as follows:</p> <pre><code>import sys def randnums(): sum = 0 for num in range(0, 6): num1 = random.randint(1,9) sum += num1 sys.stdout.write(str(num1)+" ") print("\nThe total is: "+str(sum)) </code></pre> <p>OR (if Python 3)</p> <pre><code>def randnums(): ...
0
2016-06-24T04:37:07Z
[ "python" ]
Printing 6 numbers on the same line with a for /range loop
38,005,613
<p>I am having an issue printing random numbers to the same line, then printing the total of the 6 random numbers on the second print statement. Here is what i have so far.</p> <pre><code>import random def main(): randnums() def randnums(): for num in range(0, 6): num1 = random.randint(1,9) ...
-3
2016-06-24T04:29:06Z
38,005,714
<p>I'm not sure what is wrong with your code because of its poor indentation but here are some things to take note of:</p> <ol> <li>You need to have a variable which stores the total</li> <li>Python print function defaults all strings to print out with a newline.</li> </ol> <h1>Store total</h1> <p>This is simple, ju...
1
2016-06-24T04:40:05Z
[ "python" ]
Printing 6 numbers on the same line with a for /range loop
38,005,613
<p>I am having an issue printing random numbers to the same line, then printing the total of the 6 random numbers on the second print statement. Here is what i have so far.</p> <pre><code>import random def main(): randnums() def randnums(): for num in range(0, 6): num1 = random.randint(1,9) ...
-3
2016-06-24T04:29:06Z
38,005,875
<p>See this: <a href="http://stackoverflow.com/questions/12032214/python-3-print-new-output-on-same-line">python 3: print new output on same line</a></p> <p>In addition:</p> <ol> <li><p>Make sure to fix your indentation; python is very strict about it.</p></li> <li><p>You need to either save the numbers in a list or ...
0
2016-06-24T04:58:54Z
[ "python" ]
Printing 6 numbers on the same line with a for /range loop
38,005,613
<p>I am having an issue printing random numbers to the same line, then printing the total of the 6 random numbers on the second print statement. Here is what i have so far.</p> <pre><code>import random def main(): randnums() def randnums(): for num in range(0, 6): num1 = random.randint(1,9) ...
-3
2016-06-24T04:29:06Z
38,008,281
<p>In python 2.7</p> <pre><code> import random def main(): randnums() def randnums(): sum=0 for num in range(0, 6): num1 = random.randint(1,9) print(str(num1)) sum+=num1, print print(" The total is: %d" % sum) main() </code></p...
0
2016-06-24T07:49:53Z
[ "python" ]
How would I go about writing a very simplistic parser for java code in python?
38,005,619
<p>I'm trying to write a very barebones parser for java code in python. </p> <p>Basically what I'd need are two methods: handle_keyword(keyword) and handle_operator(operator) which would get automatically called when keywords and operators are encountered.</p> <p>I'd also like a third method called handle_other(text)...
0
2016-06-24T04:29:24Z
38,005,700
<p>Just use ANTLR with the Java grammar and specify Python as the target language.</p>
3
2016-06-24T04:37:56Z
[ "java", "python", "parsing" ]
PEP-484 Type Annotations with own types
38,005,633
<p>PEP-484 provides semantics for type annotations. These are geared very much towards a) documentation and b) help for IDEs. They are less geared towards code optimization.</p> <p>For example, it is unfortunately not possible to use PEP 484 annotations either with Cython <a href="https://groups.google.com/d/msg/cytho...
1
2016-06-24T04:31:22Z
39,827,901
<p>Since Python 3.5, we not only have the <a href="https://www.python.org/dev/peps/pep-0483/" rel="nofollow">PEP 483</a>, <a href="https://www.python.org/dev/peps/pep-0484/" rel="nofollow">PEP 484</a>, but also <a href="https://docs.python.org/3/library/typing.html" rel="nofollow"><code>typing</code> module</a> that im...
0
2016-10-03T09:01:40Z
[ "python", "numpy", "types", "cython", "type-hinting" ]
Remove first character from string Django template
38,005,648
<p>I know this has been asked multiple times but the solution that everyone reaches (and the documentation) doesn't seem to be working for me...</p> <p>Trying to remove first character</p> <p>Code is <code>{{ picture.picture_path|slice:"1:" }}</code></p> <p>but it still comes out as <code>./DOF_mrD5T49.jpg</code>. T...
2
2016-06-24T04:32:16Z
38,005,760
<p>This should work:</p> <pre><code>{{ picture.picture_path.name|slice:"1:" }} </code></pre> <p>The reason your first attempt didn't work is that <code>picture.picture_path</code> represents a <code>FieldFile</code> object rather than a string. This is what gets passed to the <code>slice</code> filter. </p> <p>The <...
2
2016-06-24T04:46:37Z
[ "python", "django", "templates" ]
python Web socket component for erlang chat server?
38,005,717
<p>I have external web socket server writ tern in Er lang language , i need to create a python library/component for the er lang server, my aim is if the developer need to integrate the python component with their application (eg: django project ) just call the functions pass the parameters , the component need to han...
1
2016-06-24T04:40:41Z
38,006,072
<p>Yeah, it is possible.</p> <p>You first need one erlang client do something like Pid ! Message, I think you are familiar with this, or you can use OTP. The client is responsible for send message from erlang client to your erlang server.</p> <p>Next what you need is Apache thrift: <a href="http://thrift.apache.org/l...
0
2016-06-24T05:19:21Z
[ "python", "django", "websocket" ]
Dictionary count not displaying
38,005,818
<p>CS student here...Maybe it's due to lack of sleep but I cannot figure out why my counts are not showing up at all. The formatting is correct but I cannot figure out why no count is displayed. Any help is appreciated.</p> <p><strong>Description:</strong> </p> <p>Reads a small business's customer information from th...
0
2016-06-24T04:52:24Z
38,006,005
<p>In <code>generateStatesCountDictionary</code> you never actually add any values to the dictionary.</p> <p>You've calculated the <code>count</code> now you need to set that state's value in <code>statesTallyDict</code></p>
1
2016-06-24T05:12:53Z
[ "python", "python-2.7", "dictionary", "tuples" ]
Dictionary count not displaying
38,005,818
<p>CS student here...Maybe it's due to lack of sleep but I cannot figure out why my counts are not showing up at all. The formatting is correct but I cannot figure out why no count is displayed. Any help is appreciated.</p> <p><strong>Description:</strong> </p> <p>Reads a small business's customer information from th...
0
2016-06-24T04:52:24Z
38,006,067
<pre><code> if state in statesTallyDict: count = statesTallyDict.get(state) +1 else: count = 1 </code></pre> <p>Isn't actually updating the count in the dictionary itself..</p> <pre><code> if state in statesTallyDict: statesTallyDict[state] = statesTallyDict.get(state) + 1 else: ...
0
2016-06-24T05:18:44Z
[ "python", "python-2.7", "dictionary", "tuples" ]
Dictionary count not displaying
38,005,818
<p>CS student here...Maybe it's due to lack of sleep but I cannot figure out why my counts are not showing up at all. The formatting is correct but I cannot figure out why no count is displayed. Any help is appreciated.</p> <p><strong>Description:</strong> </p> <p>Reads a small business's customer information from th...
0
2016-06-24T04:52:24Z
38,006,197
<p>As <a href="http://stackoverflow.com/a/38006005/4428725">user3220892</a> has said, you are not adding any values to the <code>statesTallyDict</code> dict:</p> <pre><code>def generateStatesCountDictionary(customerList): statesTallyDict = {} for customer in customerList: state = customer[5] if...
0
2016-06-24T05:31:10Z
[ "python", "python-2.7", "dictionary", "tuples" ]
How to implement search function in django?
38,006,125
<p>I have many books in a database. Searching the database returns nothing(empty queryset).</p> <p>In the menu:</p> <pre><code>&lt;form name="myform" method="POST" action="{% url 'search' %}"&gt; {% csrf_token %} &lt;input type="text" name="search" placeholder="Search" /&gt; &lt;/form&gt; </code></pre> <p...
0
2016-06-24T05:24:38Z
38,006,218
<p>Looks like you need to use a <code>for</code>, because books is a queryset</p> <p>In template, try:</p> <pre><code>{% if books %} {% for book in books %} &lt;a href="{% url 'buy_book' pk=book.pk %}"&gt; &lt;!--Upon successful search book image with hyperlink appears --&gt; &lt;img src="{{book.image.url...
1
2016-06-24T05:33:22Z
[ "python", "django", "django-views" ]
How to implement search function in django?
38,006,125
<p>I have many books in a database. Searching the database returns nothing(empty queryset).</p> <p>In the menu:</p> <pre><code>&lt;form name="myform" method="POST" action="{% url 'search' %}"&gt; {% csrf_token %} &lt;input type="text" name="search" placeholder="Search" /&gt; &lt;/form&gt; </code></pre> <p...
0
2016-06-24T05:24:38Z
38,006,316
<p>There are couple of things I would like to add here..</p> <p>1) I think search result should be of method GET not POST. You might refer <a href="http://stackoverflow.com/questions/46585/when-do-you-use-post-and-when-do-you-use-get">this</a> link to see when to use POST and when to use GET</p> <pre><code>&lt;form n...
1
2016-06-24T05:42:51Z
[ "python", "django", "django-views" ]
Allow SVG files to be uploaded to ImageField via Django admin
38,006,200
<p>I'm switching to SVG images to represent categories on my e-commerce platform. I was using <code>models.ImageField</code> in the Category model to store the images before, but the <code>forms.ImageField</code> validation is not capable of handling a vector-based image (and therefore rejects it).</p> <p>I don't requ...
1
2016-06-24T05:31:11Z
38,010,185
<p>I have never used <code>SVGAndImageFormField</code> so I cannot really comment on that. Personally I would have opted for a simple application of <code>FileField</code>, but that clearly depends on the project requirements. I will expand on that below:</p> <p>As mentioned in the comment, the basic difference betwee...
1
2016-06-24T09:35:58Z
[ "python", "django", "svg", "django-forms" ]
Allow SVG files to be uploaded to ImageField via Django admin
38,006,200
<p>I'm switching to SVG images to represent categories on my e-commerce platform. I was using <code>models.ImageField</code> in the Category model to store the images before, but the <code>forms.ImageField</code> validation is not capable of handling a vector-based image (and therefore rejects it).</p> <p>I don't requ...
1
2016-06-24T05:31:11Z
38,010,444
<p>It turns out that <a href="https://gist.github.com/ambivalentno/9bc42b9a417677d96a21" rel="nofollow"><code>SVGAndImageFormField</code></a> has no dependencies on DRF's <code>ImageField</code>, it only adds to the validation done by <code>django.forms.ImageField</code>.</p> <p>So to accept SVGs in the Django Admin I...
0
2016-06-24T09:49:35Z
[ "python", "django", "svg", "django-forms" ]
Adding a picture to Rally artifact by using Pyral
38,006,225
<p>I have been trying to add pictures in a Test Case in Rally by using Pyral.</p> <p>I have been able to successfully add the attachment and the link to the picture.</p> <p>However, the picture is not displayed:</p> <p><a href="http://i.stack.imgur.com/EVFJg.png" rel="nofollow"><img src="http://i.stack.imgur.com/EVF...
0
2016-06-24T05:34:08Z
38,006,226
<p>The problem came from the way the Rest API read the content from the file</p> <pre><code>#extract from function addAttachment in file 'restapi.py' with open(filename, 'r') as af: contents = base64.b64encode(af.read()) </code></pre> <p>This works fine for text files but not for binary files.</p> <p>A temporary...
1
2016-06-24T05:34:08Z
[ "python", "rally", "pyral" ]
Programatically add and remove tkinter python labels causes IndexError: list index out of range
38,006,251
<p>Sorry for the vague title but I didn't know how to explain myself better. Basically what I try to do in tkinter here is adding and removing labels. The label value gets updated so that I always have an increment of 1 even though I deleted a label in the beginning. If I generate labels and delete them from the bottom...
2
2016-06-24T05:36:42Z
38,010,217
<h1>Design</h1> <ol> <li><p>The main problem comes when dealing with different indexes. Trying to manipulate them carefully leads to complicated operations resulting in a long and inefficient code. To remedy to this problem, we simply get rid of them and take advantage of the label class variable <code>Tkinter.IntVar(...
2
2016-06-24T09:38:30Z
[ "python", "python-2.7", "tkinter", "ttk" ]
Passing command line arguments from powershell script to a python script
38,006,465
<p>I call the python code from a Powershell script in order to loop over some arguments. Calling the python script from a Powershell is straight forward and works without a hitch:</p> <pre><code>PS C:\Windows\system32&gt; C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\python.exe C:\Users\Administrato...
0
2016-06-24T05:56:02Z
38,009,185
<p>Thanks to JosefZ this works:</p> <pre><code>&amp; $py $yt_ul $vid $secr $cred --title "Timelapse $title_date" --playlist "Timelapses $playlist_date" </code></pre>
0
2016-06-24T08:47:37Z
[ "python", "powershell", "command-line-arguments" ]
Nested list sorting in Python
38,006,467
<p>This is a question of nested loop where I have to find the names of students in alphabetical order with 2nd lowest marks.<br> I am getting following error:</p> <pre><code>Traceback (most recent call last): File "solution.py", line 12, in &lt;module&gt; if (l[i][0]==l[0][0]): IndexError: list index out of rang...
1
2016-06-24T05:56:18Z
38,006,578
<p>You are using <code>remove</code>, because of that <code>l</code>, in some moment, have less elements than you expect.</p>
1
2016-06-24T06:06:20Z
[ "python", "arrays", "list" ]
Nested list sorting in Python
38,006,467
<p>This is a question of nested loop where I have to find the names of students in alphabetical order with 2nd lowest marks.<br> I am getting following error:</p> <pre><code>Traceback (most recent call last): File "solution.py", line 12, in &lt;module&gt; if (l[i][0]==l[0][0]): IndexError: list index out of rang...
1
2016-06-24T05:56:18Z
38,006,716
<p>The problem is that you are removing items from a loop. The thumb rule is that you shall never remove items from a list while iterating over it.</p> <p>I don't really understand your code right now, but you can just change the way you are doing the first loop and apply the same logic for the next ones, at least you...
1
2016-06-24T06:15:41Z
[ "python", "arrays", "list" ]
Deployment error in Python-Google App Engine
38,006,472
<p>when i deployed the demo application of python in Google App engine,it works well in local host,when i am deploying the got the error,i also changed proxy_rdns=True,but it does not work,help me to solve. </p> <pre><code>File "C:\Program Files\Google\google_appengine\lib\httplib2\httplib2\__init__.py", line 1275, in...
0
2016-06-24T05:56:24Z
39,441,774
<p>I had a similar problem today, when trying to run <code>appcfg.py</code> to deploy my app to appengine</p> <p>I then downgraded my google epp engine sdk from 1.9.40 to 1.9.37, rerun, everything was Ok (note that I am using app engine sdk for ubuntu)</p> <p>So you may try to upgrade/downgrade your version and check...
0
2016-09-11T23:55:34Z
[ "python", "google-app-engine" ]
How to get the name of the groupby items when apply function with python-pandas?
38,006,498
<p>For instance, I have such a function, that extract the name of the items and mark the length of that group:</p> <pre><code>def func(name, len): with open("file.txt", "a") as f: f.write(name+len+"\n") </code></pre> <p>And how can I get the name of each group to apply this function like:</p> <pre><code...
1
2016-06-24T05:59:18Z
38,006,836
<p>I think there is problem with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.apply.html" rel="nofollow"><code>GroupBy.apply</code></a>, if you want use with function for writing to file, because first group is call twice:</p> <p><a href="http://pandas.pydata.org/pandas-do...
1
2016-06-24T06:24:21Z
[ "python", "pandas" ]
Loss of precision when transferring data from hdf5 dataset to numpy array
38,006,541
<p>I am trying to copy data from a hdf5 dataset (f_one, in the below screenshot) into a numpy array, but am finding that I'm losing some precision. <a href="http://i.stack.imgur.com/fLXGL.png" rel="nofollow"><img src="http://i.stack.imgur.com/fLXGL.png" alt="enter image description here"></a></p> <p>The last line of t...
2
2016-06-24T06:03:35Z
38,025,190
<p>The problem is that your inputs are of integer type, but when creating a numpy array without specifying the data type, you ended up casting them as floats by default. To avoid this, use <code>dtype=np.int64</code> when creating an numpy array for this data. Another option is to convert the existing integer array dir...
3
2016-06-25T05:09:39Z
[ "python", "numpy", "precision", "hdf5" ]
Unable to read HTML content
38,006,610
<p>I'm building a webCrawler which needs to read links inside a webpage. For which I'm using urllib2 library of python to open and read the websites.</p> <p>I found a website where I'm unable to fetch any data. The URL is "<a href="http://www.biography.com/people/michael-jordan-9358066" rel="nofollow">http://www.biogr...
0
2016-06-24T06:08:31Z
38,006,753
<p>What you are experiencing is most likely to be the effect of <a href="https://en.wikipedia.org/wiki/Dynamic_web_page" rel="nofollow">dynamic web pages</a>. These pages do not have static content for <code>urllib</code> or <code>requests</code> to get. The data is loaded on site. You can use Python's <a href="http://...
3
2016-06-24T06:18:29Z
[ "python", "python-2.7", "web-crawler", "urllib2" ]
Python hang when reading data from C subprocess
38,006,622
<p>I have a python GUI which will open a C subprocess when started, and kill the C subprocess when closed.</p> <p>The signal sent from python to C and from C to python is caught correctly. However, there are some problems when data receiving at python end.</p> <p><strong>Here's my program:</strong></p> <p><strong>Py...
0
2016-06-24T06:09:13Z
38,006,776
<p>Instead of <code>fclose</code> the output stream, use <code>fflush</code> to flush it so that the contents in the buffer are written out and the parent process can read it:</p> <pre><code>printf("Caught signal %d\n", signum); fflush(stdout); </code></pre>
0
2016-06-24T06:19:58Z
[ "python", "c", "linux" ]
Python hang when reading data from C subprocess
38,006,622
<p>I have a python GUI which will open a C subprocess when started, and kill the C subprocess when closed.</p> <p>The signal sent from python to C and from C to python is caught correctly. However, there are some problems when data receiving at python end.</p> <p><strong>Here's my program:</strong></p> <p><strong>Py...
0
2016-06-24T06:09:13Z
38,008,909
<p>Finally find the solution......</p> <p>If Python attempts to read data from an empty buffer, in this case, it will wait the input from C and hang.</p> <p>There're two problems should be solved in the original code:</p> <ol> <li><p>Add <code>fflush(stdout)</code> after <code>printf</code>.</p> <p>Otherwise, the o...
0
2016-06-24T08:30:47Z
[ "python", "c", "linux" ]
Pandas csv NaN values replace by the left side columns
38,006,646
<p>I'm new to python and pandas. I have 3 columns in csv file and data type of columns is string.</p> <p>example</p> <pre><code> col1 col2 col3 ABC XYZ NaN PQR LMN QPR </code></pre> <p>I'm using pandas to read the csv file. I want to replace NaN with left side column cell value. Here I want to replace co...
1
2016-06-24T06:11:18Z
38,006,684
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.combine_first.html" rel="nofollow"><code>combine_first</code></a> or <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.fillna.html" rel="nofollow"><code>fillna</code></a>:</p> <pre><code>df['col3'] = ...
0
2016-06-24T06:13:46Z
[ "python", "csv", "pandas" ]
Pandas Data frame Error
38,006,701
<p>I am trying to make some analysis on data received from Quandl.</p> <p>Following code was implemented by me:</p> <pre><code>import pandas as pd import quandl df=quandl.get("WIKI/GOOGL") df=df[['Adj. High','Adj. Low',]] df['HL_PCT'] = (df['Adj. High']) - df(['Adj. Low']) / df['Adj. Low']*100.0 df=df[['HL_PCT',]]...
1
2016-06-24T06:14:51Z
38,006,736
<p>I think there is typo with <code>()</code> in <code>df(['Adj. Low'])</code> - use <code>df['Adj. Low']</code>:</p> <pre><code>import pandas as pd import quandl df=quandl.get("WIKI/GOOGL") df=df[['Adj. High','Adj. Low']] df['HL_PCT'] = (df['Adj. High'] - df['Adj. Low']) / df['Adj. Low']*100.0 df=df[['HL_PCT']] pri...
0
2016-06-24T06:17:06Z
[ "python", "pandas", "dataframe", "quandl" ]
Python : Fabric module inconsistent connection
38,006,778
<p>I am working on a module to execute remote shell commands using the python FABRIC module.</p> <p>My base machine is a Linux Machine running on Centos 7 distribution and my remote machine is a FreeBSD distribution.</p> <p>The problem I am facing is a bit confusing.</p> <p>The problem is that sometimes the fabric r...
0
2016-06-24T06:20:05Z
38,408,205
<p>I find out that the problem is due to MTU(maximum transmission unit) of packets transmitted by shell.Due to the large size sometimes the packets were dropped on the receiving end.</p>
0
2016-07-16T05:50:01Z
[ "python", "fabric" ]