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 |
|---|---|---|---|---|---|---|---|---|---|
how to convert python dict to geojson file in form standard? | 38,072,738 | <p>I want to convert an excel file into a geojson file. The dictionary is like:</p>
<pre><code>[
{"NoAdresse": 42537006584, "NoUsager": 42537000086, "LatEffective": 45.83675, "LongDebut": 4.91956, "LatDebut": 45.75529, "LongEffective": 4.84574, "IdVehicule": "246Veh", "LatArrivee": 45.83492, "NoDemande": 42537000003, ... | 1 | 2016-06-28T09:48:00Z | 38,073,224 | <p>Here's package [geojson][1]:<a href="https://github.com/frewsxcv/python-geojson" rel="nofollow">https://github.com/frewsxcv/python-geojson</a>.</p>
| 0 | 2016-06-28T10:07:26Z | [
"python",
"dictionary",
"geojson"
] |
how to convert python dict to geojson file in form standard? | 38,072,738 | <p>I want to convert an excel file into a geojson file. The dictionary is like:</p>
<pre><code>[
{"NoAdresse": 42537006584, "NoUsager": 42537000086, "LatEffective": 45.83675, "LongDebut": 4.91956, "LatDebut": 45.75529, "LongEffective": 4.84574, "IdVehicule": "246Veh", "LatArrivee": 45.83492, "NoDemande": 42537000003, ... | 1 | 2016-06-28T09:48:00Z | 38,097,140 | <p>So if you know how to "massage" the dict into your wanted final structure - moving all the "other elements" into some properties member - then I think it is as simple as </p>
<pre><code># work on dict_list to produce some dict_in_geojson_form
# ... then:
with open('data.json','w') as f:
json.dump(dict_in_geojso... | 0 | 2016-06-29T10:37:28Z | [
"python",
"dictionary",
"geojson"
] |
How do I pick one dict inside a list of dictionaries that are differed by one value? | 38,072,888 | <p>I have a list of dictionaries like this:</p>
<pre><code>xyz =[ {"key1":"1","key2":"2","key3":"x_1"},{"key1":"1","key2":"2","key3":"x_2"},{"key1":"1","key2":"2","key3":"x_3"},{"key1":"5","key2":"6","key3":"y_1"},{"key1":"5","key2":"6","key3":"y_2"},{"key1":"5","key2":"6","key3":"y_3"}]
</code></pre>
<p>I am trying ... | -1 | 2016-06-28T09:53:50Z | 38,073,397 | <p>You can use <a href="https://docs.python.org/2.7/library/itertools.html#itertools.groupby" rel="nofollow"><code>groupby</code></a> from the <a href="https://docs.python.org/2.7/library/itertools.html" rel="nofollow"><code>itertools</code></a> library:</p>
<pre><code>import itertools
xyz =[ {"key1":"1","key2":"2","... | 3 | 2016-06-28T10:15:22Z | [
"python",
"dictionary"
] |
Handling time consuming requests in Flask-UWSGI app | 38,072,956 | <p>Am running an app with Flask , UWSGI and Nginx. My UWSGI is set to spawn out 4 parallel processes to handle multiple requests at the same time. Now I have one request that takes lot of time and that changes important data concerning the application. So, when one UWSGI process is processing that request and say all o... | -1 | 2016-06-28T09:56:32Z | 38,080,033 | <p>As an option you can do the following:</p>
<ol>
<li>Separate the heavy logic from the function which is being called
upon @route and move it into a separate place (a file, another
function, etc)</li>
<li>Introduce Celery to run that pieces of heavy logic
(it will be processed in a separate thread from the @route-de... | 0 | 2016-06-28T15:13:01Z | [
"python",
"nginx",
"flask",
"uwsgi"
] |
Sorting the handles and labels in python legend, based on part of the label strings | 38,073,076 | <p>I've plotted some data on a chart in python and then used </p>
<p>handles, labels = ax0_1.get_legend_handles_labels()</p>
<p>to get the labels and handles. The labels I get are ordered like this:</p>
<p>A1 01-01-01 01 ABC <br>
A1 01-01-01 01 ABCD<br>
A1 01-01-01 01 ABCDE<br>
A1 01-01-01 02 ABC<br>
A1 01-01-01 02... | 0 | 2016-06-28T10:01:36Z | 38,073,299 | <p>Try sorting indexes by desired key first:</p>
<pre><code>labels = [
'A1 01-01-01 01 ABC',
'A1 01-01-01 01 ABCD',
'A1 01-01-01 01 ABCDE',
'A1 01-01-01 02 ABC',
'A1 01-01-01 02 ABCD',
'A1 01-01-01 02 ABCDE'
]
handles = range(len(labels))
sorted_indexes = sorted(range(len(labels)), key=lambda... | 0 | 2016-06-28T10:10:59Z | [
"python",
"sorting",
"order",
"labels",
"handles"
] |
Sorting the handles and labels in python legend, based on part of the label strings | 38,073,076 | <p>I've plotted some data on a chart in python and then used </p>
<p>handles, labels = ax0_1.get_legend_handles_labels()</p>
<p>to get the labels and handles. The labels I get are ordered like this:</p>
<p>A1 01-01-01 01 ABC <br>
A1 01-01-01 01 ABCD<br>
A1 01-01-01 01 ABCDE<br>
A1 01-01-01 02 ABC<br>
A1 01-01-01 02... | 0 | 2016-06-28T10:01:36Z | 38,079,262 | <p>After a lot experimentation, and using Adam Sosnowski's idea as inspiration, I've found a way of doing it:</p>
<pre><code> indexes =[]
for l in labels:
indexes.append(labels.index(l))
sorted_labels = sorted(labels, key = lambda string: string.split()[-1])
sorted_indexes = []
for i, l in e... | 0 | 2016-06-28T14:39:45Z | [
"python",
"sorting",
"order",
"labels",
"handles"
] |
A variable assigned to all rows of a column, enters a loop with only the value of the last row | 38,073,204 | <p><strong>EDIT</strong></p>
<p>In this code <code>analysis.py</code> I have written, the variable <code>entropy</code> is a column of data. </p>
<p>When I pass all the rows to a loop, only the last value is considered:</p>
<p>To run this code, it is only necessary 2 files in the folder:</p>
<p><code>pressure_entha... | 0 | 2016-06-28T10:06:53Z | 38,073,357 | <p>There is a problem in your looping .First loop will get execute completely and then the entropy variable will hold the final value in the file . So when you enter the second loop and print it , you get to see only the final entry of entropy.
I guess you meant to write a nested loop there!</p>
| 1 | 2016-06-28T10:13:29Z | [
"python",
"io",
"lines"
] |
Writing nested dictionaries in python for json.dump | 38,073,228 | <p>I have a set of python lists which I want to serially write in a json file in a structure as given below</p>
<pre><code>[
{
"_id": {
"$oid": "5707b5f4e4b0c4265caf3c87"
},
"TimeStamp": 1,
"TraceData": [
{
"data": {
"y": 443.732,
"angle": 1.... | -1 | 2016-06-28T10:07:34Z | 38,073,621 | <p>I am assuming this is what you wanted, since you can't have a dict <code>{}</code> holding values with no keys:</p>
<pre><code>[{
"TimeStamp": 1,
"TraceData": [{
"data": {
"y": 443.732,
"angle": 1.11416,
"speed": 1.42906,
"ObjectType": "Pedestrians",
... | 1 | 2016-06-28T10:25:45Z | [
"python",
"json",
"dictionary"
] |
Python HTML fill and submit form | 38,073,264 | <p>I am trying to write a Python script that goes to a form on a internal website (with the name "DefaultForm") and fills in the input name="username" field in the form with 'user001', the input name="password" field with 'pass001' and click on submit</p>
<p>Tried doing this with Selenium and it works. But want to acc... | 0 | 2016-06-28T10:09:16Z | 38,116,144 | <p>This should get you loggeg in:</p>
<pre><code>import requests
from lxml import html
with requests.Session() as s:
xml = .get("http://SERVER:PORT/dashboard/portal").getroot()
form = xml.xpath("//form[@name='DefaultForm']")[0]
print(form.xpath("./input[@name]"))
data = {i.xpath("@name")[0] : i.xpath(... | 0 | 2016-06-30T07:08:06Z | [
"python",
"html",
"forms",
"python-requests",
"lxml"
] |
I'm unable to get date with a variable | 38,073,332 | <pre><code>def get_next_monday(year, month, day):
date0 = datetime.date(year, month, day)
next_monday = date0 + datetime.timedelta(7 - date0.weekday() or 7)
return next_monday
date2 = datetime.datetime.now().strftime("%Y, %m, %d")
findnextweek = get_next_monday(date2)
</code></pre>
<p>If I replace <code>(... | 0 | 2016-06-28T10:12:31Z | 38,073,525 | <p>You have some little problems in your code. Here's the fix and explanation:</p>
<pre><code>import datetime
def get_next_monday(year, month, day):
# if you want to accept str and int, you must convert the strings
date0 = datetime.date(int(year), int(month), int(day))
next_monday = date0 + datetime.tim... | 2 | 2016-06-28T10:21:19Z | [
"python",
"date",
"integer"
] |
I'm unable to get date with a variable | 38,073,332 | <pre><code>def get_next_monday(year, month, day):
date0 = datetime.date(year, month, day)
next_monday = date0 + datetime.timedelta(7 - date0.weekday() or 7)
return next_monday
date2 = datetime.datetime.now().strftime("%Y, %m, %d")
findnextweek = get_next_monday(date2)
</code></pre>
<p>If I replace <code>(... | 0 | 2016-06-28T10:12:31Z | 38,073,587 | <p>You are passing a string value to your <code>get_next_monday</code> function but it is expecting 3 arguments.</p>
<pre><code>date2 = datetime.datetime.now().strftime("%Y, %m, %d")
</code></pre>
<p>This will return a string similar to this: <code>'2016, 06, 28'</code>.
You'll want to split that string into 3 variab... | 1 | 2016-06-28T10:24:20Z | [
"python",
"date",
"integer"
] |
why is the regex function always popping up the Attribute Error? | 38,073,396 | <p>I have been writing a function in python to get the IP of a computer. The code is given below :</p>
<pre><code> def getip(self):
self.path = "/root"
self.iplist = []
os.chdir(self.path)
os.system("ifconfig > ipfinder")
try:
file... | 1 | 2016-06-28T10:15:22Z | 38,074,916 | <p>I ran it in my local. Found 4 things be be modified!</p>
<p>a) regex:- \d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}</p>
<p>b) trim for any extra space while reading:- file.readline().strip()</p>
<p>c) If it comes to end of line, break the while:-</p>
<pre><code>if line == '':
break
</code></pre>
<p>d) Instead of re.sear... | 1 | 2016-06-28T11:24:30Z | [
"python",
"regex",
"attributeerror"
] |
Mocking a side_effect with Python unittest | 38,073,406 | <p>I'm trying to mock out my requests.get to have a status code of <code>200</code> and make <code>history[0].status_code</code> trigger an <code>IndexError</code> (since there were no redirects). I'm able to get <code>status_code</code> to return <code>200</code>, but when I mock out history with the desired side effe... | 0 | 2016-06-28T10:15:43Z | 38,074,061 | <p>Ok, I checked the code and I'd like to mention a few things.</p>
<p>First of all <code>assertRises</code> method receives callable as the second parameter ;)
Its definition looks like this </p>
<pre><code>def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
</code></pre>
<p>The second thing, if y... | 1 | 2016-06-28T10:45:38Z | [
"python",
"unit-testing",
"mocking"
] |
Determine adjacent regions in numpy array | 38,073,433 | <p>I am looking for the following. I have a numpy array which is labeled as regions. The numpy array represents a segmented image. A region is a number of adjacent cells with the same value. Each region has its own unique value. A simplified version with 3 regions would look like this:</p>
<pre><code>x = np.array([[1,... | 5 | 2016-06-28T10:16:56Z | 38,078,596 | <p>I understand that the task is to return all distinct entries of the array that are adjacent to a given number (such as 2). One way to achieve this with NumPy methods is to use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.roll.html#numpy.roll" rel="nofollow">roll</a> to shift the given region by... | 3 | 2016-06-28T14:11:46Z | [
"python",
"arrays",
"numpy",
"region",
"neighbours"
] |
Determine adjacent regions in numpy array | 38,073,433 | <p>I am looking for the following. I have a numpy array which is labeled as regions. The numpy array represents a segmented image. A region is a number of adjacent cells with the same value. Each region has its own unique value. A simplified version with 3 regions would look like this:</p>
<pre><code>x = np.array([[1,... | 5 | 2016-06-28T10:16:56Z | 38,081,569 | <p>If the regions are labelled with small integers (from <code>0</code> to <code>n</code> ideally), the labels can be used to index into a result array:</p>
<pre><code>n = x.max()
tmp = np.zeros((n+1, n+1), bool)
# check the vertical adjacency
a, b = x[:-1, :], x[1:, :]
tmp[a[a!=b], b[a!=b]] = True
# check the horiz... | 1 | 2016-06-28T16:28:32Z | [
"python",
"arrays",
"numpy",
"region",
"neighbours"
] |
Drop pandas dataframe rows based on groupby() condition | 38,073,496 | <p>There is a pandas dataframe on input: </p>
<pre><code>store_id item_id items_sold date
1 1 0 2015-12-28
1 2 1 2015-12-28
1 1 0 2015-12-28
2 2 0 2015-12-28
2 1 1 2015-12-29
2 ... | 1 | 2016-06-28T10:19:52Z | 38,074,449 | <p>is that what you want?</p>
<pre><code>In [30]: df[df.groupby(['store_id', 'item_id'])['items_sold'].transform('sum') > 0]
Out[30]:
store_id item_id items_sold date
1 1 2 1 2015-12-28
3 2 2 0 2015-12-28
4 2 1 1 2015-12-29
5 ... | 1 | 2016-06-28T11:03:40Z | [
"python",
"pandas"
] |
Best way to handle ZeroDivisonError? | 38,073,503 | <p>I've got the following code:</p>
<pre><code>def chunk_trades(A):
last = A[0]
new = []
for x in A.iteritems():
if np.abs((x[1]-last)/last) > 0.1:
new.append(x[1])
last = x[1]
else:
new.append(last)
s = pd.Series(new, index=A.index)
return s
<... | 2 | 2016-06-28T10:20:27Z | 38,073,751 | <p>Just Replace your line by this:</p>
<pre><code>if not last or np.abs((x[1]-last)/last) > 0.1:
</code></pre>
<p>This will not raise an exception since the left assertion is checked first.</p>
| 1 | 2016-06-28T10:31:44Z | [
"python",
"python-3.x"
] |
Best way to handle ZeroDivisonError? | 38,073,503 | <p>I've got the following code:</p>
<pre><code>def chunk_trades(A):
last = A[0]
new = []
for x in A.iteritems():
if np.abs((x[1]-last)/last) > 0.1:
new.append(x[1])
last = x[1]
else:
new.append(last)
s = pd.Series(new, index=A.index)
return s
<... | 2 | 2016-06-28T10:20:27Z | 38,073,776 | <p>Not sure if you would really want to divide by "almost 0", since the result will be "almost infinity", but you can also do this:</p>
<pre><code>if last == 0:
last = sys.float_info.min
</code></pre>
<p>This is the minimum positive normalized float, i.e. the value closest to zero. </p>
<p>Source: <a href="https:... | 1 | 2016-06-28T10:32:51Z | [
"python",
"python-3.x"
] |
Best way to handle ZeroDivisonError? | 38,073,503 | <p>I've got the following code:</p>
<pre><code>def chunk_trades(A):
last = A[0]
new = []
for x in A.iteritems():
if np.abs((x[1]-last)/last) > 0.1:
new.append(x[1])
last = x[1]
else:
new.append(last)
s = pd.Series(new, index=A.index)
return s
<... | 2 | 2016-06-28T10:20:27Z | 38,073,803 | <p>You could always add a small value to <code>last</code> i.e. <code>(x[1]-last)/(last + 0.00000001)</code> which will definitely work if <code>last</code> will never switch between positive and negative values.
Otherwise I would use <code>(x[1]-last)/(last if last != 0 else 0.00000001)</code>. This simply uses the te... | 0 | 2016-06-28T10:34:15Z | [
"python",
"python-3.x"
] |
Best way to handle ZeroDivisonError? | 38,073,503 | <p>I've got the following code:</p>
<pre><code>def chunk_trades(A):
last = A[0]
new = []
for x in A.iteritems():
if np.abs((x[1]-last)/last) > 0.1:
new.append(x[1])
last = x[1]
else:
new.append(last)
s = pd.Series(new, index=A.index)
return s
<... | 2 | 2016-06-28T10:20:27Z | 38,073,878 | <p>If I anderstand correctly, when <code>last == 0</code> youl'll get <code>ZeroDivisionError</code>, won't you? If yes, please consider following slightly modified version of your code:</p>
<pre><code>def chunk_trades(A):
last = A[0]
new = []
for x in A.iteritems():
try:
if np.abs((x[1... | 0 | 2016-06-28T10:37:35Z | [
"python",
"python-3.x"
] |
Logical MultiIndexing in Pandas | 38,073,550 | <p>Is there a way to extract all values of <code>B</code> for index <code>One</code> where <code>C</code> is greater than zero? So I want to extract the values <code>-0.22</code> and <code>-1.21</code>.</p>
<pre><code>import numpy as np
import pandas as pd
arrays =[np.array(['One','One','One','Two','Two','Two']),np.ar... | 1 | 2016-06-28T10:22:41Z | 38,073,660 | <p>You can create <code>mask</code> and then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html" rel="nofollow"><code>loc</code></a> by <code>mask</code>:</p>
<pre><code>import numpy as np
import pandas as pd
np.random.seed(1)
arrays = [np.array(['One','One','One','Two','Two',... | 2 | 2016-06-28T10:27:26Z | [
"python",
"pandas",
"indexing",
"dataframe",
"multi-index"
] |
matplotlib plot of complex valued function | 38,073,571 | <p>In matlab plot of a complex vector will result in a plot of imaginary vs real part.</p>
<p>Is there an equivalent function in matplotlib?</p>
<p>Obviously this will work:</p>
<pre><code>def plotcomplex(c, *args):
plot(real(c), imag(c), args)
</code></pre>
<p>but does it already exist?</p>
| 0 | 2016-06-28T10:23:32Z | 38,270,553 | <p>Seems like there is no native complex numbers plotting function. Build your own.</p>
| 0 | 2016-07-08T15:37:25Z | [
"python",
"numpy",
"matplotlib"
] |
start flask server @ startup with supervisor: FATAL Exited too quickly | 38,073,592 | <p>I am trying to start my flaskserver at startup with the help of supervisor. But i get this error message: </p>
<pre><code>python_auutostart FATAL Exited too quickly (process log may have details)
</code></pre>
<p>This is the entry in my logfile:</p>
<pre><code>Traceback (most recent call last)... | 0 | 2016-06-28T10:24:34Z | 38,075,270 | <p>The python you use is the default system python (you can check that wich <code>which python</code> which should display something like <code>/usr/bin/python</code> or wherever your system python is). This does not have access (by default) to libraries that are installed in a virtual environment. Instead you should u... | 2 | 2016-06-28T11:42:15Z | [
"python",
"flask",
"supervisor"
] |
Show fewer pages in Django pagination | 38,073,629 | <p>I am working on a Django application and on one of the pages we use pagination. I have around 200 pages and if I am somewhere in the middle then it has links from page 1 - 4, displays the 4 pages behind the page I am on, 3 after the page I am on and the last 4 pages. Looking like <a href="http://i.stack.imgur.com/7U... | 0 | 2016-06-28T10:25:59Z | 38,073,824 | <p>You seem to be using the <a href="https://pypi.python.org/pypi/django-pagination" rel="nofollow">django-pagination</a> app. It has a setting for the number of items left and right of the current page</p>
<ul>
<li><code>PAGINATION_DEFAULT_WINDOW</code> The number of items to the left and to the right of the current ... | 1 | 2016-06-28T10:35:13Z | [
"python",
"django",
"pagination"
] |
Pandas error TypeError: data type not understood | 38,073,659 | <p>I've been trying to slice a pandas dataframe using boolean indexing code like:</p>
<pre><code>subset[subset.bl.str.contains("Stoke City")]
</code></pre>
<p>The column <code>bl</code> is of object type.</p>
<p>Yet when I run it, I have an error:</p>
<blockquote>
<p>TypeError: data type not understood</p>
</bloc... | 1 | 2016-06-28T10:27:25Z | 38,073,727 | <p>You can try cast to <code>str</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.astype.html" rel="nofollow"><code>astype</code></a>, because <code>object</code> can be something else as <code>string</code>:</p>
<pre><code>subset[subset.bl.astype(str).str.contains("Stoke City")]
... | 1 | 2016-06-28T10:30:31Z | [
"python",
"pandas"
] |
Flatten numpy array without double for loop | 38,073,791 | <p>I have a 2-d matrix. For the purposes of this example, let's say it is a random matrix</p>
<pre><code>>>> a = np.random.randn(5, 7)
>>> a
array([[-0.37279322, 0.28619523, -0.05309901, 0.26010327, 0.1846693 , 0.33112176, 0.75814911],
[ 1.57001151, -0.86831693, -0.20576395, 1.46450855, -... | 0 | 2016-06-28T10:33:45Z | 38,073,913 | <p>Use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html" rel="nofollow"><code>np.meshgrid</code></a> to create <code>2D</code> meshes corresponding to <code>X</code> and <code>Y</code> labels and then stack them as columns alongwith the <code>2D</code> input array <code>a</code>, like so... | 2 | 2016-06-28T10:39:32Z | [
"python",
"numpy"
] |
To add all the values of a specific subkey for a dictionary python | 38,073,843 | <p>so consider a dictionary.</p>
<pre><code>{
"b0:47:bf:af:c1:42":
{
"No. of visits": 10, "cities":
{
"Mumbai": {"count": 5,"last_visited": "5/22/2016"},
"Kolkata": {"count": 2,"last_visited": "5/22/2016"},
"Amritsar":{"count": 3,"last_visited": "5/22/2016"}
}
},
"c0:ee:fb:71:be:0d":
{... | 1 | 2016-06-28T10:35:52Z | 38,075,315 | <p>You could just iterate through each mac address <code>sum()</code> the <code>count</code>s then find the <code>max()</code>. Assuming your data is stored in the variable <code>data</code>, here is the one statement version:</p>
<pre><code>max([sum([data[visit]["cities"][city]["count"] for city in data[visit]["citie... | 2 | 2016-06-28T11:43:56Z | [
"python",
"python-2.7",
"dictionary"
] |
How to fix Selenium WebDriverException: "The browser appears to have exited" | 38,074,031 | <p>I got this exception when I want to use <code>FireFox webdriver</code></p>
<blockquote>
<p>raise WebDriverException "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the
FirefoxBinary constructor, chec... | 4 | 2016-06-28T10:44:26Z | 38,104,373 | <p>I was having the same problem with my selenium script. I had to make sure that I was using the proper software versions as described in the selenium installation documentation, namely Pyhton 3.5 and Firefox version 45 (<a href="https://support.mozilla.org/en-US/kb/install-older-version-of-firefox" rel="nofollow">htt... | 2 | 2016-06-29T15:44:22Z | [
"python",
"selenium",
"selenium-webdriver",
"selenium-firefoxdriver"
] |
How to fix Selenium WebDriverException: "The browser appears to have exited" | 38,074,031 | <p>I got this exception when I want to use <code>FireFox webdriver</code></p>
<blockquote>
<p>raise WebDriverException "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the
FirefoxBinary constructor, chec... | 4 | 2016-06-28T10:44:26Z | 38,617,777 | <p>If you're running Selenium on Firefox 47.0, you need to update to Firefox 47.0.1 which is not released in Ubuntu's main repos.. so you have to add this PPA: <a href="https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa">https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa</a></p>
<p>Rele... | 7 | 2016-07-27T15:49:04Z | [
"python",
"selenium",
"selenium-webdriver",
"selenium-firefoxdriver"
] |
How to fix Selenium WebDriverException: "The browser appears to have exited" | 38,074,031 | <p>I got this exception when I want to use <code>FireFox webdriver</code></p>
<blockquote>
<p>raise WebDriverException "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the
FirefoxBinary constructor, chec... | 4 | 2016-06-28T10:44:26Z | 38,633,122 | <p>This is fixed by updating firefox 47.0.0 to 47.0.1 manually</p>
| 4 | 2016-07-28T10:00:59Z | [
"python",
"selenium",
"selenium-webdriver",
"selenium-firefoxdriver"
] |
Rename a worksheet in google Spreadsheet using API - python | 38,074,069 | <p>I have been trying/looking to solve this problem for a long while.
I have read the documentation for gspread and I cannot find that there is a way to rename a worksheet.
Any of you know how to? I would massively appreciate it!
There is indeed worksheet.title which gives the name of the worksheet, but I cannot find a... | 15 | 2016-06-28T10:45:59Z | 39,836,674 | <p>This is an extraction of a library which I've coded personally:</p>
<pre><code>def _batch(self, requests):
body = {
'requests': requests
}
return self._service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheetId, body=body).execute()
def renameSheet(self, sheetId, newName):
return s... | 4 | 2016-10-03T16:56:51Z | [
"python",
"api",
"google-sheets-api"
] |
Rename a worksheet in google Spreadsheet using API - python | 38,074,069 | <p>I have been trying/looking to solve this problem for a long while.
I have read the documentation for gspread and I cannot find that there is a way to rename a worksheet.
Any of you know how to? I would massively appreciate it!
There is indeed worksheet.title which gives the name of the worksheet, but I cannot find a... | 15 | 2016-06-28T10:45:59Z | 39,902,826 | <p>Your answer can be solved via a HTTP request from Python. </p>
<p>Link is <a href="https://developers.google.com/google-apps/spreadsheets/worksheets#modify_a_worksheets_title_and_size" rel="nofollow">here</a></p>
<p>You need to send some sort of metadata for the worksheet via HTTP. </p>
<p>For example, get the ID... | 2 | 2016-10-06T18:04:41Z | [
"python",
"api",
"google-sheets-api"
] |
Interrupt signals awake Python process from sleeping and continue where it left off? | 38,074,071 | <p>The following code will print out the current time every 5 seconds, and it handles keyboard interrupt signals with <code>int_handler</code>.</p>
<pre><code>from signal import *
import time
from datetime import datetime
def int_handler(*args):
print 'interrupted'
signal(SIGINT, int_handler)
while True:
p... | 0 | 2016-06-28T10:46:02Z | 38,074,335 | <p>From the documentation of <code>sleep()</code>:</p>
<blockquote>
<p>The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signalâs catching routine.</p>
</blockquote>
<p><a href="https://docs.python.org/3/library/time.html#ti... | 1 | 2016-06-28T10:58:24Z | [
"python",
"multithreading",
"operating-system",
"signals",
"interrupt"
] |
insert numpy.float64 element in a numpy array | 38,074,104 | <p>I am trying to insert a numpy float in a numpy ndarray.
The Code and the output is:</p>
<pre><code>dos = np.sum(atom[:, :, 1:],axis=0)
print("type(dos)")
print(type(dos))
print("dos.shape")
print(dos.shape)
print("dos[15] Before")
print(dos[15])
print("type(atom[1,0,0])")
print(type(atom[1,0,0]))
print("atom[1,0,0]... | 0 | 2016-06-28T10:47:23Z | 38,074,553 | <p>From the doc mentionned:</p>
<blockquote>
<p>A copy of arr with values inserted. Note that insert does not occur in-place: a new array is returned. If axis is None, out is a flattened array.</p>
</blockquote>
<p>This means that your loop:</p>
<pre><code>for i in range(301):
dos2=np.insert(dos, 0, atom[1,0,0... | 2 | 2016-06-28T11:08:11Z | [
"python",
"numpy"
] |
insert numpy.float64 element in a numpy array | 38,074,104 | <p>I am trying to insert a numpy float in a numpy ndarray.
The Code and the output is:</p>
<pre><code>dos = np.sum(atom[:, :, 1:],axis=0)
print("type(dos)")
print(type(dos))
print("dos.shape")
print(dos.shape)
print("dos[15] Before")
print(dos[15])
print("type(atom[1,0,0])")
print(type(atom[1,0,0]))
print("atom[1,0,0]... | 0 | 2016-06-28T10:47:23Z | 38,076,289 | <p>From your 'expected result' it looks like you only want to insert a single value at the beginning of the already flat array. There is definitely no need to use a for loop to do this. </p>
<pre><code>>>> insert_value = 100
>>> orig_array = np.array([1, 2, 3, 4, 5])
>>> final_array = np.i... | 1 | 2016-06-28T12:27:55Z | [
"python",
"numpy"
] |
Import issue with Python six library | 38,074,156 | <p>inside my virtualenv I have a lot of libraries that use <strong>six</strong> as dependency but <em>paramiko</em> and <em>python-keystoneclient</em> raise this import error:</p>
<pre><code>ERROR:paramiko.transport:Unknown exception: cannot import name urllib_parse
ERROR:paramiko.transport:Traceback (most recent call... | 4 | 2016-06-28T10:49:41Z | 38,107,458 | <p>Try to downgrade paramiko to 1.16.0. It was a solution in my case. Good luck!</p>
| 3 | 2016-06-29T18:28:04Z | [
"python",
"cryptography",
"virtualenv",
"paramiko",
"six"
] |
Step with scipy integrator without going past final point | 38,074,340 | <p>The scipy integrators take two parameters when integrating: (1) <code>step</code> which tells the integrator to take only a single step, and (2) <code>relax</code> which tells the integrator that it is fine to step past the final time point.</p>
<p>I want to take steps (so that I can collect the entire solution), b... | 0 | 2016-06-28T10:58:39Z | 38,087,410 | <p>A bad solution is to set the <code>max_step</code> to <code>final_time - obj.t</code> at each step. It is tempting because it does actually work, but the performance is horrendous.</p>
<pre><code>from scipy.integrate import ode
obj = ode(lambda t, y: -y) # Simple exponential decay
obj.set_initial_value(4.0)
fina... | 0 | 2016-06-28T22:39:51Z | [
"python",
"scipy"
] |
Step with scipy integrator without going past final point | 38,074,340 | <p>The scipy integrators take two parameters when integrating: (1) <code>step</code> which tells the integrator to take only a single step, and (2) <code>relax</code> which tells the integrator that it is fine to step past the final time point.</p>
<p>I want to take steps (so that I can collect the entire solution), b... | 0 | 2016-06-28T10:58:39Z | 38,087,755 | <p>A passable solution is to throw away the point that steps over the final time and create an fresh integrator that starts at the penultimate time and integrates <code>step=False</code> to the final time. I have not timed it, but I suspect that this is also somewhat expensive.</p>
<pre><code>from scipy.integrate impo... | 0 | 2016-06-28T23:14:07Z | [
"python",
"scipy"
] |
Remove SNPs with wrong alleles | 38,074,347 | <p>I have two files that look like this:</p>
<ol>
<li><p>The reference panel (<strong>ReferencePanel.csv</strong>)</p>
<blockquote>
<pre><code>"id","position","allele0","allele1","allele1_frequency"
"seq-rs1010355",55102179,"T","C",0.098
"seq-rs272408",55103603,"C","T",0.787
"seq-rs11669899",55104559,"A","T",0.029
"i... | 0 | 2016-06-28T10:59:01Z | 38,076,097 | <p>If you're not against using <code>awk</code>, you can use the following command:</p>
<pre><code>awk -F'[",]*' 'NR==FNR && $4 && $5 {ref[$4][$5]=1} NR>FNR {FS=" *"} NR>FNR && ref[$6][$7]' reference.csv myfile.bim
</code></pre>
<p>which is resulting in:</p>
<pre><code>19 19:55102179... | 1 | 2016-06-28T12:19:27Z | [
"python",
"bash",
"unix",
"extract",
"rows"
] |
Differences in numba outputs | 38,074,352 | <p>I implemented a basic nearest-neighbors search in my study work.
The fact is that the basic numpy implementation is working well, but just adding the '@jit' decorator (compiling in Numba), the outputs are differents (it duplicates some neighbors in the end for some unknown reason...)</p>
<p>Here is the basic algori... | 3 | 2016-06-28T10:59:10Z | 38,074,783 | <p>I believe the issue is that Numba is handling writing one slice into another differently when those slices are overlapping than when running without. I'm not familiar with the internals of numpy, but perhaps there is special logic to handle dealing with volatile memory operations like this, that aren't there in Numb... | 1 | 2016-06-28T11:19:06Z | [
"python",
"numpy",
"numba"
] |
Understanding a solution to the Euler Project in Python | 38,074,440 | <p>I'm currently going through the Euler Project. I've started using JavaScript and I've switched to Python yesterday, as I got stuck in a problem that seemed to complex to solve with Javascript but easily solved in Python, and so I've decided to start from the first problem again in python.</p>
<p>I'm at problem 5 wh... | 4 | 2016-06-28T11:03:24Z | 38,074,660 | <p>That code is computing the <em>least common multiple</em> of the numbers from <code>1</code> to <code>20</code> (or whichever other <code>range</code> you use).</p>
<p>It starts from <code>1</code>, then for each number <code>k</code> in that range it checks if <code>k</code> is a factor of <code>i</code>, and if n... | 6 | 2016-06-28T11:13:19Z | [
"python",
"algorithm",
"search"
] |
Understanding a solution to the Euler Project in Python | 38,074,440 | <p>I'm currently going through the Euler Project. I've started using JavaScript and I've switched to Python yesterday, as I got stuck in a problem that seemed to complex to solve with Javascript but easily solved in Python, and so I've decided to start from the first problem again in python.</p>
<p>I'm at problem 5 wh... | 4 | 2016-06-28T11:03:24Z | 38,075,792 | <p>Bakuriu has answered your question by explaining lassevk's "factorial" algorithm. However, there's a simpler way to do this which is much faster for larger inputs.</p>
<p>Let <code>num</code> be the highest number in the sequence. So for your example <code>num = 20</code>.</p>
<p>Simply multiply all the numbers fr... | 3 | 2016-06-28T12:06:12Z | [
"python",
"algorithm",
"search"
] |
How to remove unicode characters from Dictionary data in python | 38,074,587 | <p>After using request library , am getting below dict in response.json()</p>
<pre><code>{u'xyz': {u'key1': None, u'key2': u'Value2'}}
</code></pre>
<p>I want to remove all unicode characters and print only key value pairs without unicode chars </p>
<p>I have tried below method to remove , but it shows malformed str... | 3 | 2016-06-28T11:09:40Z | 38,074,697 | <p>Change your None to 'None':</p>
<pre><code> c = {u'xyz': {u'key1': 'None', u'key2': u'Value2'}}
</code></pre>
<p>it is a casting issue - ast likes str's</p>
<p>Also, maybe u want to change all None to empty str or 'None' str...
See this thread :
<a href="http://stackoverflow.com/questions/1034573/python-most-idio... | 3 | 2016-06-28T11:15:12Z | [
"python",
"json",
"unicode"
] |
How to remove unicode characters from Dictionary data in python | 38,074,587 | <p>After using request library , am getting below dict in response.json()</p>
<pre><code>{u'xyz': {u'key1': None, u'key2': u'Value2'}}
</code></pre>
<p>I want to remove all unicode characters and print only key value pairs without unicode chars </p>
<p>I have tried below method to remove , but it shows malformed str... | 3 | 2016-06-28T11:09:40Z | 38,075,154 | <p>I don't really understand why you want this. Your variable is a normal Python dict with normal Unicode strings, and they happen to be printed as <code>u''</code> to distinguish them from bytestrings, but that shouldn't matter for using them.</p>
<p>If you want to save them as strings to read them as data later, JSO... | -1 | 2016-06-28T11:36:39Z | [
"python",
"json",
"unicode"
] |
How to remove unicode characters from Dictionary data in python | 38,074,587 | <p>After using request library , am getting below dict in response.json()</p>
<pre><code>{u'xyz': {u'key1': None, u'key2': u'Value2'}}
</code></pre>
<p>I want to remove all unicode characters and print only key value pairs without unicode chars </p>
<p>I have tried below method to remove , but it shows malformed str... | 3 | 2016-06-28T11:09:40Z | 38,078,182 | <p>You can use <code>unicodestring.encode("ascii","replace")</code> </p>
<pre><code>>>> ustr=u'apple'
>>> ustr
u'apple'
>>> astr=ustr.encode("ascii","replace")
>>> astr
'apple'
</code></pre>
| 0 | 2016-06-28T13:53:55Z | [
"python",
"json",
"unicode"
] |
Append existing excel sheet with new dataframe using python pandas | 38,074,678 | <p>I currently have this code. It works perfectly.</p>
<p>It loops through excel files in a folder,
removes the first 2 rows,
Then saves them out as individual excel files,
and it also saves the the files in the loop as an appended file.</p>
<p>Currently the appended file <strong>overwrites</strong> the existing file... | 3 | 2016-06-28T11:14:13Z | 38,075,046 | <p>You can use <code>openpyxl</code> engine in conjunction with <code>startrow</code> parameter:</p>
<pre><code>In [48]: writer = pd.ExcelWriter('c:/temp/test.xlsx', engine='openpyxl')
In [49]: df.to_excel(writer, index=False)
In [50]: df.to_excel(writer, startrow=len(df)+2, index=False)
In [51]: writer.save()
</co... | 3 | 2016-06-28T11:30:55Z | [
"python",
"excel",
"for-loop",
"pandas",
"append"
] |
Django generic view is not accepting arguments | 38,074,683 | <p>I am new to Django and I am just trying to pass arguments to Django generic base View and it is not showing up in terminal as I am printing the arguments passed.</p>
<p>views.py</p>
<pre><code>from django.views.generic import View
class CartView(View):
def get(self, request, *args, **kwargs):
item = re... | 1 | 2016-06-28T11:14:30Z | 38,074,879 | <p>It sounds like you may have to fix the entry in urls.py routing to the view. Could you post your urls.py as well?</p>
| 0 | 2016-06-28T11:22:51Z | [
"python",
"django"
] |
Built-in functions vs recursive functions | 38,074,742 | <p>I am not a mathematician, nor a computer scientist - just a hobbyist programmer and I am trying to teach myself Python by doing the Euler Project problems. One of them requires the use of a factorial. I wrote my own calculation using a recursive function and then realised that there was probably a built-in function ... | 4 | 2016-06-28T11:17:04Z | 38,075,423 | <p>I took your code and changed the order in which the three methods are tested, several times. I noticed the first method tested often takes twice as much time as the second one.</p>
<p>I can't really explain why, but I do know you can't measure a function's performance with one iteration. You have to repeat the func... | 6 | 2016-06-28T11:48:38Z | [
"python",
"python-3.x"
] |
Built-in functions vs recursive functions | 38,074,742 | <p>I am not a mathematician, nor a computer scientist - just a hobbyist programmer and I am trying to teach myself Python by doing the Euler Project problems. One of them requires the use of a factorial. I wrote my own calculation using a recursive function and then realised that there was probably a built-in function ... | 4 | 2016-06-28T11:17:04Z | 38,075,693 | <p>For a better comparison of the efficiency of the different functions, you would need to run your tests multiple times over a longer period while alternating between them and take the fastest time for each function being tested.</p>
<p>Execution times can vary wildly depending on current machine load due to the acti... | 2 | 2016-06-28T12:01:56Z | [
"python",
"python-3.x"
] |
Built-in functions vs recursive functions | 38,074,742 | <p>I am not a mathematician, nor a computer scientist - just a hobbyist programmer and I am trying to teach myself Python by doing the Euler Project problems. One of them requires the use of a factorial. I wrote my own calculation using a recursive function and then realised that there was probably a built-in function ... | 4 | 2016-06-28T11:17:04Z | 38,075,915 | <p>Even without using profiling libraries, you can see that the built-in method is better than your recursive one by tweaking your code so that it doesn't time the printing:</p>
<pre><code>import math
import time
x = 50
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
se... | 3 | 2016-06-28T12:11:25Z | [
"python",
"python-3.x"
] |
What is os.linesep for? | 38,074,811 | <p>Python's os module contains a value for a platform specific line separating string, but the docs explicitly say not to use it when writing to a file:</p>
<blockquote>
<p>Do not use os.linesep as a line terminator when writing files opened in text mode (the default); use a single '\n' instead, on all platforms.</p... | 5 | 2016-06-28T11:20:11Z | 38,075,207 | <p>As you know, reading and writing files in text mode in python converts the platform specific line separator to '\n' and vice versa. But if you would read a file in binary mode, no conversion takes place. Then you can explicitly convert the line endings using <code>string.replace(os.linesep, '\n')</code>. This can be... | 3 | 2016-06-28T11:39:23Z | [
"python",
"file-io",
"separator",
"platform-independent"
] |
What is os.linesep for? | 38,074,811 | <p>Python's os module contains a value for a platform specific line separating string, but the docs explicitly say not to use it when writing to a file:</p>
<blockquote>
<p>Do not use os.linesep as a line terminator when writing files opened in text mode (the default); use a single '\n' instead, on all platforms.</p... | 5 | 2016-06-28T11:20:11Z | 38,075,790 | <blockquote>
<p>the docs explicitly say not to use it when writing to a file</p>
</blockquote>
<p>This is not exact, the doc says not to used it in <strong>text</strong> mode.</p>
<p>The <code>os.linesep</code> is used when you want to iterate through the lines of a text file. The internal scanner recognise the <co... | 2 | 2016-06-28T12:06:10Z | [
"python",
"file-io",
"separator",
"platform-independent"
] |
Detect location of specific text | 38,074,963 | <pre><code>Appium 1.5.0
Xcode 7.3
IOS 10.11.4 OSX EI Capitan
Using on:Simulator iOS 8.1
</code></pre>
<p>Suppose we have a text field <code>To see more information click</code><strong>here</strong><code>and to get more click</code> <strong>here</strong>.</p>
<p>So I identified the text using <code>xpath</code> and... | 0 | 2016-06-28T11:26:48Z | 38,076,175 | <p>The idea using Objective C (I know the OP uses Appium but he told me to answer) is to use library such as <a href="https://github.com/TTTAttributedLabel/TTTAttributedLabel/" rel="nofollow">TTTAttributedLabel</a> and using it this way : </p>
<p>Create <code>TTTAttributedLabel</code> (<code>UILabel</code> subclass), ... | 1 | 2016-06-28T12:23:00Z | [
"python",
"ios",
"appium",
"appium-ios",
"python-appium"
] |
Detect location of specific text | 38,074,963 | <pre><code>Appium 1.5.0
Xcode 7.3
IOS 10.11.4 OSX EI Capitan
Using on:Simulator iOS 8.1
</code></pre>
<p>Suppose we have a text field <code>To see more information click</code><strong>here</strong><code>and to get more click</code> <strong>here</strong>.</p>
<p>So I identified the text using <code>xpath</code> and... | 0 | 2016-06-28T11:26:48Z | 38,184,755 | <p>There isn't any direct way to achieve this(no API available in Appium itself).
However, my solution is generic and will work on all devices(Android and iOS), all programming language implementation.</p>
<ol>
<li>[You have already done] get the location and size of the element.</li>
<li>Take a screenshot of the curr... | 1 | 2016-07-04T12:26:53Z | [
"python",
"ios",
"appium",
"appium-ios",
"python-appium"
] |
How do I remove globals from Flask API calls? | 38,075,026 | <p>I am working on a Flask application that will run a <code>Foo</code>. Once a <code>Foo</code> is running, it should be possible to hit endpoints at <code>hostname:8080</code> to perform some API call that changes the state of the <code>Foo</code>.</p>
<p>Below is a fairly minimal (though not complete) example. The ... | 2 | 2016-06-28T11:29:58Z | 38,075,523 | <p>In flask you should store application global objects in flask.g (<a href="http://flask.pocoo.org/docs/0.11/api/#flask.g" rel="nofollow">see the documentation for more information</a>). It is true that this is "local" to the application, but in flask it should be possible to have multiple application in the same pyth... | 1 | 2016-06-28T11:53:25Z | [
"python",
"python-3.x",
"flask",
"global-variables"
] |
What is the purpose of apps.py in Django? | 38,075,176 | <blockquote>
<p>This question has been asked earlier: <a href="http://stackoverflow.com/questions/32795227/what-is-the-purpose-of-apps-py-in-django-1-9">What is the purpose of apps.py in Django 1.9?</a></p>
<blockquote>
<p>Application configuration objects store metadata for an application. Some attributes c... | 13 | 2016-06-28T11:37:45Z | 38,244,550 | <p>A project is unique per django installation, while an app is supposed to be reusable.</p>
<p>If you put custom app settings in your project's <code>settings.py</code> they are supposed to be modifiable, especially if you (or others) reuse this app for another project.</p>
<p>Now, if you put these custom settings i... | 1 | 2016-07-07T11:40:59Z | [
"python",
"django"
] |
How to append all the loop elements in single line while using string Template? | 38,075,232 | <p>I have tried to make a Template for example.py by using string Template where I substitute each for loop elements in $i ["CA:"+<strong>$i</strong>+':'+" "]. Partially it works but substituting only the last element.</p>
<p>But, I want to append all the values in single line with certain format .</p>
<p><strong>For... | 1 | 2016-06-28T11:40:26Z | 38,075,741 | <p>One problem is that your code, because it opens the output file with mode <code>'w'</code>, overwrites the file on each iteration of the for loop. That is why you only see the last one in the file. </p>
<p>Also I wouldn't use <code>string.Template</code> to perform these substitutions. Just use <a href="https://doc... | 2 | 2016-06-28T12:03:45Z | [
"python",
"string",
"python-2.7",
"append",
"stringtemplate"
] |
How to append all the loop elements in single line while using string Template? | 38,075,232 | <p>I have tried to make a Template for example.py by using string Template where I substitute each for loop elements in $i ["CA:"+<strong>$i</strong>+':'+" "]. Partially it works but substituting only the last element.</p>
<p>But, I want to append all the values in single line with certain format .</p>
<p><strong>For... | 1 | 2016-06-28T11:40:26Z | 38,075,751 | <p>In this example I use Python's built-in <code>format</code> string method, which is relatively easy to understand. If you prefer to use string templating you can easily adapt it.</p>
<p>The trick is to observe that there are two separate operations to perform:</p>
<ol>
<li>Create the list of arguments</li>
<li>Sub... | 1 | 2016-06-28T12:04:10Z | [
"python",
"string",
"python-2.7",
"append",
"stringtemplate"
] |
SymPy: Swap two variables | 38,075,445 | <p>In an expression like</p>
<pre><code>import sympy
a = sympy.Symbol('a')
b = sympy.Symbol('b')
x = a + 2*b
</code></pre>
<p>I'd like to swap <code>a</code> and <code>b</code> to retrieve <code>b + 2*a</code>. I tried</p>
<pre><code>y = x.subs([(a, b), (b, a)])
y = x.subs({a: b, b: a})
</code></pre>
<p>but n... | 5 | 2016-06-28T11:49:45Z | 38,075,760 | <p>There is a <code>simultaneous</code> argument you can pass to the substitution, which will ensure that all substitutions happen simultaneously and don't interfere with one another as they are doing now. </p>
<pre><code>y = x.subs({a:b, b:a}, simultaneous=True)
</code></pre>
<p><strong>Outputs</strong>: </p>
<pre>... | 4 | 2016-06-28T12:04:31Z | [
"python",
"sympy"
] |
How to fix AttributeError with ImageTk and Tkinter in python3.4? | 38,075,488 | <p>This is my code that I had written, I had fixed previous errors with help from other users. However this one stumps me. This is my code</p>
<p>I placed comment markers around the area I believe is the issue. To fix this problem I had read through a few sources however, it hasn't turned up any results. </p>
<pre><c... | 1 | 2016-06-28T11:51:40Z | 38,075,707 | <p>I'm no TKinter expert, but it seems that the line which is raising the exception:
<code>photo = ImageTk.PhotoImage(imgset)</code> Is not needed; You've already loaded the image in the previous line. </p>
<p>The exception is raised because you are passing in an instance of <code>ImageTk.PhotoImage()</code> to <code... | 1 | 2016-06-28T12:02:26Z | [
"python",
"python-3.x",
"tkinter"
] |
How to recognize a music sample using Python and Gracenote? | 38,075,577 | <p>I recently discovered the <a href="https://developer.gracenote.com/gnsdk" rel="nofollow">GNSDK</a> (Gracenote SDK) that seems to provide examples in several programming languages to recognize music samples by fingerprinting them, and then to request their audio database to get the corresponding artist and song title... | 3 | 2016-06-28T11:56:13Z | 38,076,723 | <p>Keywords are: Beat Spectrum Analysis and Rhythm Detection.</p>
<p>This is a well know Python library can contain a solution for your question:
<a href="https://github.com/aubio/aubio" rel="nofollow">https://github.com/aubio/aubio</a></p>
<p>Also I recommend that you should check this page for other libraries:
<a h... | 2 | 2016-06-28T12:48:53Z | [
"python",
"audio",
"gracenote"
] |
How to recognize a music sample using Python and Gracenote? | 38,075,577 | <p>I recently discovered the <a href="https://developer.gracenote.com/gnsdk" rel="nofollow">GNSDK</a> (Gracenote SDK) that seems to provide examples in several programming languages to recognize music samples by fingerprinting them, and then to request their audio database to get the corresponding artist and song title... | 3 | 2016-06-28T11:56:13Z | 38,083,441 | <p>Just reading your headline question and because there are no examples or tutorials for GNSDK, try looking at other options,<br>
for one: </p>
<p><strong>dejavu</strong></p>
<blockquote>
<p>Audio fingerprinting and recognition algorithm implemented in Python,
see the explanation here:</p>
<p>Dejavu can m... | 0 | 2016-06-28T18:13:11Z | [
"python",
"audio",
"gracenote"
] |
How to recognize a music sample using Python and Gracenote? | 38,075,577 | <p>I recently discovered the <a href="https://developer.gracenote.com/gnsdk" rel="nofollow">GNSDK</a> (Gracenote SDK) that seems to provide examples in several programming languages to recognize music samples by fingerprinting them, and then to request their audio database to get the corresponding artist and song title... | 3 | 2016-06-28T11:56:13Z | 39,433,823 | <p>I ended up using <a href="https://www.acrcloud.com/" rel="nofollow">ACRCloud</a> which works very well. Seems that everyone that want to use Gracenote fall back to ACRCloud for reasons... Now I know why.</p>
<p>Python example:</p>
<pre><code>from acrcloud.recognizer import ACRCloudRecognizer
config = {
'host'... | 0 | 2016-09-11T07:26:32Z | [
"python",
"audio",
"gracenote"
] |
Python range with start larger than stop | 38,075,609 | <p>I want to extract the <code>i</code> indices of a vector uniformly <code>t</code> times. For instance, if I have a vector <code>x = [1,2,3,4,5,6,7]</code>, <code>i = 3</code> and <code>t = 5</code>, my indices in each time must be:</p>
<pre><code>t = 1; [1,2,3]
t = 2; [4,5,6]
t = 3; [7,1,2]
t = 4; [3,4,5]
t = 5... | 1 | 2016-06-28T11:57:49Z | 38,075,860 | <p>Try this:</p>
<pre><code>x = [1,2,3,4,5,6,7]
xc = len(x)
i = 3
for t in range(5):
y = [x[(i*t + j) % xc] for j in range(i)]
print(y)
</code></pre>
<p>This produces:</p>
<pre><code>[1, 2, 3]
[4, 5, 6]
[7, 1, 2]
[3, 4, 5]
[6, 7, 1]
</code></pre>
| 1 | 2016-06-28T12:09:26Z | [
"python",
"loops",
"indexing"
] |
Python range with start larger than stop | 38,075,609 | <p>I want to extract the <code>i</code> indices of a vector uniformly <code>t</code> times. For instance, if I have a vector <code>x = [1,2,3,4,5,6,7]</code>, <code>i = 3</code> and <code>t = 5</code>, my indices in each time must be:</p>
<pre><code>t = 1; [1,2,3]
t = 2; [4,5,6]
t = 3; [7,1,2]
t = 4; [3,4,5]
t = 5... | 1 | 2016-06-28T11:57:49Z | 38,076,070 | <p>You can use <a href="https://docs.python.org/2.7/library/itertools.html#itertools.islice" rel="nofollow"><code>itertools.islice</code></a> on <a href="https://docs.python.org/2.7/library/itertools.html#itertools.cycle" rel="nofollow"><code>itertools.cycle</code></a>. Make a <code>cycle</code> object from the iterabl... | 3 | 2016-06-28T12:18:11Z | [
"python",
"loops",
"indexing"
] |
Compile user subroutine only once when running consecutive jobs in Abaqus | 38,075,642 | <p>I have a script written in Python which calibrates material parameters based on the output of the last job, that is, it runs many jobs in Abaqus consecutively until an error is small enough.</p>
<p>I use a Fortran subroutine which compiles before each job.</p>
<p>The problem is that for each job I submit, the user... | 0 | 2016-06-28T11:59:27Z | 38,659,035 | <p>By entering</p>
<pre><code>module add abaqus
module add intel
module add gcc
</code></pre>
<p>I <em>then</em> was allowed to enter</p>
<pre><code>abaqus make library=usub.f
</code></pre>
<p>which would compile the subroutine.</p>
| 1 | 2016-07-29T12:36:01Z | [
"python",
"compilation",
"fortran",
"subroutine",
"abaqus"
] |
How to calculate distance between 2D matrices | 38,075,714 | <p>
Hello Community, </p>
<blockquote>
<p>I'm new (as a member) to the site, so if you think it might be better to post it on <a href="http://datascience.stackexchange.com">http://datascience.stackexchange.com</a>, let me know. </p>
</blockquote>
<p>I am tackling a Machine Learning problem which requires to calcula... | 6 | 2016-06-28T12:02:44Z | 38,078,013 | <p>Given two different transition matrices <code>A</code> and <code>B</code> and a probability distribution <code>x</code> as a row vector, the distribution after one step according to <code>A</code> is <code>xA</code>, and the distribution after one step according to <code>B</code> is <code>xB</code>. You could take (... | 0 | 2016-06-28T13:46:18Z | [
"python",
"algorithm",
"matrix",
"machine-learning",
"distance"
] |
How to rotate a figure in all directions in matplotlib | 38,075,821 | <p>I am trying to rotate a figure horizontally in python. With the mouse I am only able to rotate through one degree of freedom as well as being able to spin the figure, for example this is what I can do at the momement:</p>
<p><a href="http://i.stack.imgur.com/amYaQ.png" rel="nofollow"><img src="http://i.stack.imgur.... | 1 | 2016-06-28T12:07:34Z | 38,076,234 | <p>Unfortunately, I don't think you can; From the <a href="http://matplotlib.org/1.4.3/mpl_toolkits/mplot3d/api.html#mpl_toolkits.mplot3d.axes3d.Axes3D.view_init" rel="nofollow">documentation</a>:</p>
<blockquote>
<p>âelevâ stores the elevation angle in the z plane. âazimâ stores the
azimuth angle in the x... | 3 | 2016-06-28T12:25:38Z | [
"python",
"matplotlib"
] |
can I get the POST data from environment variables in python? | 38,075,861 | <p>I am trying to understand http queries and was succesfully getting the data from GET requests through the environment variables by first looking through the keys of the environment vars and then accessing 'QUERY_STRING' to get the actual data.</p>
<p>like this:</p>
<pre><code>#!/usr/bin/python3
import sys
import c... | 0 | 2016-06-28T12:09:32Z | 38,078,914 | <p>the possible duplicate link solved it, as syntonym pointed out in the comments and user Schien explains in one of the answers to the linked question:</p>
<p>the raw http post data (the stuff after the query) can be read through stdin.
so the <code>sys.stdin.read()</code> method can be used.</p>
<p>my code now wo... | 0 | 2016-06-28T14:25:08Z | [
"python",
"http",
"http-post",
"environment-variables",
"cgi"
] |
Parse POST HTTP response using Python | 38,075,920 | <p>i want to parse a POST HTTP response using python.</p>
<p>My response looks like:</p>
<pre><code>{
"Result": 0,
"ResponseStatus": {
"ErrorCode": null,
"Message": null,
"StackTrace": null,
"Errors": null
},
"SessionId": "68ebcd6f-0aef-420d-a12b-c953f8df8ed1",
"ResponseHeader": {
"Succe... | 0 | 2016-06-28T12:11:38Z | 38,076,087 | <pre><code>import json
response = '{"Result": 0, "ResponseStatus": { "ErrorCode": null,"Message": null, "StackTrace": null, "Errors": null },"SessionId": "68ebcd6f-0aef-420d-a12b-c953f8df8ed1", "ResponseHeader": { "Succeeded": true, "Errors": [] } }'
json_response = json.loads(response)
print json_response['SessionId'... | 2 | 2016-06-28T12:19:06Z | [
"python",
"parsing",
"httprequest",
"httpresponse"
] |
Auth0 - why insufficient scope and what to do with it? | 38,075,924 | <p>I am trying to authnticate with Auth0 and get user data.</p>
<pre><code>import json
import requests
payload = {
'grant_type': 'password',
'username': '********',
'password': '********',
'client_id': '********',
'connection': 'Username-Password-Authentication',
'scope': 'openid'
# 'scope... | 0 | 2016-06-28T12:11:50Z | 38,090,567 | <p>You cannot use an <code>id_token</code> for the Auth0 API. You need a specific token for the API (v2) (and in your case you need a <code>read:client</code> scope). See here: <a href="https://auth0.com/docs/api/management/v2" rel="nofollow">https://auth0.com/docs/api/management/v2</a></p>
| 2 | 2016-06-29T04:44:01Z | [
"python",
"oauth",
"auth0"
] |
django annotate a function that returns the maximum of a field among all objects that has a feature | 38,076,046 | <p>Suppose that I have this model:</p>
<pre><code>class Student(models.Model):
class_name = models.CharField()
mark = models.IntegerField()
</code></pre>
<p>And I want to get all the students that have the highest <code>mark</code> in their class. I can get the student who has the highest <code>mark</code> in... | 1 | 2016-06-28T12:17:21Z | 38,076,559 | <p>You will have to use 2 queries for that:</p>
<pre><code>import operator
from functools import reduce
from django.db.models import Max, Q
best_marks = Student.objects.values('class_name').annotate(mark=Max('mark'))
q_object = reduce(operator.or_, (Q(**x) for x in best_marks))
queryset = Student.objects.filter(q_obj... | 0 | 2016-06-28T12:40:44Z | [
"python",
"django",
"django-orm",
"django-annotate"
] |
Dictionary of directories | 38,076,128 | <p>I have some paths like (simplified):
/rootFolder/subfolder_1/subsubfolder_1/</p>
<pre><code>paths = {
'rootFolder':'rootFolder/'
'subFolder_1':paths[rootFolder]+'subFolder/'
'subsubFolder_1:paths[subfolder]+'subsubFolder/'
}
</code></pre>
<p>Basically, I want a static dictionary of paths, but I also wa... | 2 | 2016-06-28T12:21:00Z | 38,076,317 | <p>With dictionaries being a key-value store this should be fairly easy with Python and using variables to make it so that all you have to do is change one value and it should ripple throughout the code. An example is below:</p>
<pre><code>>>> paths = {"root" : rootvariable, "path1" : "/somepath"}
>>>... | -1 | 2016-06-28T12:29:18Z | [
"python",
"dictionary"
] |
Dictionary of directories | 38,076,128 | <p>I have some paths like (simplified):
/rootFolder/subfolder_1/subsubfolder_1/</p>
<pre><code>paths = {
'rootFolder':'rootFolder/'
'subFolder_1':paths[rootFolder]+'subFolder/'
'subsubFolder_1:paths[subfolder]+'subsubFolder/'
}
</code></pre>
<p>Basically, I want a static dictionary of paths, but I also wa... | 2 | 2016-06-28T12:21:00Z | 38,076,455 | <p>You can just create a function to return the dictionary that you want.</p>
<pre><code>def path_dict(root):
return {'rootFolder':root,
'subFolder_1':root+'subFolder/'
'subsubFolder_1:root+'subfolder/subsubFolder/'
}
</code></pre>
<p>Then,</p>
<pre><code>>>> path_dict... | 0 | 2016-06-28T12:35:42Z | [
"python",
"dictionary"
] |
Dictionary of directories | 38,076,128 | <p>I have some paths like (simplified):
/rootFolder/subfolder_1/subsubfolder_1/</p>
<pre><code>paths = {
'rootFolder':'rootFolder/'
'subFolder_1':paths[rootFolder]+'subFolder/'
'subsubFolder_1:paths[subfolder]+'subsubFolder/'
}
</code></pre>
<p>Basically, I want a static dictionary of paths, but I also wa... | 2 | 2016-06-28T12:21:00Z | 38,076,913 | <p>You can use functions as values for the keys. Because functions are not called before the <code>dict</code> is constructed, there'll be no <code>NameError</code>. </p>
<pre><code>In [320]: paths = { 'root': lambda: '/', 'usr': lambda: os.path.join(paths['root'](), 'usr')}
In [321]: paths['root']()
Out[321]: '/'... | 2 | 2016-06-28T12:58:04Z | [
"python",
"dictionary"
] |
Dictionary of directories | 38,076,128 | <p>I have some paths like (simplified):
/rootFolder/subfolder_1/subsubfolder_1/</p>
<pre><code>paths = {
'rootFolder':'rootFolder/'
'subFolder_1':paths[rootFolder]+'subFolder/'
'subsubFolder_1:paths[subfolder]+'subsubFolder/'
}
</code></pre>
<p>Basically, I want a static dictionary of paths, but I also wa... | 2 | 2016-06-28T12:21:00Z | 38,076,989 | <pre><code>paths = {
'rootFolder' : "'rootFolder/'",
'subFolder_1' : "eval(paths['rootFolder']) + 'subFolder/'",
'subsubFolder_1': "eval(paths['subFolder_1'])+ 'subsubFolder/'"
}
</code></pre>
<p>access via: </p>
<pre><code>eval(paths["subsubFolder_1"])
# 'rootFolder/subFolder/subsubFolder/'
</code></pr... | 0 | 2016-06-28T13:01:23Z | [
"python",
"dictionary"
] |
Python MySQLdb - Connection in a class | 38,076,220 | <p>I am making a Python project where I have to seek and retreive data from a database.<br>
I tried making a class, in which I declare the connection and do my queries, here is moreless what I have so far. </p>
<pre><code>import MySQLdb
dbc =("localhost","root","1234","users")
class sql:
db = MySQLdb.connect(dbc[... | 0 | 2016-06-28T12:25:04Z | 38,076,422 | <p>That's not how you write classes in Python. You need to define your connection and cursor inside the <code>__init__</code> method, and refer to them via <code>self</code>.</p>
<pre><code>class sql:
dbc = ("localhost","root","1234","users")
def __init__(self):
db = MySQLdb.connect(*self.dbc)
... | 2 | 2016-06-28T12:34:19Z | [
"python",
"python-3.x",
"mysql-python"
] |
Python MySQLdb - Connection in a class | 38,076,220 | <p>I am making a Python project where I have to seek and retreive data from a database.<br>
I tried making a class, in which I declare the connection and do my queries, here is moreless what I have so far. </p>
<pre><code>import MySQLdb
dbc =("localhost","root","1234","users")
class sql:
db = MySQLdb.connect(dbc[... | 0 | 2016-06-28T12:25:04Z | 38,078,544 | <p>I usually use psycopg2 / postgres, but this is the basic DB class that I use over and over and over again:</p>
<pre><code>class DBase:
dsn = ("localhost","root","1234","users")
def __init__(self):
self.conn = MySQLdb.connect(*self.dsn)
self.cur = self.conn.cursor()
def __enter__(self)... | 0 | 2016-06-28T14:09:44Z | [
"python",
"python-3.x",
"mysql-python"
] |
Matplotlib/Pandas: How to plot multiple scatterplots within different locations in the same plot? | 38,076,348 | <p>I often have two pandas dataframes, which I would like to plot within the same plot. Normally these are two samples, and I would like to contrast their properties, as an example: </p>
<p><a href="http://i.stack.imgur.com/IlOrO.png" rel="nofollow"><img src="http://i.stack.imgur.com/IlOrO.png" alt="enter image descri... | -1 | 2016-06-28T12:30:56Z | 38,076,485 | <p>Use <code>return_type='axes'</code> to get <code>data1.boxplot</code> to return a matplotlib Axes object. Then pass that axes to the second call to boxplot using <code>ax=ax</code>. This will cause both boxplots to be drawn on the same axes.</p>
<pre><code>ax = df1.plot()
df2.plot(ax=ax)
a1=a[['a','time']]
ax = ... | 1 | 2016-06-28T12:36:40Z | [
"python",
"pandas",
"matplotlib",
"plot",
"scatter"
] |
Pandas Dataframe dropping rows and setting column names | 38,076,377 | <p>I have a pandas dataframe like this: </p>
<pre><code> 1 2 3
0
NaN ingr contr count
2.0 water 0.02 275
3.0 oil 0.23 11
.....
</code></pre>
<p>and I would like to transfer it to this: </p>
<pre><code>ingr contr count
water 0.02 275
oil 0.23 11
....
</code></pre>
<p... | 0 | 2016-06-28T12:32:19Z | 38,076,467 | <p>try <a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.DataFrame.iloc.html" rel="nofollow">iloc</a> indexer:</p>
<pre><code>In [66]: df
Out[66]:
1 2 3
NaN ingr contr count
2.0 water 0.02 275
3.0 oil 0.23 11
In [67]: df.columns = df.iloc[0]
In [6... | 1 | 2016-06-28T12:36:04Z | [
"python",
"pandas",
"dataframe"
] |
Pandas Dataframe dropping rows and setting column names | 38,076,377 | <p>I have a pandas dataframe like this: </p>
<pre><code> 1 2 3
0
NaN ingr contr count
2.0 water 0.02 275
3.0 oil 0.23 11
.....
</code></pre>
<p>and I would like to transfer it to this: </p>
<pre><code>ingr contr count
water 0.02 275
oil 0.23 11
....
</code></pre>
<p... | 0 | 2016-06-28T12:32:19Z | 38,076,488 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.iloc.html" rel="nofollow"><code>iloc</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow"><code>reset_index</code></a> and <a href="http://pandas.pydata.org/... | 1 | 2016-06-28T12:36:45Z | [
"python",
"pandas",
"dataframe"
] |
Ask for user input, run specified function, then go back to asking | 38,076,676 | <p>I am making a CLI in python using click. What i want to have is a kind of "idle state" which the program starts in. The script asks for user input, and depending on the input a specific function should be run. This sub-function can also ask for user input and do different things. </p>
<p>What im having trouble with... | 0 | 2016-06-28T12:46:59Z | 38,109,496 | <p>you can try this:</p>
<pre><code>def cli():
print "Welcome. What do you want to do?"
choice = click.prompt('')
if choice == 'add':
add()
cli()
else:
subtract()
</code></pre>
| 0 | 2016-06-29T20:30:15Z | [
"python",
"command-line-interface"
] |
How to add colors to each individual face of a cylinder using matplotlib | 38,076,682 | <p>I am trying to color each individual face of a cylinder, however I am not sure how to go about it, I have tried the following:</p>
<pre><code>for i in range(10):
col.append([])
for i in range(10):
for j in range(20):
col[i].append(plt.cm.Blues(0.4))
ax.plot_surface(X, Y, Z,facecolors = col,edge... | 0 | 2016-06-28T12:47:10Z | 38,078,404 | <p>Your <code>Z</code> array is of size <code>100x200</code>, yet you are only specifying <code>10x20</code> colors. A quicker way to make <code>col</code> (with the right dimensions) might be something like:</p>
<pre><code>col1 = plt.cm.Blues(np.linspace(0,1,200)) # linear gradient along the t-axis
col1 = np.repeat(c... | 2 | 2016-06-28T14:04:24Z | [
"python",
"matplotlib"
] |
How do you specify a policy name when creating a new role? | 38,076,911 | <p>I'm converting some aws-iot java code over to use boto3 and am stuck when creating a new role. The old code specifies a policy name when specifying the policy for a role, but I don't know how to specify that in boto3. Here's the java code block (note: withId(assumePolicyName)):</p>
<pre><code>iamClient.createRole(n... | 0 | 2016-06-28T12:57:59Z | 38,079,981 | <p>As far as I know, IAM provides no way to associate a policy name with the <code>AssumedRolePolicyDocument</code>. I'm not sure what purpose a name would serve since there can be only one such policy per role and these trust relationships cannot be shared between roles.</p>
| 0 | 2016-06-28T15:10:28Z | [
"java",
"python",
"amazon-web-services",
"boto",
"boto3"
] |
How do you specify a policy name when creating a new role? | 38,076,911 | <p>I'm converting some aws-iot java code over to use boto3 and am stuck when creating a new role. The old code specifies a policy name when specifying the policy for a role, but I don't know how to specify that in boto3. Here's the java code block (note: withId(assumePolicyName)):</p>
<pre><code>iamClient.createRole(n... | 0 | 2016-06-28T12:57:59Z | 38,084,240 | <p>I was pretty close. I should have just attempted a few trial/errors. The correct solution is this document:</p>
<pre><code>self.iamClient.create_role(RoleName=role_name, AssumeRolePolicyDocument={
'Id': 'assume_role_id',
'Statement': [
{
'Principal... | 0 | 2016-06-28T19:00:38Z | [
"java",
"python",
"amazon-web-services",
"boto",
"boto3"
] |
TypeError: 'type' object is not subscriptable with pypyodbc (Python) | 38,076,925 | <p>What is wrong with my below python code ?</p>
<p>I want to connect to my database, select some information. These are in a list of list, I grab the list and I do a "select..from..where..IN" : </p>
<pre><code> import pypyodbc
connection = pypyodbc.connect('Driver={SQL Server};'
... | 0 | 2016-06-28T12:58:37Z | 38,077,435 | <p>I think because you have an empty list in:</p>
<pre><code>L=[[4702, 3095, 3543], [2040, 2030, 2020], []]
^^
</code></pre>
<p>And when testing with <code>if</code>, even thought the list is empty, it passes the test, similar to the following example:</p>
<pre><code>>&g... | 0 | 2016-06-28T13:20:41Z | [
"python",
"sql-server",
"pypyodbc"
] |
pandas get the max 3 score rows for each category | 38,076,976 | <p>I get a list as follows:</p>
<pre><code>cat score name
a 80 fa
c 88 lu
b 36 li
b 96 liu
d 99 zc
b 76 mi
d 89 lu
a 50 fa
d 69 zhang
b 36 huang
d 59 guan
b 96 ka
b 86 chao
c 98 le
a 50 mi
a 90 zc
c 83 chao
b 66 guan
</code></pre>
<p>How to use pandas can get the ... | 1 | 2016-06-28T13:00:51Z | 38,077,017 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.SeriesGroupBy.nlargest.html" rel="nofollow"><code>nlargest</code></a>:</p>
<pre><c... | 4 | 2016-06-28T13:02:23Z | [
"python",
"pandas",
"dataframe",
"group-by",
"greatest-n-per-group"
] |
Get match of two lists | 38,076,995 | <p>I have two lists and i like to browse them to get the matchs and the difference
but i don't understand why my index don't reach the end of list
there is my code:</p>
<pre><code>recordedEvents=[u'/app//wakeup', u'/app/hdmi/state', u'/homepage/ws/view', u'/homepage//activate', u'/live//activate', u'/live//zap', u'/l... | 1 | 2016-06-28T13:01:39Z | 38,077,128 | <p>You can use <code>set</code> operations to do this. What you're asking for is essentially <code>set.intersection</code> and <code>set.difference</code>.</p>
<pre><code>>>> set(recordedEvents).intersection(expectedEvents)
{'/app/optin/state',
'/live/virtualzappinglistbanner/zap',
'/qos/live/',
'/live/ppl... | 1 | 2016-06-28T13:07:24Z | [
"python"
] |
python subprocess does not write to stdout | 38,076,996 | <p>If I run the following python code (in python 2.7) I get an empty output file while I would expect a line. What is wrong?</p>
<pre><code>import subprocess
with open('outfile.out', 'w') as out:
pp=subprocess.Popen(['/bin/cat'],stdin=subprocess.PIPE,stdout=out)
pp.stdin.write('Line I want into out file\n')
... | 1 | 2016-06-28T13:01:40Z | 38,077,105 | <p>You <code>terminate</code>d the process, and never flushed/closed the input to it, so all the data was stuck in buffers and discarded when the process was forcibly killed. You can use <code>communicate</code> to combine passing input, closing <code>stdin</code>, then waiting for the process to complete:</p>
<pre><c... | 2 | 2016-06-28T13:06:22Z | [
"python",
"subprocess"
] |
Scrapy Xpath output empty | 38,077,170 | <p>I would like extract data on this website : <a href="http://www.pokepedia.fr/Pikachu" rel="nofollow">http://www.pokepedia.fr/Pikachu</a>
I'm learning the python and how to use Scrapy and my problem is : Why I can't retrieve the data with Xpath ? </p>
<p>My Xpath look good when i test xpath in my browser, it return ... | 1 | 2016-06-28T13:09:15Z | 38,077,364 | <p>Try this </p>
<pre><code>question.xpath( '//*[@id="mw-content-text"]/table[2]/tr[1]/th[2]/text()').extract()[0]
</code></pre>
<p>The browser adds the <em>tbody</em> tags. They are not in the original HTML, that's why scrapy returns an empty file.</p>
<p>PS: you might want to consider using</p>
<pre><code>scrapy ... | 0 | 2016-06-28T13:17:00Z | [
"python",
"xpath",
"web-scraping",
"scrapy"
] |
How to increase the model accuracy of logistic regression in Scikit python? | 38,077,190 | <p>I am trying to predict the admit variable with predictors such as gre,gpa and ranks.But the prediction accuracy is very less(0.66).The dataset is given below.
<a href="https://gist.github.com/abyalias/3de80ab7fb93dcecc565cee21bd9501a" rel="nofollow">https://gist.github.com/abyalias/3de80ab7fb93dcecc565cee21bd9501a</... | 0 | 2016-06-28T13:09:49Z | 38,083,189 | <p>Since machine learning is more about experimenting with the features and the models, there is no correct answer to your question. Some of my suggestions to you would be:</p>
<p><strong>1. Feature Scaling and/or Normalization</strong> - Check the scales of your <em>gre</em> and <em>gpa</em> features. They differ on ... | 4 | 2016-06-28T17:59:34Z | [
"python",
"machine-learning",
"scikit-learn",
"regression",
"logistic-regression"
] |
How to use self join to reshape duplicate rows in Pandas? | 38,077,203 | <p>I have a duplicates rows and I want to concatenate them. They are like : </p>
<pre><code>ID Col1 Col2 Col3 ... Col46
-----------------------------------
id1 a1 b1 c1 ... x1
id2 a2 b2 c2 ... x2
id1 a1 b1 c1 ... y1
id3 a3 b3 c3 ... x3
id3 a3 b3 ... | 2 | 2016-06-28T13:10:14Z | 38,077,368 | <p>I think you need first create <code>groups</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.cumcount.html" rel="nofollow"><code>cumcount</code></a> and then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"><... | 4 | 2016-06-28T13:17:18Z | [
"python",
"pandas",
"merge",
"reshape",
"self-join"
] |
How to access a model with its name in a string in django 1.9 | 38,077,297 | <p>I want to access to a model and its attribute that I defined in my django app via string name.
I found these two solutions but they are not fit to my question.</p>
<p><a href="http://stackoverflow.com/questions/2612610/how-to-access-object-attribute-given-string-corresponding-to-name-of-that-attrib">How to access o... | 2 | 2016-06-28T13:14:08Z | 38,077,443 | <p>You can use <code>getattr</code> on the module containing the model, and then apply the same on the model to get the field in the model:</p>
<pre><code>from app_name import models
s = "Foo.var2"
attrs = s.split('.')
my_model = my_field = None
# get attribute from module
if hasattr(models, attrs[0]):
my_model ... | 1 | 2016-06-28T13:21:08Z | [
"python",
"django"
] |
Postional arguements in python Docopt | 38,077,420 | <p>I am writing a simple command line contact manager.
i want to be able to add a new contact with the following command.<br>
<code>manager.py add -n NAME -p PHONENUMBER</code><br>
but whenver i add a contact using firstname and lastname, the code throws errors.<br>
eg. <code>manager.py add -n emeka onwuzulike +234... | 0 | 2016-06-28T13:19:45Z | 38,077,712 | <p>the problem you are having is because each argument is split on the space character so what is being sent is:</p>
<ul>
<li>add </li>
<li>-n </li>
<li>emeka</li>
<li>onwuzulike</li>
<li>+23464715326</li>
</ul>
<p>you have a few options around this, the easiest I can think of is instead of using a space in a name, u... | 0 | 2016-06-28T13:33:44Z | [
"python",
"docopt"
] |
Postional arguements in python Docopt | 38,077,420 | <p>I am writing a simple command line contact manager.
i want to be able to add a new contact with the following command.<br>
<code>manager.py add -n NAME -p PHONENUMBER</code><br>
but whenver i add a contact using firstname and lastname, the code throws errors.<br>
eg. <code>manager.py add -n emeka onwuzulike +234... | 0 | 2016-06-28T13:19:45Z | 38,430,772 | <p>to achieve this, you need to put a string a one the name arguement like so<br>
manager.py add -n 'emeka onwuzulike' -p 08064715300</p>
| 0 | 2016-07-18T07:22:28Z | [
"python",
"docopt"
] |
SSH programming with Python 3 paramiko, EOFError when trying to execute commands | 38,077,556 | <p>Wizards of stackoverflow. I'm trying to read in commands from a .txt file to SSH using paramiko. Currently it will read in the first line from the file and execute it. When I get to the second line though, it will throw an EOFError and quit. I put a check in to see if the second command makes it to print and it does... | 0 | 2016-06-28T13:26:17Z | 38,083,679 | <p>Possible bug. Current implementation of <code>sendCommand</code> may not receive output (or full output). </p>
<p>Reason
<code>exit_status_ready</code> is a non blocking way to find that exit status is received. It is possible that lastpart of output still not readed by script. You need to call <code>recv</code> af... | 0 | 2016-06-28T18:28:19Z | [
"python",
"ssh",
"paramiko"
] |
Reading integers from file using Python | 38,077,570 | <p>I´ve a "binary" file with variable size record. Each record is composed of an amount of little endians 2 byte-sized integer numbers. I know the start position of each record and it´s size.</p>
<p>What´s the fastest way to read this to a Python array of integer?</p>
| 0 | 2016-06-28T13:26:59Z | 38,079,966 | <p>I don't think you can do better than opening the file and reading the size of each recorde then use <code>struct.unpack('<i', buff)</code> for each integer you want to read, <code>file.read(2)</code>, will get you 2 integers.</p>
| 0 | 2016-06-28T15:09:39Z | [
"python",
"file",
"integer"
] |
I can't assignment a value to the cell python pandas | 38,077,576 | <p>I have the following code:</p>
<pre><code>for i in range(len(list_sort)):
list_sort[i] = list_sort[i].reset_index()
classification = 1
list_sort[i].set_value(0, list_column[k], classification)
for j in range(len(df))[1::]:
if(list_sort[i].ix[j][1] == list_sort[i].ix[j-1][1]):
lis... | 1 | 2016-06-28T13:27:15Z | 38,080,198 | <p>You are trying to set a value on a copy:</p>
<blockquote>
<p>C:\Anaconda2\lib\site-packages\ipykernel__main__.py:10: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame</p>
<p>See the caveats in the documentation: <a href="http://pandas.pydata.org/pandas-docs/stable/i... | 0 | 2016-06-28T15:19:35Z | [
"python",
"pandas",
"floating-point"
] |
Django CreateView - How do I call form class __init__? | 38,077,600 | <p>I have a django create view and I want to call the <code>__init__</code> of the form class and I don't know how to do that.</p>
<pre><code>class PersonCreateView(CreateView):
model = Person
form_class = PersonForm
</code></pre>
<p>In the form class I made some logic to redefine the queryset of some combos.... | 0 | 2016-06-28T13:28:33Z | 38,077,680 | <p>You shouldn't call it yourself. You can override <a href="https://docs.djangoproject.com/en/1.9/ref/class-based-views/mixins-editing/#django.views.generic.edit.FormMixin.get_form_kwargs" rel="nofollow"><code>get_form_kwargs</code></a> to provide extra arguments to pass to the form instantiation.</p>
<pre><code>clas... | 2 | 2016-06-28T13:32:19Z | [
"python",
"django",
"forms"
] |
Django CreateView - How do I call form class __init__? | 38,077,600 | <p>I have a django create view and I want to call the <code>__init__</code> of the form class and I don't know how to do that.</p>
<pre><code>class PersonCreateView(CreateView):
model = Person
form_class = PersonForm
</code></pre>
<p>In the form class I made some logic to redefine the queryset of some combos.... | 0 | 2016-06-28T13:28:33Z | 38,077,802 | <p>The <strong>init</strong> method is actually called automatically by the class when a new instance of the object is instantiated.</p>
<p>Consider the following example:</p>
<pre><code>class House():
__init__(self,x,y):
self.x = x
self.y = y
self.z = x*y
</code></pre>
<p>To call <strong... | 0 | 2016-06-28T13:36:43Z | [
"python",
"django",
"forms"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.