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
Json to CSV Conversion
39,714,035
<p>I have a very large JSON file with multiple individual JSON objects in the format shown below. I am trying to convert it to a CSV so that each row is a combination of the outer id/name/alphabet in a JSON object and 1 set of conversion: id/name/alphabet. This is repeated for all the sets of id/name/alphabet within an...
0
2016-09-26T23:50:51Z
39,725,278
<p>Your question is unclear about exactly the mapping from input JSON data to rows of the CSV file, so I had to guess on what should happen when there's more than one "name" associated with an inner or outer object.</p> <p>Regardless, hopefully the following will give you a general idea of how to solve such problems.<...
0
2016-09-27T12:55:31Z
[ "python", "json", "csv" ]
Did I write this recursively?
39,714,040
<p>I need to write a recursive method to reverse a list, using no loops and no built-in functions such as <strong>reverse, reversed</strong>, or <strong>::</strong> (the list-slicing operator).</p> <p>Did I do this properly?</p> <pre><code>def reverseList(alist): if len(alist) == 1: return alist else:...
0
2016-09-26T23:51:12Z
39,714,063
<p>Looks like it works, except for the empty list []. You should add it as a base case. For example a correct code would look like:</p> <pre><code>def reverseList(alist): if len(alist) &lt;= 1: return alist else: return reverseList(alist[1:]) + [alist[0]] print (reverseList([1,2,3,4,5])) </cod...
0
2016-09-26T23:53:47Z
[ "python", "recursion" ]
Did I write this recursively?
39,714,040
<p>I need to write a recursive method to reverse a list, using no loops and no built-in functions such as <strong>reverse, reversed</strong>, or <strong>::</strong> (the list-slicing operator).</p> <p>Did I do this properly?</p> <pre><code>def reverseList(alist): if len(alist) == 1: return alist else:...
0
2016-09-26T23:51:12Z
39,729,844
<p>Yes, you did great. The code is short, clear, readable, and calls itself appropriately. Yes, you can recode this for the empty list.</p> <pre><code>if len(alist) &lt;= 1: return alist </code></pre> <p>Also, try a few more test cases:</p> <pre><code>print (reverseList([1,2,3,4,5])) print (reverseList([1, [Fa...
1
2016-09-27T16:28:02Z
[ "python", "recursion" ]
What is first value that is passed into StatsModels predict function?
39,714,057
<p>I have the following OLS model from StatsModels:</p> <pre><code>X = df['Grade'] y = df['Results'] X = statsmodels.tools.tools.add_constant(X) mod = sm.OLS(y,X) results = mod.fit() </code></pre> <p>When trying to predict a new Y value for an X value of 4, I have to pass the following:</p> <pre><code>results.pre...
0
2016-09-26T23:53:05Z
39,714,418
<p>You are adding a constant to the regression equation with <code>X = statsmodels.tools.tools.add_constant(X)</code>. So your regressor X has two columns where the first column is a array of ones.</p> <p>You need to do the same with the regressor that is used in prediction. So, the <code>1</code> means include the co...
1
2016-09-27T00:43:05Z
[ "python", "statsmodels" ]
How to write a function with a list as parameters
39,714,150
<p>Here is the question, I'm trying to define a function <code>sample_mean</code> that takes in a list of numbers as a parameter and returns the sample mean of the the numbers in that list. Here is what I have so far, but I'm not sure it is totally right. </p> <pre><code>def sample_mean(list): """ (list) -&gt; n...
0
2016-09-27T00:06:33Z
39,714,346
<p>As stated above by @idjaw, don't use <code>list</code> as a parameter instead use <code>listr</code> (for example). Your <code>values = [list]</code> is erroneous (also stated by @idjaw) and should be removed.</p> <p>Also, according to <a href="https://www.python.org/dev/peps/pep-0257/" rel="nofollow">PEP257</a>, y...
0
2016-09-27T00:31:58Z
[ "python" ]
How to write a function with a list as parameters
39,714,150
<p>Here is the question, I'm trying to define a function <code>sample_mean</code> that takes in a list of numbers as a parameter and returns the sample mean of the the numbers in that list. Here is what I have so far, but I'm not sure it is totally right. </p> <pre><code>def sample_mean(list): """ (list) -&gt; n...
0
2016-09-27T00:06:33Z
39,714,435
<p>Firstly, don't use <code>list</code> as a name because it shadows/hides the builtin <a href="https://docs.python.org/3/library/functions.html#func-list" rel="nofollow"><code>list</code></a> class for the scope in which it is declared. Use a name that describes the values in the list, in this case <code>samples</code...
1
2016-09-27T00:45:12Z
[ "python" ]
Generating data from meshgrid data (Numpy)
39,714,176
<p>I'd like to ask how to generate corresponding values from a meshgrid. I have a function "foo" that takes one 1D array with the length of 2, and returns some real number. </p> <pre><code>import numpy as np def foo(X): #this function takes a vector, e.g., np.array([2,3]), and returns a real number. return ...
2
2016-09-27T00:09:55Z
39,714,550
<p>Stack your two numpy arrays in "depth" using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.dstack.html" rel="nofollow"><code>np.dstack</code></a>, and then modify your <code>foo</code> function, so that it operates on only the last axis of your stacked array. This is easily done using <a href="h...
1
2016-09-27T00:59:38Z
[ "python", "numpy", "matplotlib" ]
how to rotate xticks on one axis of figure in matplotlib without "getting" the labels as a list
39,714,183
<p>suppose i have the following code which creates one matplotlib figure with two axes, the second of which has x-axis labels as dates:</p> <pre><code>import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt import datetime as dt x1 = np.arange(0,30) x2 = pd.date_range('1/1/201...
0
2016-09-27T00:10:46Z
39,736,364
<p>i was able to use this approach. not sure if it is the most elegant way, but it works without outputting an array</p> <pre><code>for tick in ax[1].get_xticklabels(): tick.set_rotation(90) </code></pre>
0
2016-09-28T00:46:53Z
[ "python", "matplotlib" ]
scrapy shell not opening long link
39,714,205
<p>I'm dealing with scrapy shell. URL that I'm trying to crawl is: <a href="http://allegro.pl/sportowe-uzywane-251188?a_enum[127779][15]=15&amp;a_text_i[1][0]=2004&amp;a_text_i[1][1]=2009&amp;a_text_i[5][0]=950&amp;id=251188&amp;offerTypeBuyNow=1&amp;order=p&amp;string=gsxr&amp;bmatch=base-relevance-aut-1-5-0913" rel=...
0
2016-09-27T00:13:51Z
39,714,274
<p>It's working for me, I suggest you to start with very basic tutorial:</p> <pre><code>import scrapy class BlogSpider(scrapy.Spider): name = 'blogspider' start_urls = ['http://allegro.pl/sportowe-uzywane-251188?a_enum%5B127779%5D%5B15%5D=15&amp;a_text_i%5B1%5D%5B0%5D=2004&amp;a_text_i%5B1%5D%5B1%5D=2009&amp;...
0
2016-09-27T00:22:10Z
[ "python", "scrapy" ]
scrapy shell not opening long link
39,714,205
<p>I'm dealing with scrapy shell. URL that I'm trying to crawl is: <a href="http://allegro.pl/sportowe-uzywane-251188?a_enum[127779][15]=15&amp;a_text_i[1][0]=2004&amp;a_text_i[1][1]=2009&amp;a_text_i[5][0]=950&amp;id=251188&amp;offerTypeBuyNow=1&amp;order=p&amp;string=gsxr&amp;bmatch=base-relevance-aut-1-5-0913" rel=...
0
2016-09-27T00:13:51Z
39,736,462
<p>Thank you very much mertyildiran for help.</p> <p>scrapy shell is not working for me. Some times it fetch web but for most of times not.I don't know why.</p> <p>Anyway I end up with code that works great every single time.</p> <p>import scrapy</p> <p>class QuotesSpider(scrapy.Spider): name = "allegro" st...
0
2016-09-28T01:00:07Z
[ "python", "scrapy" ]
missing required Charfield in django is saved as empty string and do not raise an error
39,714,214
<p>If I try to save incomplete model instance in Django 1.10, I would expect Django to raise an error. It does not seem to be the case.</p> <p>models.py:</p> <pre><code>from django.db import models class Essai(models.Model): ch1 = models.CharField(max_length=100, blank=False) ch2 = models.CharField(max_lengt...
0
2016-09-27T00:15:11Z
39,714,325
<p>It seems like you have a slight misunderstanding of what <code>[blank][1]</code> stands for </p> <blockquote> <p>Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, form validation will allow entry of an empty value. If a fi...
0
2016-09-27T00:29:14Z
[ "python", "mysql", "django" ]
missing required Charfield in django is saved as empty string and do not raise an error
39,714,214
<p>If I try to save incomplete model instance in Django 1.10, I would expect Django to raise an error. It does not seem to be the case.</p> <p>models.py:</p> <pre><code>from django.db import models class Essai(models.Model): ch1 = models.CharField(max_length=100, blank=False) ch2 = models.CharField(max_lengt...
0
2016-09-27T00:15:11Z
39,716,793
<blockquote> <p>Use this,</p> </blockquote> <pre><code>from django.db import models class Essai(models.Model): ch1 = models.CharField(max_length=100) ch2 = models.CharField(max_length=100) </code></pre>
0
2016-09-27T05:42:01Z
[ "python", "mysql", "django" ]
Why do large values cause an infinite loop in this program?
39,714,236
<p>This is a program I made to calculate credit card balance. It works for most inputs, but when <code>balance</code> gets too large, the program runs an infinite loop. What can be done to improve the code so that it calculates even the larger values?</p> <pre><code>monthlyPayment = 0 monthlyInterestRate = annualInte...
-3
2016-09-27T00:16:52Z
39,714,292
<p>You must make the testing condition of <code>while</code> become <code>False</code>. Since it is <code>newbalance &gt; 0</code>, it should eventually emerge from the <code>for</code> loop with a positive value.</p>
0
2016-09-27T00:23:47Z
[ "python", "python-3.x", "infinite-loop" ]
Why do large values cause an infinite loop in this program?
39,714,236
<p>This is a program I made to calculate credit card balance. It works for most inputs, but when <code>balance</code> gets too large, the program runs an infinite loop. What can be done to improve the code so that it calculates even the larger values?</p> <pre><code>monthlyPayment = 0 monthlyInterestRate = annualInte...
-3
2016-09-27T00:16:52Z
39,714,298
<pre><code>while newbalance &gt; 0: monthlyPayment += .1 newbalance = balance </code></pre> <p>Here is your problem. As long as <code>balance</code> is greater than 0, <code>newbalance</code> will always be reset to <code>balance</code> and the while loop will evaluate as true and will cause an infinite loop. ...
4
2016-09-27T00:24:10Z
[ "python", "python-3.x", "infinite-loop" ]
How to use pd.melt for two rows as headers
39,714,267
<p>I have a dataframe that looks like this:</p> <pre><code> DATETIME | TAGNAME1 | TAGNAME2 0 DESCRIPTION | TAG_DESCRIPTION | TAG2_DESCRIPTION 1 01/01/2015 00:00:00 | 100 | 200 </code></pre> <p>I need to have following result</p> <pre><code> DATETIME ...
0
2016-09-27T00:20:49Z
39,716,140
<p>Consider slicing dataframe by rows and running two melts with final merge:</p> <pre><code>from io import StringIO import pandas as pd data = '''DATETIME|TAGNAME1|TAGNAME2 DESCRIPTION|TAG_DESCRIPTION|TAG2_DESCRIPTION 1/01/2015 00:00:00|100|200''' df = pd.read_table(StringIO(data), sep="|") # DATETIME ...
1
2016-09-27T04:46:06Z
[ "python", "pandas" ]
Python XML Parsing - Aligning Indexed Elements
39,714,273
<p>I am in dire need of some help on parsing an xml file. I have been spinning my wheels for a couple of weeks and have not made much progress. I have the below XML snippet and am trying to create a column with the names and values. The problem is that some names are indexed and causing alignment issues when I print t...
0
2016-09-27T00:21:33Z
39,714,765
<p>I don't see a quick and fancy way of solving it, this code works:</p> <pre><code>import xml.etree.ElementTree as ET tree = ET.parse('test_xml_file.xml') elements = [] mgmtids = tree.getroot().findall(".//mgmtid") for mgmtid in mgmtids: names = mgmtid.findall(".//name") objids = mgmtid.findall(".//valuegroup...
0
2016-09-27T01:36:45Z
[ "python", "xml", "parsing", "xml-parsing", "lxml" ]
Python Creating a dictionary of dictionaries structure, nested values are the same
39,714,344
<p>I'm attempting to build a data structure that can change in size and be posted to Firebase. The issue I am seeing is during the construction of the data structure. I have the following code written: </p> <pre><code>for i in range(len(results)): designData = {"Design Flag" : results[i][5], "performance" : re...
0
2016-09-27T00:31:52Z
39,714,477
<p>It is probably because you put the variables like <code>objectives</code>, <code>variables</code>, <code>responses</code> directly to the <code>designData</code>. Try the following:</p> <pre><code>import copy .... designData['objectives'] = copy.copy(objectives) .... designData['variables'] = copy.copy(variables) ...
0
2016-09-27T00:50:04Z
[ "python", "dictionary" ]
Search for element in list of list Python
39,714,372
<p>New to programming. I'm trying to create a program that has a list o list (As a data base) the first element being an invoice, the second the value of that invoice and the third, the margin of income. Given an invoice (input), it will search within the list o lists(data base).</p> <p>I currently have:</p> <pre><co...
0
2016-09-27T00:36:40Z
39,714,442
<p><code>in</code> keyword in Python is used to check the membership of an element in a <code>iterator</code>. That is each element of the <code>iterator</code> is checked with the operand and returns True if the operand exists in the <code>iterator</code>.</p> <p>The <code>in</code> keyword is specifically looking fo...
1
2016-09-27T00:46:07Z
[ "python", "list", "search", "element" ]
Search for element in list of list Python
39,714,372
<p>New to programming. I'm trying to create a program that has a list o list (As a data base) the first element being an invoice, the second the value of that invoice and the third, the margin of income. Given an invoice (input), it will search within the list o lists(data base).</p> <p>I currently have:</p> <pre><co...
0
2016-09-27T00:36:40Z
39,714,529
<p>If you wish to search by invoice number, a better data structure to use is the dictionary. Use the invoice number as the key, and the invoice value and margin as values. Example:</p> <pre><code>invoices = {'f1': [2000, .24], 'f2': [150000, .32], 'f3': [345000, .32]} invoice = input("Enter i...
1
2016-09-27T00:57:14Z
[ "python", "list", "search", "element" ]
Search for element in list of list Python
39,714,372
<p>New to programming. I'm trying to create a program that has a list o list (As a data base) the first element being an invoice, the second the value of that invoice and the third, the margin of income. Given an invoice (input), it will search within the list o lists(data base).</p> <p>I currently have:</p> <pre><co...
0
2016-09-27T00:36:40Z
39,714,543
<p>Here's the solution I found:</p> <pre><code>data_base = [["f1",2000,.24],["f2",150000,.32],["f3",345000,.32]] invoice = input("Enter invoice: ") found = False for data in data_base: if invoice == data[0]: found = True break result = "Invoice is valid" if found else "Invoice does not exist, en...
0
2016-09-27T00:58:32Z
[ "python", "list", "search", "element" ]
Search for element in list of list Python
39,714,372
<p>New to programming. I'm trying to create a program that has a list o list (As a data base) the first element being an invoice, the second the value of that invoice and the third, the margin of income. Given an invoice (input), it will search within the list o lists(data base).</p> <p>I currently have:</p> <pre><co...
0
2016-09-27T00:36:40Z
39,714,606
<pre><code>Data_base= [["f1",2000,.24],["f2",150000,.32],["f3",345000,.32]] invoice = 2000 result = [i for i in Data_base if i[1] == invoice] for item in result: print item </code></pre>
0
2016-09-27T01:11:11Z
[ "python", "list", "search", "element" ]
NaN results in tensorflow Neural Network
39,714,374
<p>I have this problem that after one iteration nearly all my parameters (cost function, weights, hypothesis function, etc.) output 'NaN'. My code is similar to the tensorflow tutorial MNIST-Expert (<a href="https://www.tensorflow.org/versions/r0.9/tutorials/mnist/pros/index.html" rel="nofollow">https://www.tensorflow....
4
2016-09-27T00:36:47Z
39,716,676
<p>1e^-3 is still fairly high, for the classifier you've described. NaN actually means that the weights have tended to infinity, so I would suggest exploring even lower learning rates, around 1e^-7 specifically. If it continues to diverge, multiply your learning rate by 0.1, and repeat until the weights are finite-valu...
0
2016-09-27T05:33:00Z
[ "python", "neural-network", "tensorflow", null ]
NaN results in tensorflow Neural Network
39,714,374
<p>I have this problem that after one iteration nearly all my parameters (cost function, weights, hypothesis function, etc.) output 'NaN'. My code is similar to the tensorflow tutorial MNIST-Expert (<a href="https://www.tensorflow.org/versions/r0.9/tutorials/mnist/pros/index.html" rel="nofollow">https://www.tensorflow....
4
2016-09-27T00:36:47Z
39,738,059
<p>Finally, no more NaN values. The solution is to <strong>scale</strong> my input and output data. The result (accuracy) is still not good, but at least I get some real values for the parameters. I tried feature scaling before in other attempts (where I probably had some other mistakes as well) and assumed it wouldn't...
0
2016-09-28T04:27:56Z
[ "python", "neural-network", "tensorflow", null ]
Group unique 0th elements of CSV for unique ith elements in python or hive
39,714,574
<p>Please see the image at link to best see the input and required output formats and read description below</p> <p><a href="http://i.stack.imgur.com/vWCpc.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/vWCpc.jpg" alt="enter image description here"></a></p> <p>I'm seeking to take a 3 (or 2) column csv and cre...
1
2016-09-27T01:03:44Z
39,717,658
<p>You can do it this way:</p> <pre><code>In [34]: df Out[34]: c1 c2 0 1 p1 1 1 p1 2 1 p2 3 2 p2 4 2 p3 5 3 p3 6 3 p3 7 3 p3 8 3 p4 9 3 p4 10 3 p5 In [36]: (df.groupby('c2')['c1'] ....: .apply(lambda x: ','.join(x.unique().astype(str))) ....: .to_frame('uniq...
1
2016-09-27T06:37:31Z
[ "python", "csv", "pandas", "hive", "itertools" ]
json file is not populating my comboboxes correctly
39,714,588
<p>I am trying to iterate a json file such that my ui - if it found geos in scene, it will append the info into the first column and while doing so, it will append the color options for each of the geos it found in the second column (color options comes from a json file)</p> <p>While I am able to add in geos into the ...
0
2016-09-27T01:07:06Z
39,714,632
<p>This bit of <code>get_color()</code>:</p> <pre><code>for item in (data[name]): print "{0} - {1}".format(name, item) return item </code></pre> <p>will return from your function (as soon as it hits the return statement) before going though all your colors.</p> <p>You probably want to accumulate all your col...
2
2016-09-27T01:14:55Z
[ "python", "json", "combobox", "maya" ]
Django tests slows after MacOS Sierra
39,714,611
<p>I'm working on a Django project using Python 3 and Django 1.10 on Mac.</p> <p>Before update I was running 40 tests in 0.441s.</p> <p>Now after MacOS Sierra: Ran 40 tests in 5.487s</p> <p>I did some investigations and found this line to be the problem:</p> <pre><code>response = self.client.post(r('subscriptions:n...
2
2016-09-27T01:11:48Z
39,802,359
<p>I found that to resolve local DNS was taking forever to resolve.</p> <p>If anyone has the same problem run this commands:</p> <p>sudo scutil --get LocalHostName sudo scutil --get HostName</p> <p>If the result is not the same, use this commands to put them equal:</p> <p>sudo scutil --set LocalHostName My-MacBook ...
2
2016-10-01T02:12:57Z
[ "python", "django", "macos-sierra" ]
How to add new column with handling nan value
39,714,682
<p>I have a dataframe like this</p> <pre><code> A B 0 a 1 1 b 2 2 c 3 3 d nan 4 e nan </code></pre> <p>I would like to add column C like below</p> <pre><code> A B C 0 a 1 a1 1 b 2 b2 2 c 3 c3 3 d nan d 4 e nan e </code></pre> <p>So I tried </p> <pre><co...
4
2016-09-27T01:24:02Z
39,714,714
<p>In your code, I think the data type of the element in the dataframe is str, so, try <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.fillna.html?highlight=fillna#pandas.DataFrame.fillna" rel="nofollow">fillna</a>.</p> <pre><code>In [10]: import pandas as pd In [11]: import numpy as np...
2
2016-09-27T01:29:47Z
[ "python", "pandas" ]
How to add new column with handling nan value
39,714,682
<p>I have a dataframe like this</p> <pre><code> A B 0 a 1 1 b 2 2 c 3 3 d nan 4 e nan </code></pre> <p>I would like to add column C like below</p> <pre><code> A B C 0 a 1 a1 1 b 2 b2 2 c 3 c3 3 d nan d 4 e nan e </code></pre> <p>So I tried </p> <pre><co...
4
2016-09-27T01:24:02Z
39,714,744
<pre><code>df['C'] = pd.Series(df.fillna('').values.tolist()).str.join(' ') </code></pre>
0
2016-09-27T01:33:34Z
[ "python", "pandas" ]
How to add new column with handling nan value
39,714,682
<p>I have a dataframe like this</p> <pre><code> A B 0 a 1 1 b 2 2 c 3 3 d nan 4 e nan </code></pre> <p>I would like to add column C like below</p> <pre><code> A B C 0 a 1 a1 1 b 2 b2 2 c 3 c3 3 d nan d 4 e nan e </code></pre> <p>So I tried </p> <pre><co...
4
2016-09-27T01:24:02Z
39,719,187
<p>You can use <code>add</code> method with the <code>fill_value</code> parameter</p> <pre><code>df['C'] = df.A.add(df.B, fill_value='') df </code></pre> <p><a href="http://i.stack.imgur.com/JLttG.png" rel="nofollow"><img src="http://i.stack.imgur.com/JLttG.png" alt="enter image description here"></a></p>
1
2016-09-27T07:57:29Z
[ "python", "pandas" ]
Text Parser in Python
39,714,692
<p>I have to write a code to read data in text file. This text file has a specific format. It is like comma-separated values (CSV) file that stores tabular data. And, I must be able to perform calculations on the data of that file.</p> <p>Here's the format instruction of that file:</p> <p>A dataset has to start with ...
0
2016-09-27T01:25:21Z
39,714,925
<p>Here is a simple solution that I came up with:</p> <p>The idea is to read the file line by line and apply rules depending on the type of line encountered.</p> <p>As you see in the sample input, there could be broadly 5 types of input you may encounter.</p> <ol> <li><p>A comment which could start with '%' -> no ac...
3
2016-09-27T02:02:46Z
[ "python", "parsing", "text" ]
Tkinter formatting multiple frames next to each other
39,714,710
<p>so I am creating a GUI and I essentially want to have two different "toolbars" at the top of the GUI, similar to <img src="http://i.imgur.com/NZByh97.png" alt="this">.<br> Currently, I have the respective buttons for each toolbar placed into two different respective frames called Toolbar and Selectbar. On each butto...
-1
2016-09-27T01:29:29Z
39,714,911
<p>You can try putting the <code>toolbar</code> and <code>selectBar</code> inside a <code>Frame</code>, and use <code>pack()</code> instead of <code>grid()</code>:</p> <pre><code>topbar = Frame(self) .... toolbar = Frame(topbar, ...) toolbar.pack(side=LEFT, fill=X, expand=True) ... selectBar = Frame(topbar, ...) selec...
1
2016-09-27T02:00:54Z
[ "python", "python-3.x", "user-interface", "tkinter" ]
Python - legend values duplicate
39,714,758
<p>I'm plotting a matrix, as shown below, and the legend repeats over and over again. I've tried using numpoints = 1 and this didn't seem to have any effect. Any hints?</p> <pre><code>import numpy as np import matplotlib.pyplot as plt import pandas as pd import matplotlib %matplotlib inline matplotlib.rcParams['figu...
0
2016-09-27T01:35:33Z
39,715,215
<p>It's nearly impossible to understand the problem if you don't put an example of data format especially if one is not familiar with pandas. However, assuming your input has this format:</p> <pre><code>x=pd.DataFrame(np.array([np.arange(10),np.arange(10)**2]).T,columns=['exam1','exam2']).as_matrix() y=pd.DataFrame(np...
0
2016-09-27T02:44:39Z
[ "python", "matplotlib", "legend" ]
Scrapy Post Data
39,714,810
<p>Im moving from python requests to scrapy, I'd like to make a post request that clicks a button at the bottom of an instagram hashtag page.</p> <p>The cURL is this</p> <pre><code>curl "https://www.instagram.com/query/" -H "cookie: mid=VwBJIwAEAAGiVNY3epWm9pRgD9Ge; fbm_124024574287414=base_domain=.instagram.com; ig_...
0
2016-09-27T01:45:36Z
39,718,694
<p>You seem to be missing correct headers or any headers for that matter.</p> <p>You should provide every header that you see in the network inspector, aside from cookies that scrapy managed and populates by itself.</p> <p>You can easily extract the headers from the curl string network inspect gives you by:</p> <pre...
1
2016-09-27T07:31:09Z
[ "python", "curl", "scrapy" ]
How to pass values to a generator in a for loop?
39,714,852
<p>I know that you can use <code>.send(value)</code> to send values to an generator. I also know that you can iterate over a generator in a for loop. Is it possible to pass values to a generator while iterating over it in a for loop?</p> <p>What I'm trying to do is</p> <pre><code>def example(): previous = yield...
0
2016-09-27T01:53:01Z
39,714,970
<p>Ok, so I figured it out. The trick is to create an additional generator that wraps <code>t.send(value)</code> in a for loop <code>(t.send(value) for value in [...])</code>.</p> <pre><code>def example(): previous = yield for i in range(0,10): previous = yield previous * i t = examplr() t.send(None)...
0
2016-09-27T02:10:37Z
[ "python", "generator" ]
How to pass values to a generator in a for loop?
39,714,852
<p>I know that you can use <code>.send(value)</code> to send values to an generator. I also know that you can iterate over a generator in a for loop. Is it possible to pass values to a generator while iterating over it in a for loop?</p> <p>What I'm trying to do is</p> <pre><code>def example(): previous = yield...
0
2016-09-27T01:53:01Z
39,715,014
<p>You technically could, but the results would be confusing. eg:</p> <pre><code>def example(): previous = (yield) for i in range(1,10): received = (yield previous) if received is not None: previous = received*i t = example() for i, value in enumerate(t): t.send(i) print value...
1
2016-09-27T02:16:27Z
[ "python", "generator" ]
404 Response when running FlaskClient test method
39,714,995
<p>I'm baffled by this. I'm using an application factory in a Flask application and under the test configuration my routes always return 404s.</p> <p>However when I use Flask-Script and load the app from the interpreter everything works as expected, the response comes back as 200. </p> <p>Navigating to the URL with t...
0
2016-09-27T02:13:46Z
39,727,804
<p>You're not using the factory pattern correctly. You should use blueprints to collect routes and register them with the app in the factory. (Or use <code>app.add_url_rule</code> in the factory.) Nothing outside the factory should affect the app.</p> <p>Right now you create an instance of the app and then use that...
1
2016-09-27T14:50:28Z
[ "python", "flask" ]
Pyspark ml can't fit the model and always "AttributeError: 'PipelinedRDD' object has no attribute '_jdf'
39,715,051
<pre><code>data = sqlContext.sql("select a.churn,b.pay_amount,c.all_balance from db_bi.t_cust_churn a left join db_bi.t_cust_pay b on a.cust_id=b.cust_id left join db_bi.t_cust_balance c on a.cust_id=c.cust_id limit 5000").cache() def labelData(df): return df.map(lambda row: LabeledPoint(row[0], row[1:])) traindat...
-1
2016-09-27T02:21:11Z
40,127,006
<p>I guess you are using the tutorial for the latest spark version <a href="https://spark.apache.org/docs/latest/ml-classification-regression.html" rel="nofollow">(2.0.1)</a> with <code>pyspark.ml.classification import LogisticRegression</code> whereas you need some other version, e.g. <a href="https://spark.apache.or...
0
2016-10-19T09:12:21Z
[ "python", "apache-spark", "pyspark", "apache-spark-mllib" ]
Selenium click a button if the parameter is true
39,715,120
<p>I wanted to create a function which takes a parameter and if the parament is True then the button is click otherwise no. Can i use this?</p> <pre><code>def buttonClick(self, Button): if Button == True: self.driver.find_element_by_id('button').click </code></pre>
-2
2016-09-27T02:30:18Z
39,715,276
<p>Two main things to fix from the top of my head:</p> <ul> <li>you can avoid having <code>== True</code> part</li> <li>you are not calling the <code>click</code> method - add the <code>()</code></li> </ul> <p>Fixed version:</p> <pre><code>def buttonClick(self, should_click_button): if should_click_button: ...
1
2016-09-27T02:51:40Z
[ "python", "selenium" ]
How do I access each element in list in for-loop operations?
39,715,121
<p>I am looping through this list and don't understand why <code>print(d)</code> returns each number in <code>seed</code> but assigning <code>i["seed"] = d</code> assigns the last element of <code>seed</code>.</p> <p>How do I access each element in <code>seed</code> for operations other than <code>print()</code>?</p> ...
2
2016-09-27T02:30:19Z
39,715,163
<p>The issue is there is only one object <code>i</code>, and you're replacing its value every time in the loop. By the last iteration your (one instance) of i has its value set to the last item you assigned it to. Each time you append to <code>res</code>, you're basically appending the a pointer to the same object (s...
0
2016-09-27T02:36:29Z
[ "python", "for-loop" ]
How do I access each element in list in for-loop operations?
39,715,121
<p>I am looping through this list and don't understand why <code>print(d)</code> returns each number in <code>seed</code> but assigning <code>i["seed"] = d</code> assigns the last element of <code>seed</code>.</p> <p>How do I access each element in <code>seed</code> for operations other than <code>print()</code>?</p> ...
2
2016-09-27T02:30:19Z
39,715,165
<p>To answer your first question, it is because thew value of seed is being overwritten, as shown here:</p> <pre><code>&gt;&gt;&gt; p = {'t':'H'} &gt;&gt;&gt; p['t'] = 'k' &gt;&gt;&gt; p {'t': 'k'} </code></pre> <p>I am confused on your second part of the question. Elaborate more?</p>
0
2016-09-27T02:36:35Z
[ "python", "for-loop" ]
How do I access each element in list in for-loop operations?
39,715,121
<p>I am looping through this list and don't understand why <code>print(d)</code> returns each number in <code>seed</code> but assigning <code>i["seed"] = d</code> assigns the last element of <code>seed</code>.</p> <p>How do I access each element in <code>seed</code> for operations other than <code>print()</code>?</p> ...
2
2016-09-27T02:30:19Z
39,715,172
<p>The problem is where you are defining i. I <em>think</em> you intended to have a dictionary object named i that has single attribute named "seed". and you want to add those dictionaries to res.</p> <p>In actual fact you only have one dictionary called i and you just update the value in it every time through the lo...
1
2016-09-27T02:37:05Z
[ "python", "for-loop" ]
How do I access each element in list in for-loop operations?
39,715,121
<p>I am looping through this list and don't understand why <code>print(d)</code> returns each number in <code>seed</code> but assigning <code>i["seed"] = d</code> assigns the last element of <code>seed</code>.</p> <p>How do I access each element in <code>seed</code> for operations other than <code>print()</code>?</p> ...
2
2016-09-27T02:30:19Z
39,715,176
<p>Curly braces <code>{}</code> in python represent <a href="http://www.tutorialspoint.com/python/python_dictionary.htm" rel="nofollow">dictionaries</a> which works based on a key and value. Each time you iterate through your loop you overwrite the key: 'seed' with the current value of the list seed. So by the time the...
0
2016-09-27T02:37:23Z
[ "python", "for-loop" ]
Turning Python Object into a JSON string
39,715,136
<p>I have been working on this bot that takes the twitter api and brings it into my database. Before I was grabbing 1 tweet at a time which wasn't efficient considering I was using 1 request out of the limit they had. So instead I decided to grab 150 results. I get these results back:</p> <p><code>[Status(ID=780587171...
0
2016-09-27T02:32:44Z
39,715,187
<p>Yes, a quick Google search would have revealed the <a href="https://docs.python.org/2.7/library/json.html" rel="nofollow">json</a> module.</p> <pre><code>import json # instead of an empty list, create a list of dict objects # representing the statues as you'd like to see them in JSON. statuses = { 'statuses': [] ...
0
2016-09-27T02:39:13Z
[ "python", "json" ]
Turning Python Object into a JSON string
39,715,136
<p>I have been working on this bot that takes the twitter api and brings it into my database. Before I was grabbing 1 tweet at a time which wasn't efficient considering I was using 1 request out of the limit they had. So instead I decided to grab 150 results. I get these results back:</p> <p><code>[Status(ID=780587171...
0
2016-09-27T02:32:44Z
39,715,191
<pre><code>import json jsondata = json.dumps(TwitterStatusObject.__dict__) </code></pre>
0
2016-09-27T02:40:03Z
[ "python", "json" ]
Turning Python Object into a JSON string
39,715,136
<p>I have been working on this bot that takes the twitter api and brings it into my database. Before I was grabbing 1 tweet at a time which wasn't efficient considering I was using 1 request out of the limit they had. So instead I decided to grab 150 results. I get these results back:</p> <p><code>[Status(ID=780587171...
0
2016-09-27T02:32:44Z
39,715,201
<p>If you're using 2.6+ there's a bundled library you can use (<a href="https://docs.python.org/2.7/library/json.html" rel="nofollow">docs</a>), just:</p> <pre><code>import json json_string = json.dumps(object) </code></pre> <p>We use this a lot for quick API endpoints, you just need to be careful about having functi...
2
2016-09-27T02:42:22Z
[ "python", "json" ]
tensorflow python 2.7 interactive shell: function call fails
39,715,183
<p><a href="http://i.stack.imgur.com/PieQ0.png" rel="nofollow"><img src="http://i.stack.imgur.com/PieQ0.png" alt="enter image description here"></a></p> <p>I am studying udacity course: deep learning. Actually it teaches Google's tensorFlow. In Python interactive shell, I define the function softmax, when I invoke it,...
0
2016-09-27T02:38:30Z
39,715,262
<p>When using interactive, make sure that the <code>...</code> is not there. The compiler will include anything in <code>...</code> in a function, method, while, or for block. To escape from the <code>...</code>, just hit enter again and call the method from <code>&gt;&gt;&gt;</code>. </p>
1
2016-09-27T02:50:28Z
[ "python", "tensorflow" ]
Perfect numbers program python
39,715,186
<p>I'm taking an intro course for python, and in one excercise we are to write a function where we type in a number and return bool True or False, if the number is a perfect number. Then we are to create another function that takes an upperlimit and will check every number up until that limit and if it is a perfect num...
0
2016-09-27T02:39:03Z
39,715,209
<p>Your second function is very close.</p> <pre><code>def perfectList(upperlimit): x=1 while x &lt; upperlimit: if perfect(x)==True: print(x) # changed from print(perfect(x)) x=x+1 </code></pre> <p>you just needed to change to <code>print(x)</code> (the number) not <code>print(perf...
0
2016-09-27T02:43:43Z
[ "python", "function", "perfect-numbers" ]
making a function that can take arguments in various shapes
39,715,227
<p>Q1) Numpy functions can take arguments in different shapes. For instance, np.sum(V) can take either of two below and return outputs with different shapes.</p> <pre><code>x1= np.array( [1,3] ) #(1) x2= np.array([[[1,2],[3,4]], [[5,6],[7,8]]]) #(2) </code></pre> <p>I am making my own function something like below, w...
3
2016-09-27T02:45:46Z
39,715,281
<p>for Q1 you can pack and unpack arguments:</p> <pre><code>def foo(*args): result = [] for v in args: result.append(v[0] + v[1]) return result </code></pre> <p>This will allow you pass in as many vector arguments as you want, then iterate over them, returning a list of each result. You can also...
1
2016-09-27T02:52:54Z
[ "python", "numpy" ]
making a function that can take arguments in various shapes
39,715,227
<p>Q1) Numpy functions can take arguments in different shapes. For instance, np.sum(V) can take either of two below and return outputs with different shapes.</p> <pre><code>x1= np.array( [1,3] ) #(1) x2= np.array([[[1,2],[3,4]], [[5,6],[7,8]]]) #(2) </code></pre> <p>I am making my own function something like below, w...
3
2016-09-27T02:45:46Z
39,715,470
<p>For Q1, I'm guessing you want to add the innermost dimensions of your arrays, regardless of how many dimensions the arrays have. The simplest way to do this is to use <a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#basic-slicing-and-indexing" rel="nofollow">ellipsis indexing</a>. Here's a det...
1
2016-09-27T03:22:29Z
[ "python", "numpy" ]
making a function that can take arguments in various shapes
39,715,227
<p>Q1) Numpy functions can take arguments in different shapes. For instance, np.sum(V) can take either of two below and return outputs with different shapes.</p> <pre><code>x1= np.array( [1,3] ) #(1) x2= np.array([[[1,2],[3,4]], [[5,6],[7,8]]]) #(2) </code></pre> <p>I am making my own function something like below, w...
3
2016-09-27T02:45:46Z
39,715,487
<p>Your function works with both arrays:</p> <pre><code>In [1]: def foo(V): ...: return V[0]+V[1] ...: In [2]: foo(np.array([1,3])) Out[2]: 4 In [3]: foo(np.array([[[1,2],[3,4]], [[5,6],[7,8]]])) Out[3]: array([[ 6, 8], [10, 12]]) </code></pre> <p>This answer is just the sum of these two arrays:</...
2
2016-09-27T03:24:47Z
[ "python", "numpy" ]
slice a list based on some values
39,715,311
<p>Hi I'm looking for a way to split a list based on some values, and assuming the list's length equals to sum of some values, e.g.:</p> <p>list: <code>l = ['a','b','c','d','e','f']</code> values: <code>v = (1,1,2,2)</code> so <code>len(l) = sum(v)</code></p> <p>and I'd like to have a function to return a tuple or a...
0
2016-09-27T02:57:21Z
39,715,361
<p>If you weren't stuck on ancient Python, I'd point you to <a href="https://docs.python.org/3/library/itertools.html#itertools.accumulate" rel="nofollow"><code>itertools.accumulate</code></a>. Of course, even on ancient Python, you could use the (roughly) equivalent code provided in the docs I linked to do it. Using e...
2
2016-09-27T03:07:06Z
[ "python", "python-2.7" ]
slice a list based on some values
39,715,311
<p>Hi I'm looking for a way to split a list based on some values, and assuming the list's length equals to sum of some values, e.g.:</p> <p>list: <code>l = ['a','b','c','d','e','f']</code> values: <code>v = (1,1,2,2)</code> so <code>len(l) = sum(v)</code></p> <p>and I'd like to have a function to return a tuple or a...
0
2016-09-27T02:57:21Z
39,715,362
<p>You could just write a simple loop to iterate over <code>v</code> to generate a result:</p> <pre><code>l = ['a','b','c','d','e','f'] v = (1,1,2,2) result = [] offset = 0 for size in v: result.append(l[offset:offset+size]) offset += size print result </code></pre> <p>Output:</p> <pre><code>[['a'], ['b'],...
1
2016-09-27T03:07:18Z
[ "python", "python-2.7" ]
slice a list based on some values
39,715,311
<p>Hi I'm looking for a way to split a list based on some values, and assuming the list's length equals to sum of some values, e.g.:</p> <p>list: <code>l = ['a','b','c','d','e','f']</code> values: <code>v = (1,1,2,2)</code> so <code>len(l) = sum(v)</code></p> <p>and I'd like to have a function to return a tuple or a...
0
2016-09-27T02:57:21Z
39,715,366
<p>Maybe make a generator of the values in l?</p> <pre><code>def make_list(l, v): g = (x for x in l) if len(l) == sum(v): return [[next(g) for _ in range(val)] for val in v] return None </code></pre>
1
2016-09-27T03:07:41Z
[ "python", "python-2.7" ]
slice a list based on some values
39,715,311
<p>Hi I'm looking for a way to split a list based on some values, and assuming the list's length equals to sum of some values, e.g.:</p> <p>list: <code>l = ['a','b','c','d','e','f']</code> values: <code>v = (1,1,2,2)</code> so <code>len(l) = sum(v)</code></p> <p>and I'd like to have a function to return a tuple or a...
0
2016-09-27T02:57:21Z
39,715,413
<p>The idea here is using a nested loop. Assuming that your condition will always holds true, the logic then is to run through <code>v</code> and pick up <code>i</code> elements from <code>l</code> where <code>i</code> is an number from <code>v</code>. </p> <pre><code>index = 0 # this is the start index for num in v: ...
1
2016-09-27T03:13:54Z
[ "python", "python-2.7" ]
slice a list based on some values
39,715,311
<p>Hi I'm looking for a way to split a list based on some values, and assuming the list's length equals to sum of some values, e.g.:</p> <p>list: <code>l = ['a','b','c','d','e','f']</code> values: <code>v = (1,1,2,2)</code> so <code>len(l) = sum(v)</code></p> <p>and I'd like to have a function to return a tuple or a...
0
2016-09-27T02:57:21Z
39,715,461
<p>Best I could find is a two line solution:</p> <pre><code>breaks=[0]+[sum(v[:i+1]) for i in range(len(v))] #build a list of section indices result=[l[breaks[i]:breaks[i+1]] for i in range(len(breaks)-1)] #split array according to indices print result </code></pre>
1
2016-09-27T03:21:29Z
[ "python", "python-2.7" ]
How to put if and then statements while creating snowflakes in python
39,715,354
<p>--im a beginner ..so im not sure how to make sure that the snowflakes don't overlap. Thanks!</p> <pre><code>import turtle turtle.right(90) turtle.penup() turtle.goto(-700,300) turtle.pendown() def snowflakebranch(n): turtle.forward(n*4) for i in range(3): turtle.backward(n) turtle.righ...
3
2016-09-27T03:05:12Z
39,716,593
<p>One approach would be to calculate a bounding rectangle (or circle) for each snowflake. Save these as a list or a set. Whenever you plan to make a new snowflake, first check if its bounding rectangle (or circle) overlaps with the bounds of any previous snowflakes. If it does, don't draw it. If it doesn't, draw i...
0
2016-09-27T05:25:47Z
[ "python", "turtle-graphics" ]
Using XPath with Scrapy
39,715,429
<p>I am new to using Scrapy and is trying get all the URLs of the listings on the page using Xpath.</p> <p>The first xpath works</p> <pre><code>sel.xpath('//[contains(@class, "attraction_element")]') </code></pre> <p>but the second xpath is giving an error</p> <pre><code>get_parsed_string(snode_attraction, '//[@cla...
2
2016-09-27T03:16:18Z
39,715,490
<p>Both are not valid XPath expressions, you need to add the tag names after the <code>//</code>. You can also use a wildcard <code>*</code>:</p> <pre><code>snode_attractions = sel.xpath('//*[contains(@class, "attraction_element")]') </code></pre> <p>Note that aside from that you second XPath expression that is used ...
3
2016-09-27T03:25:40Z
[ "python", "python-2.7", "xpath", "scrapy" ]
How to put an overlay on a video
39,715,472
<p>I am currently working in Python and using OpenCV's videocapture and cv.imshow to show a video. I am trying to put an overlay on this video so I can draw on it using cv.line, cv.rectangle, etc. Each time the frame changes it clears the image that was drawn so I am hoping if I was to put an overlay of some sort on to...
0
2016-09-27T03:22:46Z
39,716,115
<p>What you need are 2 Mat objects- one to stream the camera (say Mat_cam), and the other to hold the overlay (Mat_overlay).</p> <p>When you draw on your main window, save the line and Rect objects on Mat_overlay, and make sure that it is not affected by the streaming video</p> <p>When the next frame is received, Mat...
0
2016-09-27T04:43:31Z
[ "python", "opencv", "video", "overlay" ]
How to put an overlay on a video
39,715,472
<p>I am currently working in Python and using OpenCV's videocapture and cv.imshow to show a video. I am trying to put an overlay on this video so I can draw on it using cv.line, cv.rectangle, etc. Each time the frame changes it clears the image that was drawn so I am hoping if I was to put an overlay of some sort on to...
0
2016-09-27T03:22:46Z
39,721,387
<p>I am not sure that I have understood your question properly.What I got from your question is that you want the overlay to remain on your frame, streamed from Videocapture, for that one simple solution is to declare your "Mat_cam"(camera streaming variable) outside the loop that is used to capture frames so that "Ma...
0
2016-09-27T09:45:30Z
[ "python", "opencv", "video", "overlay" ]
Find the number of terms required in the Leibniz formula to approximate pi to n significant figures?
39,715,509
<p>I have to find the number of terms required to approximate pi to n significant figures using the sum of the Leibniz series. I have already found the sum and the approximation of pi, but I don't know how to start writing the function that compares sigfigs in the two variables, or even how to determine the number of s...
0
2016-09-27T03:27:39Z
39,715,562
<p>Because of the context of this question, I suspect you are not actually interested in knowing how to check for the least significant digits, but rather to know when your approximation is '<em>good enough</em>'.</p> <p>When approximating any value by computing the sum of a sequence, the easiest way to terminate your...
1
2016-09-27T03:35:35Z
[ "python", "loops", "pi" ]
Find the number of terms required in the Leibniz formula to approximate pi to n significant figures?
39,715,509
<p>I have to find the number of terms required to approximate pi to n significant figures using the sum of the Leibniz series. I have already found the sum and the approximation of pi, but I don't know how to start writing the function that compares sigfigs in the two variables, or even how to determine the number of s...
0
2016-09-27T03:27:39Z
39,715,563
<p>The factor of (-1)**i means that the terms in the series have alternating signs. Also, the magnitudes of the terms are monotonically decreasing. One property of such series is that the error you incur by truncating the series is smaller than the smallest term that was included.</p>
1
2016-09-27T03:35:36Z
[ "python", "loops", "pi" ]
Can anyone assist with this task?
39,715,532
<p>Write a while loop that exits when the sum of the squares 1^2 + 2^2 + 3^2 + … exceeds an input m. Print the largest sum less than m and the number of terms in the sum.</p> <pre><code>Example: If m = 18 then 1^2 +2^2 + 3^2 = 1 + 4 + 9 = 14 1^2 +2^2 + 3^2 + 4^2 = 1 + 4 + 9 + 16 = 30 </code></pre> <p>Therefore you...
-1
2016-09-27T03:31:31Z
39,715,628
<p>What's wrong in your code is that you check <code>result + result**2</code> where <code>result</code> is each number in <code>range(y)</code>. You are basically checking if <code>1 + 1**2 &gt;= m</code>, <code>2 + 2**2 &gt;= m</code>, and so on. Here's how I would do it:</p> <pre><code>def sum_printer(): ceil =...
1
2016-09-27T03:45:48Z
[ "python" ]
While loop is not breaking when condition is met, What am I doing wrong?
39,715,584
<p>The program I am writing is a Python 3.5 rocks paper scissors game that plays rocks paper scissors until the cpu or player gets to a score of 5. The best way I could think of to do this was in a while loop, but by some mistake of mine the games continue infinitely and the loop does not break when the score becomes 5...
-3
2016-09-27T03:39:40Z
39,715,659
<p>Use <code>and</code> instead of <code>or</code> in the <code>while</code> condition:</p> <pre><code>while user_score != 5 and cpu_score != 5: </code></pre>
1
2016-09-27T03:49:41Z
[ "python", "while-loop" ]
How to create a line chart using Matplotlib
39,715,601
<p>I am trying to create a line chart for a sample data shown in screenshot. I googled quite a bit and looked at some links below and tried to use <code>matplotlib</code>, but I could not get the desired output as shown in the linegraph (screenshot) below, can anyone provide me a sample reference to get started? How to...
1
2016-09-27T03:42:35Z
39,717,210
<p>Using your data provided in screenshot:</p> <pre><code>import matplotlib.pyplot as plt import numpy as np builds = np.array([1, 2, 3, 4]) y_stack = np.row_stack(([1, 2, 3, 4], [5, 2, 9, 1], [20, 10, 15, 1], [5, 10, 15, 20])) fig = plt.figure(figsize=(11,8)) ax1 = fig.add_subplot(111) ax1.plot(builds, y_stack[0,...
3
2016-09-27T06:11:22Z
[ "python", "matplotlib", "linechart" ]
Use a previous input while asking for input to define a new variable
39,715,606
<pre><code>userName = input("What is your name?") firstInteger = (input ("Hi," , userName , "what is the first integer?")) </code></pre> <p>This just returns TypeError: input expected at most 1 arguments, got 3</p> <p>I tried changing the userName to str(input(...)) and the userName in the firstInteger input to str...
-1
2016-09-27T03:43:07Z
39,717,144
<p>Here's the updated code based on the comments.</p> <p>Also I'm not sure what version of python you're using, but older versions may require <code>raw_input</code> instead of <code>input</code>. If you're using Python 3.x, just <code>input</code> should work. Here's the updated code. Just replace <code>raw_input</co...
0
2016-09-27T06:06:40Z
[ "python", "variables", "input" ]
classification with LSTM RNN in tensorflow, ValueError: Shape (1, 10, 5) must have rank 2
39,715,612
<p>I am trying to design a simple lstm in tensorflow. I want to classify a sequence of data into classes from 1 to 10.</p> <p>I have <em>10 timestamps</em> and data X. I am only taking one sequence for now, so my batch size = 1. At every epoch, a new sequence is generated. For example X is a numpy array like this-</p>...
0
2016-09-27T03:44:06Z
39,715,887
<p>Looking at your code, your rnn output should have a dimension of <code>batch_size x 1 x num_hidden</code> while your w has dimension <code>batch_size x num_classes x 1</code> however you want multiplication of those two to be <code>batcH_size x num_classes</code>. </p> <p>Can you try <code>output = tf.reshape(outpu...
0
2016-09-27T04:18:06Z
[ "python", "tensorflow", "deep-learning", "recurrent-neural-network", "lstm" ]
Selenium starts but does not load a page
39,715,653
<p>I am running python 2.7.12 with selenium version 2.53.6 and firefox 49.0. I have looked here for <a href="http://stackoverflow.com/questions/18768658/selenium-webdriver-firefox-starts-but-does-not-open-the-url">Selenium WebDriver: Firefox starts, but does not open the URL</a> but the solutions mentioned have not sol...
1
2016-09-27T03:49:03Z
39,716,270
<p>you must used Firefox version&lt;=46.0</p>
1
2016-09-27T04:58:39Z
[ "python", "selenium" ]
Selenium starts but does not load a page
39,715,653
<p>I am running python 2.7.12 with selenium version 2.53.6 and firefox 49.0. I have looked here for <a href="http://stackoverflow.com/questions/18768658/selenium-webdriver-firefox-starts-but-does-not-open-the-url">Selenium WebDriver: Firefox starts, but does not open the URL</a> but the solutions mentioned have not sol...
1
2016-09-27T03:49:03Z
39,717,037
<p>Download Firefox from this link <a href="https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64-EME-free/en-GB/Firefox%20Setup%2046.0.1.exe" rel="nofollow">https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64-EME-free/en-GB/Firefox%20Setup%2046.0.1.exe</a> and then try again </p>
1
2016-09-27T05:59:42Z
[ "python", "selenium" ]
Selenium starts but does not load a page
39,715,653
<p>I am running python 2.7.12 with selenium version 2.53.6 and firefox 49.0. I have looked here for <a href="http://stackoverflow.com/questions/18768658/selenium-webdriver-firefox-starts-but-does-not-open-the-url">Selenium WebDriver: Firefox starts, but does not open the URL</a> but the solutions mentioned have not sol...
1
2016-09-27T03:49:03Z
39,719,909
<p>For higher version of Firefox either use Selenium 3.0.x or use <code>geckodriver</code>.</p>
1
2016-09-27T08:36:02Z
[ "python", "selenium" ]
Selenium starts but does not load a page
39,715,653
<p>I am running python 2.7.12 with selenium version 2.53.6 and firefox 49.0. I have looked here for <a href="http://stackoverflow.com/questions/18768658/selenium-webdriver-firefox-starts-but-does-not-open-the-url">Selenium WebDriver: Firefox starts, but does not open the URL</a> but the solutions mentioned have not sol...
1
2016-09-27T03:49:03Z
39,720,178
<p>i am also facing the same problem. I downgraded the Firefox to 47.0.1 and it works</p>
1
2016-09-27T08:49:13Z
[ "python", "selenium" ]
Selenium starts but does not load a page
39,715,653
<p>I am running python 2.7.12 with selenium version 2.53.6 and firefox 49.0. I have looked here for <a href="http://stackoverflow.com/questions/18768658/selenium-webdriver-firefox-starts-but-does-not-open-the-url">Selenium WebDriver: Firefox starts, but does not open the URL</a> but the solutions mentioned have not sol...
1
2016-09-27T03:49:03Z
39,721,992
<p>As you are using selenium version 2.53.6 .So it is not compatible with firefox version 49.0.</p> <p>You should downgrade your firefox version to &lt;=46 </p> <p>Download older version of firefox from the below address:</p> <p><a href="https://support.mozilla.org/en-US/kb/install-older-version-of-firefox" rel="nof...
1
2016-09-27T10:13:34Z
[ "python", "selenium" ]
Formatting a static AES Key for decryption in Python
39,715,658
<p>I'm working to decrypt several files in python using a given AES key via the PyCrypto AES implementation. I've currently set it to a static list of hex bytes (as this was how it was provided to me). However, when I try to decrypt the files, I get a warning stating the key size must be 16, 24, or 32 bytes. My code fo...
0
2016-09-27T03:49:28Z
39,715,755
<p>You didn't mention what AES implementation you're using, but the right answer is likely to look like</p> <pre><code>k = bytes([0x01, 0x23, 0x34, 0x56]) </code></pre>
0
2016-09-27T04:01:42Z
[ "python", "encryption", "aes" ]
Search Text File and Email Results
39,715,667
<p>Working with a text file to search for a string and then email the nex few lines. </p> <p>I have the search working and it prints the correct lines The email sends successfully, however it only contains the last line of the output </p> <p>Any thoughts? </p> <p>File.txt </p> <pre><code>first second thrid -------...
0
2016-09-27T03:50:27Z
39,715,693
<p>your for loop prints all the lines, but then the loop ends, and l is set to the last item in the loop: after fifth</p> <p>then you email that last l</p>
-1
2016-09-27T03:53:43Z
[ "python" ]
Search Text File and Email Results
39,715,667
<p>Working with a text file to search for a string and then email the nex few lines. </p> <p>I have the search working and it prints the correct lines The email sends successfully, however it only contains the last line of the output </p> <p>Any thoughts? </p> <p>File.txt </p> <pre><code>first second thrid -------...
0
2016-09-27T03:50:27Z
39,715,999
<p>Your indentation is wonky. The loop should collect the lines, then you should send an email when you have collected them all.</p> <pre><code>with open("file.txt", "r") as f: searchlines = f.readlines() # &lt;-- unindent; we don't need this in the "with" for i, line in enumerate(searchlines): # Aesthetics: ...
0
2016-09-27T04:31:24Z
[ "python" ]
Python SQL query using variables
39,715,735
<pre><code>#Delete suspense window class dWindow(QtGui.QMainWindow, Ui_dWindow): def __init__(self, parent = None): QtGui.QMainWindow.__init__(self, parent) self.setupUi(self) for row in cursor.execute("SELECT FIRSTNAME FROM Staff"): self.comboUser.addItems(row) con.clos...
-1
2016-09-27T03:59:50Z
39,716,161
<p>You use the <a href="http://www.w3schools.com/sql/sql_delete.asp" rel="nofollow"><code>DELETE</code></a> sql command.</p> <p>This assumes your <code>DATE</code> field is actually a date field and not a string field.</p> <pre><code>user = self.comboUser.currentText() date = self.dateEdit.date().toString("yyyy-MM-dd...
0
2016-09-27T04:47:50Z
[ "python", "sql", "pyqt", "pyodbc", "pypyodbc" ]
Python SQL query using variables
39,715,735
<pre><code>#Delete suspense window class dWindow(QtGui.QMainWindow, Ui_dWindow): def __init__(self, parent = None): QtGui.QMainWindow.__init__(self, parent) self.setupUi(self) for row in cursor.execute("SELECT FIRSTNAME FROM Staff"): self.comboUser.addItems(row) con.clos...
-1
2016-09-27T03:59:50Z
39,755,807
<p>As mentioned in a comment to another answer, you should be using a proper <em>parameterized query</em>, for example:</p> <pre class="lang-python prettyprint-override"><code># assumes that autocommit=False (the default) crsr = conn.cursor() sql = "DELETE FROM [Suspense] WHERE [TO]=? AND [DATE]&lt;=?" user = self.com...
1
2016-09-28T19:10:34Z
[ "python", "sql", "pyqt", "pyodbc", "pypyodbc" ]
Python SQL query using variables
39,715,735
<pre><code>#Delete suspense window class dWindow(QtGui.QMainWindow, Ui_dWindow): def __init__(self, parent = None): QtGui.QMainWindow.__init__(self, parent) self.setupUi(self) for row in cursor.execute("SELECT FIRSTNAME FROM Staff"): self.comboUser.addItems(row) con.clos...
-1
2016-09-27T03:59:50Z
39,757,110
<p>What I came up with was the following:</p> <pre><code>qdate = self.dateTimeEdit.dateTime().toPyDateTime() #grabs the raw datetime from the QDateTimeEdit object and converts to python datetime query = "SELECT DATE FROM Suspense WHERE DATE &gt;= ?" #creates the query using ? as a placeholder for variable cursor.ex...
1
2016-09-28T20:30:57Z
[ "python", "sql", "pyqt", "pyodbc", "pypyodbc" ]
Python counting in nested forloops
39,715,841
<p>I'm brand new to python and have an assignment to "Use two nested for loops. Count up in the outer for loop from 0 to 9 and then at every step count back down to zero."</p> <p>The answer is supposed to be this:</p> <pre><code>i= 0 k= 0 i= 1 k= 1 k= 0 i= 2 k= 2 k= 1 k= 0 i= 3 k= 3 k= 2 k= 1 k= 0 i= 4 k= 4 k= 3 k= 2...
-1
2016-09-27T04:13:26Z
39,715,880
<p>You just need your second for loop to go backwards instead of forwards. Right now it is going from 0 to i. </p> <p>The syntax for this is:</p> <pre><code>for k in range(i, -1, -1): </code></pre> <p>This starts k at i, until k is not -1, applying -1 to it in each iteration. </p> <p>So your complete program would ...
0
2016-09-27T04:17:28Z
[ "python", "for-loop", "nested-loops" ]
Python Selenium - how to access methods from different modules using the same webdriver instance
39,715,909
<p>I am getting very confused and was hoping someone here could help me out.</p> <p>So here is my scenario: I have one module containing the Base class where the webdriver instance is created and this will be inherited by all tests; a separate module containing a class that will be inherited by all tests for a specifi...
0
2016-09-27T04:20:30Z
39,785,582
<p>If you want to avoid <strong>multiple inheritance</strong> you could use <strong>composition</strong>. This article explains inheritance vs composition in nice way with example <a href="https://learnpythonthehardway.org/book/ex44.html" rel="nofollow">https://learnpythonthehardway.org/book/ex44.html</a></p> <p><stro...
0
2016-09-30T07:03:21Z
[ "python", "selenium", "inheritance", "selenium-webdriver", "py.test" ]
Python Selenium - how to access methods from different modules using the same webdriver instance
39,715,909
<p>I am getting very confused and was hoping someone here could help me out.</p> <p>So here is my scenario: I have one module containing the Base class where the webdriver instance is created and this will be inherited by all tests; a separate module containing a class that will be inherited by all tests for a specifi...
0
2016-09-27T04:20:30Z
39,786,311
<p>I was able to use the methods from CheckReportsPage by adding a constructor to it and passing a browser instance when calling it. It basically looked like this:</p> <pre><code>class CheckReportsPage(Base): def __init__(self, browser): self.browser = browser </code></pre> <p>So in TestVoice I did this:<...
0
2016-09-30T07:48:35Z
[ "python", "selenium", "inheritance", "selenium-webdriver", "py.test" ]
Trying to create a pandas series within a dataframe with values based on whether or not keys are in another dataframe
39,715,910
<p>Boiling it down simply...</p> <p>Dataframe 1 = yellow_fruits The columns are fruit_name, and location</p> <p>Dataframe 2 = red_fruits The columns are fruit_name, and location</p> <p>Dataframe 3 = fruit_montage The columns are fruit_name, pounds_of_fruit_needed, freshness</p> <p>Let's say I want to add a column t...
3
2016-09-27T04:20:31Z
39,716,580
<p>The classic way would be to use your conditions as indexers:</p> <pre><code>df1 = pd.DataFrame({'fruit_name':['banana', 'lemon']}) df2 = pd.DataFrame({'fruit_name':['strawberry', 'apple']}) df3 = pd.DataFrame({'fruit_name':['lemon', 'rockmelon', 'apple']}) df3["color"] = "unknown" df3["color"][df3['fruit_name'].is...
1
2016-09-27T05:24:51Z
[ "python", "pandas", "dataframe", "series" ]
How do I run a binary search for words that start with a certain letter?
39,715,933
<p>I am asked to binary search a list of names and if these names start with a particular letter, for example A, then I am to print that name. I can complete this task by doing much more simple code such as</p> <pre><code>for i in list: if i[0] == "A": print(i) </code></pre> <p>but instead I am asked to u...
0
2016-09-27T04:23:35Z
39,716,337
<p>Not too sure if this is what you want as it seems inefficient... as you mention it seems a lot more intuitive to just iterate over the entire list but using binary search i found <a href="http://code.activestate.com/recipes/81188-binary-search/" rel="nofollow">here</a> i have:</p> <pre class="lang-python prettyprin...
0
2016-09-27T05:03:44Z
[ "python", "binary-search" ]
How do I run a binary search for words that start with a certain letter?
39,715,933
<p>I am asked to binary search a list of names and if these names start with a particular letter, for example A, then I am to print that name. I can complete this task by doing much more simple code such as</p> <pre><code>for i in list: if i[0] == "A": print(i) </code></pre> <p>but instead I am asked to u...
0
2016-09-27T04:23:35Z
39,723,697
<p>You just need to found one item starting with the letter, then you need to identify the range. This approach should be fast and memory efficient.</p> <pre><code>def binary_search(list,item): low_b = 0 up_b = len(list) - 1 found = False midPos = ((low_b + up_b) // 2) if list[low_b][0]==item: ...
0
2016-09-27T11:38:31Z
[ "python", "binary-search" ]
Try to download image from image url, but get html instead
39,715,939
<p>similar to <a href="http://stackoverflow.com/questions/29433699/try-to-scrape-image-from-image-url-using-python-urllib-but-get-html-instead">Try to scrape image from image url (using python urllib ) but get html instead</a> , but the solution does not work for me.</p> <pre><code>from BeautifulSoup import BeautifulS...
0
2016-09-27T04:24:13Z
39,716,394
<p>Your referrer was not being set correctly. I have hard coded the referrer and it works fine</p> <pre><code>from BeautifulSoup import BeautifulSoup import urllib2 import requests img_url='http://7-themes.com/data_images/out/79/7041933-beautiful-backgrounds-wallpaper.jpg' r = requests.get(img_url, allow_redirects=F...
0
2016-09-27T05:09:48Z
[ "python", "httprequest", "urllib2" ]
Try to download image from image url, but get html instead
39,715,939
<p>similar to <a href="http://stackoverflow.com/questions/29433699/try-to-scrape-image-from-image-url-using-python-urllib-but-get-html-instead">Try to scrape image from image url (using python urllib ) but get html instead</a> , but the solution does not work for me.</p> <pre><code>from BeautifulSoup import BeautifulS...
0
2016-09-27T04:24:13Z
39,716,410
<p>I found a root cause in my code is that refer field in the header is still a html, not image.</p> <p>So I change the refer field to the <code>img_url</code>, and this works.</p> <pre><code>from BeautifulSoup import BeautifulSoup import urllib2 import urllib import requests img_url='http://7-themes.com/data_images...
0
2016-09-27T05:10:42Z
[ "python", "httprequest", "urllib2" ]
groupby and add some rows
39,715,950
<p>I have a dataframe below</p> <pre><code> A B 0 a 1 1 a 2 2 c 3 3 c 4 4 e 5 </code></pre> <p>I would like to get summing result below.key = column A</p> <pre><code>df.B.groupby(df.A).agg(np.sum) </code></pre> <p>But I want to add specific row. </p> <pre><code> B a 3 b 0 c 7 d 0 e 5 f 0 </cod...
3
2016-09-27T04:25:18Z
39,716,069
<p>Use <code>reindex</code></p> <pre><code>df.groupby('A').B.sum().reindex(list('abcdef'), fill_value=0) A a 3 b 0 c 7 d 0 e 5 f 0 Name: B, dtype: int64 </code></pre>
3
2016-09-27T04:38:45Z
[ "python", "pandas" ]
curve_fit doesn't work properly with 4 parameters
39,716,026
<p>Running the following code, </p> <pre><code>x = np.array([50.849937, 53.849937, 56.849937, 59.849937, 62.849937, 65.849937, 68.849937, 71.849937, 74.849937, 77.849937, 80.849937, 83.849937, 86.849937, 89.849937, 92.849937]) y = np.array([410.67800, 402.63800, 402.63800, 386.55800, 330.27600, 217.71400, 72.98990, 16...
1
2016-09-27T04:33:49Z
39,718,226
<p>It looks like it isn't converging (see <a href="http://stackoverflow.com/questions/15624070/why-does-scipy-optimize-curve-fit-not-fit-to-the-data">this</a> and <a href="http://stackoverflow.com/questions/21420792/exponential-curve-fitting-in-scipy?rq=1">this</a>). Try adding an initial condition,</p> <pre><code>par...
1
2016-09-27T07:09:20Z
[ "python", "numpy", "matplotlib", "scipy", "curve-fitting" ]
curve_fit doesn't work properly with 4 parameters
39,716,026
<p>Running the following code, </p> <pre><code>x = np.array([50.849937, 53.849937, 56.849937, 59.849937, 62.849937, 65.849937, 68.849937, 71.849937, 74.849937, 77.849937, 80.849937, 83.849937, 86.849937, 89.849937, 92.849937]) y = np.array([410.67800, 402.63800, 402.63800, 386.55800, 330.27600, 217.71400, 72.98990, 16...
1
2016-09-27T04:33:49Z
39,723,506
<p>You can calculate the initial condition from data:</p> <pre><code>%matplotlib inline import pylab as pl import numpy as np from scipy.optimize import curve_fit x = np.array([50.849937, 53.849937, 56.849937, 59.849937, 62.849937, 65.849937, 68.849937, 71.849937, 74.849937, 77.849937, 80.849937, 83.849937, 86.84993...
0
2016-09-27T11:29:31Z
[ "python", "numpy", "matplotlib", "scipy", "curve-fitting" ]
How to iterate a list of string, using Sikuli
39,716,156
<p>I am using sikuli to automate an application; it process a file and save the output of this file.</p> <p>I am taking a snapshot of the file itself, so Sikuli can find it, but I have to process 30 files; so taking 30 snapshot of each file is really not that logic. Is there a way to loop through a list of files, as s...
0
2016-09-27T04:47:42Z
39,760,995
<p>I still don't completely understand what are you trying to do but the <code>findText()</code> function that you are using is actually attempting to find text on the screen by using OCR extraction of text in the region. Are you sure that's what you want to do? If yes you have to:</p> <ol> <li>Setup Sikuli properly t...
0
2016-09-29T03:36:15Z
[ "python", "sikuli" ]
pandas series drop when multiindex is not unique
39,716,210
<p>consider the <code>pd.Series</code> <code>s</code></p> <pre><code>midx = pd.MultiIndex.from_product([list('ABC'), np.arange(3)]) s = pd.Series(1, midx) s A 0 1 1 1 2 1 B 0 1 1 1 2 1 C 0 1 1 1 2 1 dtype: int64 </code></pre> <p>It is very convenient to use <code>drop<...
2
2016-09-27T04:53:37Z
39,716,240
<p>I'm not sure why the <code>s.drop('B')</code> doesn't work but using the <code>level=0</code> parameter does.</p> <pre><code>s.drop('B', level=0) A 0 1 1 1 2 1 2 0 C 0 1 1 1 2 1 dtype: int64 </code></pre>
1
2016-09-27T04:55:41Z
[ "python", "pandas", "multi-index" ]
How to log and save file with date and timestamp in Python
39,716,271
<p>I am trying to log temperature from a DS18B20 sensor using Raspberry Pi 3 via Python code executed from shell.</p> <p>I want to log temperature with timestamp and then save the file.</p> <p>What I am doing presently is saving it to a filename entered in the code, but I want to log the file with date and timestamp ...
2
2016-09-27T04:58:47Z
39,716,325
<p>Try :</p> <pre><code>with open('Log-%s.csv' % filename1, 'a') as log: </code></pre>
2
2016-09-27T05:02:40Z
[ "python", "csv", "datetime", "raspberry-pi" ]
How to log and save file with date and timestamp in Python
39,716,271
<p>I am trying to log temperature from a DS18B20 sensor using Raspberry Pi 3 via Python code executed from shell.</p> <p>I want to log temperature with timestamp and then save the file.</p> <p>What I am doing presently is saving it to a filename entered in the code, but I want to log the file with date and timestamp ...
2
2016-09-27T04:58:47Z
39,716,356
<p>In <strong>Case 2</strong>, every time <code>write_temp</code> is called, it is populating <code>filename1</code> with timestamp.</p> <p>So consider,for example, you called it at <code>10:15:13 (hh:mm:ss)</code>, then <code>filename1</code> will be <code>10-15-13.csv</code>. When you will call it again at <code>10:...
1
2016-09-27T05:05:32Z
[ "python", "csv", "datetime", "raspberry-pi" ]
Django: How to save the POST.get of a checkbox as false (0) in a DataBase?
39,716,303
<p>I'm trying to save the value of a checkbox as true or false in a database. I have to use a model for this. If the box is checked the value of '1' is saved. However, if the box is not checked I get the error message: </p> <pre><code>Django Version: 1.9.4 Exception Type: IntegrityError Exception Value: (10...
0
2016-09-27T05:01:17Z
39,716,431
<p>You can print the value of <code>request.POST</code> to see what you are getting in the views.</p> <p>If you have not specified a <code>value</code> attribute in the checkbox HTML element, the default value which will passed in the <code>POST</code> is <code>on</code> if the checkbox is checked.</p> <p>In the view...
2
2016-09-27T05:12:27Z
[ "python", "django", "django-models", "django-views" ]
Django: How to save the POST.get of a checkbox as false (0) in a DataBase?
39,716,303
<p>I'm trying to save the value of a checkbox as true or false in a database. I have to use a model for this. If the box is checked the value of '1' is saved. However, if the box is not checked I get the error message: </p> <pre><code>Django Version: 1.9.4 Exception Type: IntegrityError Exception Value: (10...
0
2016-09-27T05:01:17Z
39,716,753
<blockquote> <p>Use this code snippet</p> </blockquote> <pre><code>def create_myClass(request): completed = request.POST.get('completed') if not completed: completed = False toSave = models.myClass(completed=completed) toSave.save() </code></pre>
0
2016-09-27T05:38:55Z
[ "python", "django", "django-models", "django-views" ]
Django: How to save the POST.get of a checkbox as false (0) in a DataBase?
39,716,303
<p>I'm trying to save the value of a checkbox as true or false in a database. I have to use a model for this. If the box is checked the value of '1' is saved. However, if the box is not checked I get the error message: </p> <pre><code>Django Version: 1.9.4 Exception Type: IntegrityError Exception Value: (10...
0
2016-09-27T05:01:17Z
39,720,049
<p>To tackle that problem you have to know how checkboxes work: if they are checked, a value is passed to <code>request.POST</code> -- but if a checkbox isn't checked, no value will be passed <strong>at all</strong>. So if the statement</p> <pre><code>'completed' in request.POST </code></pre> <p>is true, the checkbox...
0
2016-09-27T08:43:09Z
[ "python", "django", "django-models", "django-views" ]
Filtering data out of Excel file via CSV
39,716,437
<p>Is there eny alternative for this than making multiple for loop ? </p> <p>I have an Excel file : </p> <pre><code>|col1|col2|col3| 1 x y 2 s r 3 o o </code></pre> <p>I want an output like this: When first column argument equals 1, print argument from column 3 from the same row.</p> <...
-2
2016-09-27T05:12:55Z
39,716,740
<pre><code>import pandas as pd reader = pd.read_csv("alerts.csv") print reader[['col1','col3']].loc[reader['col1'] == 1] </code></pre>
0
2016-09-27T05:38:09Z
[ "python", "excel", "csv" ]
Filtering data out of Excel file via CSV
39,716,437
<p>Is there eny alternative for this than making multiple for loop ? </p> <p>I have an Excel file : </p> <pre><code>|col1|col2|col3| 1 x y 2 s r 3 o o </code></pre> <p>I want an output like this: When first column argument equals 1, print argument from column 3 from the same row.</p> <...
-2
2016-09-27T05:12:55Z
39,718,136
<p>So i have difrent idea to sort everything out to diffrent list. </p> <pre><code>import csv reader = csv.reader(open("alerts.csv"), delimiter=',') rows=[] for row in reader: rows.append(row) num_lists=int(len(rows)) lists = [] for p in range(num_lists): lists.append([]) for i in rows: lists[i...
0
2016-09-27T07:04:21Z
[ "python", "excel", "csv" ]
python array of unicodes to float conversion
39,716,472
<p>I have an array which looks as:</p> <pre><code>MyArray array(['1445.98', '1422.64', '1392.93', ..., '2012.21', '1861.19', '1681.02'], dtype=object) type(MyArray[0]) </code></pre> <p>I tried:</p> <pre><code>MyArray.astype(np.float) </code></pre> <p>Error:</p> <pre><code>ValueError: could not convert stri...
-1
2016-09-27T05:16:01Z
39,716,571
<p>Maybe convert each memeber individually. Try something like, </p> <pre><code>map(lambda x: float(x),mydata) </code></pre>
1
2016-09-27T05:24:04Z
[ "python", "unicode" ]
python array of unicodes to float conversion
39,716,472
<p>I have an array which looks as:</p> <pre><code>MyArray array(['1445.98', '1422.64', '1392.93', ..., '2012.21', '1861.19', '1681.02'], dtype=object) type(MyArray[0]) </code></pre> <p>I tried:</p> <pre><code>MyArray.astype(np.float) </code></pre> <p>Error:</p> <pre><code>ValueError: could not convert stri...
-1
2016-09-27T05:16:01Z
39,716,590
<p>Obviously some of your lines don't have valid float data</p> <pre><code>map(lambda x: float(x),MyArray) </code></pre> <p>or </p> <p>if you have a list</p> <pre><code>[float(x) for x in MyList] </code></pre>
2
2016-09-27T05:25:21Z
[ "python", "unicode" ]
Splitting string in python when last part may not exist
39,716,473
<p>How do I split the foll. in python:</p> <pre><code>'a_b_c' </code></pre> <p>The appraoch should also work if string is <code>'a_b'</code></p>
-4
2016-09-27T05:16:02Z
39,716,513
<pre><code>splited = "a_b_c".split('_') </code></pre> <p><code>inputstring.split('_')</code> will split it.</p>
2
2016-09-27T05:19:19Z
[ "python" ]