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: Check if a numpy array contains an object with specific attribute
39,782,113
<p>I want to check if there is any object with a specific attribute in my numpy array:</p> <pre><code>class Test: def __init__(self, name): self.name = name l = numpy.empty( (2,2), dtype=object) l[0][0] = Test("A") l[0][1] = Test("B") l[1][0] = Test("C") l[1][1] = Test("D") </code></pre> <p>I know that following...
1
2016-09-30T00:56:32Z
39,782,767
<p>There are a number SO questions about object dtype arrays, and even some about getting or testing the attributes of the elements of such arrays. The general point is that such an array behaves much like a list. For the most part you have to iterate over the array as though it were a list. Most of the cool things ...
1
2016-09-30T02:32:08Z
[ "python", "python-2.7", "numpy" ]
Named optional argument and multiple argument order
39,782,137
<p>I have a function wrapper like this. </p> <pre><code>def funcWrapper(fn_ng, order=None, *args ): def clsr(X): if order is not None: X = calc_poli_dsX(X, order) return fn_ng(X, *args); return clsr; </code></pre> <p>However, if I use this function as below:</p> <pre><code>mGrdnt ...
0
2016-09-30T01:01:28Z
39,782,229
<p>You can just modify the call:</p> <pre><code>arr = [dsX1, dy] funcWrapper(gd.squared_error, None, *arr) </code></pre> <p>or you can do something like this: </p> <pre><code>funcWrapper(gd.squared_error, [dsX1, dy]) </code></pre>
1
2016-09-30T01:12:31Z
[ "python", "closures" ]
Modify multiple keys of dictionary by a mapping dictionary
39,782,190
<p>I have 2 dict, one original and one for mapping the original one's key to another value simultaneously,for instance:</p> <p><strong>original dict</strong></p> <pre><code>built_dict={'China':{'deportivo-cuenca-u20':{'danny':'test1'}}, 'Germany':{'ajax-amsterdam-youth':{'lance':'test2'}}} </code></pre> ...
0
2016-09-30T01:08:17Z
39,782,420
<p>Well I have found a solution for this,the code:</p> <pre><code>def club2team(built_dict,club_team_dict): for row in built_dict: # print test_dict[row] for sub_row in built_dict[row].keys(): for key in club_team_dict: # the key of club_team_dict must be a subset of test_dict,or you have t...
0
2016-09-30T01:39:13Z
[ "python", "dictionary" ]
Iterating through list (Python)
39,782,221
<pre><code>collection = ["81851 19AJA01", "68158 17ARB03", "104837 20AAH02", </code></pre> <p>I have a list that extends on like this and I would like to sort them based on the first 2 digits of the second part of each. I'm really rushed right now so some help would be nice. </p> <p>I tried this and it didn't work. ...
-2
2016-09-30T01:11:57Z
39,782,236
<p>Use the <a href="https://docs.python.org/3/library/functions.html#sorted" rel="nofollow"><code>key</code> function</a> to define a custom sorting rule:</p> <pre><code>In [1]: collection = ["81851 19AJA01", "68158 17ARB03", "104837 20AAH02"] In [2]: sorted(collection, key=lambda x: int(x.split()[1][:2])) Out[2]: ['...
3
2016-09-30T01:13:41Z
[ "python" ]
How to use cross_val_score with random_state
39,782,243
<p>I'm getting different values for different runs ... what am I doing wrong here:</p> <pre><code>X=np.random.random((100,5)) y=np.random.randint(0,2,(100,)) clf=RandomForestClassifier() cv = StratifiedKFold(y, random_state=1) s = cross_val_score(clf, X,y,scoring='roc_auc', cv=cv) print(s) # [ 0.42321429 0.44360902 ...
0
2016-09-30T01:14:27Z
39,787,608
<p>The mistake you are making is calling the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html" rel="nofollow"><code>RandomForestClassifier</code></a> whose default arg, <code>random_state</code> is None. So, it picks up the seed generated by <code>np.random</code> t...
3
2016-09-30T09:00:31Z
[ "python", "machine-learning", "scikit-learn" ]
Scrapy - encoding issue - scraping out quotes
39,782,247
<p>I have this class:</p> <pre><code>class PitchforkTracks(scrapy.Spider): name = "pitchfork_tracks" allowed_domains = ["pitchfork.com"] start_urls = [ "http://pitchfork.com/reviews/best/tracks/?page=1", "http://pitchfork.com/reviews/best/tracks/?page=2", ...
1
2016-09-30T01:14:46Z
39,782,625
<p>Inside <code>parse(self, response)</code>, add:</p> <pre><code>item['track'] = sel.xpath('.//h2[@class="title"]/text()').extract_first().strip(u'\u201c\u201d') </code></pre>
1
2016-09-30T02:11:23Z
[ "python", "scrapy" ]
Loop through categories recursively
39,782,278
<p>I'm building a python function which returns an array to be used in a select dropdown field. I have tried two versions so far. </p> <p>Both of them work, with the first returning a properly formatted select field. However, the first solution only goes two levels deep. I intend to add more depth to the categories. <...
1
2016-09-30T01:19:00Z
39,782,394
<p>I change you example 2, and it will add dashes after the id, but it won't add spaces like your example 1.</p> <pre><code># second example goes multiple levels, needs dashes def build_choice_tree2(): # For the convenience of the test, I changed `categories` to a list. categories = [{ 'id': 1, ...
1
2016-09-30T01:36:19Z
[ "python", "recursion" ]
Loop through categories recursively
39,782,278
<p>I'm building a python function which returns an array to be used in a select dropdown field. I have tried two versions so far. </p> <p>Both of them work, with the first returning a properly formatted select field. However, the first solution only goes two levels deep. I intend to add more depth to the categories. <...
1
2016-09-30T01:19:00Z
39,782,439
<p>Use a counter to store the number of dashes you want to add and multiply the dashes by that count. Also to make a function truly recursive you need to add the <code>return</code> statement.</p> <pre><code>def build_choice_tree2(): categories = Category.query.get(1).children items = [] count = 1 def...
2
2016-09-30T01:41:22Z
[ "python", "recursion" ]
Python handling NoneType when parsing tables
39,782,283
<p>I am trying to compare two tables (table_a and table_b) and subtract the last column of table_a from the last column of table_b. However, table_a includes an extra row and is causing me to get a NoneType Error. Is there a away I can still include the "Plums" row from table_a and just output 'NULL' for the delta cell...
1
2016-09-30T01:19:44Z
39,782,328
<p><a href="https://docs.python.org/3/library/itertools.html#itertools.zip_longest" rel="nofollow"><code>itertools.zip_longest</code></a> accepts an optional <code>fillvalue</code> parameter. If it's provided, it is used instead of <code>None</code>:</p> <pre><code>&gt;&gt;&gt; list(itertools.zip_longest([1, 2, 3], [4...
2
2016-09-30T01:25:56Z
[ "python", "python-3.x", "parsing", "itertools", "nonetype" ]
Python handling NoneType when parsing tables
39,782,283
<p>I am trying to compare two tables (table_a and table_b) and subtract the last column of table_a from the last column of table_b. However, table_a includes an extra row and is causing me to get a NoneType Error. Is there a away I can still include the "Plums" row from table_a and just output 'NULL' for the delta cell...
1
2016-09-30T01:19:44Z
39,782,367
<p><a href="https://docs.python.org/3/library/itertools.html#itertools.zip_longest" rel="nofollow">zip_longest</a> returns a singular <code>None</code> type when it runs out of values. You want a list of <code>None</code>s or you get a <code>TypeError</code> when you try and use the subscript <code>[]</code> operator. ...
1
2016-09-30T01:33:13Z
[ "python", "python-3.x", "parsing", "itertools", "nonetype" ]
Displaying Legend in Matplotlib Basemap
39,782,391
<p>I have a basemap plotted using the following code snippet:</p> <pre><code>#setting the size plt.figure(figsize=(20,10)) #iterating through each country in shape file and filling them with color assigned using the colors array for nshape,seg in enumerate(m.countries): #getting x,y co-ordinates xx,yy = zip(*seg)...
0
2016-09-30T01:35:46Z
39,782,772
<p>Solved it using patches in matplotlib. I just added this code below to display the custom legend.</p> <pre><code>#setting the legend for the plot using patch lt = mpatches.Patch(color='orange', label='&lt;200') btwn = mpatches.Patch(color='yellow', label='200-400') gt = mpatches.Patch(color='red', label='&gt;400') ...
1
2016-09-30T02:32:50Z
[ "python", "pandas", "matplotlib" ]
Remove punctuations in pandas
39,782,418
<pre><code>code: df['review'].head() index review output: 0 These flannel wipes are OK, but in my opinion </code></pre> <p>I want to remove punctuations from the column of the dataframe and create a new column.</p> <pre><code>code: import string def remove_punctuations(text): ret...
0
2016-09-30T01:39:04Z
39,782,704
<p>I solved the problem by looping through the string.punctuation</p> <pre><code>def remove_punctuations(text): for punctuation in string.punctuation: text = text.replace(punctuation, '') return text </code></pre> <p>You can call the function the same way you did and It should work.</p> <pre><code>df...
1
2016-09-30T02:23:03Z
[ "python", "python-2.7", "pandas" ]
Remove punctuations in pandas
39,782,418
<pre><code>code: df['review'].head() index review output: 0 These flannel wipes are OK, but in my opinion </code></pre> <p>I want to remove punctuations from the column of the dataframe and create a new column.</p> <pre><code>code: import string def remove_punctuations(text): ret...
0
2016-09-30T01:39:04Z
39,782,973
<p>Using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.replace.html" rel="nofollow">Pandas str.replace</a> and regex:</p> <pre><code>df["new_column"] = df['review'].str.replace('[^\w\s]','') </code></pre>
2
2016-09-30T02:59:49Z
[ "python", "python-2.7", "pandas" ]
How to loop through keys in a dict to find the corresponding value?
39,782,484
<p>When a user enters a name (e.g. "Jim") as an argument for an instance of my "Test" class, the <code>def find</code> function is called and for-loops through all the names in the dict matching "Jim". If <code>def find</code> finds the key word "Jim" in the dict, then it should print out the corresponding value. But...
-2
2016-09-30T01:49:01Z
39,782,619
<p>@nk001,<br> I think this is a little more like what you are trying for:</p> <pre><code>class Test(object): def __init__(self, x=0): self.x = x # &lt;-- indent the __init__ statements users = { # &lt;-- users = { 'John': 1, # KEY: VALUE...
2
2016-09-30T02:10:13Z
[ "python" ]
How to loop through keys in a dict to find the corresponding value?
39,782,484
<p>When a user enters a name (e.g. "Jim") as an argument for an instance of my "Test" class, the <code>def find</code> function is called and for-loops through all the names in the dict matching "Jim". If <code>def find</code> finds the key word "Jim" in the dict, then it should print out the corresponding value. But...
-2
2016-09-30T01:49:01Z
39,782,629
<p>I write a worked code:</p> <pre><code>class Test(object): users = { 'John': 1, 'Jim': 2, 'Bob': 3 } def __init__(self, x=0): # So I don't get an error in (def find) self.x = x def find(self, x): # The user is suppose to type in the name "x" for name in Test...
1
2016-09-30T02:12:13Z
[ "python" ]
Django: extending models of other apps
39,782,563
<p>I'm working on small ERP-like project on Django which contains different apps (Products, Sales, Purchases, Accounting, MRP, ...). A few of them have dependencies (for example, a Sales app requires the Products app).</p> <p>For the sake of modularity and loose-coupling, I'm trying to keep the apps as independent as ...
1
2016-09-30T02:02:50Z
39,900,585
<p>I d recommend you to create a database tabel to save all your possible registered modules and class. so you can use it as variable python code inside an eval statement. and if you have pre-defined methods names, in this approach bellow i called it common_method.</p> <p>you don t even need to have an abstract class<...
1
2016-10-06T15:55:43Z
[ "python", "django", "django-models", "django-migrations", "django-apps" ]
How to transfer data from Django to Ext JS
39,782,576
<p>I'm new to web programming. I would like to create a simple Django application with Ext JS interface. Task: The user enters data into a database using forms and sees the database upgrade.It has been done to solve the problem as follows. Written Django application.</p> <p><strong>views.py</strong></p> <pre class="...
0
2016-09-30T02:04:16Z
39,783,319
<p>Use ajax.</p> <p>just like this:</p> <pre><code>$('#likes').click(function () { var catid; catid = $(this).attr("data-catid"); $.get('/rango/like_category/', {category_id: catid}, function (data) { $('#like_count').html(data); $('#likes').hide(); }); }); </code></pre>
0
2016-09-30T03:40:53Z
[ "python", "django", "extjs" ]
How to transfer data from Django to Ext JS
39,782,576
<p>I'm new to web programming. I would like to create a simple Django application with Ext JS interface. Task: The user enters data into a database using forms and sees the database upgrade.It has been done to solve the problem as follows. Written Django application.</p> <p><strong>views.py</strong></p> <pre class="...
0
2016-09-30T02:04:16Z
39,801,650
<p>I see two ways: 1) Make special server action, that will be return JSON-based view. On main template create Ext.grid.Grid with remote store, that will request data from server action, that returns JSON. It's mostly usable case. Look here example: <a href="http://docs.sencha.com/extjs/6.2.0/modern/Ext.grid.Grid.htm...
0
2016-10-01T00:04:11Z
[ "python", "django", "extjs" ]
List contains exactly three of the same elements?
39,782,641
<p>This will return Boolean True if the list has three of the same integers given. It will return a Boolean False if it does not have three of the same integers. I am having trouble writing this. Does the count feature do this? Also, is importing an empty list necessary? I have this and I get the error "'int' object ha...
0
2016-09-30T02:13:52Z
39,793,809
<p>This line:</p> <pre><code>if aList.count(n): </code></pre> <p>is the reason why your code is not working.</p> <p>The <code>count</code> function of <code>list</code> returns the number of occurences of <code>n</code> in the list. If your arguments are [1,2,3,4,4,4] and 4, <code>aList.count(n)</code> will return 3...
0
2016-09-30T14:25:10Z
[ "python", "list", "count", "integer" ]
Automatically Run a Script in my Browser console after opening a link using Python
39,782,670
<p>I want to run some JavaScript in my browser DevTools console. So far, I have opened up a specific website only through it. Can it be done in Python?</p> <p>Right now, I am using the following code:</p> <pre><code>url = 'http://some-website.com/' webbrowser.open(url) </code></pre> <p>What I want to do now is open...
0
2016-09-30T02:18:25Z
39,782,792
<p>I don't belive this can be done, as </p> <blockquote> <p>ChromeDriver 2 and the DevTools windows both compete for the same automation channel, and ChromeDriver automatically closes the DevTools window in order for it to work.</p> </blockquote> <p>See here for more: <a href="http://stackoverflow.com/questions...
0
2016-09-30T02:34:35Z
[ "javascript", "python", "selenium", "google-chrome-devtools" ]
speed improvement in postgres INSERT command
39,782,681
<p>I am writing a program to load data into a particular database. This is what I am doing right now ...</p> <pre><code> conn = psycopg2.connect("dbname='%s' user='postgres' host='localhost'"%dbName) cur = conn.cursor() lRows = len(rows) i, iN = 0, 1000 while True: ...
2
2016-09-30T02:19:55Z
39,787,963
<ol> <li><p>As you mentioned at p.3 you are worried about database connection, that might break, so if you use one <code>conn.commit()</code> only after all inserts, you can easily loose already inserted, but not commited data if your connection breaks before <code>conn.commit()</code>. If you do <code>conn.commit()</c...
1
2016-09-30T09:17:23Z
[ "python", "postgresql", "psycopg2" ]
Print a list of items separated by commas but with the word "and" before the last item
39,782,689
<p>I've been working on this for two days. This is what the assignment states:</p> <blockquote> <p>Say you have a list value like this: <code>listToPrint = ['apples', 'bananas', 'tofu', 'cats']</code> Write a program that prints a list with all the items separated by a comma and a space, with "and" inserted before t...
2
2016-09-30T02:21:02Z
39,783,442
<p>Here is how I would do it, but be careful if this is for school. Your instructor will frown on you if any of the things I have done below are using features or techniques that haven't yet been covered.</p> <pre><code>listToPrint = ['a', 'b', 'c'] def list_to_string(L, sep = '', last_sep = None): if last _sep ...
0
2016-09-30T03:57:00Z
[ "python", "list", "python-3.x", "loops", "for-loop" ]
Print a list of items separated by commas but with the word "and" before the last item
39,782,689
<p>I've been working on this for two days. This is what the assignment states:</p> <blockquote> <p>Say you have a list value like this: <code>listToPrint = ['apples', 'bananas', 'tofu', 'cats']</code> Write a program that prints a list with all the items separated by a comma and a space, with "and" inserted before t...
2
2016-09-30T02:21:02Z
39,783,454
<p>The code you've shown appears to be solving a different problem than what your assignment wants you to do. The assignment is focused on <code>print</code>ing the values from a provided <code>list</code>, while your code is all about <code>input</code>ing items from the user and putting them into a list. It could mak...
1
2016-09-30T03:58:05Z
[ "python", "list", "python-3.x", "loops", "for-loop" ]
How to measure the length of a 2-dimensional path in separate steps
39,782,696
<p>I am a newbie in python. I am stuck by finding the length of a path in 2d. I have no idea what I'm doing wrong. Please help!</p> <pre><code>import math vector1 = v1 vector2 = v2 def length (v): """ Length of a vector in 2-space. Params: v (2-tuple) vector in 2-space Returns: (float) length """ ...
0
2016-09-30T02:21:42Z
39,783,369
<p>Yes, please fix your formatting, shift everything by four spaces.</p> <p>But I believe your first method is:</p> <pre><code> def length(v): """ Length of a vector in 2-space. Params: v (2-tuple) vector in 2-space Returns: (float) length """ v = sqrt(v1**2 + v2**2) retur...
0
2016-09-30T03:46:43Z
[ "python", "python-3.x", "vector", "euclidean-distance" ]
Translate cURL headers command to python-requests
39,782,699
<p>I need to pass a POST containing a token to a website to get an auth key, I've done it successfully using cURL with this statement:</p> <p><code>curl -D - --request POST https://login.website.com/g/aaa/authorize --data-urlencode token=[TOKEN] </code></p> <p>However, I cannot seem to get the same outcome using the ...
1
2016-09-30T02:22:26Z
39,783,252
<p>Found the answer, <code>requests.json()</code> needed to be used instead of <code>json.dumps(data)</code>, the latter is improperly formatted, so this code worked out fine:</p> <pre><code>s.token = requests.post(url, data=data) s.recieved = s.token.json() t = requests.post(url, data=s.recieved) </code></pre>
0
2016-09-30T03:34:48Z
[ "python", "curl", "python-requests" ]
Parsed timed_id3 values from HLS stream
39,782,706
<p>How do I parse timed_id3 values taken from a HLS stream chunk?</p> <p>Twitch stream chunks contain info like encoding time in a 3rd data stream that ffprobe identifies as timed_id3, the extracted data is:</p> <pre><code>b'\x00\x00\x00\x020TRCK\x00\x00\x00\x06\x00\x00\x033936\x00TDEN\x00\x00\x00\x15\x00\x00\x032016...
1
2016-09-30T02:23:17Z
39,814,987
<p>Timed metadata is part of the HLS specification, A quick google search would have provided the answer. <a href="https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/HTTP_Live_Streaming_Metadata_Spec/Introduction/Introduction.html" rel="nofollow">https://developer.apple.com/library/content/...
1
2016-10-02T07:55:31Z
[ "python", "ffmpeg", "id3", "mpeg2-ts", "id3v2" ]
Sum Series with Functions - Continously adding previous answers?
39,782,752
<p>I'm learning the concepts of functions in Python and could use a little advice. </p> <p>I'm trying to write a program that will use the algebraic function <code>m(i) = (i) / (i + 1)</code> for inputs 1 through 20. So far I've got that to work, but now I want to add all previous outputs together for each new output....
0
2016-09-30T02:29:37Z
39,782,782
<p>Try this:</p> <pre><code>def equation(i): if i &lt;= 0: return 0 mi = ((i) / (i + 1)) return mi + equation(i - 1) </code></pre>
0
2016-09-30T02:33:42Z
[ "python", "function", "math", "sum", "continuous" ]
Sum Series with Functions - Continously adding previous answers?
39,782,752
<p>I'm learning the concepts of functions in Python and could use a little advice. </p> <p>I'm trying to write a program that will use the algebraic function <code>m(i) = (i) / (i + 1)</code> for inputs 1 through 20. So far I've got that to work, but now I want to add all previous outputs together for each new output....
0
2016-09-30T02:29:37Z
39,782,803
<p>You just need an accumulator to save the values of equation(i)</p> <p>Here's my solution:</p> <pre><code>def equation(i): mi = ((i) / (i + 1)) return mi acc = 0 for i in range(1,21): acc += equation(i) print(format(i, '2d')," ",format(acc, '.2f')) </code></pre>
0
2016-09-30T02:35:33Z
[ "python", "function", "math", "sum", "continuous" ]
Sum Series with Functions - Continously adding previous answers?
39,782,752
<p>I'm learning the concepts of functions in Python and could use a little advice. </p> <p>I'm trying to write a program that will use the algebraic function <code>m(i) = (i) / (i + 1)</code> for inputs 1 through 20. So far I've got that to work, but now I want to add all previous outputs together for each new output....
0
2016-09-30T02:29:37Z
39,782,833
<p>You can do something like this. </p> <pre><code>#!/usr/bin/python def equation(i): mi = (float(i) / (i + 1)) return mi def main(): sumOfMi = 0 for i in range(1,21): sumOfMi+= equation(i) print(format(i, '2d')," ",format(sumOfMi, '.2f')) main() </code></pre>
0
2016-09-30T02:40:41Z
[ "python", "function", "math", "sum", "continuous" ]
Sum Series with Functions - Continously adding previous answers?
39,782,752
<p>I'm learning the concepts of functions in Python and could use a little advice. </p> <p>I'm trying to write a program that will use the algebraic function <code>m(i) = (i) / (i + 1)</code> for inputs 1 through 20. So far I've got that to work, but now I want to add all previous outputs together for each new output....
0
2016-09-30T02:29:37Z
39,782,835
<p>You could do it with a generator: </p> <pre><code>def equation(i): n = 0 tot = 0 while n &lt; i: n += 1 mi = n/(n+n) tot += mi yield n, tot def main(): for i, mi in equation(21): print(format(i, '2d')," ",format(mi, '.2f')) </code></pre>
0
2016-09-30T02:40:53Z
[ "python", "function", "math", "sum", "continuous" ]
Sum Series with Functions - Continously adding previous answers?
39,782,752
<p>I'm learning the concepts of functions in Python and could use a little advice. </p> <p>I'm trying to write a program that will use the algebraic function <code>m(i) = (i) / (i + 1)</code> for inputs 1 through 20. So far I've got that to work, but now I want to add all previous outputs together for each new output....
0
2016-09-30T02:29:37Z
39,782,862
<pre><code>def function(i): return i/(i+1) e = 0 for i in range(1, 21): print(i, end=' ') e += function(i) print(e) </code></pre> <p>Seems you just need to increment resulting return from function to variable.Good luck!</p>
0
2016-09-30T02:44:24Z
[ "python", "function", "math", "sum", "continuous" ]
Open excel file through Python win32com which having foreign language in a filename
39,782,802
<p>I am trying to open excel file through win32com. But when I run a code with foreign(Korean) language then it gives an error which wans't happened with a english filename.</p> <p>How do I solve this problem?</p> <pre><code>#-*- coding: utf-8 -*- import os import win32com.client xl=win32com.client.Dispatch("Excel.A...
0
2016-09-30T02:35:31Z
39,785,490
<p>It was an encoding problem.</p> <pre><code>#-*- coding: utf-8 -*- import os import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Visible = True xl.Workbooks.Open("C:\\Users\\Jongho\\dev_jhk\\VNI Automation Pilot Test\\Nikkei225_10\xbf\xf9.xlsm") xl.Application.Quit() # Comment this out if y...
0
2016-09-30T06:58:10Z
[ "python", "excel", "win32com" ]
script that able to download zip file from server
39,782,899
<p>Can you please help me to make script in python that do the following:</p> <ol> <li>download zip file http (I already have a code for this one)</li> <li>download zip file in <code>file://&lt;server location&gt;</code>, I have problem with this one. the location of the file is in <code>file://&lt;server location&gt;...
-1
2016-09-30T02:48:43Z
39,785,199
<p>urllib2 does not have handlers for the <code>file://</code> protocol; I think it will open local files if there is <em>no</em> protocol given (<code>//server/file.zip</code>), but I've never used that, and haven't tested it. If you have a local file name, you can just use <code>open()</code> and <code>read()</code>...
0
2016-09-30T06:40:32Z
[ "python", "urllib2" ]
Changing Chrome Preferences Through Script
39,782,947
<p>Is it possible to alter your preferences <a href="http://chrome://settings/search#privacy" rel="nofollow">Preferences</a> on your chrome browser through a script? Is this done with selenium? Can anyone help me by writing a python script to change one radio button on the chrome preferences page? Thanks</p>
-1
2016-09-30T02:55:49Z
39,788,284
<p>Here you can find the list of chrome options and capabilities you can pass to the chromedriver in order to modify some preferences.</p> <p><a href="https://sites.google.com/a/chromium.org/chromedriver/capabilities" rel="nofollow">https://sites.google.com/a/chromium.org/chromedriver/capabilities</a></p> <p>Hope it ...
0
2016-09-30T09:34:56Z
[ "python", "selenium" ]
Append first item into array list when still have space in array list
39,782,951
<p>let's say I need to store 2 elements into a list.</p> <p>I have 5 items: apple, orange, lemon, papaya, banana</p> <p>These items i save in a text file, hence there're 5 lines.</p> <p>I connect the file and start read line by line. Everytime I read a line I append one item in array. Each time the array will fill u...
0
2016-09-30T02:55:59Z
39,783,172
<p>Actually you can avoid clearing your <code>ele</code> array. There are some useful built-in modules like <code>collection</code>. It allow you to create your custom array. You can set the <code>maxlen</code> of your array. Moreover you can set left/right append.</p> <pre><code>d = collections.deque([], maxlen=2) </...
0
2016-09-30T03:25:31Z
[ "python", "arrays", "python-2.7", "loops" ]
Hover tool not working in Bokeh
39,782,955
<p>I have a table that contains the number of times a student accessed an activity.</p> <pre><code> df_act5236920.head() activities studs 0 3.0 student 1 1 4.0 student 10 2 5.0 student 11 3 6.0 student 12 4 2.0 student 13 5 4.0 student 14 6 19.0 student 15 ...
3
2016-09-30T02:57:10Z
39,793,409
<p>So, after going through a lot of the documentation, I've finally figured out a few things.</p> <p>Firstly, the NoneType error was due to the fact that for a bar chart, you need to pass the dataframe as well as the ColumnDataSource, for the bar-chart to display. So the code needed to be:</p> <pre><code>bar = Bar(d...
0
2016-09-30T14:05:14Z
[ "python", "pandas", "hover", "tooltip", "bokeh" ]
split python list given the index start
39,782,958
<p>I have looked at this:<a href="http://stackoverflow.com/questions/18570740/python-split-a-list-into-sub-lists-based-on-index-ranges">Split list into sublist based on index ranges</a></p> <p>But my problem is slightly different. I have a list</p> <pre><code>List = ['2016-01-01', 'stuff happened', 'details', ...
2
2016-09-30T02:57:32Z
39,783,211
<p>You don't need to perform a two-pass grouping at all, because you can use <a href="https://docs.python.org/3/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a> to both segment by dates and their associated events in a single pass. By avoiding the need to compute indices and t...
1
2016-09-30T03:30:04Z
[ "python", "string", "list" ]
split python list given the index start
39,782,958
<p>I have looked at this:<a href="http://stackoverflow.com/questions/18570740/python-split-a-list-into-sub-lists-based-on-index-ranges">Split list into sublist based on index ranges</a></p> <p>But my problem is slightly different. I have a list</p> <pre><code>List = ['2016-01-01', 'stuff happened', 'details', ...
2
2016-09-30T02:57:32Z
39,783,483
<p>Try:</p> <pre><code>def split_by_date(arr, patt='\d+\-\d+\-\d+'): results = [] srch = re.compile(patt) rec = ['', []] for item in arr: if srch.match(item): if rec[0] or rec[1]: results.append(rec) rec = [item, []] else: rec[1].appen...
1
2016-09-30T04:02:16Z
[ "python", "string", "list" ]
TensorFlow issue with feed_dict not being noticed when using batching
39,783,039
<p>I have been trying to do the mnist tutorial with png files, and have gotten most things to the point where they make sense.</p> <p>The gist of the code is <a href="https://gist.github.com/ThaHypnotoad/4438a6658c89bb803bd74080e78cf170" rel="nofollow">here</a> however I'm going to walk through what it does and where ...
0
2016-09-30T03:08:33Z
39,793,174
<p>In answer to your question, "Is there a better way to do this switching between testing and training sets?", yes there is. <code>tf.cond()</code> evaluates both functions at each step (see <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/control_flow_ops.html#cond" rel="nofollow">here</a>) and ther...
1
2016-09-30T13:52:23Z
[ "python", "tensorflow", "batching" ]
wxPython: Redirecting events on other widgets (TextCtrl)
39,783,070
<p>The case study doesn't seem too hard to explain, but I guess TextCtrl in wxPython aren't often used in this way. So here it is: I have a simple window with two TextCtrls. One is an input widget (the user is supposed to enter commands there), the second is an output widget (the system displays the result of the co...
0
2016-09-30T03:12:16Z
39,796,778
<p>Give <code>self.input.EmulateKeyPress(e)</code> a try. If you're on Windows it should work fine. On other platforms it is not perfect, but basically works there too.</p> <p>Other options would be to use <code>wx.UiActionSimulator</code>, or simply to append the new character to the input textctrl in your code.</p...
1
2016-09-30T17:17:27Z
[ "python", "events", "widget", "wxpython", "textctrl" ]
python manipulations on lists
39,783,098
<p>I have 2 lists</p> <pre><code>l1 = ('A','B','C') l2 = ('X','Y','Z') </code></pre> <p>I want to create a list based on these 2 </p> <p>result = ('A is same as X', 'B is same as Y', 'C is same as Z')</p> <p>when I concatenate , I do not get the result I expect How can I combine the lists ? Thanks PMV</p>
0
2016-09-30T03:16:19Z
39,783,155
<p>You can <code>zip</code> the lists together which will combine the two lists into a list of tuples and then iterate over those tuples.</p> <pre><code>z = zip(l1,l2) #[(A,X), (B,Y), (C,Z)] result = ["{0} is the same as {1}".format(t[0], t[1]) for t in z] # ['A is the same as X', 'B is the same as Y', 'C is the sam...
0
2016-09-30T03:23:40Z
[ "python", "string", "list", "data-manipulation" ]
python manipulations on lists
39,783,098
<p>I have 2 lists</p> <pre><code>l1 = ('A','B','C') l2 = ('X','Y','Z') </code></pre> <p>I want to create a list based on these 2 </p> <p>result = ('A is same as X', 'B is same as Y', 'C is same as Z')</p> <p>when I concatenate , I do not get the result I expect How can I combine the lists ? Thanks PMV</p>
0
2016-09-30T03:16:19Z
39,783,169
<p>the zip() function can help you here.</p> <pre><code>result = [] for a, b in zip(l1, l2): result.append("{0} is same as {1}".format(a, b)) </code></pre>
2
2016-09-30T03:25:20Z
[ "python", "string", "list", "data-manipulation" ]
python manipulations on lists
39,783,098
<p>I have 2 lists</p> <pre><code>l1 = ('A','B','C') l2 = ('X','Y','Z') </code></pre> <p>I want to create a list based on these 2 </p> <p>result = ('A is same as X', 'B is same as Y', 'C is same as Z')</p> <p>when I concatenate , I do not get the result I expect How can I combine the lists ? Thanks PMV</p>
0
2016-09-30T03:16:19Z
39,783,279
<p>Just a more direct way...</p> <pre><code>&gt;&gt;&gt; map('{} is same as {}'.format, l1, l2) ['A is same as X', 'B is same as Y', 'C is same as Z'] </code></pre>
0
2016-09-30T03:37:44Z
[ "python", "string", "list", "data-manipulation" ]
Why is plt.errorbox giving me continuous graph when I just want data in dots?
39,783,277
<p>I'm using errorbox in matplotlib to plot a graph in which </p> <pre><code>x1 = (0, 100, 60, 20, 80, 40) y1 = (0.0, 0.058823529411764705, 0.058823529411764705, 0.0, 0.0, 0.0) plt.figure() plt.errorbar(x1, y1) plt.title("Errors") plt.show() </code></pre> <p>This would give me continuous lines instead of separate 6 ...
0
2016-09-30T03:37:38Z
39,783,562
<p>You may use the following properties:</p> <pre><code>plt.errorbar(x1, y1,ls='None', marker = 'o') </code></pre>
2
2016-09-30T04:12:56Z
[ "python", "matplotlib", "errorbar" ]
Within Dango, how do I add a new value to request.POST data before saving?
39,783,299
<p>I'm trying to allow the user to either manually enter a text field if they have the license info, or let it auto generate (based on form info) if its original content.</p> <p>I'm stuck because from my tests (using print command) the form is correctly updating with the information given in the form if LicenseTag fie...
2
2016-09-30T03:39:21Z
39,783,826
<p>As I see it the best way is to override the save method in your model.</p> <pre><code>class UploadedFiles(models.Model): def save(self, *args, **kwargs): if not self.LicenseTag: if self.user: liscname = self.user.get_full_name() or self.user.email self.License...
0
2016-09-30T04:43:18Z
[ "python", "django", "request", "immutability" ]
Iterating over numbers within XPath
39,783,329
<p>I am using the Selenium webdriver in Python to find elements on a web page to process, in the way shown below: </p> <pre><code>driver.find_element_by_xpath('//div[@class="gsc-cursor-page" and text()="1"]') </code></pre> <p>Ideally, I would like to go through all the texts within that div, <code>text()="1"</code>, ...
2
2016-09-30T03:41:44Z
39,783,380
<p>This XPath,</p> <pre><code>//div[@class="gsc-cursor-page" and number() &gt;= 1 and number() &lt;= 10] </code></pre> <p>will select all of the <code>div</code> elements of the specified <code>@class</code> with values in the range of <code>1..10</code>.</p> <hr> <p><strong>Specific Python/Selenium code to address...
2
2016-09-30T03:48:59Z
[ "python", "html", "xml", "selenium", "xpath" ]
Iterating over numbers within XPath
39,783,329
<p>I am using the Selenium webdriver in Python to find elements on a web page to process, in the way shown below: </p> <pre><code>driver.find_element_by_xpath('//div[@class="gsc-cursor-page" and text()="1"]') </code></pre> <p>Ideally, I would like to go through all the texts within that div, <code>text()="1"</code>, ...
2
2016-09-30T03:41:44Z
39,800,840
<p>somehow I am able to put in the variable for iteration through "position" instead of usnig the internal text of a div. thanks for all of your helps and tips!</p> <pre><code>driver.find_element_by_xpath('//div[@class="gsc-cursor"]/div[position()='+str(i)+']') </code></pre>
-1
2016-09-30T22:16:08Z
[ "python", "html", "xml", "selenium", "xpath" ]
Can a MagicMock object be iterated over?
39,783,460
<p>What I would like to do is this...</p> <pre><code>x = MagicMock() x.iter_values = [1, 2, 3] for i in x: i.method() </code></pre> <p>I am trying to write a unit test for this function but I am unsure about how to go about mocking all of the methods called without calling some external resource...</p> <pre><co...
1
2016-09-30T03:59:22Z
39,811,615
<p>What you actually want to do is not return a <code>Mock</code> with a <code>return_value=[]</code>. You actually want to return a <code>list</code> of <code>Mock</code> objects. Here is a snippet of your test code with the correct components and a small example to show how to test one of the iterations in your loop:...
1
2016-10-01T21:27:16Z
[ "python", "django", "unit-testing", "mocking" ]
Can substitute default softmax with self-implemented one in TensorFlow?
39,783,470
<p>I just wonder could the softmax provided by the TensorFlow package, namely, tensorflow.nn.softmax, be substituted by one implemented by myself?</p> <p>I run the original tutorial file mnist_softmax.py with cross_entropy calculation:</p> <pre><code>cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(tf.nn.sof...
0
2016-09-30T04:00:39Z
39,783,838
<p>Your <code>y2</code> as a matter of fact is not equivalent to computing softmax. Softmax is</p> <pre><code>softmax(y) = e^y / S </code></pre> <p>Where <code>S</code> is a normalizing factor (the sum of <code>e^y</code> across all <code>y</code>s). Also, when you compute the normalizing factor, you only need to red...
1
2016-09-30T04:45:10Z
[ "python", "tensorflow" ]
colorbar units don't appear in figure (matplotlib)
39,783,537
<p>Im trying to do the following figure, but the units below the colorbar do not appear. The units only appear when I make the width and the height of the figure extremely large.</p> <p>This is the code I use for inserting a customized colorbar:</p> <pre><code>from mpl_toolkits.axes_grid.axes_grid import AxesGrid fro...
0
2016-09-30T04:10:01Z
39,784,063
<p><code>set_xticklabels</code> might help. Check this: <a href="http://matplotlib.org/examples/pylab_examples/colorbar_tick_labelling_demo.html" rel="nofollow">http://matplotlib.org/examples/pylab_examples/colorbar_tick_labelling_demo.html</a></p>
0
2016-09-30T05:07:42Z
[ "python", "matplotlib" ]
NetworkX D3 Force Layout Plugin for mpld3
39,783,547
<p>I'm in the process of creating a mpld3 plugin for converting a NetworkX Graph to a Force Layout. I'm having some trouble understanding how the zoom on the axes works in mpld3 and how I can get it to translate to the force layout graph.</p> <pre><code>import matplotlib import matplotlib.pyplot as plt import numpy as...
0
2016-09-30T04:11:07Z
39,822,216
<p>I've posted a working example <a href="http://blog.kdheepak.com/mpld3-networkx-d3js-force-layout.html" rel="nofollow">here</a> for anyone searching for something similar.</p>
0
2016-10-02T22:07:18Z
[ "javascript", "python", "d3.js", "mpld3" ]
Passing pandas DataFrame by reference
39,783,570
<p>My question is regarding immutability of pandas DataFrame when it is passed by reference. Consider the following code:</p> <pre><code>import pandas as pd def foo(df1, df2): df1['B'] = 1 df1 = df1.join(df2['C'], how='inner') return() def main(argv = None): # Create DataFrames. df1 = pd.Data...
1
2016-09-30T04:13:49Z
39,783,626
<p>The issue is because of this line:</p> <pre><code>df1 = df1.join(df2['C'], how='inner') </code></pre> <p><code>df1.join(df2['C'], how='inner')</code> returns a new dataframe. After this line, <code>df1</code> no longer refers to the same dataframe as the argument, but a new one, because it's been reassigned to the...
2
2016-09-30T04:20:10Z
[ "python", "pandas", "dataframe", "pass-by-reference", "immutability" ]
Passing pandas DataFrame by reference
39,783,570
<p>My question is regarding immutability of pandas DataFrame when it is passed by reference. Consider the following code:</p> <pre><code>import pandas as pd def foo(df1, df2): df1['B'] = 1 df1 = df1.join(df2['C'], how='inner') return() def main(argv = None): # Create DataFrames. df1 = pd.Data...
1
2016-09-30T04:13:49Z
39,783,805
<p>Python doesn't have pass by value vs. pass by reference - there are just <a href="https://docs.python.org/2/reference/executionmodel.html#naming-and-binding" rel="nofollow">bindings from names to objects</a>. </p> <p>If you change your function to</p> <pre><code>def foo(df1, df2): res = df1.join(df2['C'], how...
3
2016-09-30T04:40:36Z
[ "python", "pandas", "dataframe", "pass-by-reference", "immutability" ]
Count sub_lists length in python3
39,783,675
<p>My python is 3 ver. I have a list, which contains sub lists, like:</p> <pre><code>L=[[1,2], [3,4], [5,6,7]] </code></pre> <p>I want to calculate length of all sub_list and write down them to a dictionary, like this:</p> <pre><code>D={2:2,3:1} </code></pre> <p>that is, we have 2 lists which have length 2, and 1 l...
0
2016-09-30T04:25:32Z
39,783,782
<p>Use <code>defaultdict</code> where you store the length of the list as the key, and just increment each value by 1 every time to get a matching list length:</p> <pre><code>from collections import defaultdict d = defaultdict(int) L = [[1,2], [3,4], [5,6,7]] for li in L: d[len(li)] += 1 print(d) # defaultdict(...
2
2016-09-30T04:36:38Z
[ "python", "python-3.x" ]
Count sub_lists length in python3
39,783,675
<p>My python is 3 ver. I have a list, which contains sub lists, like:</p> <pre><code>L=[[1,2], [3,4], [5,6,7]] </code></pre> <p>I want to calculate length of all sub_list and write down them to a dictionary, like this:</p> <pre><code>D={2:2,3:1} </code></pre> <p>that is, we have 2 lists which have length 2, and 1 l...
0
2016-09-30T04:25:32Z
39,783,784
<p>You need to iterate over the list, and check that the length exists as key or not. If it exists, increment the value by 1, else add the value as 1. Below is the sample code.</p> <pre><code>&gt;&gt;&gt; L = [[1,2], [3,4], [5,6,7]] &gt;&gt;&gt; my_len_dict = {} &gt;&gt;&gt; for item in L: ... item_length = len(it...
0
2016-09-30T04:36:53Z
[ "python", "python-3.x" ]
Why is my python app continues to get a 500 Internal Server Error?
39,783,687
<p>I'm trying to get my app.py to link with MySQL database but I keep getting the following errors shown below. The link to my repository is here: <a href="https://github.com/trhubwork/python-mysql-proj.git" rel="nofollow">https://github.com/trhubwork/python-mysql-proj.git</a></p> <p>I'm running python 3.5.1</p> <p>...
0
2016-09-30T04:26:40Z
39,787,818
<p>@epascarello is right, if your code doesn't enter that <code>if</code> statement, then you'll never even create the cursor. I think the <code>try</code> and <code>finally</code> blocks are a good idea; just move your cursor up like this:</p> <pre><code>try: conn = mysql.connect() cursor = conn.cursor() ...
0
2016-09-30T09:10:12Z
[ "jquery", "python", "python-3.x", "flask" ]
What does a number mean before a for-loop
39,783,916
<p>I'm new to Python. Would greatly appreciate if you could explain how this line works. What does it mean to have a number before a for-loop?</p> <pre><code>adjacency_matrix = [[0 for i in range(max_index + 1)] for j in range(max_index + 1)] </code></pre> <p>I know that </p> <pre><code>max_index = 4 adjacency_matri...
1
2016-09-30T04:52:44Z
39,783,983
<p>It is a <a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>. You can rewrite that as follows:</p> <pre><code>&gt;&gt;&gt; adjacency_matrix = [] &gt;&gt;&gt; for j in range(max_index + 1): ... inner_list = [] ... for i in range(max_index ...
3
2016-09-30T04:59:59Z
[ "python", "list-comprehension" ]
What does a number mean before a for-loop
39,783,916
<p>I'm new to Python. Would greatly appreciate if you could explain how this line works. What does it mean to have a number before a for-loop?</p> <pre><code>adjacency_matrix = [[0 for i in range(max_index + 1)] for j in range(max_index + 1)] </code></pre> <p>I know that </p> <pre><code>max_index = 4 adjacency_matri...
1
2016-09-30T04:52:44Z
39,784,081
<p>The <code>0</code> is the value which the list comprehension is adding to the array (list) - same way each list of zeros is getting nested in the parent list. Try changing it to a different integer, float, string, boolean, etc...</p> <pre><code>&gt;&gt;&gt; max_index = 4 &gt;&gt;&gt; adjacency_matrix = adjacency_ma...
0
2016-09-30T05:10:17Z
[ "python", "list-comprehension" ]
What does a number mean before a for-loop
39,783,916
<p>I'm new to Python. Would greatly appreciate if you could explain how this line works. What does it mean to have a number before a for-loop?</p> <pre><code>adjacency_matrix = [[0 for i in range(max_index + 1)] for j in range(max_index + 1)] </code></pre> <p>I know that </p> <pre><code>max_index = 4 adjacency_matri...
1
2016-09-30T04:52:44Z
39,784,288
<p>If we use variable in list comprehension to populate a list, the resultant list takes the value of the variable whenever condition met. Since we are using '0' means list get populated by the value '0' whenever condition met.</p>
1
2016-09-30T05:29:04Z
[ "python", "list-comprehension" ]
python-Cannot call a function in script but can in the interactive mode
39,784,042
<p>It's a simple task about kNN, and I'm a newbee of pyhton.</p> <pre><code># coding=utf-8 from numpy import * import operator def createDataSet(): group = array([[112, 110], [128, 162], [83, 206], [142, 267], [188, 184], [218, 268], [234, 108], [256, 146], [ 333, 177], [350, 86], [364, 237], [...
0
2016-09-30T05:05:30Z
39,785,782
<p>Your raw_input is not taken what you expect as input for the classify0 function.</p> <pre><code>sample = array(raw_input('Enter you data:')) </code></pre> <p>This would give something like ["111 111"]</p> <pre><code>sample = [int(x) for x in raw_input().split()] </code></pre> <p>This would give [111,111]</p> <p...
0
2016-09-30T07:15:23Z
[ "python", "numpy" ]
Indentation error in python and index out of range error
39,784,088
<p>I am getting an indentation error. Can anyone help me to fix it and also getting <code>tuple index out of range error</code> too</p> <p>here is my code</p> <pre><code>def POST(self): form = web.input(name="a", newname="s", number="d") conn = MySQLdb.connect(host= "localhost", user="root", passwd=""...
0
2016-09-30T05:11:09Z
39,784,178
<p>This is a very basic error.If you are using sublime text.Please select all the rows. In the beginning of each line of def POST, there will be two patterns. One is '_____' and '.......' .The pattern should be similar for whole 'def POST(self):' Please make sure this and error will get removed.</p> <p>Copy and past...
1
2016-09-30T05:19:20Z
[ "python", "python-2.7" ]
Remove all the parentheses and replace all spaces by underscores?
39,784,099
<p>Here is what I did:</p> <pre><code>import re def demicrosoft (fn): fn = re.sub('[()]', '', fn) for ch in [' ']: fn = fn.replace(ch,"_"+ch) return fn print(demicrosoft('a bad file name (really)')) </code></pre> <p><br></p> <pre><code>&gt;&gt;&gt; (executing lines 1 to 12 of "&lt;tmp 2&gt;") a...
2
2016-09-30T05:12:16Z
39,784,158
<p>You can just chain a number of <code>replace</code>s for this:</p> <pre><code>a = 'a bad file name (really)' &gt;&gt;&gt; a.replace('(', '').replace(')', '').replace(' ', '_') 'a_bad_file_name_really' </code></pre>
2
2016-09-30T05:17:35Z
[ "python", "string", "replace" ]
Remove all the parentheses and replace all spaces by underscores?
39,784,099
<p>Here is what I did:</p> <pre><code>import re def demicrosoft (fn): fn = re.sub('[()]', '', fn) for ch in [' ']: fn = fn.replace(ch,"_"+ch) return fn print(demicrosoft('a bad file name (really)')) </code></pre> <p><br></p> <pre><code>&gt;&gt;&gt; (executing lines 1 to 12 of "&lt;tmp 2&gt;") a...
2
2016-09-30T05:12:16Z
39,784,183
<p>remove <strong>ch</strong> from <strong>"_"+ch</strong> in replace call as follows</p> <pre><code>import re def demicrosoft (fn): fn = re.sub('[()]', '', fn) for ch in [' ']: fn = fn.replace(ch,"_") return fn </code></pre>
1
2016-09-30T05:19:33Z
[ "python", "string", "replace" ]
Remove all the parentheses and replace all spaces by underscores?
39,784,099
<p>Here is what I did:</p> <pre><code>import re def demicrosoft (fn): fn = re.sub('[()]', '', fn) for ch in [' ']: fn = fn.replace(ch,"_"+ch) return fn print(demicrosoft('a bad file name (really)')) </code></pre> <p><br></p> <pre><code>&gt;&gt;&gt; (executing lines 1 to 12 of "&lt;tmp 2&gt;") a...
2
2016-09-30T05:12:16Z
39,784,260
<p>You can do this with <code>str.translate()</code>:</p> <pre><code>&gt;&gt;&gt; table = str.maketrans({'(':None, ')':None, ' ':'_'}) &gt;&gt;&gt; 'a bad file name (really)'.translate(table) 'a_bad_file_name_really' </code></pre>
2
2016-09-30T05:26:57Z
[ "python", "string", "replace" ]
How to add external arguments in python script?
39,784,136
<p>I want the user to provide some external arguments while calling a python script from command line, what changes I suppose to make inside my python script to add this functionality?</p>
0
2016-09-30T05:15:24Z
39,784,510
<p>I think this is what you are looking for</p> <p>pass arguments in command line.</p> <pre><code>$ python test.py arg1 arg2 arg3 </code></pre> <p>access it using sys.argv which gives list of arguments that you entered above</p> <pre><code>import sys print 'Number of arguments:', len(sys.argv), 'arguments.' print ...
0
2016-09-30T05:47:03Z
[ "python", "command-line-interface" ]
Google Cloud Storage Python list_blob() not printing object list
39,784,244
<p>I am Python and Google Cloud Storage newbie. I am writing a python script to get a file list from Google Cloud Storage bucket using Google Cloud Python Client Library and list_blobs() function from Bucket class is not working as I expected.</p> <p><a href="https://googlecloudplatform.github.io/google-cloud-python/s...
0
2016-09-30T05:25:11Z
39,784,381
<p>What do you see if you:</p> <pre><code>for blob in bucket.list_blobs(): print(blob) print(blob.name) </code></pre>
0
2016-09-30T05:36:59Z
[ "python", "google-app-engine", "google-cloud-storage", "google-cloud-platform", "google-cloud-python" ]
Google Cloud Storage Python list_blob() not printing object list
39,784,244
<p>I am Python and Google Cloud Storage newbie. I am writing a python script to get a file list from Google Cloud Storage bucket using Google Cloud Python Client Library and list_blobs() function from Bucket class is not working as I expected.</p> <p><a href="https://googlecloudplatform.github.io/google-cloud-python/s...
0
2016-09-30T05:25:11Z
39,793,896
<p>On <a href="https://webcache.googleusercontent.com/search?q=cache:9FyUQhlI9z8J:https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/cloud-client/manage_blobs.py%20&amp;cd=3&amp;hl=en&amp;ct=clnk&amp;gl=be" rel="nofollow">this</a> page you can find some example functions. An example list fun...
1
2016-09-30T14:29:07Z
[ "python", "google-app-engine", "google-cloud-storage", "google-cloud-platform", "google-cloud-python" ]
Gaussian Function in Python 2.7
39,784,326
<p>I need help making a program that calculates the Gaussian function <code>f(x)=1/(sqrt(2*pi)s)*exp[-.5*((x-m)/s)**2]</code> when <code>m=0</code>, <code>s=2</code>, and <code>x=1</code>.</p> <p>Would it be just:</p> <pre><code>def Gaussian(m,s,x): return 1/(sqrt(2*pi)s)*exp[-.5*((x-m)/s)**2] print Gaussian(0,2,...
-1
2016-09-30T05:31:39Z
39,784,383
<p>I think you are missing <code>from math import sqrt</code>, <code>from math import exp</code> and <code>from math import pi</code> unless you didn't show it in your code.</p>
0
2016-09-30T05:37:07Z
[ "python", "python-2.7" ]
When I will Rerun the file it will get error like following
39,784,388
<p>IndexError: list index out of range.</p> <p>my code is :</p> <pre><code>from openpyxl import load_workbook from common.log import logging class TestData: def get_data(self): wb = load_workbook(filename="demo.xlsx") ws = wb.active ws['A2'] = "ammy" ws['A3'] = "raju" ws[...
-1
2016-09-30T05:37:35Z
39,784,613
<p>You need to be more specific, Try adding a try, except block in the get_data method and print the stack trace. </p> <pre><code>import traceback # for exception tracing class TestData: def get_data(self): try: wb = load_workbook(filename="demo.xlsx") ws = wb.active w...
-1
2016-09-30T05:55:00Z
[ "python", "openpyxl" ]
When I will Rerun the file it will get error like following
39,784,388
<p>IndexError: list index out of range.</p> <p>my code is :</p> <pre><code>from openpyxl import load_workbook from common.log import logging class TestData: def get_data(self): wb = load_workbook(filename="demo.xlsx") ws = wb.active ws['A2'] = "ammy" ws['A3'] = "raju" ws[...
-1
2016-09-30T05:37:35Z
39,789,815
<pre><code>start Traceback (most recent call last): File "/home/amol.pawar/Globeflexresearch/gri/gri-be/scripts/xlsxdata.py", line 41, in &lt;module&gt; obj.get_data() File "/home/amol.pawar/Globeflexresearch/gri/gri-be/scripts/xlsxdata.py", line 23, in get_data wb = load_workbook(filename="demo.xlsx") Fi...
0
2016-09-30T10:51:26Z
[ "python", "openpyxl" ]
python simple basic program on geeksforgeeks
39,784,402
<p>Can anyone help me with the solution of this ?</p> <p>Given a number N, print all the composite numbers less than or equal to N. The number should be printed in ascending order.</p> <p>Input: The first line contain an Integer T denoting the number of test cases . Then T test cases follow. Each test case consist o...
-1
2016-09-30T05:38:31Z
39,785,234
<p>This error occurs when you are providing lesser input values than required. Your program is expecting more input's than you actually provided.</p> <p>if you are using a pipe to send data to stdin of the script then make sure each input is sent in a newline as shown below.</p> <pre><code> time echo -e "2\n'3 4 5 ...
0
2016-09-30T06:42:34Z
[ "python" ]
python simple basic program on geeksforgeeks
39,784,402
<p>Can anyone help me with the solution of this ?</p> <p>Given a number N, print all the composite numbers less than or equal to N. The number should be printed in ascending order.</p> <p>Input: The first line contain an Integer T denoting the number of test cases . Then T test cases follow. Each test case consist o...
-1
2016-09-30T05:38:31Z
39,785,316
<p>A simple solution using recursion.</p> <pre><code>def check_prime(n): for i in range(2,int(math.sqrt(n))+1): if(n%i==0): return 0 return 1 def print_composite(n): if(n&lt;5): print(n), return print_composite(n-1) if(check_prime(n)==0): print(n), ...
-2
2016-09-30T06:47:15Z
[ "python" ]
python simple basic program on geeksforgeeks
39,784,402
<p>Can anyone help me with the solution of this ?</p> <p>Given a number N, print all the composite numbers less than or equal to N. The number should be printed in ascending order.</p> <p>Input: The first line contain an Integer T denoting the number of test cases . Then T test cases follow. Each test case consist o...
-1
2016-09-30T05:38:31Z
39,785,680
<p>The culprit here is the <code>while</code> loop instead of <code>if</code>. As, the <code>t</code> is a constant value, the <code>while</code> loop will never end and thus, <code>p = int(input(""))</code> will get executed more than the required times. Hence, <code>EOFError</code> on <code>p = int(input(""))</code>....
0
2016-09-30T07:09:17Z
[ "python" ]
How to isolate Anaconda from system python without set the shell path
39,784,418
<p>I want to install Anaconda locally on my home directory ~/.Anaconda3 (Archlinux) and without setting the path in the shell because I like to keep my system python as the default.</p> <p>So I like to launch the Spyder (or other Anaconda's app) as isolated app from system binaries. I mean when I launch for example <c...
2
2016-09-30T05:39:52Z
39,787,575
<p>You could use virtualenv</p> <p>1) create a virtual env using the python version you need for anaconda <code>virtualenv -p /usr/bin/pythonX.X ~/my_virtual_env</code></p> <p>2) <code>virtualenv ~/my_virtual_env/bin/activate</code></p> <p>3) Run anaconda, then <code>deactivate</code></p>
0
2016-09-30T08:58:58Z
[ "python", "linux", "shell", "anaconda", "spyder" ]
How to isolate Anaconda from system python without set the shell path
39,784,418
<p>I want to install Anaconda locally on my home directory ~/.Anaconda3 (Archlinux) and without setting the path in the shell because I like to keep my system python as the default.</p> <p>So I like to launch the Spyder (or other Anaconda's app) as isolated app from system binaries. I mean when I launch for example <c...
2
2016-09-30T05:39:52Z
39,800,213
<p>Currently <a href="https://gist.github.com/esc/4967965" rel="nofollow">this</a> zsh function solves the problem using temporarily change the shell path variable. I just need to:</p> <p>1) anaconda_on</p> <p>2) <code>which python</code> or <code>python --version</code> or <code>spyder</code> ....</p> <p>3) anacond...
0
2016-09-30T21:15:30Z
[ "python", "linux", "shell", "anaconda", "spyder" ]
How to loop through 3 different arrays by using a single for loop in Python
39,784,438
<p>I have 3 different arrays:</p> <pre><code>a = (x, y, z) b = (p, q) c = (r, s) </code></pre> <p>I need to loop through all this arrays. Presently I am using the below method:</p> <pre><code>for loop_a in a: loop_a = some_value for loop_b in b: loop_b = some_value for loop_c in c: loop_c = some_value </code...
-2
2016-09-30T05:41:13Z
39,784,501
<p>There are two ways. The more traditional way is to use an index and a for loop. In this case, it's assumed that all lists are the same length and gets that length from the first item:</p> <pre><code>for i in range(len(a)): a[i] = some_value b[i] = some_value c[i] = some_value </code></pre> <p>Python, h...
1
2016-09-30T05:46:01Z
[ "python", "arrays", "for-loop" ]
How to loop through 3 different arrays by using a single for loop in Python
39,784,438
<p>I have 3 different arrays:</p> <pre><code>a = (x, y, z) b = (p, q) c = (r, s) </code></pre> <p>I need to loop through all this arrays. Presently I am using the below method:</p> <pre><code>for loop_a in a: loop_a = some_value for loop_b in b: loop_b = some_value for loop_c in c: loop_c = some_value </code...
-2
2016-09-30T05:41:13Z
39,784,572
<p>If as you mention, the functionality inside the loop is the same for all three arrays, then why not factoring it into a single function and call such function on your three arrays?</p> <p>For example:</p> <pre class="lang-py prettyprint-override"><code>def my_functionality(array): for loop in array: lo...
0
2016-09-30T05:51:54Z
[ "python", "arrays", "for-loop" ]
How to loop through 3 different arrays by using a single for loop in Python
39,784,438
<p>I have 3 different arrays:</p> <pre><code>a = (x, y, z) b = (p, q) c = (r, s) </code></pre> <p>I need to loop through all this arrays. Presently I am using the below method:</p> <pre><code>for loop_a in a: loop_a = some_value for loop_b in b: loop_b = some_value for loop_c in c: loop_c = some_value </code...
-2
2016-09-30T05:41:13Z
39,784,575
<p>Why not just this?</p> <pre><code>for array in [a, b, c]: for element in array: ... </code></pre> <p>or</p> <pre><code>def f (x) : ... for e in a: e = f(e) for e in b: e = f(e) for e in c: e = f(e) </code></pre>
0
2016-09-30T05:52:09Z
[ "python", "arrays", "for-loop" ]
How to loop through 3 different arrays by using a single for loop in Python
39,784,438
<p>I have 3 different arrays:</p> <pre><code>a = (x, y, z) b = (p, q) c = (r, s) </code></pre> <p>I need to loop through all this arrays. Presently I am using the below method:</p> <pre><code>for loop_a in a: loop_a = some_value for loop_b in b: loop_b = some_value for loop_c in c: loop_c = some_value </code...
-2
2016-09-30T05:41:13Z
39,784,653
<pre><code>def t(): a = [1, 2, 3] b = [4, 5] c = [6, 7] l1 = [a, b, c] someValue = "This should print 4 times" for i in l1: l1[0] = someValue l1[1] = someValue l1[2] = someValue print(someValue) print(l1[0]) print(l1[1]) print(l1[2]) t(); </code></pre> <p>I pu...
0
2016-09-30T05:57:41Z
[ "python", "arrays", "for-loop" ]
How to loop through 3 different arrays by using a single for loop in Python
39,784,438
<p>I have 3 different arrays:</p> <pre><code>a = (x, y, z) b = (p, q) c = (r, s) </code></pre> <p>I need to loop through all this arrays. Presently I am using the below method:</p> <pre><code>for loop_a in a: loop_a = some_value for loop_b in b: loop_b = some_value for loop_c in c: loop_c = some_value </code...
-2
2016-09-30T05:41:13Z
39,784,929
<h2>Problem 1: updating a tuple</h2> <p>You cannot modify a tuple. Tuples are immutable!</p> <pre><code>&gt;&gt;&gt; a = (1, 2, 3) &gt;&gt;&gt; a[0] = 11 Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: 'tuple' object does not support item assignment </code></pre> <p>Yo...
0
2016-09-30T06:21:41Z
[ "python", "arrays", "for-loop" ]
How to loop through 3 different arrays by using a single for loop in Python
39,784,438
<p>I have 3 different arrays:</p> <pre><code>a = (x, y, z) b = (p, q) c = (r, s) </code></pre> <p>I need to loop through all this arrays. Presently I am using the below method:</p> <pre><code>for loop_a in a: loop_a = some_value for loop_b in b: loop_b = some_value for loop_c in c: loop_c = some_value </code...
-2
2016-09-30T05:41:13Z
39,785,482
<p>You could also use lambda function (or just normal function) with map function. Map runs the function given to it as first argument for each value of iterable given as second argument and returns iterator.</p> <p><a href="https://docs.python.org/3/library/functions.html#map" rel="nofollow">Python map documentation<...
0
2016-09-30T06:57:54Z
[ "python", "arrays", "for-loop" ]
List field input in django rest frameowrk browsable api - mongoengine
39,784,483
<p>I have created a <code>serializer</code> that takes a list argument <code>tags</code>, but on the <code>django-rest-framework</code> browsable api, It doesn't seem to work.</p> <p>Code:</p> <p><strong>Model</strong></p> <pre class="lang-py prettyprint-override"><code>class SocialFeed(Document): platform = Str...
0
2016-09-30T05:44:36Z
39,788,563
<p>DRF does only support Django's fields. You likely need to make some fields more explicits in the serializer's declaration, like making <code>tags</code> inherit from a <code>serializer.ListField</code>.</p>
0
2016-09-30T09:48:57Z
[ "python", "django", "django-rest-framework", "mongoengine", "browsable" ]
Delete Specific Part Of A String
39,784,709
<p>I want to delete the part after the last <code>'/'</code> of a string in this following way:</p> <pre><code>str = "live/1374385.jpg" formated_str = "live/" </code></pre> <p>or</p> <pre><code>str = "live/examples/myfiles.png" formated_str = "live/examples/" </code></pre> <p><strong>I have tried this so far ( work...
2
2016-09-30T06:03:36Z
39,784,778
<p>Use <a href="https://docs.python.org/2.4/lib/string-methods.html" rel="nofollow"><code>rsplit</code></a>:</p> <pre><code>str = "live/1374385.jpg" print (str.rsplit('/', 1)[0] + '/') live/ str = "live/examples/myfiles.png" print (str.rsplit('/', 1)[0] + '/') live/examples/ </code></pre>
2
2016-09-30T06:09:24Z
[ "python", "string", "substring" ]
Delete Specific Part Of A String
39,784,709
<p>I want to delete the part after the last <code>'/'</code> of a string in this following way:</p> <pre><code>str = "live/1374385.jpg" formated_str = "live/" </code></pre> <p>or</p> <pre><code>str = "live/examples/myfiles.png" formated_str = "live/examples/" </code></pre> <p><strong>I have tried this so far ( work...
2
2016-09-30T06:03:36Z
39,784,814
<p>You can also use <a href="https://docs.python.org/3/library/stdtypes.html#str.rindex" rel="nofollow"><code>.rindex</code></a> string method:</p> <pre><code>s = 'live/examples/myfiles.png' s[:s.rindex('/')+1] </code></pre>
2
2016-09-30T06:12:31Z
[ "python", "string", "substring" ]
Delete Specific Part Of A String
39,784,709
<p>I want to delete the part after the last <code>'/'</code> of a string in this following way:</p> <pre><code>str = "live/1374385.jpg" formated_str = "live/" </code></pre> <p>or</p> <pre><code>str = "live/examples/myfiles.png" formated_str = "live/examples/" </code></pre> <p><strong>I have tried this so far ( work...
2
2016-09-30T06:03:36Z
39,784,839
<pre><code>#!/usr/bin/python def removePart(_str1): return "/".join(_str1.split("/")[:-1])+"/" def main(): print removePart("live/1374385.jpg") print removePart("live/examples/myfiles.png") main() </code></pre>
0
2016-09-30T06:14:29Z
[ "python", "string", "substring" ]
Numpy boolean indexing issue
39,784,911
<p>Here is my code snippet that uses numpy</p> <pre><code>import numpy as np n = 10 arr = np.array(range(n)) print(arr) selection = [i % 2 == 0 for i in range(n)] print(selection) neg_selection = np.invert(selection) print(neg_selection) print(arr[selection]) print(arr[neg_selection]) </code></pre> <p>The above code...
0
2016-09-30T06:19:22Z
39,784,994
<p>looks like numpy has trouble dealing with <code>list</code> of <code>boolean</code>s.</p> <pre><code>n = 10 arr = np.array(range(n)) selection = [i % 2 == 0 for i in range(n)] neg_selection = np.invert(selection) print(type(selection), arr[selection]) print(type(neg_selection), arr[neg_selection]) </code></pre> <...
2
2016-09-30T06:25:34Z
[ "python", "numpy" ]
Numpy boolean indexing issue
39,784,911
<p>Here is my code snippet that uses numpy</p> <pre><code>import numpy as np n = 10 arr = np.array(range(n)) print(arr) selection = [i % 2 == 0 for i in range(n)] print(selection) neg_selection = np.invert(selection) print(neg_selection) print(arr[selection]) print(arr[neg_selection]) </code></pre> <p>The above code...
0
2016-09-30T06:19:22Z
39,786,062
<p>Note that you can (should) write:</p> <pre><code>arr = np.arange(n) # elements of arr have the same type as n (int, float, complex, etc) arr = np.arange(n, dtype=int) arr = np.arange(n, dtype=float) </code></pre> <p>depending on what type you want for <code>arr</code>.</p>
0
2016-09-30T07:32:39Z
[ "python", "numpy" ]
Numpy boolean indexing issue
39,784,911
<p>Here is my code snippet that uses numpy</p> <pre><code>import numpy as np n = 10 arr = np.array(range(n)) print(arr) selection = [i % 2 == 0 for i in range(n)] print(selection) neg_selection = np.invert(selection) print(neg_selection) print(arr[selection]) print(arr[neg_selection]) </code></pre> <p>The above code...
0
2016-09-30T06:19:22Z
39,795,865
<pre><code>In [63]: arr=np.arange(10) In [64]: arr Out[64]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) In [65]: mask = [n%2==0 for n in arr] In [66]: mask Out[66]: [True, False, True, False, True, False, True, False, True, False] </code></pre> <p>Trying to index with this list:</p> <pre><code>In [67]: arr[mask] /usr/loca...
1
2016-09-30T16:16:15Z
[ "python", "numpy" ]
subprocess.Popen: 'OSError: [Errno 2] No such file or directory' only on Linux
39,785,140
<blockquote> <p>This is not a duplicate of <a href="http://stackoverflow.com/questions/39777345/subprocess-popen-oserror-errno-13-permission-denied-only-on-linux">subprocess.Popen: &#39;OSError: [Errno 13] Permission denied&#39; only on Linux</a> as that problem occurred due to wrong permissions. That has been fixed ...
0
2016-09-30T06:37:02Z
40,018,953
<p>I've tested your <code>espeak</code> Python wrapper on Linux, and it works for me. Probably it's just an issue with Windows trailing <code>\r</code> characters. You could try the following:</p> <pre><code>sed -i 's/^M//' espeak4py/__init__.py </code></pre> <p>To enter the <code>^M</code>, type <code>Ctrl-V</code> ...
0
2016-10-13T10:51:33Z
[ "python", "linux", "python-3.x", "cross-platform", "travis-ci" ]
How to locate this kind of element with Selenium
39,785,200
<p>I'm trying to learn how to make script in python with selenium. Most of the time I was practising with "static element" but now I want to select some elements which have a dynamic id but the problem is that their id don't have a partial static part.</p> <p>However they have another "id", static this time but I don'...
2
2016-09-30T06:40:34Z
39,785,705
<p>You can build a cssSelector using attribute like this:</p> <pre><code>driver.find_element_by_css_selector("Yourtag[attributeName='Your AttributeValue']"); </code></pre> <p>For your specific case use below code snippet:</p> <pre><code>driver.find_element_by_css_selector("div[data-shift-id='134514']"); </code></pre...
0
2016-09-30T07:10:46Z
[ "python", "selenium" ]
Displaying data on new page in Python
39,785,259
<p>I want to display each row from a database in a <code>&lt;td&gt;</code> in the following index.html page:</p> <pre><code>$def with(items) &lt;h1&gt;&lt;/h1&gt; &lt;br/&gt; &lt;br&gt; &lt;table border="1"&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;address&lt;/th&gt; &lt;th&gt;numb...
0
2016-09-30T06:43:59Z
39,785,605
<p>items (results fetched) will be an array of tuples. Return the array as it is as you want to display whole data on the html and HTML is only rendered once.</p> <p>app.py code</p> <pre><code>import web import MySQLdb urls = ( '/', 'Index' ) app = web.application(urls, globals()) render = web.template.render('t...
1
2016-09-30T07:04:30Z
[ "python", "python-2.7", "web.py" ]
NameError when reordering for statements in a list comprehension
39,785,299
<p>Hi please bear with me as I'm an amateur programmer. I'm learning list comprehensions and am getting 2 different results by switching variables though they look like they should work the same. </p> <p>An array <code>a</code> equals <code>[[0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0,...
1
2016-09-30T06:45:40Z
39,785,416
<p>When you have a double <code>for</code> loop in a single list comprehension it's equivalent to doing those <code>for</code> loops in the same order using "traditional" <code>for</code> loops. So</p> <pre><code>result = [(j,i) for i in range(len(a[j])) for j in range(len(a))] </code></pre> <p>is (almost exactly) eq...
6
2016-09-30T06:53:32Z
[ "python", "list" ]
NameError when reordering for statements in a list comprehension
39,785,299
<p>Hi please bear with me as I'm an amateur programmer. I'm learning list comprehensions and am getting 2 different results by switching variables though they look like they should work the same. </p> <p>An array <code>a</code> equals <code>[[0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0,...
1
2016-09-30T06:45:40Z
39,785,544
<p>It's not the order of the variables that matters here. In fact, running List Comprehension 1 does not work either, for the same reason as List Comprehension 2. I'm guessing you had defined <code>i</code> earlier in the program, which is why List Comprehension 1 worked for you. The problem is the order of the <code>f...
4
2016-09-30T07:00:59Z
[ "python", "list" ]
Running command from Node.js with sudo
39,785,436
<p>Being new to Node.js, I have this question..</p> <p>I see it mentioned in a few places that node should not be run as root, such as <a href="http://syskall.com/dont-run-node-dot-js-as-root/" rel="nofollow">this</a>. I am just using node to set up a <strong>simple</strong> web service and executing a python script w...
0
2016-09-30T06:54:56Z
39,786,027
<p>The hacker could do anything if there is any security issues. You could give the user witch runs the web server the permission to do the task your task is intending to do.</p> <p>In general try to avoid root whenever you can (put the tinfoil hat on).</p>
1
2016-09-30T07:30:36Z
[ "javascript", "python", "node.js", "express", "child-process" ]
Plotting more than two columns in python using Panda from a CSV file
39,785,468
<p>I am very new to python and coding in general. I have a CSV file that has the first row a string of flight attributes (ie. time, speed, heading, battery voltage etc.) I want to be able to plot time vs speed vs battery voltage. Or battery voltage vs speed. I have tried several examples, however, every example I have ...
2
2016-09-30T06:57:11Z
39,785,944
<p>As you're new with python you probably should start slower and try to mess around with <code>numpy</code> first. <code>pandas</code> is a library build around <code>numpy</code>, which expects you to be familiar with that.</p> <p>We can simplify your code a bit. I've added some comments to guide you through.</p> <...
1
2016-09-30T07:25:34Z
[ "python", "pandas", "plot" ]
Plotting more than two columns in python using Panda from a CSV file
39,785,468
<p>I am very new to python and coding in general. I have a CSV file that has the first row a string of flight attributes (ie. time, speed, heading, battery voltage etc.) I want to be able to plot time vs speed vs battery voltage. Or battery voltage vs speed. I have tried several examples, however, every example I have ...
2
2016-09-30T06:57:11Z
39,785,987
<p>To directly solve your problem without going deeper just do this:</p> <pre><code>subp = plt.figure().add_subplot(111) df.plot(x='mSec', y='Airspeed(m/s)', color="g", ax=subp) df.plot(x='mSec', y='AS_Cmd(m/s)', color="r", ax=subp) </code></pre> <p>You need to define a common object which to plot your plots on and g...
1
2016-09-30T07:28:01Z
[ "python", "pandas", "plot" ]
Plotting more than two columns in python using Panda from a CSV file
39,785,468
<p>I am very new to python and coding in general. I have a CSV file that has the first row a string of flight attributes (ie. time, speed, heading, battery voltage etc.) I want to be able to plot time vs speed vs battery voltage. Or battery voltage vs speed. I have tried several examples, however, every example I have ...
2
2016-09-30T06:57:11Z
39,787,634
<p>You can simply set your desired index and plot everything in one shot:</p> <pre><code>import matplotlib matplotlib.style.use('ggplot') df.set_index('time(ms)')[['ground_speed','battery_voltage(v)']].plot(rot=0, figsize=(16,10)) </code></pre> <p><a href="http://i.stack.imgur.com/mKKFH.png" rel="nofollow"><img src...
1
2016-09-30T09:01:49Z
[ "python", "pandas", "plot" ]
Draw Line on Webcam Stream -Python
39,785,476
<p>I am attempting to draw a line to the webcam output. However, I am having difficulty with the following code and specifically with "img" portion of the draw line function. I have seen numerous examples of adding an image to another image, so please don't refer me to those examples. This is specifically a question of...
1
2016-09-30T06:57:40Z
39,786,279
<p>You need to draw the line on the <code>frame</code> you get. Try the following:</p> <pre><code>import cv2 cv2.namedWindow("preview") vc = cv2.VideoCapture(0) if vc.isOpened(): # try to get the first frame rval, frame = vc.read() else: rval = False while rval: cv2.imshow("preview", frame) rval, fr...
2
2016-09-30T07:46:26Z
[ "python", "opencv" ]
"Backlog" of a loop through a list in Python
39,785,543
<p>I have a weird Python beginner's question,.. playing around in my virtual env in the interpreter (python 3.5):</p> <p>I have a list with mixed types: </p> <pre><code>lissi = ["foo", "bar". "boo", "baz", 4, 7] </code></pre> <p>And then "accidentally" try to print out all elements in a <strong>for loop</strong> con...
0
2016-09-30T07:00:56Z
39,785,657
<p>I believe the problem is not with the <code>for</code> loop, but with the <code>print()</code> statement.</p> <p>You cannot <code>+</code> a <code>string</code> with an <code>integer</code>, example:</p> <p>This will not work:</p> <pre><code>print("Hallo " + 4) </code></pre> <p>nor will this:</p> <pre><code>pri...
-1
2016-09-30T07:08:00Z
[ "python", "python-3.x", "for-loop", "memory" ]
"Backlog" of a loop through a list in Python
39,785,543
<p>I have a weird Python beginner's question,.. playing around in my virtual env in the interpreter (python 3.5):</p> <p>I have a list with mixed types: </p> <pre><code>lissi = ["foo", "bar". "boo", "baz", 4, 7] </code></pre> <p>And then "accidentally" try to print out all elements in a <strong>for loop</strong> con...
0
2016-09-30T07:00:56Z
39,785,676
<p>The for loop is part of the scope it is declared in, so the following code will change the value of <code>x</code>:</p> <pre><code>x = 9 for x in xrange(3): # iterate 0, 1, 2 print(x) print(x) # x == 2, x != 9 </code></pre> <p>When the element was <code>"baz"</code>, everything was okay and the print stateme...
2
2016-09-30T07:08:55Z
[ "python", "python-3.x", "for-loop", "memory" ]