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 |
|---|---|---|---|---|---|---|---|---|---|
Change color when button is sunken Tkinter | 40,023,841 | <p>How could I make it, so when any button in my program is sunken (so being clicked) that button gets a certain background color (white) for 1 sec.</p>
<p>I was thinking of something like this:</p>
<p>Whenever ButtonClicked = Sunken, ButtonClicked['bg'] = 'white' for 1 sec</p>
<p>But I have lots of buttons, and eve... | 0 | 2016-10-13T14:29:00Z | 40,024,740 | <p>The simplest solution is to create your own custom button class, and add the behavior to that class.</p>
<p>You can use <code>after</code> to arrange for the color to be restored after some amount of time.</p>
<p>For example:</p>
<pre><code>class CustomButton(tk.Button):
def __init__(self, *args, **kwargs):
... | 1 | 2016-10-13T15:09:28Z | [
"python",
"button",
"tkinter",
"click"
] |
Having trouble navigating file explorer with python | 40,023,890 | <p>I am building an automated browser with selenium and it is working flawlessly! (thank you selenium (: )
But I am having trouble uploading a file. One of the steps I need to execute is to upload a file.</p>
<p>The code I use to upload, and seems like it works for many people, is:</p>
<pre><code>file_input = driver.... | 1 | 2016-10-13T14:31:12Z | 40,024,204 | <p>Seems that you use wrong locator to upload file. You should handle <code>input</code> element, not <code>button</code>:</p>
<pre><code>file_input = driver.find_element_by_xpath('//input[@type="file"]')
file_input.send_keys('C:\\image.jpg')
</code></pre>
| 2 | 2016-10-13T14:44:46Z | [
"python",
"selenium"
] |
Php : read output from exec | 40,023,925 | <p>I'm launching a Python script from PHP and I'd like to get the line printed from that Python:</p>
<pre><code>exec( "python plotModule.py $myArray[0] $myArray[1]", $output, $ret_code);
$fp = fopen('logDisp.txt', 'w');
fwrite($fp, "$output");
fclose($fp);
</code></pre>
<p>In Python I have a <code>print("hello")</co... | 0 | 2016-10-13T14:32:28Z | 40,024,037 | <p>You try write $output as string, but it`s an array</p>
<p>Use foreach or $output[0]</p>
| 0 | 2016-10-13T14:37:17Z | [
"php",
"python"
] |
Php : read output from exec | 40,023,925 | <p>I'm launching a Python script from PHP and I'd like to get the line printed from that Python:</p>
<pre><code>exec( "python plotModule.py $myArray[0] $myArray[1]", $output, $ret_code);
$fp = fopen('logDisp.txt', 'w');
fwrite($fp, "$output");
fclose($fp);
</code></pre>
<p>In Python I have a <code>print("hello")</co... | 0 | 2016-10-13T14:32:28Z | 40,073,428 | <pre><code>exec( "python plotModule.py $myArray[0] $myArray[1]", $output, $ret_code);
$fp = fopen('logDisp.txt', 'w');
fwrite($fp, json_encode($output));
fclose($fp);
</code></pre>
<p>Here you can see the jsonified response</p>
| 1 | 2016-10-16T17:48:26Z | [
"php",
"python"
] |
How to get real estate data with Idealista API? | 40,023,931 | <p>I've been trying to use the API of the website Idealista (<a href="https://www.idealista.com/" rel="nofollow">https://www.idealista.com/</a>) to retrieve information of real estate data. </p>
<p>Since I'm not familiarized with OAuth2 I haven't been able to obtain the token so far. I have just been provided with the... | 0 | 2016-10-13T14:32:36Z | 40,106,540 | <p>After some days of research I came up with a basic python code to retrieve real estate data from the Idealista API.</p>
<pre><code>def get_oauth_token():
http_obj = Http()
url = "https://api.idealista.com/oauth/token"
apikey= urllib.parse.quote_plus('Provided_API_key')
secret= urllib.parse.quote_plus('Provided_API_... | 0 | 2016-10-18T11:05:08Z | [
"python",
"oauth2"
] |
Kivy Python: Accordion inside an accordion, using a variable | 40,023,979 | <p>I am trying to create an accordion menu (no.1), in which there is another accordion menu (no.2).
The size of accordion no.2 will be defined by the user (an example of the outcome is shown in this image).
<a href="https://i.stack.imgur.com/VDjs6.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/VDjs6.jpg" alt="... | 0 | 2016-10-13T14:34:37Z | 40,039,164 | <p>It isn't displaying because of you returning an instance of <code>Accordion</code> into nothing in <code>addFloor</code>/<code>calc</code> in <code>on_text_validate</code>. To create a widget you have to call <code><parent>.add_widget(<widget>)</code>, so let's do that:</p>
<pre><code>on_text_validate: ... | 1 | 2016-10-14T09:04:00Z | [
"python",
"kivy",
"kivy-language"
] |
Is decorators in python example of monkey patching technique? | 40,023,987 | <p>Recently I was reading about monkey patching technique and wondered if it can be said.</p>
| 0 | 2016-10-13T14:35:02Z | 40,024,454 | <p>Decorator = a function that takes a function as an argument and returns a function</p>
<p>Monkey patching = replacing a value of a field on an object with a different value (not necessarly functions)</p>
<p>In case of functions monkey patching can be performed via a decorator. So I guess decorator might be thought... | 3 | 2016-10-13T14:55:08Z | [
"python",
"monkeypatching"
] |
Is decorators in python example of monkey patching technique? | 40,023,987 | <p>Recently I was reading about monkey patching technique and wondered if it can be said.</p>
| 0 | 2016-10-13T14:35:02Z | 40,024,979 | <p>I suppose on some grammatical level they may be equivalent. However, decorators are applied at the time a function or class is defined, and monkeypatching modifies an object at runtime, making them very different both in spirit and in actual use. </p>
| 1 | 2016-10-13T15:19:52Z | [
"python",
"monkeypatching"
] |
Multithreading to handling multiple incoming requests | 40,024,016 | <p>I am new to python. And I have to write a listener/server which will handle requests coming from same network. So I am using <code>socket</code>. I will be getting request json from client, server/listener will do processing and return the result. Thats all what is going to happen. And there will be no back and fort... | 0 | 2016-10-13T14:36:39Z | 40,024,179 | <p>No need to extend <code>Thread</code> class. The simpliest version is this:</p>
<pre><code>import threading
def client_handler(connection):
#read request data
#process request
#reply response to **connection** object
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('loca... | 0 | 2016-10-13T14:43:47Z | [
"python",
"multithreading",
"sockets"
] |
How does Django's `url` template tag reverse a Regex? | 40,024,017 | <p>How does Django's <code>url</code> template tag work? What magic does it use under the covers to "reverse" a regex?</p>
<p>You give it a regex like this:</p>
<pre><code>urlpatterns = [
# ex: /polls/5/
url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'),
]
</code></pre>
<p>... and then i... | 2 | 2016-10-13T14:36:46Z | 40,024,499 | <p>The key to reversing the regex is the <a href="https://github.com/django/django/blob/master/django/utils/regex_helper.py#L50" rel="nofollow"><code>normalize()</code></a> function, which takes a regex and returns a list of possibilities. Each possibility is a tuple of a placeholder string and a list of parameters. </... | 2 | 2016-10-13T14:57:22Z | [
"python",
"regex",
"django"
] |
Finding Max Shape of Multiple .npz files | 40,024,118 | <p>I have a number of .npz files that potentially vary in shape and I'd like to find which file has the larges shape. The npzs have 2 arrays within in them, and I'm looking for the largest of the 2nd. The following snippet works, but it takes longer than I expected to return shapes. Is this the most efficient way of ... | 1 | 2016-10-13T14:41:13Z | 40,024,277 | <p>Bear in mind that I/O operations might be relatively slow. That said, you can reduce the logic for finding the maximum to the following using the builtin <a href="https://docs.python.org/2/library/functions.html#max" rel="nofollow"><code>max</code></a> which will run in <a href="http://stackoverflow.com/questions/54... | 1 | 2016-10-13T14:47:30Z | [
"python",
"numpy"
] |
Creating dynamic URLS by concatenating strings rises UnicodeEncodeError | 40,024,266 | <p>I am trying to build my urls dynamically upon my project execution, it retrieves all my projects and concatenates the strings to create the urls like following:</p>
<pre><code>for project in projects:
domain = Settings.objects.get(id_project=project).site_domain
urlpatterns += patterns('',
(r'^'+proje... | 0 | 2016-10-13T14:47:05Z | 40,024,660 | <p>Is that <code>patterns</code> a typo? </p>
<pre><code>for project in projects:
domain = Settings.objects.get(id_project=project).site_domain
urlpatterns += url(r'^'+project.type+r'/'+project.name+r'/', include('apps.'+project.type+'.urls'))
</code></pre>
| 1 | 2016-10-13T15:05:40Z | [
"python",
"django",
"django-urls",
"url-pattern"
] |
Pandas data frame combine rows | 40,024,294 | <p>My problem is a large data frame which I would like to clear out. The two main problems for me are: </p>
<ol>
<li><p>The whole data frame is time-based. That means I can not shift rows around, otherwise, the timestamp wouldn't fit anymore.</p></li>
<li><p>The data is not always in the same order.</p></li>
</ol>
<p... | 2 | 2016-10-13T14:48:10Z | 40,026,199 | <p>This may not be the most general solution, but it solves your problem:</p>
<p><strong>First</strong>, isolate the right half:</p>
<pre><code>r = df[['x1', 'x2', 'y1', 'y2']].dropna(how='all')
</code></pre>
<p><strong>Second</strong>, use <code>dropna</code> applied column by column to compress the data:</p>
<pre... | 0 | 2016-10-13T16:19:57Z | [
"python",
"python-3.x",
"pandas",
"dataframe",
"spyder"
] |
Keeping columns in the specified order when using UseCols in Pandas Read_CSV | 40,024,406 | <p>I have a csv file with 50 columns of data. I am using Pandas read_csv function to pull in a subset of these columns, using the usecols parameter to choose the ones I want:</p>
<pre><code>cols_to_use = [0,1,5,16,8]
df_ret = pd.read_csv(filepath, index_col=False, usecols=cols_to_use)
</code></pre>
<p>The trouble is... | 2 | 2016-10-13T14:53:12Z | 40,024,462 | <p>you can reuse the same <code>cols_to_use</code> list for selecting columns in desired order:</p>
<pre><code>df_ret = pd.read_csv(filepath, index_col=False, usecols=cols_to_use)[cols_to_use]
</code></pre>
| 3 | 2016-10-13T14:55:27Z | [
"python",
"pandas",
"dataframe"
] |
Ordered/Prioritized return of a regular expression | 40,024,526 | <p>I have the following group of possible values that can appear in a field of a DataFrame (extract from a database):</p>
<p>(N2|N1|N11|N12|N3|N4|N6|N10|N13|N5|N7|N8|N9)</p>
<p>The field can contain any of the above in any combination, for example:</p>
<p>"N1, N6, N9"</p>
<p>I want to extract from every element of ... | 1 | 2016-10-13T14:59:10Z | 40,025,075 | <p>Considering you have a dataframe <code>df</code> with your column of data named <code>data</code>, here is a simple way without using regex. Split the strings into columns, then sort the resulting list and take the first element:</p>
<pre><code>df.data.str.split(',').apply(lambda l: sorted(l, reverse=True)[0])
Out[... | 1 | 2016-10-13T15:24:25Z | [
"python",
"regex",
"pandas"
] |
Pairing Elements w/o Repeating | 40,024,544 | <p>I am close to figuring out this problem but am hung on one one thing in particular. I am trying to pair/zip together elements in a list pair by pair, and then checking which value is greater. I just can't figure out how to pair these elements without repeating values. </p>
<pre><code>[35,10,5,3,1,26,15]
</code></pr... | 0 | 2016-10-13T15:00:10Z | 40,024,738 | <pre><code>l = [35,10,5,3,1,26,15]
g = (i for i in l)
output = [(next(g), next(g)) for i in range(len(l)//2)]
</code></pre>
<p><code>g</code> is a generator. This doesn't do anything with the last element of odd-length lists. That element is available at <code>next(g)</code></p>
| 0 | 2016-10-13T15:09:13Z | [
"python",
"indexing",
"pair"
] |
Pairing Elements w/o Repeating | 40,024,544 | <p>I am close to figuring out this problem but am hung on one one thing in particular. I am trying to pair/zip together elements in a list pair by pair, and then checking which value is greater. I just can't figure out how to pair these elements without repeating values. </p>
<pre><code>[35,10,5,3,1,26,15]
</code></pr... | 0 | 2016-10-13T15:00:10Z | 40,024,835 | <p>Even simpler:</p>
<pre><code>>>> l = [35,10,5,3,1,26,15]
>>> [l[i:i+2] for i in range(0, len(l)-1, 2)]
[[35, 10], [5, 3], [1, 26]]
</code></pre>
<p>This will cut off any odd-numbered elements of the list.</p>
| 1 | 2016-10-13T15:14:19Z | [
"python",
"indexing",
"pair"
] |
Optimize a transformation from a 2-dim numpy array with day of the year values (doy) into an array with date values | 40,024,548 | <p>Does anyone know how to optimize a transformation from a 2-dim numpy array with day of the year values (doy) into
an array with date values?
The function below works but unfortunately in an very inelegant way. I would be very happy if anyone has a good idea
how to avoid the loop over the 2-dim array which should ma... | 1 | 2016-10-13T15:00:13Z | 40,032,051 | <p>you can do this kind of thing</p>
<pre><code>offset = (datetime.datetime(2013, 9, 30) - datetime.datetime(2012, 12, 31)).days
yearlen = (datetime.datetime(2013, 1, 1) - datetime.datetime(2012, 1, 1)).days
doy[doy >= offset] -= yearlen
dates = np.datetime64('2013-01-01') + doy
</code></pre>
<p>but to extract YMD... | 0 | 2016-10-13T22:26:49Z | [
"python",
"arrays",
"datetime"
] |
Keras - Generator for large dataset of Images and Masks | 40,024,619 | <p>I'm trying to build a Model that has Images for both its Inputs and Outputs (masks).
Because of the size of the Dataset and my limited Memory, I tried using <a href="https://keras.io/preprocessing/image/" rel="nofollow">the Generator Approach introduced in the Keras Documentation</a>:</p>
<pre><code># Provide the s... | 1 | 2016-10-13T15:03:38Z | 40,025,498 | <p>You can user <code>itertools.izip()</code> to return an iterator instead of a list.</p>
<pre><code>itertools.izip(*iterables)
Make an iterator that aggregates elements from each of the iterables. Like zip() except that it returns an iterator instead of a list. Used for lock-step iteration over several iterables at... | 2 | 2016-10-13T15:44:54Z | [
"python",
"machine-learning",
"computer-vision",
"theano",
"keras"
] |
Logic to jump weekends Django/python | 40,024,627 | <p>I got this function. What I need is to make some changes in my model depending on the day. As my if statements shown below, if the "ddate" is today or tomorrow make some changes in my "pull_ins" column and set it up as "Ready to ship" but if is the day after tomorrow and the next day, set "Not yet". This is working ... | 0 | 2016-10-13T15:04:08Z | 40,025,448 | <p><a href="http://labix.org/python-dateutil#head-470fa22b2db72000d7abe698a5783a46b0731b57" rel="nofollow"><code>dateutil.rrule</code></a> is library you could leverage. To get the next weekday:</p>
<pre><code>from dateutil import rrule
next_weekday = rrule.rrule(rrule.DAILY, count=3, byweekday=(0, 1, 2, 3, 4), dtstar... | 1 | 2016-10-13T15:42:10Z | [
"python",
"django",
"python-2.7",
"datetime",
"weekday"
] |
Regular expression to match a specific pattern | 40,024,643 | <p>I have the following string:</p>
<pre><code>s = "<X> First <Y> Second"
</code></pre>
<p>and I can match any text right after <code><X></code> and <code><Y></code> (in this case "First" and "Second"). This is how I already did it:</p>
<pre><code>import re
s = "<X> First <Y> Seco... | 1 | 2016-10-13T15:04:39Z | 40,024,784 | <p>If you know which whitespace char to match, you can just add it to your expression.
If you want any whitespace to match, you can use \s</p>
<pre><code>pattern = r'\<([XxYy])\>([^\<]+)'
</code></pre>
<p>would then be</p>
<pre><code>pattern = r'\<([XxYy])\>\s([^\<]+)'
</code></pre>
<p>Always keep... | 1 | 2016-10-13T15:11:36Z | [
"python",
"regex"
] |
Regular expression to match a specific pattern | 40,024,643 | <p>I have the following string:</p>
<pre><code>s = "<X> First <Y> Second"
</code></pre>
<p>and I can match any text right after <code><X></code> and <code><Y></code> (in this case "First" and "Second"). This is how I already did it:</p>
<pre><code>import re
s = "<X> First <Y> Seco... | 1 | 2016-10-13T15:04:39Z | 40,024,857 | <p>Assuming that a the whitespace token to match is a single space character, the pattern is:</p>
<pre><code>pattern = r'([XxYy]) ([^ ]+)'
</code></pre>
| 1 | 2016-10-13T15:15:12Z | [
"python",
"regex"
] |
Regular expression to match a specific pattern | 40,024,643 | <p>I have the following string:</p>
<pre><code>s = "<X> First <Y> Second"
</code></pre>
<p>and I can match any text right after <code><X></code> and <code><Y></code> (in this case "First" and "Second"). This is how I already did it:</p>
<pre><code>import re
s = "<X> First <Y> Seco... | 1 | 2016-10-13T15:04:39Z | 40,024,973 | <p>How about something like: <code><?[XY]>? ([^<>XY$ ]+)</code></p>
<p>Example in javascript:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const re = /<?[... | 3 | 2016-10-13T15:19:38Z | [
"python",
"regex"
] |
Regular expression to match a specific pattern | 40,024,643 | <p>I have the following string:</p>
<pre><code>s = "<X> First <Y> Second"
</code></pre>
<p>and I can match any text right after <code><X></code> and <code><Y></code> (in this case "First" and "Second"). This is how I already did it:</p>
<pre><code>import re
s = "<X> First <Y> Seco... | 1 | 2016-10-13T15:04:39Z | 40,025,288 | <p>So i came up with this solution:</p>
<pre><code>pattern = r"([XxYy]) (.*?)(?= [XxYy] |$)"
</code></pre>
| 0 | 2016-10-13T15:34:37Z | [
"python",
"regex"
] |
if statment not responding (python) | 40,024,656 | <p>the if statement is not responding. I'm trying to get the <code>gcd(20,6)</code>
the program outputs: <code>gcd(20,6): 20=6(4) + -3</code>, I need it to be if the last number(-3) is less than 0 the the program should output <code>20=6(3) + 3</code>,but the if statement isn't responding. thanks</p>
<pre><code>rnumtu... | -1 | 2016-10-13T15:05:24Z | 40,024,774 | <p><code>z</code> is equal to <code>0</code>, so your <code>if</code> statements aren't doing anything.</p>
<p>Explanation in the code comments</p>
<pre><code>rnumtup = (20, 6)
if rnumtup[0] > rnumtup[1]:
x= rnumtup[1] #x = 20
y =rnumtup[0] #y = 6
w = x / y #w = 3
w = round(w) # Does nothing
z = x - (y*w) ... | 0 | 2016-10-13T15:11:11Z | [
"python"
] |
if statment not responding (python) | 40,024,656 | <p>the if statement is not responding. I'm trying to get the <code>gcd(20,6)</code>
the program outputs: <code>gcd(20,6): 20=6(4) + -3</code>, I need it to be if the last number(-3) is less than 0 the the program should output <code>20=6(3) + 3</code>,but the if statement isn't responding. thanks</p>
<pre><code>rnumtu... | -1 | 2016-10-13T15:05:24Z | 40,025,016 | <p>You would think that z cannot be 0 because of </p>
<pre><code>while z!=0:
</code></pre>
<p>but when your program reaches the statement</p>
<pre><code>z= round(z)
</code></pre>
<p>z can be 0 and you program checks only for strictly positive or negative numbers since 0>0 is false, a better gdc function would be <a... | 0 | 2016-10-13T15:21:38Z | [
"python"
] |
if statment not responding (python) | 40,024,656 | <p>the if statement is not responding. I'm trying to get the <code>gcd(20,6)</code>
the program outputs: <code>gcd(20,6): 20=6(4) + -3</code>, I need it to be if the last number(-3) is less than 0 the the program should output <code>20=6(3) + 3</code>,but the if statement isn't responding. thanks</p>
<pre><code>rnumtu... | -1 | 2016-10-13T15:05:24Z | 40,025,463 | <p>I figured out an alternative, thanks guys :)</p>
<pre><code>rnumtup = (20, 6)
if rnumtup[0] > rnumtup[1]:
x= rnumtup[1]
y =rnumtup[0]
w = x / y
w = round(w) # Does nothing
z = x - (y*w)
z = round(z)
if z< 0:
w = x / y
w = round(w)
w = w-1
z = x - (y*w)
z = round(z)
while z !... | 0 | 2016-10-13T15:42:55Z | [
"python"
] |
Pandas distinct count as a DataFrame | 40,024,666 | <p>Suppose I have a Pandas DataFrame called <code>df</code> with columns <code>a</code> and <code>b</code> and what I want is the number of distinct values of <code>b</code> per each <code>a</code>. I would do:</p>
<pre><code>distcounts = df.groupby('a')['b'].nunique()
</code></pre>
<p>which gives the desidered resul... | 2 | 2016-10-13T15:05:53Z | 40,024,699 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html" rel="nofollow"><code>reset_index</code></a>:</p>
<pre><code>distcounts = df.groupby('a')['b'].nunique().reset_index()
</code></pre>
<p>Sample:</p>
<pre><code>df = pd.DataFrame({'a':[7,8,8],
... | 4 | 2016-10-13T15:07:10Z | [
"python",
"sql",
"pandas",
"count",
"distinct"
] |
Pandas distinct count as a DataFrame | 40,024,666 | <p>Suppose I have a Pandas DataFrame called <code>df</code> with columns <code>a</code> and <code>b</code> and what I want is the number of distinct values of <code>b</code> per each <code>a</code>. I would do:</p>
<pre><code>distcounts = df.groupby('a')['b'].nunique()
</code></pre>
<p>which gives the desidered resul... | 2 | 2016-10-13T15:05:53Z | 40,024,829 | <p>Another alternative using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.agg.html" rel="nofollow"><code>Groupby.agg</code></a> instead:</p>
<pre><code>df.groupby('a', as_index=False).agg({'b': 'nunique'})
</code></pre>
| 3 | 2016-10-13T15:13:57Z | [
"python",
"sql",
"pandas",
"count",
"distinct"
] |
Possible to switch between python 2 and 3 in Sublime Text 3 build systems? (Windows) | 40,024,713 | <p>All my current coding has been in python 3, which I've installed via the Anaconda package. However I need to work on some code simultaneously in python 2. Is there a way I can add a build system in Sublime so I can switch between the two fluidly? I have both python 2 and 3 installed, however can't see a way of simpl... | 1 | 2016-10-13T15:08:12Z | 40,031,389 | <p>Specify the absolute path to the version of Python. For example, if Python version 3 is located at <code>/usr/bin/python3</code> and Python version 2 is located at <code>/usr/bin/python2</code>:</p>
<p>Python 3 Build Configuration:</p>
<pre><code>{
"cmd": ["/usr/bin/python3", "-u", "$file"],
"file_regex": ... | 0 | 2016-10-13T21:34:15Z | [
"python",
"sublimetext3"
] |
pandas slicing multiindex dataframe | 40,024,721 | <p>I want to slice a multi-index pandas dataframe</p>
<p>here is the code to obtain my test data: </p>
<pre><code>import pandas as pd
testdf = {
'Name': {
0: 'H', 1: 'H', 2: 'H', 3: 'H', 4: 'H'}, 'Division': {
0: 'C', 1: 'C', 2: 'C', 3: 'C', 4: 'C'}, 'EmployeeId': {
0: 14, 1: ... | 5 | 2016-10-13T15:08:27Z | 40,024,825 | <p>You can use:</p>
<pre><code>idx = pd.IndexSlice
df = testdf2.loc[:, idx[['sum', 'count'], 'A']]
print (df)
sum count
Provider A A
Employer Year Division Name EmployeeId PersonId
Z 2012 C ... | 4 | 2016-10-13T15:13:46Z | [
"python",
"pandas",
"pivot-table",
"data-manipulation",
"multi-index"
] |
pandas slicing multiindex dataframe | 40,024,721 | <p>I want to slice a multi-index pandas dataframe</p>
<p>here is the code to obtain my test data: </p>
<pre><code>import pandas as pd
testdf = {
'Name': {
0: 'H', 1: 'H', 2: 'H', 3: 'H', 4: 'H'}, 'Division': {
0: 'C', 1: 'C', 2: 'C', 3: 'C', 4: 'C'}, 'EmployeeId': {
0: 14, 1: ... | 5 | 2016-10-13T15:08:27Z | 40,024,904 | <p>Use <code>xs</code> for cross section</p>
<pre><code>testdf2.xs('A', axis=1, level=1)
</code></pre>
<p><a href="https://i.stack.imgur.com/nx1np.png"><img src="https://i.stack.imgur.com/nx1np.png" alt="enter image description here"></a></p>
<p>Or keep the column level with <code>drop_level=False</code></p>
<pre><... | 5 | 2016-10-13T15:17:13Z | [
"python",
"pandas",
"pivot-table",
"data-manipulation",
"multi-index"
] |
How to add more space in `__str__` method of Django model? | 40,024,769 | <p>I want to add more spaces to <code>__str__</code> method, but method cut off spaces to 1.</p>
<p>For example:</p>
<pre><code>class Spam(models.Model):
foo = models.IntegerField()
bar = models.IntegerField()
def __str__(self):
return 'more spaces {} {}!'.format(self.foo, self.bar)
</... | 1 | 2016-10-13T15:11:04Z | 40,024,838 | <p>If you use the print method it prints ok.</p>
<p>I guess you have a problem with html? Replace whitespaces with (but then it looks like crap in the shell) or try a more explicit representation in admin...</p>
<p>Or you could try wrapping the string in the <code><pre></code> tag</p>
| 0 | 2016-10-13T15:14:29Z | [
"python",
"django"
] |
How to add more space in `__str__` method of Django model? | 40,024,769 | <p>I want to add more spaces to <code>__str__</code> method, but method cut off spaces to 1.</p>
<p>For example:</p>
<pre><code>class Spam(models.Model):
foo = models.IntegerField()
bar = models.IntegerField()
def __str__(self):
return 'more spaces {} {}!'.format(self.foo, self.bar)
</... | 1 | 2016-10-13T15:11:04Z | 40,025,355 | <p>I am not familiar with django, but you are checking the results at web-page, indeed.</p>
<p>So full answer for your question will be:
You should use special HTML symbols for HTML-page to indent your second part of text. You can check special symbols here: <a href="http://www.wikihow.com/Insert-Spaces-in-HTML" rel="... | 0 | 2016-10-13T15:37:38Z | [
"python",
"django"
] |
Developing a scatter plot in Python using Turtle | 40,024,789 | <p>I am working on the "How to think like a computer scientist" course, and am stuck on this question:</p>
<p>Interpret the data file labdata.txt such that each line contains a an x,y coordinate pair. Write a function called plotRegression that reads the data from this file and uses a turtle to plot those points and a... | -1 | 2016-10-13T15:11:45Z | 40,033,773 | <p>I think your turtle graphics is a secondary issue -- you're not reading your data in correctly. You're tossing all but the last x, y pair. And <code>map()</code> isn't your friend here as you'll want to index the result inside <code>plotRegression()</code>. Also you're accessing <code>plot_data</code> directly in ... | 0 | 2016-10-14T02:02:22Z | [
"python",
"plot",
"statistics",
"turtle-graphics",
"introduction"
] |
What is regex for website domain to use in tokenizing while keeping punctuation apart from words? | 40,024,874 | <p>This is normal output:
<a href="https://i.stack.imgur.com/fFfnQ.png" rel="nofollow"><img src="https://i.stack.imgur.com/fFfnQ.png" alt="enter image description here"></a></p>
<p>What I want is to keep domain names as single tokens. For ex: "<a href="https://www.twitter.com" rel="nofollow">https://www.twitter.com</... | 1 | 2016-10-13T15:15:58Z | 40,025,011 | <p>Use a 'standard' domain regex</p>
<pre><code>import re
line="My website: http://www.cartoon.com is not accessible."
print(re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', line))
</code></pre>
<p>Returns: ['<a href="http://www.cartoon.com" rel="nofollow">http://www.ca... | 0 | 2016-10-13T15:21:24Z | [
"python",
"regex",
"nltk",
"tokenize"
] |
What is regex for website domain to use in tokenizing while keeping punctuation apart from words? | 40,024,874 | <p>This is normal output:
<a href="https://i.stack.imgur.com/fFfnQ.png" rel="nofollow"><img src="https://i.stack.imgur.com/fFfnQ.png" alt="enter image description here"></a></p>
<p>What I want is to keep domain names as single tokens. For ex: "<a href="https://www.twitter.com" rel="nofollow">https://www.twitter.com</... | 1 | 2016-10-13T15:15:58Z | 40,025,530 | <p>You may use</p>
<pre><code>tokeniser=RegexpTokenizer(r'\b(?:http|ftp)s?://\S*\w|\w+|[^\w\s]+')
</code></pre>
<p>See the <a href="https://regex101.com/r/HazY6N/1" rel="nofollow">regex demo</a></p>
<p><strong>Details</strong>:</p>
<ul>
<li><code>\b</code> - leading word boundary (there must be a non-word char befo... | 2 | 2016-10-13T15:46:23Z | [
"python",
"regex",
"nltk",
"tokenize"
] |
how to export a dictionary into a csv file in python | 40,024,925 | <p>I have a very big dictionary and want to export into a text or csv file in such a way that keys would be in the first column and values in the 2nd column.
could anyone help to do so?</p>
| -5 | 2016-10-13T15:18:01Z | 40,025,105 | <p>Simply iterate through the dictionary and output:</p>
<pre><code>with open 'my_csv.csv' as f:
for k, v in my_dict.items(): # or iteritems in python 2
f.write("%s,%s\n" % (k, v)) # or whatever format code of your data types
</code></pre>
| 0 | 2016-10-13T15:25:39Z | [
"python"
] |
Is there a way to overlay figures or to get figure handles in bokeh, python | 40,024,952 | <p>I created two figures with bokeh and python wich are plotted side by side, then I created another two figures. These are now plotted underneath the first two. What I want is to replace the first two with the new ones. Is there a way to clear the old ones and overlay them with the new ones or at least to get their h... | 0 | 2016-10-13T15:18:55Z | 40,079,664 | <p>I found the answer. For this simple example one needs to add</p>
<pre><code>curdoc().clear()
</code></pre>
<p>before the second <code>curdoc().add_root(column(p))</code></p>
<p>If you want to do it while keeping buttons or other features alive (because clear deletes everything) here is an example how to deal with... | 0 | 2016-10-17T06:20:06Z | [
"python",
"bokeh",
"figure"
] |
Keras: how to set learning phase after model loading | 40,025,013 | <p>I faced with problem when I try to train pre-trained model loaded from json config + weights file.</p>
<p>I use following code (simplified):</p>
<pre><code>from keras.utils.layer_utils import layer_from_config
with open("config.json", "rb") as f:
config = json.loads(f.read())
model = layer_from_config(... | 0 | 2016-10-13T15:21:29Z | 40,045,129 | <p>Let me answer to this question by myself.</p>
<p>This issue is related only to keras 1.0.0 version and it was fixed in 1.0.2. So code snippet above is perfectly work on newer version of keras, no need to explicitly set learning phase. </p>
<p>More details in <a href="https://github.com/fchollet/keras/issues/2281" ... | 0 | 2016-10-14T14:03:11Z | [
"python",
"theano",
"keras"
] |
How to get number of dimensions in OneHotEncoder in Scikit-learn | 40,025,102 | <p>I am using the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html" rel="nofollow"><code>OneHotEncoder</code></a> from Scikit-learn in my project. And I need to know what would be the size of each one-hot vector when the <code>n_value</code> is set to be <code>auto</cod... | 1 | 2016-10-13T15:25:36Z | 40,026,253 | <p>Is this what you are looking for?</p>
<pre><code>>>> encoder.active_features_
array([1, 3, 5])
>>> len(encoder.active_features_)
3
</code></pre>
| 1 | 2016-10-13T16:22:41Z | [
"python",
"machine-learning",
"scikit-learn",
"one-hot-encoding"
] |
How to get number of dimensions in OneHotEncoder in Scikit-learn | 40,025,102 | <p>I am using the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html" rel="nofollow"><code>OneHotEncoder</code></a> from Scikit-learn in my project. And I need to know what would be the size of each one-hot vector when the <code>n_value</code> is set to be <code>auto</cod... | 1 | 2016-10-13T15:25:36Z | 40,028,873 | <p>I think the better solution is to define the vector size in <code>n_values</code>. Because the automatic option creates odd behavior with missing features comparing to out of range feature numbers. Trying this example again, it produces zero vector for missing numbers:</p>
<pre><code>from sklearn.preprocessing impo... | 0 | 2016-10-13T18:57:33Z | [
"python",
"machine-learning",
"scikit-learn",
"one-hot-encoding"
] |
VisualStudio django.conf.urls | 40,025,208 | <p>This is my first question ever. I am working in VisualStudio to create a django/python application for smartshopping AI. This is also my first python/django technology application. I have trouble with the urls.py and have read that django versions do not include urlpatterns. I've changed my url patterns to reflect t... | 0 | 2016-10-13T15:30:58Z | 40,025,805 | <p>You don't need to change your views. The problem is still in your urls.py. Instead of referring to eg <code>"app.views.home"</code> as a string, you need to import the view and refer to <code>views.home</code> directly.</p>
| 0 | 2016-10-13T16:00:27Z | [
"python",
"django",
"django-urls"
] |
VisualStudio django.conf.urls | 40,025,208 | <p>This is my first question ever. I am working in VisualStudio to create a django/python application for smartshopping AI. This is also my first python/django technology application. I have trouble with the urls.py and have read that django versions do not include urlpatterns. I've changed my url patterns to reflect t... | 0 | 2016-10-13T15:30:58Z | 40,029,342 | <p>After learning more about the Django framework from this youtube tutorial I was able to fix my code (<a href="https://www.youtube.com/watch?v=nAn1KpPlN2w&index=3&list=PL6gx4Cwl9DGBlmzzFcLgDhKTTfNLfX1IK#t=4.759461" rel="nofollow">https://www.youtube.com/watch?v=nAn1KpPlN2w&index=3&list=PL6gx4Cwl9DGBlm... | 0 | 2016-10-13T19:26:19Z | [
"python",
"django",
"django-urls"
] |
Given only source file, what files does it import? | 40,025,238 | <p>I'm building a dependency graph in python3 using the <code>ast</code> module. How do I know what file(s) will be imported if that import statement were to be executed?</p>
| 3 | 2016-10-13T15:32:05Z | 40,025,403 | <p>Not a complete answer, but here are some bits you should be aware of:</p>
<ul>
<li>Imports might happen in conditional or try-catch blocks. So depending on a setting of an environment variable, module A might or might not import module B.</li>
<li>There's a wide variety of import syntax: <code>import A</code>, <cod... | 1 | 2016-10-13T15:40:03Z | [
"python",
"python-3.x",
"python-import",
"abstract-syntax-tree"
] |
Given only source file, what files does it import? | 40,025,238 | <p>I'm building a dependency graph in python3 using the <code>ast</code> module. How do I know what file(s) will be imported if that import statement were to be executed?</p>
| 3 | 2016-10-13T15:32:05Z | 40,040,710 | <p>As suggested in a comment: the other answers are valid, but one of the fundamental problems is that your examples only work for 'simple' scripts or files: A lot of more complex code will use things like dynamic imports: consider the following:</p>
<pre><code>path, task_name = "module.function".rsplit(".", 1);
modul... | 0 | 2016-10-14T10:17:07Z | [
"python",
"python-3.x",
"python-import",
"abstract-syntax-tree"
] |
Inherit from scikit-learn's LassoCV model | 40,025,406 | <p>I tried to extend scikit-learn's RidgeCV model using inheritance:</p>
<pre><code>from sklearn.linear_model import RidgeCV, LassoCV
class Extended(RidgeCV):
def __init__(self, *args, **kwargs):
super(Extended, self).__init__(*args, **kwargs)
def example(self):
print 'Foo'
x = [[1,0],[2,0]... | 1 | 2016-10-13T15:40:12Z | 40,027,200 | <p>You probably want to make scikit-learn compatible model, to use it further with available scikit-learn functional. If you do - you need to read this first:
<a href="http://scikit-learn.org/stable/developers/contributing.html#rolling-your-own-estimator" rel="nofollow">http://scikit-learn.org/stable/developers/contrib... | 1 | 2016-10-13T17:16:59Z | [
"python",
"scikit-learn"
] |
Python Threading With Excel Com Object | 40,025,495 | <p>I am trying to open a workbook using a pre-opened excel com object within a python thread. Using the below code:</p>
<pre><code>from multiprocessing import Process, Queue
def open_workbook(excel,iSub_Loc,q):
p = Process(target = open_workbook_helper, args = (excel,iSub_Loc))
p.daemon = True
p.start()
... | 1 | 2016-10-13T15:44:32Z | 40,026,072 | <p>"multiprocessing" is not "threading" - Use <code>from threading import Thread, Queue</code> instead.
WHat happnes is that for inter-process comunication the dtaa is serialized to make the calls to the code on the other process, and COM objects use system resources that are not serializable.</p>
<p>If the operations... | 0 | 2016-10-13T16:13:04Z | [
"python",
"excel",
"multithreading",
"com-object"
] |
multithreading from a tkinter app | 40,025,616 | <p>I have a tkinter application that runs on the main thread. After receiving some input from the user, a new thread is created to perform functions in a separate class. The main thread continues to a Toplevel progress window. </p>
<p>My question is, how can I communicate to the main thread when the second thread has ... | 2 | 2016-10-13T15:51:14Z | 40,025,789 | <p>I'm not too familiar with tkinter so i can't show you ze code, but you should look at tkinter's event system, particularly firing custom events.</p>
<p><a href="http://stackoverflow.com/questions/270648/tkinter-invoke-event-in-main-loop">This question</a> may help you get started</p>
| 2 | 2016-10-13T15:59:41Z | [
"python",
"multithreading",
"tkinter",
"python-3.4"
] |
multithreading from a tkinter app | 40,025,616 | <p>I have a tkinter application that runs on the main thread. After receiving some input from the user, a new thread is created to perform functions in a separate class. The main thread continues to a Toplevel progress window. </p>
<p>My question is, how can I communicate to the main thread when the second thread has ... | 2 | 2016-10-13T15:51:14Z | 40,025,975 | <p>You can use <code>Queue</code>, from <code>Queue</code> module.</p>
<pre><code>def get_queue(self, queue):
status = queue.get()
if status:
self.do_your_action()
self.master.after(1000, self.get_queue)
</code></pre>
<p>And in the progress bar window, You pass queue and put something in it when p... | 1 | 2016-10-13T16:08:36Z | [
"python",
"multithreading",
"tkinter",
"python-3.4"
] |
looking for API to scan formated textfiles for specific information | 40,025,724 | <p>I have a a bunch of textfiles formated like this:</p>
<p>material Material.138_39BE7F6A_c.bmp.002
{
receive_shadows on </p>
<pre><code>technique
{
pass Material.138_39BE7F6A_c.bmp.002
{
ambient 0.800000011920929 0.800000011920929 0.800000011920929 1.0
diffuse 0.6400000190734865 0.64000... | 0 | 2016-10-13T15:56:18Z | 40,025,804 | <p>Since your input data actually has a <em>structure</em> and is constructed and can be parsed based on some <em>rules</em>. There are a number of parsers to choose from:</p>
<ul>
<li><a href="http://pyparsing.wikispaces.com/" rel="nofollow"><code>pyparsing</code></a></li>
<li><a href="http://www.dabeaz.com/ply/ply.h... | 0 | 2016-10-13T16:00:21Z | [
"python",
"scanning",
"data-extraction"
] |
After installation of vtk with brew (macosx): "import vtk" aborts python console | 40,025,812 | <p>I tried to install vtk with homebrew but, now when I <code>import vtk</code> on Python, my python session is aborted...</p>
<p>I work on MacOSX and I ran this line:</p>
<pre><code>brew install vtk --with-qt --with-python --with-pyqt
</code></pre>
<p>It returns:</p>
<pre class="lang-none prettyprint-override"><co... | 0 | 2016-10-13T16:00:49Z | 40,026,809 | <p>I am currently updating to vtk/7.0.0_5 (used 7.0.0_3 before), the line I used to install it was :</p>
<pre><code>brew install vtk --with-qt --with-qt5 --with-python
</code></pre>
<p>And I did not get any issue using it in python (2.7).</p>
<p>Ok - So just finished to do the upgrade to 7.0.0_5 and I got the same ... | 0 | 2016-10-13T16:51:45Z | [
"python",
"osx",
"homebrew",
"vtk",
"failed-installation"
] |
Can't use sympy parser in my class; TypeError : 'module' object is not callable | 40,025,837 | <p>I wrote some code for calculating the differential equation and it's solution using sympy, but I'm getting an error, my code : ( example )</p>
<pre><code>from sympy.parsing import sympy_parser
expr=1/2
r='3/2'
r=sympy_parser(r)
</code></pre>
<p>I get </p>
<pre><code>TypeError: 'module' object is not callable
</co... | 2 | 2016-10-13T16:01:58Z | 40,025,910 | <p><code>sympy_parser</code> is a <em>module</em>, and modules are not a <em>callable</em>. What you want is <a href="http://docs.sympy.org/dev/modules/parsing.html" rel="nofollow"><code>sympy_parser.parse_expr</code></a>:</p>
<pre><code>>>> from sympy.parsing import sympy_parser
>>> r ='3/2'
>>... | 2 | 2016-10-13T16:04:53Z | [
"python",
"python-3.x",
"sympy"
] |
Problems when pandas reading Excel file that has blank top row and left column | 40,026,020 | <p>I tried to read an Excel file that looks like below,
<a href="https://i.stack.imgur.com/vD3Di.png" rel="nofollow"><img src="https://i.stack.imgur.com/vD3Di.png" alt="enter image description here"></a></p>
<p>I was using pandas like this</p>
<pre><code>xls = pd.ExcelFile(file_path)
assets = xls.parse(sheetname="Sh... | 1 | 2016-10-13T16:10:50Z | 40,030,423 | <p>The <code>read_excel</code> <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html" rel="nofollow">documentation</a> is not clear on a point.</p>
<ul>
<li><code>skiprows=1</code> to skip the first empty row at the top of the file or <code>header=1</code> also works to use the second r... | 0 | 2016-10-13T20:30:51Z | [
"python",
"python-3.x",
"pandas"
] |
Find filenames in folders and match up to an Excel table | 40,026,117 | <p>I need to extract file names (drawing numbers) from a given folder and subfolders. Then I need to cross-reference the list of found drawing numbers against an Excel file that contains a list of drawing numbers and corresponding drawing descriptions. The output needs to be an Excel table with two columns, for the dra... | 0 | 2016-10-13T16:15:57Z | 40,026,500 | <p><code>walk</code> from the <code>os</code> module is probably going to be helpful, as is the <code>csv</code> module for making files excel can read. Without more details, I can only give you a rough skeleton. In the following, <code>root</code> is the top-level directory that contains all the directories you want... | 2 | 2016-10-13T16:34:28Z | [
"python",
"excel",
"windows"
] |
Importing CherryPy fails on openshift | 40,026,173 | <p>I'm running a cherrypy based app on an openshift gear. Recently I've been getting a "503 service temporarily unavailable" error whenever I try to go to the site. Inspecting the logs, I see I'm getting an ImportError where I try to import CherryPy. This is strange - CherryPy is listed as a dependency in my requiremen... | 0 | 2016-10-13T16:18:17Z | 40,030,040 | <p>I use the app.py entry point for Openshift. Here are several examples on how I start my server using the pyramid framework on Openshift. I use waitress as the server but I have also used the cherrypy wsgi server. Just comment out the code you don't want.</p>
<p><strong>app.py</strong></p>
<pre><code>#Openshift ... | 1 | 2016-10-13T20:09:07Z | [
"python",
"python-2.7",
"openshift",
"cherrypy"
] |
Is there a function in python to get the size of an arbitrary precision number? | 40,026,200 | <p>I'm working on a cryptographic scheme in python, so I use arbitrary precision numbers (<code>long</code>) all the time. I'm using python 2.7.</p>
<p>My problem is that I need to get the most significant two bytes (16 bits) of a number and check if they are the padding I inserted. I've tried <code>sys.getsizeof()</c... | 1 | 2016-10-13T16:20:02Z | 40,026,256 | <p>This should do it for you:</p>
<pre><code>>>> n = 1 << 1000
>>> n.bit_length()
1001
>>> n >> (n.bit_length() - 16)
32768L
</code></pre>
| 2 | 2016-10-13T16:23:01Z | [
"python",
"arbitrary-precision"
] |
Is there a function in python to get the size of an arbitrary precision number? | 40,026,200 | <p>I'm working on a cryptographic scheme in python, so I use arbitrary precision numbers (<code>long</code>) all the time. I'm using python 2.7.</p>
<p>My problem is that I need to get the most significant two bytes (16 bits) of a number and check if they are the padding I inserted. I've tried <code>sys.getsizeof()</c... | 1 | 2016-10-13T16:20:02Z | 40,026,284 | <p>Use <code>long.bit_length()</code>. E.g.:</p>
<pre><code>% long.bit_length(1024L)
11
</code></pre>
<p>Or:</p>
<pre><code>% 1024L.bit_length()
11
</code></pre>
<p>To get the first 2 bytes, assuming "first" means "least significant", use modulo 16:</p>
<pre><code>x = 123456789
x % 2**16
52501
</code></pre>
| 1 | 2016-10-13T16:24:41Z | [
"python",
"arbitrary-precision"
] |
python3.5 not opening a .py file | 40,026,247 | <p>Hello im having trouble opening a .py file using processes call in python 3.5.
ive have opened other files for example a text file using this method but with .py files it seems to just skip the command. Here is my code :</p>
<p><code>import subprocess
subprocess.call(['C:\\Users\\Edvin\\AppData\\Local\\Programs\\Py... | 0 | 2016-10-13T16:22:24Z | 40,026,504 | <p>Try to use run instead of call, and you had a typo in your path.</p>
<pre><code>subprocess.run(['C:\\Users\\Edvin\\AppData\\Local\\Programs\\Python\\Python35-32\\python.exe', 'C:\\Users\\Edvin\\Desktop\\test.py'])
</code></pre>
| 1 | 2016-10-13T16:34:33Z | [
"python",
"subprocess"
] |
Sort list of strings with data in the middle of them | 40,026,332 | <p>So I have a list of strings which correlates to kibana indices, the strings look like this: </p>
<pre><code>λ curl '10.10.43.210:9200/_cat/indices?v'
health status index pri rep docs.count docs.deleted store.size pri.store.size
yellow open filebeat-2016.10.08 5 1 899 0 913.... | 1 | 2016-10-13T16:26:57Z | 40,026,532 | <p>Is it what you need?</p>
<pre><code>lines = """yellow open filebeat-2016.10.08 5 1 899 0 913.8kb 913.8kb
yellow open filebeat-2016.10.12 5 1 902 0 763.9kb 763.9kb
yellow open filebeat-2016.10.13 5 1 816 0 588.9kb 5... | 1 | 2016-10-13T16:36:31Z | [
"python",
"sorting"
] |
Sort list of strings with data in the middle of them | 40,026,332 | <p>So I have a list of strings which correlates to kibana indices, the strings look like this: </p>
<pre><code>λ curl '10.10.43.210:9200/_cat/indices?v'
health status index pri rep docs.count docs.deleted store.size pri.store.size
yellow open filebeat-2016.10.08 5 1 899 0 913.... | 1 | 2016-10-13T16:26:57Z | 40,027,212 | <p>I copied your sample data into a text file as UTF-8 since I don't have access to the server you referenced. Using list comprehensions and string methods you can clean the data then break it down into its component parts. Sorting is accomplished by passing a lambda function as an argument to the builtin sorted() meth... | 0 | 2016-10-13T17:17:37Z | [
"python",
"sorting"
] |
Joining Dataframes on DatetimeIndex by Seconds and Minutes for NaNs | 40,026,441 | <p>I'm looking for a good way to align dataframes each having a timestamp that "includes" seconds without loosing data. Specifically, my problem looks as follows:</p>
<p>Here <code>d1</code> is my "main" dataframe.</p>
<pre><code>ind1 = pd.date_range("20120101", "20120102",freq='S')[1:20]
data1 = np.random.randn(le... | 0 | 2016-10-13T16:32:13Z | 40,026,898 | <p>Use the DateTimeIndex attribute <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.minute.html" rel="nofollow"><code>.minute</code></a> to perform grouping and later fill the missing values with it's mean across each group(every minute):</p>
<pre><code>df['0'] = df.groupby(df.index.... | 0 | 2016-10-13T16:57:18Z | [
"python",
"pandas",
"datetimeindex",
"datetime64"
] |
Python SQLite removes/escapes part of regular expression pattern in user defined function | 40,026,570 | <p>I did a simple replace implementation for regular expressions in python sqlite3:</p>
<pre><code>import sqlite3, re
db = sqlite3.connect(':memory:')
c = db.cursor()
c.executescript("""
create table t2 (n REAL, v TEXT, t TEXT);
insert into t2 VALUES (6, "F", "ef");
insert into t2 VALUES (1, "A", "aa");
insert into t... | 0 | 2016-10-13T16:38:47Z | 40,028,549 | <p>You must tell <a href="https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.create_function" rel="nofollow">create_function()</a> how many parameters the function has.</p>
<p>Your <code>preg_replace</code> will be used if the SQL calls <code>replace()</code> with one parameter.</p>
| 0 | 2016-10-13T18:38:51Z | [
"python",
"sqlite",
"sqlite3"
] |
How to identify if __iter__ is called by dict or list? | 40,026,579 | <p>What I understand is <code>__iter__</code> method makes an object iterable. If it yields a pair, it produces a dictionary if called with <code>dict</code>. Now, if I want to create
class that creates a list of values if called with <code>list</code> and creates a dict if
called with <code>dict</code>, how to do that... | 1 | 2016-10-13T16:39:29Z | 40,026,656 | <p>This isn't specifically what you want to do, but I'm not sure that what you want to do is that necessary. Let me know if it is-- though I'm not sure it's possible. In the meantime:</p>
<p><code>list_data = [val for key,val in list(data)]</code></p>
<p>Also what Blender said. That was really my first inclination, b... | 0 | 2016-10-13T16:44:38Z | [
"python"
] |
How to identify if __iter__ is called by dict or list? | 40,026,579 | <p>What I understand is <code>__iter__</code> method makes an object iterable. If it yields a pair, it produces a dictionary if called with <code>dict</code>. Now, if I want to create
class that creates a list of values if called with <code>list</code> and creates a dict if
called with <code>dict</code>, how to do that... | 1 | 2016-10-13T16:39:29Z | 40,026,697 | <p>I think you have to do it manually with something like a list comprehension</p>
<pre><code>[v for k, v in data]
</code></pre>
| 1 | 2016-10-13T16:46:30Z | [
"python"
] |
How to identify if __iter__ is called by dict or list? | 40,026,579 | <p>What I understand is <code>__iter__</code> method makes an object iterable. If it yields a pair, it produces a dictionary if called with <code>dict</code>. Now, if I want to create
class that creates a list of values if called with <code>list</code> and creates a dict if
called with <code>dict</code>, how to do that... | 1 | 2016-10-13T16:39:29Z | 40,027,115 | <p>This is a terrible idea! But you can try reading the calling line to see if the explicit <code>list</code> constructor was calling using the <code>inspect</code> module. Note that this only works when the <code>list</code> constructor is called and will probably produce unexpected results when the regex matches some... | 1 | 2016-10-13T17:11:57Z | [
"python"
] |
Use scrapy with selenium for dynamic pages | 40,026,586 | <p>I want to crawl this pages for all the exibitors:</p>
<p><a href="https://greenbuildexpo.com/Attendee/Expohall/Exhibitors" rel="nofollow">https://greenbuildexpo.com/Attendee/Expohall/Exhibitors</a></p>
<p>But scrapy doesn't load the content, what I'm doing now it using selenium to load the page and search the link... | 1 | 2016-10-13T16:40:13Z | 40,026,713 | <p>You don't need <code>selenium</code> for that, there is an XHR request to get all exhibitors, simulate it, demo from the <a href="https://doc.scrapy.org/en/latest/topics/shell.html" rel="nofollow">Scrapy Shell</a>:</p>
<pre><code>$ scrapy shell https://greenbuildexpo.com/Attendee/Expohall/Exhibitors
In [1]: fetch("... | 3 | 2016-10-13T16:47:31Z | [
"python",
"selenium",
"xpath",
"scrapy"
] |
How to stop script if user inputs certain characters - PYTHON | 40,026,651 | <p>I'm a beginner in programming and I'm creating a roll the dice type of game. And I want to create a command in which if the user types in Exit, the whole script would print bye and stop. I tried something like:</p>
<pre><code>commandLine = "Exit"
if commandLine == "Exit".
print ("Bye!")
quit()
</code></pre... | 0 | 2016-10-13T16:44:18Z | 40,026,906 | <p>try:</p>
<pre><code>while again == "yes":
dice = input("Press 'x' to roll the dice!\n")
if dice == "x":
print(random.randint(1, 9))
if dice == "no":
print("See you later!")
quit()
</code></pre>
| 1 | 2016-10-13T16:57:44Z | [
"python"
] |
How to stop script if user inputs certain characters - PYTHON | 40,026,651 | <p>I'm a beginner in programming and I'm creating a roll the dice type of game. And I want to create a command in which if the user types in Exit, the whole script would print bye and stop. I tried something like:</p>
<pre><code>commandLine = "Exit"
if commandLine == "Exit".
print ("Bye!")
quit()
</code></pre... | 0 | 2016-10-13T16:44:18Z | 40,026,983 | <pre><code>again = input("Sweet ! Would you like to try again?\n")
while again == "Yes".lower():
dice = input("Press 'x' to roll the dice!\n")
if dice == "X".lower():
print(random.randint(1, 9))
again = input("Sweet ! Would you like to try again?\n")
if again == "No".lower():
print("See you ... | 0 | 2016-10-13T17:03:32Z | [
"python"
] |
Arrow colour quiver plot - Python | 40,026,718 | <p>I am plotting an arrow graph and my code uses an external file as follows:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from pylab import rcParams
data=np.loadtxt(r'data.dat')
x = data[:,0]
y = data[:,1]
u = data[:,2]
v = data[:,3]
plt.quiver(x, y, u, v, angles=... | 1 | 2016-10-13T16:48:02Z | 40,026,959 | <p>This probably do the trick:</p>
<pre><code>plt.quiver(x, y, u, v, np.arctan2(v, u), angles='xy', scale_units='xy', scale=1, pivot='mid',color='g')
</code></pre>
<p>Note that the fifth's argument of <code>plt.quiver</code> is a color.
<a href="https://i.stack.imgur.com/Nc5mK.png" rel="nofollow"><img src="https://i.... | 3 | 2016-10-13T17:01:45Z | [
"python",
"arrays",
"matplotlib",
"plot",
"arrow"
] |
3D surface plot from a .dat file | 40,026,758 | <p>Hi I am trying to do a 3D surface plot in python by plotting from a .dat file. I am having quite some trouble. I finally have a code that does not produce any error messages, however the plot displays nothing, even though the .dat file is not empty. My code is below. </p>
<p>How can I plot my data from a .dat fi... | 0 | 2016-10-13T16:49:38Z | 40,048,917 | <p>My guess is that your problem comes down to a rather trivial mistake you're making with <code>np.linspace</code> that I didn't notice when I commented. The third argument of <code>np.linspace</code> is the number of points in the array, not the spacing between points (that would be <code>np.arange</code>).</p>
<p>I... | 1 | 2016-10-14T17:32:05Z | [
"python",
"matplotlib",
"plot"
] |
Load preset directory in Maya with python/MEL? | 40,026,880 | <p>I have a folder where I'm storing some maya presets (specifically nCloth presets) and I would like to make this directory available to all of the users on my current network. To do this, I would like to have this folder added to the MAYA_PRESET_PATH on startup. However, I am not able to create/modify the maya.env fi... | 0 | 2016-10-13T16:56:21Z | 40,041,458 | <p>in your maya.env: </p>
<pre><code>CUSTOM_BASE_PATH = C:\MayaResource #your custom env
MAYA_PRESET_PATH = %CUSTOM_BASE_PATH%\preset;%CUSTOM_BASE_PATH%\plugins;
</code></pre>
| 0 | 2016-10-14T10:55:26Z | [
"python",
"maya",
"mel",
"pymel"
] |
Data Scraping a Locally Stored HTML File - using Python | 40,026,885 | <p>I have a big Excel file, and in each cell I have various HTML content containing comments made by a database user. The content in each cell is unique and varying in length. I need to get rid of all HTML syntax/tags so that I can upload this content to a database table. How can I scrape this data using Python (or Ja... | 0 | 2016-10-13T16:56:44Z | 40,031,131 | <p>In a terminal, <code>pip install bs4</code>. Then you can extract the text with python like so:</p>
<pre><code>import bs4
for cell in [
'<html>The indicator lights on the control cabinet&nbsp;are to be replaced with 24Vdc&nbsp;LED\'s. 3 Red &amp;&nbsp;3 Green.</html>',
'<html... | 0 | 2016-10-13T21:16:08Z | [
"java",
"python",
"html",
"web-scraping"
] |
Python "list index out of range" other rule works | 40,026,900 | <p>I have tried to make a script to read out a csv file and determine some information.</p>
<p>Now I receive an error: </p>
<pre><code>Traceback (most recent call last):
File "/home/pi/vullijst/vullijst.py", line 26, in <module>
startdate = datetime.datetime.strptime (row[0],"%d-%m-%Y")
IndexError: list i... | 1 | 2016-10-13T16:57:23Z | 40,064,126 | <p>Your csv file appears to have an empty line at the end, after the last row with real data. So your script reads all the real lines and processes them, but it breaks when the last line is parsed into an empty list. The <code>row[0]</code> you're trying to parse into a date isn't valid in that situation.</p>
<p>To av... | 0 | 2016-10-15T20:56:08Z | [
"python"
] |
Python Version (sys.version) Meaning? | 40,026,902 | <p>I've hit what should be a basic question... but my googles are failing me and I need a sanity check. </p>
<p>If I run the following in my Python shell:</p>
<pre><code>>>> import sys
>>> sys.version
</code></pre>
<p>from two different Python environments, I get:</p>
<pre><code>'2.7.8 (default, ... | 1 | 2016-10-13T16:57:31Z | 40,026,927 | <p>All you need to compare is the first bit, the 2.7.8 string.</p>
<p>The differences you see are due to the <em>compiler</em> used to build the binary, and when the binary was built. That shouldn't really make a difference here.</p>
<p>The string is comprised of information you can find in machine-readable form else... | 5 | 2016-10-13T16:58:58Z | [
"python"
] |
Python - REGEX issue with RE using function re.compile + search | 40,026,923 | <p>I'm using regex library 're' in Python (2.7) to validate a flight number.</p>
<p>I've had no issues with expected outputs using a really helpful online editor here: <a href="http://regexr.com/" rel="nofollow">http://regexr.com/</a></p>
<p>My results on regexr.com are: <a href="http://imgur.com/nB0QDug" rel="nofoll... | 0 | 2016-10-13T16:58:44Z | 40,027,046 | <p>Python's <code>re.compile</code> is treating your leading <code>/</code> and trailing <code>/g</code> as part of the regular expression, not as delimiters and modifiers. This produces a compiled RE that will never match anything, since you have <code>^</code> with stuff before it and <code>$</code> with stuff after... | 1 | 2016-10-13T17:08:15Z | [
"python",
"regex",
"if-statement"
] |
Python: Connecting list values with array values | 40,026,930 | <p>I have created a tornado plot taking inspiration from <a href="http://stackoverflow.com/questions/32132773/a-tornado-chart-and-p10-p90-in-python-matplotlib">here</a>. It has input variables labelled on the y-axis (a1,b1,c1...) and their respective correlation coefficients plotted next to them. See pic below:</p>
<p... | 0 | 2016-10-13T16:59:21Z | 40,028,171 | <p>use build-in zip function - returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. But aware the returned list is truncated in length to the length of the shortest argument sequence.</p>
| 0 | 2016-10-13T18:16:24Z | [
"python",
"python-2.7",
"matplotlib"
] |
scikit- DBSCAN giving error on clustering (x.y) co-ordinate points | 40,027,042 | <p>I am trying to computer ORB descriptors for an image and cluster them <em>spatially</em>. I was trying to use DBSCAN in scikit</p>
<pre><code>detector = cv2.ORB(500)
orb_kp = detector.detect(gray,None)
# compute the descriptors with ORB
kps, descs = detector.compute(gray, orb_kp)
img2 = cv2.drawKeypoints(gray,kps,c... | 0 | 2016-10-13T17:07:56Z | 40,028,389 | <p>OK posting an answer for anyone who has the same issue:</p>
<p><code>pts = (p.pt for p in kps)</code> is incorrect</p>
<p>it should be:
<code>pts = [p.pt for p in kps]</code></p>
<p>Silly me!</p>
| 0 | 2016-10-13T18:29:15Z | [
"python",
"scikit-learn"
] |
Aborted connection error in flask | 40,027,108 | <p>If the client closes an established connection that it has made with the <em>flask</em> server, I get the following error in the terminal: </p>
<pre><code>[Errno 10053] An established connection was aborted by the software in your host machine
</code></pre>
<p>It seems when <em>flask</em> tries to write in the cl... | 2 | 2016-10-13T17:11:19Z | 40,027,326 | <p>The cause of this problem is, as we previously discussed, insufficient permissions to perform the network operation. The remedy to the problem was to run the process as an administrator and/or to modify the system policy to allow connections on the restricted port.</p>
| 2 | 2016-10-13T17:24:46Z | [
"python",
"flask",
"flask-restful"
] |
URL parameters with GET request in django | 40,027,119 | <p>guys. I'm passing parameters via GET requests to my view. But it seems that django is not properly handling my URL.</p>
<p>With parameters longer than one char, it works, but if I use a single char, I get Page not found (404) error.</p>
<p>Example:</p>
<p><strong>Works:</strong> <a href="http://localhost:8000/my_... | 0 | 2016-10-13T17:12:17Z | 40,027,353 | <p>Remove dot from regex string <code>r'^my_url/(?P<username>\w+)/$'</code></p>
| 2 | 2016-10-13T17:26:08Z | [
"python",
"regex",
"django"
] |
python subprocess module hangs for spark-submit command when writing STDOUT | 40,027,207 | <p>I have a python script that is used to submit spark jobs using the spark-submit tool. I want to execute the command and write the output both to STDOUT and a logfile in real time. i'm using python 2.7 on a ubuntu server.</p>
<p>This is what I have so far in my SubmitJob.py script</p>
<pre><code>#!/usr/bin/python
... | 0 | 2016-10-13T17:17:09Z | 40,046,887 | <p>Figured out what the problem was.
I was trying to redirect both stdout n stderr to pipe to display on screen. This seems to block the stdout when stderr is present. If I remove the stderr=stdout argument from Popen, it works fine. So for spark-submit it looks like you don't need to redirect stderr explicitly as it ... | 0 | 2016-10-14T15:29:52Z | [
"python",
"linux",
"python-2.7",
"apache-spark",
"subprocess"
] |
How to connect PyQt signal to external function | 40,027,221 | <p>How does one connect a pyqt button signal in one file, to a function in another python file? I've tried various things, but nothing seems to work.
This is the first file:</p>
<pre><code>from PyQt4 import QtGui
from PyQt4.QtGui import QMainWindow
from MainUIFile import Ui_Main
from pythonfile import myOutsideFunctio... | 0 | 2016-10-13T17:18:06Z | 40,027,367 | <p>You are currently making a call to <code>myOutsideFunction</code> and passing the result to the <code>connect</code> function, which expects a callable as an argument. </p>
<p>Remove the parenthesis from <code>myOutsideFunction</code> in the connect call</p>
<pre><code>self.btn.clicked.connect(myOutsideFunction)
<... | 2 | 2016-10-13T17:26:58Z | [
"python",
"windows",
"file",
"pyqt"
] |
How to connect PyQt signal to external function | 40,027,221 | <p>How does one connect a pyqt button signal in one file, to a function in another python file? I've tried various things, but nothing seems to work.
This is the first file:</p>
<pre><code>from PyQt4 import QtGui
from PyQt4.QtGui import QMainWindow
from MainUIFile import Ui_Main
from pythonfile import myOutsideFunctio... | 0 | 2016-10-13T17:18:06Z | 40,031,710 | <p>What is the importance of connecting to a function outside of your code? Could you not just do something like this:</p>
<pre><code>def myOutsideFunction(a,b,c,d):
#process variables/objects a,b,c,d as you wish
return answer
from PyQt4 import QtGui
from PyQt4.QtGui import QMainWindow
from MainUIFile import... | 0 | 2016-10-13T21:59:01Z | [
"python",
"windows",
"file",
"pyqt"
] |
access pandas axes by axis number | 40,027,233 | <p>consider the <code>pd.Panel</code> <code>pn</code> and <code>pd.DataFrame</code> <code>df</code></p>
<pre><code>import pandas as pd
import numpy as np
pn = pd.Panel(np.arange(27).reshape(3, 3, 3), list('XYZ'), list('abc'), list('ABC'))
pn.to_frame().rename_axis('item', 1).unstack()
</code></pre>
<p><a href="http... | 2 | 2016-10-13T17:19:08Z | 40,029,515 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Panel.axes.html" rel="nofollow"><code>.axes</code></a> to return a list of the index axis labels as well as the column axis labels and then you could access it via slice-notation.</p>
<pre><code>pn.axes
#[Index(['X', 'Y', 'Z'], dtype='object'... | 2 | 2016-10-13T19:37:24Z | [
"python",
"pandas"
] |
Django Across All Apps | 40,027,239 | <p>I am creating a rather large django project which will require two things. 1) I need a few template files to be accessible across all apps. 2) I need a model to be accessible across all apps. How do I go about doing that? </p>
<p>As far as the templates are concerned, it seems adding it to the TEMPLATES directi... | 0 | 2016-10-13T17:19:24Z | 40,028,159 | <p>Was able to work it out with this work around.</p>
<pre><code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR + '/templates'],
'APP_DIRS': True,
'OPTIONS': {
[.... | 0 | 2016-10-13T18:15:46Z | [
"python",
"django"
] |
Installed Python 3.5.2 (64bit) however can't open python | 40,027,272 | <p>I have installed Python 3.5.2 (64bit) however once I had installed it I couldn't find a link to open python and I couldn't find it on the program files. Is there a way to open it on the run command or how do I open it?</p>
<p>I am using a 64bit AMD processsor and Windows 7 home basic 64 bit</p>
<p>Kind Regards</p>... | -2 | 2016-10-13T17:21:54Z | 40,027,535 | <p><strong>Windows</strong></p>
<p>Default location on Windows <code>C:\Python</code>
You can open cmd type <code>python</code> SHELL opens immediatly
If python command not recognized you can add python location: <code>C:\Python</code> to <code>PATH</code> Environment variable
Then reopen cmd type <code>python</cod... | 0 | 2016-10-13T17:36:50Z | [
"python"
] |
Can a python unittest class add an assert statement for each test method in a parent class? | 40,027,324 | <p>I have a unit test class that is a sub-class of python's <code>unittest</code>:</p>
<pre><code>import unittest
class MyTestClass(unittest.TestCase):
run_parameters = {param1: 'on'}
def someTest(self):
self.assertEquals(something, something_else)
</code></pre>
<p>Now I want to create a child class ... | 0 | 2016-10-13T17:24:39Z | 40,029,718 | <p>Yes there is but it may not be a good idea because:</p>
<ul>
<li>assertions are hidden behind difficult to understand python magic</li>
<li>assertions aren't explicit</li>
</ul>
<p>Could you update your methods to reflect the new contract, and expected param?</p>
<p>Also if a single parameter change breaks a huge... | 0 | 2016-10-13T19:49:59Z | [
"python",
"unit-testing",
"oop"
] |
same code diferent output in different pcs with python 3.5 | 40,027,392 | <p>I have this code:</p>
<pre><code>import gc
def hacerciclo():
l=[0]
l[0]=l
recolector=gc.collect()
print("Garbage collector %d" % recolector)
for i in range (10):
hacerciclo()
recolector=gc.collect()
print("Garbage collector %d" % recolector)
</code></pre>
<p>This is an example code to the use of gc.... | 2 | 2016-10-13T17:28:47Z | 40,027,843 | <blockquote>
<p>The current version of Python uses reference counting to keep track of allocated memory. Each object in Python has a reference count which indicates how many objects are pointing to it. When this reference count reaches zero the object is freed. This works well for most programs. However, there is one... | 2 | 2016-10-13T17:56:30Z | [
"python",
"python-3.x"
] |
Python Tornado BadYieldError for POST request with timeout | 40,027,394 | <p>I'm trying to write a post request for a Python Tornado server that sleeps for a second before sending a response back to a client. The server must handle many of these post requests per minute. The following code doesn't work because of <code>BadYieldError: yielded unknown object <generator object get at 0x10d0b... | -1 | 2016-10-13T17:28:52Z | 40,027,711 | <p>Either use callbacks or "yield", not both. So you could do:</p>
<pre><code>@asynchronous
def post(self):
IOLoop.instance().add_timeout(time.time() + 1, self._process)
def _process(self):
self.write("{}")
self.finish()
</code></pre>
<p>Or, better:</p>
<pre><code>@gen.coroutine
def post(self):
yiel... | 1 | 2016-10-13T17:47:31Z | [
"python",
"tornado",
"yield"
] |
How to get my network adapter IP with python? | 40,027,402 | <p>If I type "ipconfig" in cmd, its gives some IPs... I need the one who belongs to my network adapter\internal IP.
So. for example:
If I have 3 Ips:</p>
<pre><code>10.100.102.2
192.168.231.1
192.168.233.1
</code></pre>
<p>And I need the first one. How do I make python know that this is the one I need\The one belongs... | 0 | 2016-10-13T17:29:32Z | 40,028,077 | <p>The solution for extracting the first <strong>IPv4</strong> address of ethernet adapter (Python on Windows):<br>
- used modules: <code>os</code>, <code>re</code></p>
<pre><code>import os, re
addresses = os.popen('IPCONFIG | FINDSTR /R "Ethernet adapter Local Area Connection .* Address.*[0-9][0-9]*\.[0-9][0-9]*\.[0... | 0 | 2016-10-13T18:09:48Z | [
"python"
] |
Pandas: Select data between Sunday 23:00-Friday 23:00 (1 year span) | 40,027,447 | <p>I have the timeseries of Euro-US Dollar Exchange Rate at minute granularity spanning the entire 2015 year, including non-trading days (ex.weekends) where the timeseries value get repeated for the entire non-trading period.</p>
<p>I need to discard such periods by selecting only the data between Sunday 23:00 pm and ... | 1 | 2016-10-13T17:32:23Z | 40,029,237 | <p>consider the <code>pd.DataFrame</code> <code>df</code> and <code>pd.tseries.index.DatetimeIndex</code> <code>tidx</code></p>
<pre><code>tidx = pd.date_range('2010-01-01', '2011-01-01', freq='H')
df = pd.DataFrame(np.ones((tidx.shape[0], 2)), tidx, columns=list('AB'))
</code></pre>
<p>we can construct a series of v... | 1 | 2016-10-13T19:19:47Z | [
"python",
"datetime",
"pandas",
"time-series",
"datetimeindex"
] |
Scraping Javascript using Selenium via Python | 40,027,455 | <p>I'm trying to scrape javascript data from a site. Currently I'm given myself the challenge of trying to scrape the number of Followers from <a href="http://freelegalconsultancy.blogspot.co.uk/" rel="nofollow">this website</a>. Here's my code so far: </p>
<pre><code>import os
from selenium import webdriver
import ti... | 0 | 2016-10-13T17:32:50Z | 40,027,551 | <p><code>find_element_by_class_name</code> is a function but you're not calling it, you're just asking for a reference to the function. The output you get is the stringified version of that function reference.
<hr>
<strong>Update:</strong> Your error tells you what's wrong towards the bottom:</p>
<pre><code>NoSuchElem... | 0 | 2016-10-13T17:37:48Z | [
"javascript",
"python",
"selenium"
] |
Scraping Javascript using Selenium via Python | 40,027,455 | <p>I'm trying to scrape javascript data from a site. Currently I'm given myself the challenge of trying to scrape the number of Followers from <a href="http://freelegalconsultancy.blogspot.co.uk/" rel="nofollow">this website</a>. Here's my code so far: </p>
<pre><code>import os
from selenium import webdriver
import ti... | 0 | 2016-10-13T17:32:50Z | 40,027,589 | <p>You need to provide the class name you're looking for as a parameter.</p>
<p><code>title = driver.find_element_by_class_name("TheNameOfTheClass")</code></p>
| 0 | 2016-10-13T17:40:07Z | [
"javascript",
"python",
"selenium"
] |
How to install a python package named figures | 40,027,486 | <p>I am trying to run an <a href="http://toblerity.org/shapely/code/polygon.py" rel="nofollow">example code</a>, but an exception No module named figures is thrown. I google how to install the figures package, but there is no clue how to do it except the example code as shown above. If you know how to install it, pleas... | -1 | 2016-10-13T17:34:02Z | 40,027,570 | <p>The code you linked is all from a package called <code>shapely</code>. None of it uses a module named <code>figures</code>. The reason the word figure is used on the page is because figure is another word for diagram</p>
| 0 | 2016-10-13T17:39:17Z | [
"python",
"anaconda",
"figures"
] |
Pulling Cuisine Type from TripAdvisor Restaurants using Python | 40,027,492 | <p>I am currently trying to pull data from TripAdvisor Restaurant from different countries. The fields I am trying to pull is name, address, and cuisine type (chinese, steakhouse, etc.). I have successfully been able to pull name and address using my script; however, pulling cuisine type is proving pretty difficult for... | 0 | 2016-10-13T17:34:28Z | 40,031,849 | <p>This approach is not especially elegant but might be acceptable to you. I notice that the information you want seems to be repeated under the 'Details' tab for 'Cuisine'. I've found it easier to access there this way.</p>
<pre><code>>>> import requests
>>> from bs4 import BeautifulSoup
>>>... | 0 | 2016-10-13T22:08:47Z | [
"python",
"python-2.7",
"web-scraping",
"beautifulsoup"
] |
Apply a function to pandas dataframe and get different sized ndarray output | 40,027,612 | <p>My goal is to get the indexes of the local max heights of a dataframe. These change between 3 and 5 per column.</p>
<p>I have tried using the apply function, but get either the error <code>Shape of passed values is (736, 4), indices imply (736, 480)</code> or <code>could not broadcast input array from shape (0) int... | 1 | 2016-10-13T17:41:17Z | 40,029,290 | <p>pandas is trying to do "something" with the arrays. You can short circuit that "something" by wrapping your <code>lambda</code>'s return value in a <code>pd.Series</code></p>
<p>Try this:</p>
<pre><code>df.apply(lambda x: pd.Series(peakutils.indexes(x, thres=0.02/max(x), min_dist=100)))
</code></pre>
| 2 | 2016-10-13T19:23:00Z | [
"python",
"python-3.x",
"pandas",
"scipy"
] |
subprocess.Popen process stdout returning empty? | 40,027,670 | <p>I have this python code</p>
<pre><code>input()
print('spam')
</code></pre>
<p>saved as <code>ex1.py</code></p>
<p>in interactive shell</p>
<pre><code>>>>from subprocess import Popen ,PIPE
>>>a=Popen(['python.exe','ex1.py'],stdout=PIPE,stdin=PIPE)
>>> a.communicate()
(b'', None)
>... | 0 | 2016-10-13T17:44:52Z | 40,027,736 | <p>What you're looking for is <code>subprocess.check_output</code></p>
| 0 | 2016-10-13T17:49:28Z | [
"python",
"python-3.x",
"subprocess"
] |
subprocess.Popen process stdout returning empty? | 40,027,670 | <p>I have this python code</p>
<pre><code>input()
print('spam')
</code></pre>
<p>saved as <code>ex1.py</code></p>
<p>in interactive shell</p>
<pre><code>>>>from subprocess import Popen ,PIPE
>>>a=Popen(['python.exe','ex1.py'],stdout=PIPE,stdin=PIPE)
>>> a.communicate()
(b'', None)
>... | 0 | 2016-10-13T17:44:52Z | 40,027,747 | <p>Input expects a whole line, but your input is empty. So there is only an exception written to <code>stderr</code> and nothing to <code>stdout</code>. At least provide a newline as input:</p>
<pre><code>>>> a = Popen(['python3', 'ex1.py'], stdout=PIPE, stdin=PIPE)
>>> a.communicate(b'\n')
(b'spam\n... | 1 | 2016-10-13T17:50:02Z | [
"python",
"python-3.x",
"subprocess"
] |
Can't install Selenium WebDriver with Python | 40,027,675 | <p>I am trying to install Selenium WebDriver with Python on my Mac. I used this command:</p>
<pre><code>sudo easy_install selenium
</code></pre>
<p>After that, I tried the following simple test:</p>
<p>python</p>
<pre><code>from selenium import webdriver
driver = webdriver.Firefox()
</code></pre>
<p>And I got the ... | 2 | 2016-10-13T17:45:13Z | 40,027,920 | <p>If you call a selenium driver without any arguments, the path to the webdriver executable must be in the system PATH environment variables.</p>
<p>Alternatively, you can specify the path explicitly as such:</p>
<pre><code>driver = webdriver.Firefox("path/to/the/FireFoxExecutable")
</code></pre>
| 1 | 2016-10-13T18:00:34Z | [
"python",
"selenium-webdriver"
] |
AbstractUser Login View | 40,027,694 | <p>I've spent a couple of days on this, read the docs, read some Two Scoops info, and I'm missing something. I'm trying to make a view to log in an AbstractUser. The AbstractUser model is in <code>my_app</code> and the view is in an app called <code>mainsite</code>, that I use to store project-wide views.</p>
<p>After... | 0 | 2016-10-13T17:46:29Z | 40,043,592 | <p>I found an answer (with help from reddit) in the docs.</p>
<p><a href="https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms" rel="nofollow">When you use AbstractUser, you need to create your own UserCreationForm and UserChangeForm.</a> If you use AbstractBaseUser,... | 1 | 2016-10-14T12:49:02Z | [
"python",
"django"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.