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
listlengths
1
5
How to remove multiple selections from a listbox
38,296,715
<p>I got this code that put in the variable ativo what is selected in the listbox</p> <pre><code>def selecionado(evt): global ativo a=evt.widget b=a.curselection() if len(b) &gt; 0: ativo=[a.get(i) for i in a.curselection()] else: ativo=[] </code></pre> <p>How can i create a function that...
-1
2016-07-10T21:43:07Z
38,306,539
<p>Just use yourlistboxname.delete(index)</p> <pre><code>def removeclicked(evt): w = evt.widget index = int(w.curselection()[0]) label = w.get(index) yourlistboxname.delete(index) </code></pre> <p>To bind the evt, add this where you create the widget</p> <pre><code>yourlistboxname.bind('&lt;&lt;ListboxSelect&gt;&gt;...
0
2016-07-11T12:07:03Z
[ "python", "tkinter", "listbox" ]
Making a module with classes accessible as a direct child of the imported module
38,296,748
<p>So I'm making a module that will be have classes that will be accessible globally, and I am having an issue with how they are called.</p> <p>Let's call my module <code>jacks_lib</code>. In it, there is a file called <code>website_export</code> with a class named <code>ExportFromWebsite</code></p> <p>The following ...
0
2016-07-10T21:49:13Z
38,296,894
<p>I just figured this out after toying around:</p> <p>In the file <code>__init__.py</code> you have to put in <code>from file_name import ClassName</code></p> <p>In my case, I would make <code>__init__.py</code> contain:</p> <pre><code>from website_import import ExportFromWebsite </code></pre>
0
2016-07-10T22:12:37Z
[ "python", "python-3.5" ]
Making a module with classes accessible as a direct child of the imported module
38,296,748
<p>So I'm making a module that will be have classes that will be accessible globally, and I am having an issue with how they are called.</p> <p>Let's call my module <code>jacks_lib</code>. In it, there is a file called <code>website_export</code> with a class named <code>ExportFromWebsite</code></p> <p>The following ...
0
2016-07-10T21:49:13Z
38,296,914
<p>In your module, you have an <code>__init__.py</code> file.</p> <p>In it, you can put something like</p> <pre><code>from website_export import ExportFromWebsite </code></pre> <p>This should let you do what you want</p>
1
2016-07-10T22:16:35Z
[ "python", "python-3.5" ]
Python Google Maps API not returning the same time as Google Maps website
38,296,767
<p>I'm trying to use the Google Maps API to extract the time required to drive between two locations, but the URL request doesn't seem to match the results from the Google Maps website.</p> <p>For example, if I write a url that I expect to give me the time between Los Angeles and San Diego, and copy the following link...
0
2016-07-10T21:52:02Z
38,334,706
<p>You shouldn't expect the Web Services API and the Google Maps website to work in the exact same way. These are different products managed by different teams at Google. The search stack is also different, so results may differ.</p> <p>Please refer to this <a href="http://stackoverflow.com/questions/38310559/google-m...
0
2016-07-12T16:43:04Z
[ "python", "google-maps", "matrix", "match", "distance" ]
Dictionaries, for loop, and python
38,296,808
<pre><code>fhand = open('mail.txt') days = dict() for line in fhand: split = line.split() if line.startswith('From') and len(split) &gt; 2: days[str(split[2])] = days.get(str([split[2]]), 0) + 1 else: continue print days </code></pre> <p>And this is the output: </p> <pre><code>{'Fri': 1,...
0
2016-07-10T21:58:47Z
38,296,945
<p>is there a typo here? <code>days.get(str([split[2]]), 0)</code> shouldn't it be <code>days.get(str(split[2]), 0)?</code></p>
1
2016-07-10T22:21:29Z
[ "python", "loops" ]
Can't use submit() with Selenium (Python)
38,296,844
<p>I have used <code>driver.find_element_by_id('SearchProductName')</code> to find the element with the following HTML:</p> <pre><code>&lt;input autocomplete="off" name="SearchProductName" id="SearchProductName" class="sg-input headerSearchBox ac_input" placeholder="Search for a product" tabindex="0"&gt; </code></pre...
-3
2016-07-10T22:03:48Z
38,297,132
<p><code>.submit()</code> is intended for controls that are inside of a <code>FORM</code>. It's a shortcut way to submit the form without clicking the Submit button. It looks like in your case the <code>INPUT</code> is not inside a <code>FORM</code> tag, thus the error message. I don't know what your page looks like bu...
3
2016-07-10T22:50:40Z
[ "python", "forms", "selenium" ]
Trouble extending scipy.stats.multivariate_normal [__init__() takes from 1 to 2 positional arguments]
38,296,867
<p>I'm trying to extend a base class (<a href="http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.multivariate_normal.html" rel="nofollow">scipy.stats.multivariate_normal</a>) but I'm having some difficulty with calling <code>super</code>'s <code>__init__</code>:</p> <pre><code>from scipy.stats imp...
0
2016-07-10T22:08:50Z
38,296,931
<p>You're trying to subclass <code>multivariate_normal</code>, but it isn't a class, it's an instance of a class that has defined a <code>__call__</code> method:</p> <pre><code>In [24]: isinstance(multivariate_normal, scipy.stats._multivariate.multivariate_normal_gen) Out[24]: True </code></pre> <p>You'll have to sub...
3
2016-07-10T22:19:43Z
[ "python", "inheritance", "scipy", "arguments", "super" ]
python pandas binning numerical range
38,296,949
<p>I have a reqt., where I want to bin a numeric value</p> <pre><code>If the student marks is b/w 0-50 (incl 50) then assign the level column value = "L" b/w 50-75(incl. 75) then assign the level column value ="M" &gt;75 then assign the level column value ="H" </code></pre> <p>Here is what I have got </p> <pre><co...
1
2016-07-10T22:22:44Z
38,296,995
<p>Try this: </p> <pre><code> bins = [0,50,75,101] or bins = [0,50,75,np.inf] </code></pre>
2
2016-07-10T22:29:52Z
[ "python", "pandas", "numeric", "binning" ]
python pandas binning numerical range
38,296,949
<p>I have a reqt., where I want to bin a numeric value</p> <pre><code>If the student marks is b/w 0-50 (incl 50) then assign the level column value = "L" b/w 50-75(incl. 75) then assign the level column value ="M" &gt;75 then assign the level column value ="H" </code></pre> <p>Here is what I have got </p> <pre><co...
1
2016-07-10T22:22:44Z
38,296,998
<p>Just define the upper bound as the best possible mark:</p> <pre><code>bins = [0, 50, 75, 100] </code></pre> <p>The result is as you expect:</p> <pre><code> student marks_maths maths_level 0 A 75 M 1 B 90 H 2 C 99 H </code></pre>
0
2016-07-10T22:30:06Z
[ "python", "pandas", "numeric", "binning" ]
python pandas binning numerical range
38,296,949
<p>I have a reqt., where I want to bin a numeric value</p> <pre><code>If the student marks is b/w 0-50 (incl 50) then assign the level column value = "L" b/w 50-75(incl. 75) then assign the level column value ="M" &gt;75 then assign the level column value ="H" </code></pre> <p>Here is what I have got </p> <pre><co...
1
2016-07-10T22:22:44Z
38,298,015
<p>Hope this helps</p> <pre><code>import numpy as np import pandas as pd # 20 random numbers between 0 and 100 scores = np.random.randint(0,100,20) df = pd.DataFrame(scores, columns=['scores']) bins = [0,50,75, np.inf] df['binned_scores'] = pd.cut(df.scores, bins=[0,50,75, np.inf], include_lowest=False, right=True)...
1
2016-07-11T01:35:52Z
[ "python", "pandas", "numeric", "binning" ]
Override QSpinBox.stepby method make spinbox only increment
38,296,986
<p>I want to override the stepBy method of QSpinBox in pyqt5 in order to force verifications before the value is changed. But with my code when I click on the "increase" button of the spinbox, all goes well, but the "decrease" button doesn't seem to work... Why only this one ?</p> <p>Here is the code :</p> <pre><code...
0
2016-07-10T22:28:47Z
38,303,177
<p>You are overriding <code>stepBy</code>, and that mean it's up to you to change the value shown in the spinbox. In your code, the value does not change at all.</p> <p>Now, by default, the minimum value of the spinbox is 0. And at zero, the step down button is disabled. Hence, your clicking of step-down button does n...
0
2016-07-11T09:13:05Z
[ "python", "qt", "pyqt5" ]
Knowing when to create an instance of class over creating a subclass?
38,296,993
<p>I'm in the process of adding items to a text-based RPG I'm making. My classes look like this:</p> <pre><code>class Item(object): def __init__(self, name, value, description): self.name = name self.value = value self.description = description class Weapon(Item): def __init__(self, n...
2
2016-07-10T22:29:28Z
38,297,071
<p>In terms of code style, creating subclasses is better because it allows for a more dynamic code base so you can expand on it further. In addition, it makes your code more readable, and you can also add help messages/info text more easily. However, if, as you said, you only need to store the damage, there is not much...
0
2016-07-10T22:41:00Z
[ "python", "oop" ]
Knowing when to create an instance of class over creating a subclass?
38,296,993
<p>I'm in the process of adding items to a text-based RPG I'm making. My classes look like this:</p> <pre><code>class Item(object): def __init__(self, name, value, description): self.name = name self.value = value self.description = description class Weapon(Item): def __init__(self, n...
2
2016-07-10T22:29:28Z
38,297,089
<p>It all depends on if you want to add different variables to the newly created subclass. The danger will take on the weapon class with the name, value, damage, and description. I would have my different weapons have subclasses like longsword, sword, dagger, staff, etc. These would be for the different types of weapon...
0
2016-07-10T22:43:52Z
[ "python", "oop" ]
Knowing when to create an instance of class over creating a subclass?
38,296,993
<p>I'm in the process of adding items to a text-based RPG I'm making. My classes look like this:</p> <pre><code>class Item(object): def __init__(self, name, value, description): self.name = name self.value = value self.description = description class Weapon(Item): def __init__(self, n...
2
2016-07-10T22:29:28Z
38,297,097
<p>Use subclass when there is natural is-a relationship. </p> <p><strong>Don't use inheritance just to get code reuse</strong> </p> <p><strong>Don't use inheritance just to get polymorphism</strong></p> <p>In your example case Dagger is a Weapon, so it makes perfect sense to use sub class.</p> <p>You can get good r...
3
2016-07-10T22:45:35Z
[ "python", "oop" ]
What does this overflow error in python mean?
38,297,010
<p>The full error is: <code>OverflowError: timestamp too large to convert to C _PyTime_t</code></p> <p>I have no idea what this means, and have not been able to find it anywhere else online. I am new to python so it may be something really simple that I'm missing.</p> <p>The error is coming from this line of code wi...
0
2016-07-10T22:31:36Z
38,297,208
<p>Looks like this error happens in Python 3.5.0 like this issue here: <a href="https://bugs.python.org/issue25155" rel="nofollow">https://bugs.python.org/issue25155</a></p> <p>Check your Python version. If its 3.5.0 change for the newest version 3.5.2</p>
1
2016-07-10T23:03:30Z
[ "python", "python-3.x" ]
Inserting a Variable into Tkinter Listbox from Another Class
38,297,031
<p>I am trying to insert a variable named 'Variable A' from 'Class_A' class into a Listbox which is at another class named 'App(tk)'. Can anyone help me?</p> <p>The result should look like this:<a href="http://i.stack.imgur.com/omHlz.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/omHlz.jpg" alt="Ideal Result">...
0
2016-07-10T22:35:15Z
38,297,283
<p>You're getting a new window because your <code>class_A</code> instance creates a new <code>App</code> instance in <code>turnOn</code>. Probably you want to pass the existing <code>App</code> to the class at some point (either to the constuctor, or to <code>turnOn</code> itself).</p> <p>Here's a quick and dirty fix....
1
2016-07-10T23:18:08Z
[ "python", "python-3.x", "tkinter" ]
Create dataframe column using np.where or similar when criteria matches
38,297,060
<p>Im trying to create a dataframe column using np.where or similar when certain criteria matches as follows:</p> <p>This linked <a href="https://dl.dropboxusercontent.com/u/32282382/data_df" rel="nofollow">pickle file</a> is a segment of the data Im using. Here is the code I've used so far:</p> <pre><code>data = pd...
2
2016-07-10T22:39:49Z
38,409,779
<p>I think I heard once that pickled files shouldn't be shared amongst unknown/untrusted entities as it's not build to be a secure deserialization, so this is answer is just based on skimming your code.</p> <p>I think you get pandas.Series of inequal lengths, because your boolean creates a new pandas Series of length ...
0
2016-07-16T09:40:32Z
[ "python", "pandas" ]
Create dataframe column using np.where or similar when criteria matches
38,297,060
<p>Im trying to create a dataframe column using np.where or similar when certain criteria matches as follows:</p> <p>This linked <a href="https://dl.dropboxusercontent.com/u/32282382/data_df" rel="nofollow">pickle file</a> is a segment of the data Im using. Here is the code I've used so far:</p> <pre><code>data = pd...
2
2016-07-10T22:39:49Z
39,047,845
<p>If You have problem with lengths and could put data to same array, do it like here:...</p> <pre><code>&gt;&gt;&gt; a = pd.Series(np.arange(10)) &gt;&gt;&gt; b = pd.Series(np.arange(100,111)) &gt;&gt;&gt; df = pd.DataFrame([a,b]) &gt;&gt;&gt; df = df.T &gt;&gt;&gt; df.loc[4.5]=nan &gt;&gt;&gt; df.sort_index(inplace=...
0
2016-08-19T21:21:41Z
[ "python", "pandas" ]
Pickling pygame clock
38,297,095
<p>I am currently looking into implementing a save functionality to a small rpg I have made using the <code>shelve</code> module which uses <code>pickle</code>.</p> <p>After finding out I couldn't pickle pygame surfaces I followed advice suggesting passing a dictionary key instead as my object attribute. Once I had s...
0
2016-07-10T22:45:17Z
38,297,634
<p>I believe you may be attempting to address your problem in the wrong way. I would say that instead of attempting to serialize python objects directly, you should stick to only saving the data that you actually need in the form of dictionaries. </p> <p>I cannot think of a case when you would actually need to use mor...
1
2016-07-11T00:26:47Z
[ "python", "serialization", "pygame", "pickle", "pygame-clock" ]
Twitter streaming stop collecting data
38,297,150
<p>I've this following code that retrieves Twitter Streaming data and crete a JSON file. What I'd like to get is to stop the data collecting after fo eg.1000 tweets. How can I set the code?</p> <pre><code>#Import the necessary methods from tweepy library from tweepy.streaming import StreamListener from tweepy import O...
1
2016-07-10T22:53:58Z
38,341,413
<p>Here is a possible solution:</p> <pre><code>class StdOutListener(StreamListener): tweet_number=0 # class variable def __init__(self,max_tweets): self.max_tweets=max_tweets # max number of tweets def on_data(self, data): self.tweet_number+=1 try: tweet = json.l...
0
2016-07-13T01:49:38Z
[ "python", "api", "python-3.x", "twitter" ]
Twitter streaming stop collecting data
38,297,150
<p>I've this following code that retrieves Twitter Streaming data and crete a JSON file. What I'd like to get is to stop the data collecting after fo eg.1000 tweets. How can I set the code?</p> <pre><code>#Import the necessary methods from tweepy library from tweepy.streaming import StreamListener from tweepy import O...
1
2016-07-10T22:53:58Z
38,341,541
<p>This is the 2.7 code I would use -- sorry, I do not know 3.0 as well... I think you want what is is on my second line. .items(1000) part...?</p> <p>stackoverflow messed up my indentations in my code. I am also using tweepy.</p> <h2>CODE:</h2> <pre><code> results = [] for tweet in tweepy.Cursor(api.s...
0
2016-07-13T02:06:38Z
[ "python", "api", "python-3.x", "twitter" ]
Removing values in dataframe once threshold (min/max) value has been reached with Pandas
38,297,266
<p>I would like to make a filter for the entire dataframe, which includes many columns beyond column C. I'd like this filter to return values in each column once a minimum threshold value has been reached, and stop when a maximum threshold value has been reached. I'd like the min threshold to be 6.5 and the max to be 9...
3
2016-07-10T23:15:23Z
38,298,049
<p>Try this: </p> <pre><code>df A1 A2 A3 Time 1 6.305 6.191 5.918 2 6.507 6.991 6.203 3 6.407 6.901 6.908 4 6.963 7.127 7.116 5 7.227 7.330 7.363 6 7.445 7.632 7.575 7 7.710 7.837 7.663 8 8.904 8.971 8.895 9 9.394 9.194 8.994 1...
1
2016-07-11T01:42:50Z
[ "python", "numpy", "pandas" ]
Removing values in dataframe once threshold (min/max) value has been reached with Pandas
38,297,266
<p>I would like to make a filter for the entire dataframe, which includes many columns beyond column C. I'd like this filter to return values in each column once a minimum threshold value has been reached, and stop when a maximum threshold value has been reached. I'd like the min threshold to be 6.5 and the max to be 9...
3
2016-07-10T23:15:23Z
38,299,352
<p><strong>Implementation</strong></p> <p>Here's a vectorized approach using <a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#boolean-array-indexing" rel="nofollow"><code>NumPy boolean indexing</code></a> -</p> <pre><code># Extract values into an array arr = df.values # Determine the min,max l...
1
2016-07-11T04:49:57Z
[ "python", "numpy", "pandas" ]
Apply a for loop to multiple DataFrames in Pandas
38,297,292
<p>I have multiple DataFrames that I want to do the same thing too.</p> <p>First I create a list of the DataFrames. All of them have the same column called 'result'.</p> <pre><code>df_list = [df1,df2,df3] </code></pre> <p>I want to keep only the rows in all the DataFrames with value 'passed' so I use a for loop on m...
1
2016-07-10T23:20:03Z
38,297,645
<p>This is because every time you do a subset like this <code>df[&lt;whatever&gt;]</code> you are returning a new dataframe, and assigning it to the <code>df</code> looping variable, which gets obliterated each time you go to the next iteration (although you do keep the last one). This similar to slicing lists:</p> <p...
2
2016-07-11T00:28:44Z
[ "python", "pandas", "dataframe" ]
"hdf5.h" not found when installing Neon
38,297,302
<p>I'm trying to install Neon, a machine learning package (<a href="http://neon.nervanasys.com/docs/latest/installation.html" rel="nofollow">http://neon.nervanasys.com/docs/latest/installation.html</a>), after cloning the Github repository, cd'ing to the <code>neon</code> directory, and running the <code>make</code> co...
0
2016-07-10T23:21:14Z
38,297,508
<p>Following Evert's suggestion (and reading the instructions more carefully), I installed <code>libhdf5-dev</code> from a .deb file from <a href="http://packages.ubuntu.com/trusty/amd64/libhdf5-dev/download" rel="nofollow">http://packages.ubuntu.com/trusty/amd64/libhdf5-dev/download</a>. After this <code>neon</code> w...
0
2016-07-11T00:04:53Z
[ "python" ]
python .findall results into readable
38,297,403
<p>Need some help sorting the results from .findall in python to convert the results in some readable format. I have a snippet giving me following output</p> <pre><code>[('Jul 11 11:25:51', 'ul 11 11:25:51', '', '', ''), ('', '', 'u2k', '', ''), ('', '', '', 'CBDCS2.CTP', ''), ('Jul 11 11:25:52', 'ul 11 11:25:52', '',...
-2
2016-07-10T23:42:04Z
38,297,567
<p>Did you try formatting output that you already got?</p> <pre><code>p = re.compile(r'([J](\S+\W+\S+\W+\S+))|User=(\S\S+),|NetworkDeviceName=(\S\S+),|CmdAV=([^\&lt;]*)') results = re.findall(p,output) file4.write('\n'.join([' '.join([str(i) for i in row]) for row in results])) </code></pre>
-1
2016-07-11T00:15:16Z
[ "python", "list", "findall" ]
python .findall results into readable
38,297,403
<p>Need some help sorting the results from .findall in python to convert the results in some readable format. I have a snippet giving me following output</p> <pre><code>[('Jul 11 11:25:51', 'ul 11 11:25:51', '', '', ''), ('', '', 'u2k', '', ''), ('', '', '', 'CBDCS2.CTP', ''), ('Jul 11 11:25:52', 'ul 11 11:25:52', '',...
-2
2016-07-10T23:42:04Z
38,297,683
<p>This code:</p> <pre><code>line = [] for d in results: if d[0] != '': if len(line)&gt;0: print " ".join(line) line = [] for dx in d: if dx != '': line.append( dx ) if len(line)&gt;0: print " ".join(line) </code></pre> <p>produces this output when <code>res...
0
2016-07-11T00:37:04Z
[ "python", "list", "findall" ]
Python & Pandas: Set a random value to a column, based on conditions
38,297,428
<p>My dataframe look like this:</p> <p><a href="http://i.stack.imgur.com/12JTW.png" rel="nofollow"><img src="http://i.stack.imgur.com/12JTW.png" alt="enter image description here"></a></p> <p>I want to set the <code>speed</code> into a uniform random value between 0,1, if the <code>dir</code> is 999 and if 'speed' is...
0
2016-07-10T23:46:49Z
38,297,467
<p>You are "broadcasting" <code>np.random.uniform(0,1)</code> to all of the rows, meaning you're only calling <code>np.random.uniform(0,1)</code> once. This is why you always see the same number.</p> <p>You can update your dataframe based on your conditions like so:</p> <pre><code>In [46]: data = [{"dir":310, "speed...
1
2016-07-10T23:54:37Z
[ "python", "pandas" ]
Python & Pandas: Set a random value to a column, based on conditions
38,297,428
<p>My dataframe look like this:</p> <p><a href="http://i.stack.imgur.com/12JTW.png" rel="nofollow"><img src="http://i.stack.imgur.com/12JTW.png" alt="enter image description here"></a></p> <p>I want to set the <code>speed</code> into a uniform random value between 0,1, if the <code>dir</code> is 999 and if 'speed' is...
0
2016-07-10T23:46:49Z
38,297,506
<p>Alternatively, you can specify the <code>size</code> parameter in the <code>uniform</code> function to be equal to the number of rows that you are trying to modify:</p> <pre><code>ind = (df['dir'] == 999) &amp; (df['speed'] == 0) df.loc[ind, 'speed'] = np.random.uniform(0, 1, size = sum(ind)) </code></pre>
2
2016-07-11T00:04:34Z
[ "python", "pandas" ]
Python & Pandas: Set a random value to a column, based on conditions
38,297,428
<p>My dataframe look like this:</p> <p><a href="http://i.stack.imgur.com/12JTW.png" rel="nofollow"><img src="http://i.stack.imgur.com/12JTW.png" alt="enter image description here"></a></p> <p>I want to set the <code>speed</code> into a uniform random value between 0,1, if the <code>dir</code> is 999 and if 'speed' is...
0
2016-07-10T23:46:49Z
38,297,767
<pre><code>df['speed'] = np.where( (df['dir'] == 999) &amp; (df['speed'] == 0), np.random.uniform(0,1), df['speed']) </code></pre>
0
2016-07-11T00:52:47Z
[ "python", "pandas" ]
Pandas previous group min/max
38,297,700
<p>In Pandas I have dataset like this:</p> <pre><code> Value 2005-08-03 23:15:00 10.5 2005-08-03 23:30:00 10.0 2005-08-03 23:45:00 10.0 2005-08-04 00:00:00 10.5 2005-08-04 00:15:00 10.5 2005-08-04 00:30:00 11.0 2005-08-04 00:45:00 10.5 2005-08-04 01:00:00 11.0 ... 2005-08-04 23:15:0...
1
2016-07-11T00:41:33Z
38,297,943
<p>You could get the desired result by using <code>groupby/agg</code>, <code>shift</code> and <code>merge</code>:</p> <pre><code>import numpy as np import pandas as pd df = pd.DataFrame({'Value': [10.5, 10.0, 10.0, 10.5, 10.5, 11.0, 10.5, 11.0, 14.0, 13.5, 13.0, 13.5, 14.0, 14.0, 14.5]}, index=['2005-08-03 23:15:00', ...
1
2016-07-11T01:23:19Z
[ "python", "pandas" ]
Grey Level Co-Occurrence Matrix // Python
38,297,765
<p>I am trying to find the GLCM of an image using <em>greycomatrix</em> from <em>skimage</em>. I am having issues with the selection of levels. Since it's an 8-bit image, the obvious selection should be 256; however, if I select values such as 8 (for the purpose of binning and to prevent sparse matrices from forming), ...
0
2016-07-11T00:52:10Z
38,297,891
<p>The simplest way for binning 8-bits images is to divide each value by 32. Then each pixel value is going to be in [0,8[.</p> <p>Btw, more than avoiding sparse matrices (which are not really an issue), binning makes the GLCM more robust to noise.</p>
0
2016-07-11T01:13:06Z
[ "python", "image-processing", "scikit-image" ]
Matching JSON Keys
38,297,848
<p>When data come from JSON in the format below, I can turn it into a dictionary in <strong>Python</strong>. However, the information is not always in the same order. For instance, <code>first_name</code>, I would assume is always 0. However, when I get the data, depending on the form used, may be in the 2 position. So...
-1
2016-07-11T01:04:32Z
38,297,994
<p>Instead of relying on the order which, as you indicated, is fragile, you should actually look for the element which has the name you want by iterating on the array.</p> <p>For example:</p> <pre><code>data = { 'field_data' : [ { "name": "first_name", "values": [ "Joe" ...
2
2016-07-11T01:32:58Z
[ "python", "json" ]
Matching JSON Keys
38,297,848
<p>When data come from JSON in the format below, I can turn it into a dictionary in <strong>Python</strong>. However, the information is not always in the same order. For instance, <code>first_name</code>, I would assume is always 0. However, when I get the data, depending on the form used, may be in the 2 position. So...
-1
2016-07-11T01:04:32Z
38,298,026
<p>assuming</p> <pre><code>data = {"field_data":[{ "name": "first_name", "values": [ "Joe" ] }, { "name":"last_name", "values": [ "Example" ] }, { "name": "email", "values": [ "joe@example.com" ] }]} </code></pre> <p>This is fairly easy way to iterate over all of your fields and if you...
0
2016-07-11T01:37:34Z
[ "python", "json" ]
Pygame bullets not moving after being drawn
38,297,849
<p>I'm fairly new to python, and I can't figure out whats wrong. I'm trying to get a bullet to appear and move, but it won't do that, it's being stuck to the player. My code is kind of messy, but here it is:</p> <pre><code>screen = pygame.display.set_mode((512,512)) pygame.display.set_caption('The Necromancer') backg...
0
2016-07-11T01:04:51Z
38,304,899
<p>Sorry, but it's hard to help you with this problem because the code is a bit much and a little to messy. I cannot try it myself either without changing it, especially since you load many images that's on your computer. Try to make it more manageable so we easier can pinpoint the problem. You can follow these steps:<...
0
2016-07-11T10:41:04Z
[ "python", "pygame" ]
Udacity: Assignment 3: ValueError: bad input shape (1000, 10)
38,297,894
<p>I am working on <a href="https://www.udacity.com/course/viewer#!/c-ud730/l-6379031992/m-6598158989" rel="nofollow">Assignment 3: Regularization</a>. After taking a look into that <a href="https://github.com/shawpan/deep_learning_assignments/blob/master/3_regularization.ipynb" rel="nofollow">Github</a>, I tried to so...
1
2016-07-11T01:13:28Z
38,301,497
<p>You use one-hot encoding for train_labels. Meaning it has shape like [1000. 10], 1000 of samples and each has 10 'columns' with 1 indicating which class we are talking about. It is required for neural networks, but Logistics Regression from sklearn <a href="http://scikit-learn.org/stable/modules/generated/sklearn.li...
1
2016-07-11T07:36:56Z
[ "python", "machine-learning", "scikit-learn", "tensorflow", "deep-learning" ]
Udacity: Assignment 3: ValueError: bad input shape (1000, 10)
38,297,894
<p>I am working on <a href="https://www.udacity.com/course/viewer#!/c-ud730/l-6379031992/m-6598158989" rel="nofollow">Assignment 3: Regularization</a>. After taking a look into that <a href="https://github.com/shawpan/deep_learning_assignments/blob/master/3_regularization.ipynb" rel="nofollow">Github</a>, I tried to so...
1
2016-07-11T01:13:28Z
38,303,669
<p><a href="http://stackoverflow.com/users/3633250/maxim-haytovich">Maxim Haytovich</a> is right, the shape of your train_labels have changed, you should keep a copy of your train labels before reformatting it to <code>(20000, 10)</code>. Initially <code>train_labels</code> has a shape of <code>(20000,)</code> which is...
1
2016-07-11T09:37:54Z
[ "python", "machine-learning", "scikit-learn", "tensorflow", "deep-learning" ]
Why does unpacking a struct result in a tuple?
38,297,929
<p>After packing an integer in a Python struct, the unpacking results in a tuple even if it contains only one item. Why does unpacking return a tuple?</p> <pre><code>&gt;&gt;&gt; x = struct.pack("&gt;i",1) &gt;&gt;&gt; str(x) '\x00\x00\x00\x01' &gt;&gt;&gt; y = struct.unpack("&gt;i",x) &gt;&gt;&gt; y (1,) </code></...
4
2016-07-11T01:20:35Z
38,297,945
<p>Please see doc first <a href="https://docs.python.org/2/library/struct.html#functions-and-exceptions" rel="nofollow">struct doc</a></p> <blockquote> <p>struct.pack(fmt, v1, v2, ...)</p> <p>Return a string containing the values v1, v2, ... packed according to the given format. The arguments must match the...
4
2016-07-11T01:23:59Z
[ "python", "pack", "unpack" ]
Why does unpacking a struct result in a tuple?
38,297,929
<p>After packing an integer in a Python struct, the unpacking results in a tuple even if it contains only one item. Why does unpacking return a tuple?</p> <pre><code>&gt;&gt;&gt; x = struct.pack("&gt;i",1) &gt;&gt;&gt; str(x) '\x00\x00\x00\x01' &gt;&gt;&gt; y = struct.unpack("&gt;i",x) &gt;&gt;&gt; y (1,) </code></...
4
2016-07-11T01:20:35Z
38,298,042
<p>Think of a use case that loads binary data written using C language. Python won't be able to differentiate if binary data was written using a struct or using a single integer. So, I think, logically it makes sense to return tuple always, since struct pack and unpack perform conversions between Python values and C st...
1
2016-07-11T01:40:19Z
[ "python", "pack", "unpack" ]
python - not printing additional rows from json
38,297,984
<p>I have the below code but for some reason it's only writing the first row for car and ignoring every car after.</p> <p>edit - I tried putting a <code>print field</code> in the row after <code>for field in required_fields:</code> and for some reason it only shows the field when parsing the first row. Every addition...
0
2016-07-11T01:31:29Z
38,298,112
<p>The data in <code>car_list</code> is already structured as a list of dictionaries, why not use a <code>DictWriter</code> instead of this:</p> <pre><code>import csv fieldnames = ['Year', 'Make', 'Model', 'Description', 'Price'] f = csv.DictWriter(open('test.csv', 'wb+'), ...
0
2016-07-11T01:53:14Z
[ "python", "json", "python-2.7" ]
python - not printing additional rows from json
38,297,984
<p>I have the below code but for some reason it's only writing the first row for car and ignoring every car after.</p> <p>edit - I tried putting a <code>print field</code> in the row after <code>for field in required_fields:</code> and for some reason it only shows the field when parsing the first row. Every addition...
0
2016-07-11T01:31:29Z
38,298,145
<p>The reason this occurs is because of a combination of two things:</p> <ul> <li><p>Lists (and more generally <em>mutable</em> objects) are passed by reference in Python. Mutating a list passed as an argument to a function mutates that list globally.</p></li> <li><p>You're mutating <code>attrs</code> passed in to <co...
1
2016-07-11T01:58:01Z
[ "python", "json", "python-2.7" ]
Using tkinter to create an ftp app that pulls file from dialog box
38,298,005
<p>I use Filezilla to ftp files all the time at my job. I'm looking to give other people access to ftp files, but we don't want them to have the full access that filezilla gives. I was trying to create a basic python script that would do the following: 1. Let a user choose a file from a file dialog box 2. take that ...
0
2016-07-11T01:34:56Z
38,301,808
<p>use <code>self</code> keyword to use same variable across multiple function definition. create class and then create object later call mainloop()</p> <pre><code>import sys from ftplib import FTP import Tkinter as tk import tkFileDialog #import Tkinter as ttk class App(tk.Tk): def __init__(self): ...
0
2016-07-11T07:55:21Z
[ "python", "tkinter", "ftp" ]
How can I do begin transaction in pymysql ? (mysql)
38,298,152
<p>I want to use run below mysql script using with pymysql.</p> <pre><code>START TRANSACTION; BEGIN; insert into ~~~ COMMIT; </code></pre> <p>my python source code is </p> <pre><code>connection = pymysql.connect(~~~~~~~) with connection.cursor() as cursor : connection.begin() cursor.execute(~...
1
2016-07-11T01:59:13Z
38,298,596
<p>According to the <a href="http://pymysql.readthedocs.io/en/latest/user/examples.html" rel="nofollow">PyMySQL docs/example</a> (singular...this doesn't seem like a very well-supported package), by default auto-commit is off, so you do need to run <code>connection.commit()</code> to actually finish the transaction.</p...
0
2016-07-11T03:08:54Z
[ "python", "mysql", "pymysql" ]
DataFrame from jagged array
38,298,197
<p>I have a dataset that looks like follows:</p> <pre><code>date = ['01/01/2001','02/01/2001'] countries = [['US', 'UK', 'AU'],['CN']] </code></pre> <p>so basically the data ought to look like:</p> <pre><code>def flatten(array): return sum(array,[]) pd.DataFrame({'date': flatten([[date[0]]*3, [date[1]]]), 'count...
1
2016-07-11T02:05:07Z
38,298,433
<p>Try something like this: </p> <pre><code> DD = [] for x, y in zip(date, countries): for z in y: DD.append([x,z]) pd.DataFrame(DD, columns= (['date',"countries"])) date countries 0 01/01/2001 US 1 01/01/2001 UK 2 01/01/2001 AU 3 02/01/2001 ...
2
2016-07-11T02:43:35Z
[ "python", "list", "pandas", "list-comprehension" ]
DataFrame from jagged array
38,298,197
<p>I have a dataset that looks like follows:</p> <pre><code>date = ['01/01/2001','02/01/2001'] countries = [['US', 'UK', 'AU'],['CN']] </code></pre> <p>so basically the data ought to look like:</p> <pre><code>def flatten(array): return sum(array,[]) pd.DataFrame({'date': flatten([[date[0]]*3, [date[1]]]), 'count...
1
2016-07-11T02:05:07Z
38,298,604
<p>Try my 1-liner:</p> <pre><code>df = pd.DataFrame(list(chain(*[list(product([x],y)) for x, y in zip(date, countries)])), columns= ['date',"countries"]) </code></pre> <p><strong>Explanation:</strong></p> <p>Basically <a href="https://docs.python.org/2.7/library/itertools.html" rel="nofollow"><code>itertools</code><...
1
2016-07-11T03:09:53Z
[ "python", "list", "pandas", "list-comprehension" ]
Update a package by easy_install
38,298,308
<p>I'm new to python. I would like to install the latest version of mitmproxy(0.17.1). The current version installed on the system is 0.15. When I do </p> <pre><code>easy_install -U mitmproxy </code></pre> <p>It says:</p> <pre><code>Reading https://pypi.python.org/simple/mitmproxy/ Best match: mitmproxy 0.15 Proces...
0
2016-07-11T02:24:05Z
38,298,370
<p>From <a href="http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install">Why use pip over easy_install?</a> (bold mine):</p> <blockquote> <p>Binary packages are now distributed as wheels (.whl files)—not just on PyPI, but in third-party repositories like Christoph Gohlke's Extension Packages for ...
1
2016-07-11T02:35:12Z
[ "python", "ubuntu", "easy-install" ]
How to return the top 10 frequent column values with pandas?
38,298,385
<p>I am playing with a well known crime dataset. It looks like this:</p> <pre><code>Dates,Category,Descript,DayOfWeek,PdDistrict,Resolution,Address,X,Y,Time 2015-05-13,VANDALISM,"MALICIOUS MISCHIEF, VANDALISM OF VEHICLES",Wednesday,TENDERLOIN,NONE,TURK ST / JONES ST,-122.41241426358101,37.7830037964534,22:30:00 2015-0...
1
2016-07-11T02:37:50Z
38,298,504
<p>I think this does what you want, firstly construct a logic index with <code>df.Dates == "2011-01-01"</code> to filter rows on date <code>2011-01-01</code> and specify <code>Category</code> at the column index to select only the <code>Category</code> column, thus you get all the Category on <code>2011-01-01</code>. U...
1
2016-07-11T02:54:02Z
[ "python", "python-3.x", "csv", "pandas" ]
How to simulate quantization error in theano?
38,298,386
<p>I want to round a tensor variable to a lower resolution representation (e.g. round a float64 value to it's float48 representation while keeping it float64). Is there an efficient way of doing this? </p> <p>The closest thing I could find is the tensor.round function but I am not experienced enough to understand how ...
0
2016-07-11T02:37:50Z
38,317,889
<p>I figured it out.</p> <p>First determine the cast of the original tensor used in theano, usually float64 or float32 which uses <a href="http://stackoverflow.com/questions/13542944/how-many-significant-digits-have-floats-and-doubles-in-java">23 or 52 bits to represent the mantissa</a></p> <p>Then to quantize the va...
0
2016-07-11T23:44:52Z
[ "python", "types", "theano" ]
Comparing 2 periodical lists and extracting new occurrences
38,298,513
<p>I have periodical data coming in as list of unique <code>id</code>'s starting from latest occurrences.</p> <p><strong>list1</strong></p> <pre><code>['001', '003', '005', '002', '004', '006', '008', '007'] </code></pre> <p>and <code>x</code> time later I get:</p> <p><strong>list2</strong></p> <pre><code>['006', ...
0
2016-07-11T02:56:03Z
38,298,576
<p>If you're sure the new occurrences will always be at the first two indices of <code>list2</code>, then you can simply <em>slice</em> and then <em>extend</em> the slice:</p> <pre><code>list3 = list2[:2] list3.extend(list1) print(list3) # ['006', '004', '001', '003', '005', '002', '004', '006', '008', '007'] </code>...
1
2016-07-11T03:06:55Z
[ "python" ]
Comparing 2 periodical lists and extracting new occurrences
38,298,513
<p>I have periodical data coming in as list of unique <code>id</code>'s starting from latest occurrences.</p> <p><strong>list1</strong></p> <pre><code>['001', '003', '005', '002', '004', '006', '008', '007'] </code></pre> <p>and <code>x</code> time later I get:</p> <p><strong>list2</strong></p> <pre><code>['006', ...
0
2016-07-11T02:56:03Z
38,298,589
<p><strong>Assumption</strong></p> <ol> <li>List items are unique</li> <li>New items are pushed to the begining of the list</li> </ol> <p><strong>Approach</strong></p> <p>Find the first occurrence of the first item of first-list onto second-list and partition the second-list at the index of the occurrence. Combine t...
1
2016-07-11T03:08:02Z
[ "python" ]
Comparing 2 periodical lists and extracting new occurrences
38,298,513
<p>I have periodical data coming in as list of unique <code>id</code>'s starting from latest occurrences.</p> <p><strong>list1</strong></p> <pre><code>['001', '003', '005', '002', '004', '006', '008', '007'] </code></pre> <p>and <code>x</code> time later I get:</p> <p><strong>list2</strong></p> <pre><code>['006', ...
0
2016-07-11T02:56:03Z
38,300,391
<p>I am assuming that the number of new occurrences may be between 0 and n where n is the number of elements in list2. Similar in approach as @Abhijit but not as clean or efficient.</p> <pre><code>list1 = ['001', '003', '005', '002', '004', '006', '008', '007'] list2 = ['006', '004', '001', '003', '005', '002', '008',...
0
2016-07-11T06:25:16Z
[ "python" ]
Multiple thread with Autobahn, ApplicationRunner and ApplicationSession
38,298,548
<p><a href="http://stackoverflow.com/questions/25063403/python-running-autobahnpython-asyncio-websocket-server-in-a-separate-subproce">python-running-autobahnpython-asyncio-websocket-server-in-a-separate-subproce</a></p> <p><a href="http://stackoverflow.com/questions/26270681/can-an-asyncio-event-loop-run-in-the-backg...
1
2016-07-11T03:02:29Z
39,759,547
<p>A separate thread must have it's own event loop. So if poloniex_worker needs to listen to a websocket, it needs its own event loop:</p> <pre><code>def poloniex_worker(): asyncio.set_event_loop(asyncio.new_event_loop()) runner = ApplicationRunner("wss://api.poloniex.com:443", "realm1") runner.run(Polonie...
0
2016-09-29T00:25:43Z
[ "python", "multithreading", "python-3.x", "twisted" ]
PermissionError: [Errno 13] Permission denied Flask.run()
38,298,652
<p>I am running MacOS X with python 3. The folder and files have 755 but I have also tested it in 777 with no luck. My question is if I have the right permissions why does it not let me run without sudo. Or are my settings incorrect?</p> <pre><code>cris-mbp:ProjectFolder cris$ python3 zbo.py Traceback (most recent ca...
1
2016-07-11T03:16:49Z
38,298,677
<p>The "permission denied" error is occurring on the <code>bind</code> call; this has nothing to do with directory permissions.</p> <p>You're attempting to bind to port 81 (an odd choice), which is a privileged port (one that is less than 1024). This means you need to run it as root.</p>
1
2016-07-11T03:19:48Z
[ "python", "python-3.x", "flask" ]
PermissionError: [Errno 13] Permission denied Flask.run()
38,298,652
<p>I am running MacOS X with python 3. The folder and files have 755 but I have also tested it in 777 with no luck. My question is if I have the right permissions why does it not let me run without sudo. Or are my settings incorrect?</p> <pre><code>cris-mbp:ProjectFolder cris$ python3 zbo.py Traceback (most recent ca...
1
2016-07-11T03:16:49Z
38,298,682
<p>You're trying to run the app on a <a href="https://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html" rel="nofollow">privileged port</a> (81) - if you use a higher port such as 5000 you won't need sudo privileges.</p>
1
2016-07-11T03:20:19Z
[ "python", "python-3.x", "flask" ]
PermissionError: [Errno 13] Permission denied Flask.run()
38,298,652
<p>I am running MacOS X with python 3. The folder and files have 755 but I have also tested it in 777 with no luck. My question is if I have the right permissions why does it not let me run without sudo. Or are my settings incorrect?</p> <pre><code>cris-mbp:ProjectFolder cris$ python3 zbo.py Traceback (most recent ca...
1
2016-07-11T03:16:49Z
39,522,774
<blockquote> <p>In Linux, and other UNIX-like systems, you have to be root (have superuser privileges) in order to listen to TCP or UDP ports below 1024 (the well-known ports).</p> <p>This port 1024 limit is a security measure. But it is based on an obsolete security model and today it only gives a false sense o...
1
2016-09-16T02:00:44Z
[ "python", "python-3.x", "flask" ]
Django: DecimalField format values displaying from db
38,298,684
<p>I have a form with <code>DecimalField</code>:</p> <pre><code>price = forms.DecimalField(required=True, widget=forms.NumberInput( attrs={'class': 'form-control text-right', 'style': 'text-align: right', 'step': '0.00001'})) </code></pre> <p>When I displaying this field in template, it alway...
0
2016-07-11T03:20:52Z
38,298,846
<p>You can always use str.replace() at controller level, before rendering it to the template:</p> <pre><code>decimal_number = str(decimal_number).replace(",", "") </code></pre> <p>And if you wanna do this at template level, then in Django you can disable a FloatField formatting like this:</p> <pre><code>{{ form.pric...
2
2016-07-11T03:44:22Z
[ "python", "django", "django-templates" ]
Django - get_by_natural_key() takes exactly 3 arguments (2 given)
38,298,703
<p>I'm trying to create a user log in. But when I go to log in I get the Error Message:</p> <pre><code>TypeError: get_by_natural_key() takes exactly 3 arguments (2 given) </code></pre> <p><a href="http://stackoverflow.com/questions/31813712/use-another-class-for-user-login-in-django">There was a similar question aske...
2
2016-07-11T03:23:45Z
38,299,152
<p>Django's own <code>get_by_natural_key</code> method takes only a <code>username</code> argument - your method is expecting a <code>username</code> as well as a <code>password</code> (not sure where you copied it from). From the <a href="https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#django.contrib.au...
4
2016-07-11T04:25:34Z
[ "python", "django" ]
ElementTree.iterparse with streamed and cached request throws ParseError
38,298,788
<p>I have a Flask app that retrieves an XML document from a url and processes it. I'm using requests_cache with redis to avoid extra requests and ElementTree.iterparse to iterate over the streamed content. Here's an example of my code (same result occurs from both the development server and the interactive interpreter)...
2
2016-07-11T03:36:16Z
38,312,976
<p>I can tell you why it fails for both scenarios, for the latter it is because the data is <em>gzipped</em> the first time you call raw, whatever happens when you read the second time then the data is decompressed:</p> <p>If you print the lines:</p> <pre><code>for line in response.raw: print(line) </code></pre>...
0
2016-07-11T17:39:18Z
[ "python", "caching", "streaming", "python-requests", "elementtree" ]
Python3.4 **kwargs, unexpected keyword argument
38,298,825
<p>I have a dictionary of functions, all of which use 1 or 2 optional arguments. I want to iterate through this dictionary and pass both arguments to each iterated function, and have the functions that only need 1 argument to ignore the second. In these cases, however, I get an unexpected keyword argument error. </p> ...
-1
2016-07-11T03:39:51Z
38,298,837
<p>I would go about this by creating a function like the one below with the second parameter optional.</p> <pre><code>func (obj, a = 0, b = 0): return obj + a + b </code></pre>
-1
2016-07-11T03:42:15Z
[ "python", "function", "dictionary", "kwargs" ]
Python3.4 **kwargs, unexpected keyword argument
38,298,825
<p>I have a dictionary of functions, all of which use 1 or 2 optional arguments. I want to iterate through this dictionary and pass both arguments to each iterated function, and have the functions that only need 1 argument to ignore the second. In these cases, however, I get an unexpected keyword argument error. </p> ...
-1
2016-07-11T03:39:51Z
38,298,891
<p>A much better way to avoid all of this trouble is to use the following paradigm:</p> <pre><code>def func(obj, **kwargs): return obj + kwargs.get(a, 0) + kwargs.get(b,0) </code></pre> <p>This makes use of the fact that <code>kwargs</code> is a dictionary consisting of the passed arguments and their values and <...
1
2016-07-11T03:50:29Z
[ "python", "function", "dictionary", "kwargs" ]
keras custom objective function, getting data in y_pred, y_true?
38,298,835
<p>I am trying to write a custom objective function for keras, and I need to manipulate the data in y_true, y_pred to do this.</p> <pre><code>def custom_objective(y_true, y_pred): print y_true, y_pred </code></pre> <p>When I print these values, I get:</p> <pre><code>dense_1_target Softmax.0 </code></pre> <p>I a...
0
2016-07-11T03:41:30Z
38,317,148
<p>You can't print a tensor's value using the built-in print function. Check <a href="http://stackoverflow.com/q/17445280/36195">this other question and answers</a>, and also <a href="http://deeplearning.net/software/theano/tutorial/debug_faq.html#how-do-i-print-an-intermediate-value-in-a-function" rel="nofollow">Thean...
0
2016-07-11T22:24:02Z
[ "python", "python-2.7", "python-3.x", "machine-learning", "keras" ]
Python: extract the text string from a DataFrame to a long string
38,298,844
<p>I have a <code>pandas.DataFrame</code>: <code>df1</code> as following.</p> <pre><code> date text name 1 I like you hair, do you like it screen1 2 beautiful sun and wind screen2 3 today is happy, I want to...
2
2016-07-11T03:44:02Z
38,298,903
<p>Use the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.cat.html#pandas.Series.str.cat" rel="nofollow"><code>.str.cat()</code></a> method of a data frame column (<a href="http://pandas.pydata.org/pandas-docs/stable/api.html#series" rel="nofollow"><code>Series</code></a> object):</p> ...
1
2016-07-11T03:51:54Z
[ "python", "string", "pandas", "dataframe" ]
Python: extract the text string from a DataFrame to a long string
38,298,844
<p>I have a <code>pandas.DataFrame</code>: <code>df1</code> as following.</p> <pre><code> date text name 1 I like you hair, do you like it screen1 2 beautiful sun and wind screen2 3 today is happy, I want to...
2
2016-07-11T03:44:02Z
38,300,367
<p>Just use <code>tolist()</code> </p> <pre><code>' '.join(df['text'].tolist()) </code></pre> <p><strong>Explanation:</strong></p> <pre><code>df = pd.DataFrame({'date': [1, 2, 3], 'text': ['I like your', 'beautiful sun', 'good movie']}) df Out[68]: date text 0 1 I like your 1 2 beautiful s...
1
2016-07-11T06:23:20Z
[ "python", "string", "pandas", "dataframe" ]
Renaming columns in csv by column index
38,298,879
<p>I have a csv file:</p> <pre><code>visitIp userId idSite 128.227.50.161 a 35 24.222.206.154 a 35 10.12.0.1 a 35 10.12.0.1 a 35 10.12.0.1 a 35 24.222.206.154 a 35 </code></pre> <p>I want to rename the column in the third index that is 'idS...
2
2016-07-11T03:48:09Z
38,299,117
<p>Theres a better way to do this using df.rename; but this will work:</p> <pre><code>df['Id'] = df['idSite'] df = df.drop('idSite', axis=1) </code></pre> <p>you should be able to find a solution in another thread</p>
0
2016-07-11T04:21:13Z
[ "python", "python-2.7", "python-3.x", "csv", "pandas" ]
Renaming columns in csv by column index
38,298,879
<p>I have a csv file:</p> <pre><code>visitIp userId idSite 128.227.50.161 a 35 24.222.206.154 a 35 10.12.0.1 a 35 10.12.0.1 a 35 10.12.0.1 a 35 24.222.206.154 a 35 </code></pre> <p>I want to rename the column in the third index that is 'idS...
2
2016-07-11T03:48:09Z
38,299,164
<p>You can rename the column setting the <code>.columns.values[2]</code> value directly:</p> <pre><code>import pandas as pd df = pd.read_csv('Book1.csv', dtype='unicode', delim_whitespace=True) df.columns.values[2] = "id" print(df) </code></pre> <p>Prints:</p> <pre><code> visitIp userId id 0 128.227.50.1...
2
2016-07-11T04:26:17Z
[ "python", "python-2.7", "python-3.x", "csv", "pandas" ]
wxpython GUI testing tool Inquiry
38,298,905
<p>For a couple of days, I was trying to find appropriate GUI test tools for toolkits (wxwidgets). The program that am going to test is written in python.I have tried SQUISH but it did not work when using "Verification Point", meaning that object property values were not appearing in squish. The GUI testing tool doesn'...
-4
2016-07-11T03:52:17Z
38,315,116
<p>You are probably looking for tools like these:</p> <ul> <li><a href="http://uiautomationverify.codeplex.com/" rel="nofollow">http://uiautomationverify.codeplex.com/</a></li> <li><a href="https://github.com/ldtp/cobra" rel="nofollow">https://github.com/ldtp/cobra</a></li> <li><a href="http://sikuli.org/" rel="nofoll...
0
2016-07-11T19:53:29Z
[ "python", "user-interface", "testing", "wxpython", "wxwidgets" ]
Extract links from html page
38,298,995
<p>I am trying to fetch all movie/show netflix links from here <a href="http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html" rel="nofollow">http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html</a> and also their country name. e.g from the page s...
0
2016-07-11T04:03:23Z
38,299,444
<p>As for the first question - it failed for links that didn't have an href value. So instead of a string you got <code>None</code>.</p> <p>The following works:</p> <pre><code>from BeautifulSoup import BeautifulSoup import urllib2 import re html_page = urllib2.urlopen('http://netflixukvsusa.netflixable.com/2016/ 07/...
0
2016-07-11T04:58:58Z
[ "python", "html" ]
Extract links from html page
38,298,995
<p>I am trying to fetch all movie/show netflix links from here <a href="http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html" rel="nofollow">http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html</a> and also their country name. e.g from the page s...
0
2016-07-11T04:03:23Z
38,299,616
<p>I think you'd have an easier iterating through the listing rows and using a generator to assemble the data structure you're looking for (ignore the minor differences in my code, I'm using Python3):</p> <pre><code>from bs4 import BeautifulSoup import requests url = 'http://netflixukvsusa.netflixable.com/2016/07/' \...
0
2016-07-11T05:19:57Z
[ "python", "html" ]
Extract links from html page
38,298,995
<p>I am trying to fetch all movie/show netflix links from here <a href="http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html" rel="nofollow">http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html</a> and also their country name. e.g from the page s...
0
2016-07-11T04:03:23Z
38,301,078
<p>Your code can be simplified to a couple of <em>selects</em>:</p> <pre><code>import requests from bs4 import BeautifulSoup url = 'http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html' r = requests.get(url) soup = BeautifulSoup(r.content) for a in soup.select("a[href*=netflix]")...
1
2016-07-11T07:11:32Z
[ "python", "html" ]
Extract links from html page
38,298,995
<p>I am trying to fetch all movie/show netflix links from here <a href="http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html" rel="nofollow">http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html</a> and also their country name. e.g from the page s...
0
2016-07-11T04:03:23Z
38,301,309
<pre><code>url = 'http://netflixukvsusa.netflixable.com/2016/07/complete-alphabetical-list-k-sat-jul-9.html' r = requests.get(url, stream=True) count = 1 final=[] for line in r.iter_lines(): if count == 746: soup = BeautifulSoup(line) for row in soup.findAll('tr'): url = row.find('a', hr...
0
2016-07-11T07:24:57Z
[ "python", "html" ]
Getting the distribution of values at the leaf node for a DecisionTreeRegressor in scikit-learn
38,299,015
<p>By default, a scikit-learn DecisionTreeRegressor returns the mean of all target values from the training set in a given leaf node. </p> <p>However, I am interested in getting back the list of target values from my training set that fell into the predicted leaf node. This will allow me to quantify the distribution, ...
1
2016-07-11T04:05:44Z
38,318,135
<p>I think what you're looking for is the <code>apply</code> method of the <code>tree</code> object. <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/tree/_tree.pyx" rel="nofollow">See here for the source</a>. Here's an example:</p> <pre><code>import numpy as np from sklearn.tree import Decisi...
0
2016-07-12T00:19:37Z
[ "python", "machine-learning", "scikit-learn", "random-forest", "decision-tree" ]
Website submit button and python, no action attribute
38,299,065
<p>I am building a program in Python that interacts with an online store. So far I am able to find the desired item and navigate to the page using BeautifulSoup, but I am having issues clicking the "Add to cart" button. Most of the solutions I've found online using robobrowser and similar would work except that they ar...
0
2016-07-11T04:12:50Z
38,299,586
<p>You can consider using Selenium in Python.</p> <p>Please use the code snippet below as a reference:</p> <pre><code>from selenium import webdriver driver = webdriver.Firefox() driver.get("url") button = driver.find_element_by_css_selector("input[class='button']") button.click() </code></pre> <p>In case you get mu...
0
2016-07-11T05:16:43Z
[ "python", "html", "beautifulsoup", "form-submit", "robobrowser" ]
Converting dataframe to datetime in pandas
38,299,079
<p>I have a dataframe called 'times', the head of which looks like this:</p> <pre><code>year month day hour minute second 0 2015 02 03 01 12 04 1 2015 02 03 01 12 07 2 2015 02 03 01 12 11 3 2015 02 03 01 12 13 4 2015 02 03 01 12 17 </code></pre> <p>When I try to p...
0
2016-07-11T04:15:55Z
38,300,516
<p>Your solution works for me as well.</p> <p>But you can also try:</p> <pre><code>times.apply(lambda x: pd.datetime(*x), axis=1) </code></pre> <p>Or: </p> <pre><code>times.T.apply(lambda x: pd.datetime(*x)) </code></pre>
1
2016-07-11T06:35:41Z
[ "python", "datetime", "pandas" ]
Python: Polling a SQL database every n seconds and executing a task based on it
38,299,098
<p>I want to make a program that polls a SQL database every n seconds (n>10). And it validates the data in a particular column and calls a function based on it. </p> <p>For eg, </p> <pre><code>when column has '1' -&gt; call function1 when column has '2' -&gt; call function2 when column has '3' -&gt; exits </co...
1
2016-07-11T04:18:33Z
38,300,190
<p>Depending on the complexity of your query and the functions you call you may not need multiple threads. If your query runs fast and your function calls are cheap then just use the simplest solution that does the job, i.e. a loop which does the polling, calls your function and then sleeps for the remaining time.<br> ...
1
2016-07-11T06:09:57Z
[ "python", "sql-server", "multithreading", "scheduling" ]
How to mock a dictionary in Python
38,299,103
<p>Let's say I have a function like this:</p> <pre><code>def do_something(dict_obj): # access to the dict_obj then do some stuff eg. if dict_obj['doors']: do_something_with_doors() map_car_make(dict_obj['make']) ... if dict_obj['is_active']: do_something_else() </code></pre> <p>I want...
0
2016-07-11T04:19:35Z
38,299,497
<p>You can use <a href="http://www.tutorialspoint.com/python/dictionary_get.htm" rel="nofollow">dict.get</a> method to return the default value of your choice that can mock the existence of is_active entry.</p>
0
2016-07-11T05:06:25Z
[ "python", "mocking" ]
"Bus error: 10" when trying to set pandas column name
38,299,205
<p>Here is the code I'm executing trying to <em>rename pandas column by index</em>:</p> <pre><code>import pandas as pd df = pd.read_csv('input.csv', dtype='unicode', delim_whitespace=True) df.columns.values[2] = "id" print(df) </code></pre> <p>I'm pretty sure this is not the best approach, but when I run this with P...
1
2016-07-11T04:31:46Z
38,316,355
<p><a href="https://en.wikipedia.org/wiki/Bus_error" rel="nofollow">Bus error</a> occurs when a processor can't access an invalid memory address.</p> <p><code>df.columns</code> is an instance if <code>Index</code> which is an immutable object in pandas. Any operation changing it, returns in fact a new object. Modifyin...
2
2016-07-11T21:16:46Z
[ "python", "python-3.x", "pandas" ]
LED board in Python using Tkinter, matrix and pixels
38,299,305
<p>As a part of a Python project I am trying to make an LED board using <strong>Tkinter</strong> library. This board should receive an input (a sentence) and show it on the board. I have started by making <code>7*6</code> matrices of zeros and ones for each letter but I really don't know what to do next and how should ...
-3
2016-07-11T04:44:12Z
38,300,517
<p>Example code</p> <pre><code>import tkinter as tk # Should have constants in another .py or .json file DOT_WIDTH = 20 DOT_HEIGHT = 20 LETTER_WIDTH = 6 * DOT_WIDTH LETTER_HEIGHT = 7 * DOT_HEIGHT LETTERS = { 'A' : ( (0,1,1,1,0,0), (1,0,0,0,1,0), ...
0
2016-07-11T06:35:44Z
[ "python", "tkinter" ]
Import tensorflow error on mac
38,299,480
<p><strong>Enviorment</strong>:</p> <p>Mac OSX 10.10</p> <p>Pyhon: 2.7.10</p> <p>I have following error when I was trying to <code>import tensorflow</code></p> <pre><code>Python 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin Type "help", "copyright", "credi...
0
2016-07-11T05:04:30Z
38,301,904
<p>I think the issue is that your <code>numpy</code> is one version older than needed (<code>0x9</code> = 9; <code>0xa</code> = 10). Maybe upgrade numpy and see if importing <code>tensorflow</code> works after that.</p> <p><em>Edit/Update:</em> For your new error, try the pip install with the <code>--no-cache-dir</cod...
1
2016-07-11T08:01:14Z
[ "python", "python-2.7", "tensorflow" ]
Converting serial interface data to integer
38,299,571
<p>I'm writing some code to read from a serial interface and return the integer value of the data received.</p> <p>It seems that i need to remove the <code>"\r\n"</code> from it. I tried splitting, but it doesn't work.</p> <p>Here's my code:</p> <pre><code>import time import serial import string ser = seri...
1
2016-07-11T05:15:07Z
38,299,635
<p>Try it like this:</p> <pre><code>import time import serial import string ser = serial.Serial( port='/dev/ttyACM1', baudrate = 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 ) counter = 0 while True: line = ser.readline().rst...
1
2016-07-11T05:22:13Z
[ "python", "python-2.7", "integer", "pyserial" ]
Difficulty passing integer variables in struct.pack in Python
38,299,638
<p>I am trying to pack two integer variables and write them to the serial port using struct.pack in Python. The variables are defined as integer variables but I keep getting the following error: 'struct.error: required argument is not an integer'</p> <p>I have been successful at packing actual numbers, just not variab...
0
2016-07-11T05:22:40Z
38,299,780
<pre><code>ser.write(struct.pack('!BB',var1.get(),var2.get()) </code></pre> <p>I think at least ... maybe its just <code>var1(),var2()</code> ... its been a while since i messed with tkinter</p>
-1
2016-07-11T05:35:55Z
[ "python", "tkinter" ]
Difficulty passing integer variables in struct.pack in Python
38,299,638
<p>I am trying to pack two integer variables and write them to the serial port using struct.pack in Python. The variables are defined as integer variables but I keep getting the following error: 'struct.error: required argument is not an integer'</p> <p>I have been successful at packing actual numbers, just not variab...
0
2016-07-11T05:22:40Z
38,299,906
<p><code>IntVar()</code> is not an integer - is a Tkinter object used to notifying observers when it's value changes.</p> <p>To use it in struct pack you need to retrieve underlying primitive. struct.pack('!BB', var1.get(), var2.get()) </p> <p><a href="http://effbot.org/tkinterbook/variable.htm" rel="nofollow"><c...
1
2016-07-11T05:47:06Z
[ "python", "tkinter" ]
Using Gmail Through Python Authentication Error
38,299,681
<p>*EDIT: SOLVED IT (answer below)</p> <p>I'm getting an authentication error 534 from gmail when I try to run the following code:</p> <pre><code> server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login("me@gmail.com", "password") msg = "Hello from the other side!" server.sendma...
0
2016-07-11T05:27:29Z
38,299,710
<p>After telling google that it WAS my device, I just had to do this before the changes could propagate! </p> <p><a href="https://accounts.google.com/DisplayUnlockCaptcha" rel="nofollow">https://accounts.google.com/DisplayUnlockCaptcha</a></p> <p>Problem = Solved</p>
0
2016-07-11T05:29:47Z
[ "python", "amazon-web-services", "smtp", "gmail" ]
Same webdriver, multiple instances, each with its own profile
38,299,794
<p>I need to know if I can set a proxy/profile for each driver handle. I have the following code:</p> <pre><code> def browser(url, id, user1, parolauser1, user2, parolauser2): print multiprocessing.current_process() fp = webdriver.FirefoxProfile("C:\Users\yt\AppData\Roaming\Mozilla\Firefox\Profiles\hgv9qvsn...
0
2016-07-11T05:37:01Z
38,299,923
<p>While it may work sometimes, I would not recommend this, if you need the same profile, create multiple copies of it. If you have a look at the <a href="https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/firefox/webdriver.py" rel="nofollow">underlying code</a>, you'll see that just creating an i...
0
2016-07-11T05:48:35Z
[ "python", "python-2.7", "selenium", "webdriver" ]
Pandas Using sort_values to Sort 2 Dataframes then Sub-Sort by Date
38,299,831
<p>I have two dataframes consisting a similar type of informatio. I'm attempting to merge them toghether and reorganize them. Here is a sample of the dataframes:</p> <pre><code>df1 = Member Nbr Name-First Name-Last Date-Join 20 Zoe Soumas 2011-08-01 3128 Ju...
2
2016-07-11T05:41:11Z
38,299,985
<p><code>by</code> parameter can be a list of columns so that the dataframe is first sorted by the first column (and for ties by the second column, and for ties by the third column etc.)</p> <pre><code>df12.sort_values(by=['Member Nbr', 'Date-Join'], inplace=True) </code></pre> <p>produces</p> <pre><code> Member ...
1
2016-07-11T05:54:12Z
[ "python", "sorting", "pandas" ]
Using requests function in python to submit data to a website and call back a response
38,299,950
<p>I am trying to use the requests function in python to post the text content of a text file to a website, submit the text for analysis on said website, and pull the results back in to python. I have read through a number of responses here and on other websites, but have not yet figured out how to correctly modify the...
0
2016-07-11T05:51:12Z
38,300,029
<p>You need to send the same request the website is sending, usually you can get these with web debugging tools (like chrome/firefox developer tools). </p> <p>In this case the url the request is being sent to is: <code>http://www.webpagefx.com/tools/read-able/check.php</code></p> <p>With the following params: <code>t...
0
2016-07-11T05:58:22Z
[ "python", "python-requests" ]
Using requests function in python to submit data to a website and call back a response
38,299,950
<p>I am trying to use the requests function in python to post the text content of a text file to a website, submit the text for analysis on said website, and pull the results back in to python. I have read through a number of responses here and on other websites, but have not yet figured out how to correctly modify the...
0
2016-07-11T05:51:12Z
38,300,905
<p>There are two post parameters, <em>tab</em> and <em>directInput</em>:</p> <pre><code>import requests post = "http://www.webpagefx.com/tools/read-able/check.php" with open("in.txt") as f: data = {"tab":"Test by Direct Link", "directInput":f.read()} r = requests.post(post, data=data) print(r....
0
2016-07-11T07:01:07Z
[ "python", "python-requests" ]
How to delete snapshot based on the description?
38,300,044
<p>I am trying to delete any previous snapshot with description having <code>tags_description</code> , how can i do so ? The following code throws me error :</p> <p>def call_cleaner(data): regions = ['us-west-2', 'eu-central-1', 'ap-southeast-1']</p> <pre><code>for index, region in enumerate(regions): for ip_...
0
2016-07-11T05:59:48Z
38,300,110
<p>In order to use these functions in boto3 you need to use ec2 client which can be initialized like this: <code>client = boto3.client('ec2')</code>. (Basically, replace <code>ec2.*</code> with <code>client.*</code></p>
-2
2016-07-11T06:04:18Z
[ "python", "amazon-ec2" ]
PermissionError when drawing a pygraphviz chart from Jupyter
38,300,056
<p>I am trying to generate a chart with pygraphviz in Python 3.</p> <p>It works on my machine with this Anacondas version:</p> <pre><code>Python 3.3.5 |Continuum Analytics, Inc.| (default, Jun 4 2015, 15:22:11) </code></pre> <p>It returns a PermissionError when I run it from a different machine running:</p> <pre>...
0
2016-07-11T06:00:38Z
38,311,102
<p>Are you sure your user has permissions to write to <code>/tmp/</code> on that other machine? Try <code>touch /tmp/state.svg</code>. If that fails then this is an issue with the unix permissions. You'll need to <code>chmod</code> the <code>/tmp/</code> folder with whatever user owns it (probably <code>root</code>)....
0
2016-07-11T15:45:26Z
[ "python", "python-3.x", "anaconda", "pygraphviz", "pygraph" ]
Can I build a mutable range?
38,300,080
<p>Iterating over mutable objects are changable while being executed:</p> <pre><code>a = [11, 12, 13] for i in a: if i == 12: a.append(20) print(i) </code></pre> <p>Results with</p> <pre><code>11 12 13 20 </code></pre> <p>And <code>a</code> is <code>[11, 12, 13, 20]</code></p> <p>But if I use <cod...
1
2016-07-11T06:02:02Z
38,300,130
<p>In your second code snippet:</p> <pre><code>for i in range(len(a)): if i == 1: a.append(20) print(a[i]) </code></pre> <p>when you use <code>range(len(a))</code> it returns [0, 1, 2] in this case as the length of <code>a==3</code> Now the for loop would be iterated only 3 times as the <code>len(a)</...
0
2016-07-11T06:05:49Z
[ "python", "python-3.x" ]
Can I build a mutable range?
38,300,080
<p>Iterating over mutable objects are changable while being executed:</p> <pre><code>a = [11, 12, 13] for i in a: if i == 12: a.append(20) print(i) </code></pre> <p>Results with</p> <pre><code>11 12 13 20 </code></pre> <p>And <code>a</code> is <code>[11, 12, 13, 20]</code></p> <p>But if I use <cod...
1
2016-07-11T06:02:02Z
38,300,184
<p>Yes, you can, and as you said yourself a is already mutable, so instead of iterating over a range that's based upon len(a) before the loop, you can do the following:</p> <pre><code>for i,val in enumerate(a): if i == 1: a.append(20) print(val) </code></pre> <p><code>Output: 11 12 13 20</code></p>
2
2016-07-11T06:09:44Z
[ "python", "python-3.x" ]
Most elegant algorithms that use function passing/returning in Python
38,300,141
<p>In Python, functions are first-class objects, which means that one can pass and return them to and from other functions. This is a very interesting feature of the language, and I was wondering if there any classical examples where this is used in a significant way? Or are there any algorithms which use, or can be el...
0
2016-07-11T06:06:39Z
38,301,033
<p>Dependency injection is a classic. This means that I can do stuff like below, which allows you to push the decision making logic for which analysis_func to use further up the decision tree instead of having a bunch of logic in process_data. This can make it easier to reveal the underlying polymorphic nature of the ...
0
2016-07-11T07:08:24Z
[ "python" ]
Most elegant algorithms that use function passing/returning in Python
38,300,141
<p>In Python, functions are first-class objects, which means that one can pass and return them to and from other functions. This is a very interesting feature of the language, and I was wondering if there any classical examples where this is used in a significant way? Or are there any algorithms which use, or can be el...
0
2016-07-11T06:06:39Z
38,301,493
<p>One of the greatest power of the function-passing is '<strong>Closures</strong>'. A closure is data attached to code and the common use of that is:</p> <ul> <li>Replacing hard coded constants</li> <li>Eleminating globals</li> <li>Providing consistent function signatures</li> <li>Implementing Object Orientation</li>...
1
2016-07-11T07:36:41Z
[ "python" ]
Most elegant algorithms that use function passing/returning in Python
38,300,141
<p>In Python, functions are first-class objects, which means that one can pass and return them to and from other functions. This is a very interesting feature of the language, and I was wondering if there any classical examples where this is used in a significant way? Or are there any algorithms which use, or can be el...
0
2016-07-11T06:06:39Z
38,301,730
<p>A nice example is a method <code>validation_callback</code> which is usefull in validators for wxpython's UI widgets. </p> <pre class="lang-py prettyprint-override"><code>class CMyClass( object ) : # An object attribute self._my_attr = a_value # Define a validator for the widget self.textCtrl which is...
0
2016-07-11T07:50:33Z
[ "python" ]
How to significantly reduce size of dataset (say .csv) to analyse in Pandas python
38,300,152
<p>Suppose we have 1 gb dataset(say .csv) to analyse and we are unable to run quickly as delay is too much to run again and again, what to do in order to make data scalable enough to analyse. </p>
0
2016-07-11T06:07:17Z
38,300,293
<p>Many times I faced this problem and got a simple solution by making Data Frames of the dataset and creating new dataset (say .csv) by making an output out of Data Frames and what's most significant is creation of new Data sets almost 1/8 th of the real size of datasets. Below is an example of how it can work.</p> <...
0
2016-07-11T06:18:03Z
[ "python", "pandas" ]
Split on period without removing the period punctuation once split - Python
38,300,159
<p>I have seen a lot of related questions to mine but I still can't seem to get my specific example to work. I have some data in a file which is several sentences strung together. I am trying to split the sentences into a list with each sentence being an element of the list. But when I split on a period followed by a ...
0
2016-07-11T06:07:43Z
38,300,236
<p>Given you stored the splitted list in a variable:</p> <pre><code>strList = text.split() for line in strList: line.append('.') strList[len(strList) - 1] = strList[len(strList) - 1][:-1] </code></pre>
1
2016-07-11T06:13:46Z
[ "python", "regex", "split" ]
Split on period without removing the period punctuation once split - Python
38,300,159
<p>I have seen a lot of related questions to mine but I still can't seem to get my specific example to work. I have some data in a file which is several sentences strung together. I am trying to split the sentences into a list with each sentence being an element of the list. But when I split on a period followed by a ...
0
2016-07-11T06:07:43Z
38,300,258
<p>Use positive look behind:</p> <pre><code>import re re.split(r'(?&lt;=\.) ', text) </code></pre> <p>The above assumes your sentence always end with a period and a space (except the last sentence). <code>(?&lt;=\.)</code> is a positive look behind, so the regexp above will split on a space that is just after a dot, ...
2
2016-07-11T06:15:06Z
[ "python", "regex", "split" ]
Split on period without removing the period punctuation once split - Python
38,300,159
<p>I have seen a lot of related questions to mine but I still can't seem to get my specific example to work. I have some data in a file which is several sentences strung together. I am trying to split the sentences into a list with each sentence being an element of the list. But when I split on a period followed by a ...
0
2016-07-11T06:07:43Z
38,300,303
<p>You could use the following and trim the leading whitespace.</p> <pre><code>[^\.]+\. </code></pre> <p><a href="https://regex101.com/r/qS0vK3/1" rel="nofollow">REGEX demo</a></p>
0
2016-07-11T06:18:27Z
[ "python", "regex", "split" ]
Split on period without removing the period punctuation once split - Python
38,300,159
<p>I have seen a lot of related questions to mine but I still can't seem to get my specific example to work. I have some data in a file which is several sentences strung together. I am trying to split the sentences into a list with each sentence being an element of the list. But when I split on a period followed by a ...
0
2016-07-11T06:07:43Z
38,300,792
<p>this can also be done</p> <pre><code>[ i.group(0) for i in re.finditer('\S[^\.]+(\.|.$)', text)] </code></pre> <p>it matches any character other than dot till it reaches a dot or end of line</p>
0
2016-07-11T06:55:07Z
[ "python", "regex", "split" ]
execute a python method in X parallel sub-processes where x is configurable
38,300,160
<p>I'm not a python expert, and I'm trying to implement the functionality in subject.</p> <p>I know how to use a functionality which executes methods in parallel. E.g.</p> <pre><code>def main(): run_in_parallel(A,B) def A(): while True: print("A") def B(): while True: print("B") def run...
2
2016-07-11T06:07:44Z
38,300,249
<p>If I understand you question correctly, what you are looking for is a threadpool/processpool, where you can define the number of workers, and then just apply functions asynchronously with them. Python has that <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool" rel="nofollow">b...
1
2016-07-11T06:14:37Z
[ "python", "parallel-processing", "subprocess" ]
execute a python method in X parallel sub-processes where x is configurable
38,300,160
<p>I'm not a python expert, and I'm trying to implement the functionality in subject.</p> <p>I know how to use a functionality which executes methods in parallel. E.g.</p> <pre><code>def main(): run_in_parallel(A,B) def A(): while True: print("A") def B(): while True: print("B") def run...
2
2016-07-11T06:07:44Z
38,300,329
<p>Do you mean you want to run function A 10/20/100... times in parallel subprocesses? If yes then you can create 20 subprocesses like this:</p> <pre><code>def main(): run_in_parallel(A, 20) def A(): while True: print("A") def run_in_parallel(fn, proc_count): proc = [] for _ in range(proc_cou...
3
2016-07-11T06:20:12Z
[ "python", "parallel-processing", "subprocess" ]