title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
How can I add a constant percentage to each wedge of a pie chart using matplotlib
39,262,783
<p>Code snippet looks like this</p> <pre><code>#df is dataframe with 6 rows, with each row index being the label of the sector plt.pie(df.iloc[:,0], labels= df.index) #plot the first column of dataframe as a pie chart </code></pre> <p>It generates a pie chart like this:</p> <p><a href="http://i.stack.imgur.com/z9PX...
2
2016-09-01T04:36:33Z
39,333,937
<p>Disclaimer : This is my own question.</p> <p>What <a href="http://stackoverflow.com/users/3510736/ami-tavory">Ami Tavory</a> has answered is the correct approach. I was thinking it from the perspective of plotting (fitting the data to 300 degrees instead of 360) instead of manipulating the data (which is much simpl...
1
2016-09-05T15:43:24Z
[ "python", "pandas", "matplotlib" ]
Python 2.7 TypeError: 'NoneType' object has no attribute '_getitem_'
39,262,830
<p>I'm pretty new to coding and have been trying some things out. I am getting this error when I run a python script I have. I have read that this error is because something is returning "None" but I'm having trouble figuring out what is causing it (still trying to learn all of this). </p> <p>The purpose of the scri...
-1
2016-09-01T04:45:14Z
39,264,122
<p>In your <code>youtube_video_details</code> method. the response.status_code maybe is not <code>200</code>, so the method return the <code>None</code></p> <p>So you can do like this:</p> <pre><code>video_data = youtubo_video_details(video_id) if not video_data: thumbnails = video_data['items'][0]['sni...
0
2016-09-01T06:28:29Z
[ "python", "python-2.7", "typeerror" ]
python not looping search on regexe
39,262,889
<p>Sample line from file1.txt</p> <pre><code>2016-04-30 02:03:55,417 INFO [http-nio-443-exec-51] xxxxxxxxxxxxxx (xxxxxxxxxxxxxx.java:1364) - TRX[160430120042]::paymentResult::xxxxxxxxxxxxx(Billing)Response::TRANSACTION[160450001042], REFERENCE_CODE[1461953034575], END_USER_ID[tel:+639422387059], OPERATION_RESULT[...
0
2016-09-01T04:50:31Z
39,263,013
<p>To loop through each line of your file:</p> <pre><code>import re with open('file1.txt') as f: for line in f: # do something with line </code></pre> <p>Note that there is no need to do <code>f.close()</code>, it is already handled by the context manager <code>with ...</code></p>
0
2016-09-01T05:03:29Z
[ "python", "regex", "loops" ]
Python - Elements of copy.copy() still share memory with the original one?
39,262,918
<p>I wanted to make a copy of a list (literally a separated clone that has nothing sharing with the original). I used copy.copy() and created 2 separated lists, but why does the elements of each copy still seem to share?</p> <p>It's hard to explain, please check out the following output.</p> <pre><code>&gt;&gt;&gt; a...
1
2016-09-01T04:54:35Z
39,263,022
<p><strong><em>friendly dog</em></strong> commented under the OP and suggested me to use deepcopy(). It works. Thanks!</p>
2
2016-09-01T05:04:21Z
[ "python", "copy" ]
Python - Elements of copy.copy() still share memory with the original one?
39,262,918
<p>I wanted to make a copy of a list (literally a separated clone that has nothing sharing with the original). I used copy.copy() and created 2 separated lists, but why does the elements of each copy still seem to share?</p> <p>It's hard to explain, please check out the following output.</p> <pre><code>&gt;&gt;&gt; a...
1
2016-09-01T04:54:35Z
39,263,827
<p>The <code>copy.copy()</code> was shallow copy. That means, it would create a new object as same as be copied. but the elements within copied object didn't be created, and them also is a reference. <code> -&gt; a = [[0,1], [2,3]] -&gt; import copy -&gt; b = copy.copy(a) # the b be created, but [0,1] [...
1
2016-09-01T06:09:10Z
[ "python", "copy" ]
Python - Elements of copy.copy() still share memory with the original one?
39,262,918
<p>I wanted to make a copy of a list (literally a separated clone that has nothing sharing with the original). I used copy.copy() and created 2 separated lists, but why does the elements of each copy still seem to share?</p> <p>It's hard to explain, please check out the following output.</p> <pre><code>&gt;&gt;&gt; a...
1
2016-09-01T04:54:35Z
39,264,932
<p>You should use deepcopy() there because the copy() makes shallow clone of the object that you are referencing not the object inside it.If you want the whole object(with the object inside it) use deepcopy() instead.</p> <p>Please refer the links for better understanding</p> <p><a href="http://stackoverflow.com/ques...
1
2016-09-01T07:12:22Z
[ "python", "copy" ]
Removing characters from indices within multiple lists
39,263,076
<p>Just a really quick question I cannot figure out for the life of me, although it seems simple...</p> <p>How do I delete the last 2 characters of each 4th index of a list, in a list? So in less confusing terms:</p> <pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append...
2
2016-09-01T05:08:37Z
39,263,153
<pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append(f) L.append(p) for i in range(len(L)): L[i][3] = L[i][3].rstrip('\n') # Use rstrip to strip the specified character(s) from the right side of the string. print L &gt;&gt;[['yes', 'no', 'tot', 'foop'], ['ick', 'th...
1
2016-09-01T05:15:30Z
[ "python", "list" ]
Removing characters from indices within multiple lists
39,263,076
<p>Just a really quick question I cannot figure out for the life of me, although it seems simple...</p> <p>How do I delete the last 2 characters of each 4th index of a list, in a list? So in less confusing terms:</p> <pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append...
2
2016-09-01T05:08:37Z
39,263,167
<pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append(f) L.append(p) #iterate through every element in the list and #apply simple slicing for x in L: x[-1] = x[-1][:-1] </code></pre> <p>Output - </p> <pre><code>[['yes', 'no', 'tot', 'foop'], ['ick', 'throw', 'tamp...
1
2016-09-01T05:16:41Z
[ "python", "list" ]
Removing characters from indices within multiple lists
39,263,076
<p>Just a really quick question I cannot figure out for the life of me, although it seems simple...</p> <p>How do I delete the last 2 characters of each 4th index of a list, in a list? So in less confusing terms:</p> <pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append...
2
2016-09-01T05:08:37Z
39,263,238
<p>As already mentioned in comments:</p> <pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append([item.strip() for item in f]) L.append([item.strip() for item in p]) </code></pre> <p>Or in one step:</p> <pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', '...
0
2016-09-01T05:22:32Z
[ "python", "list" ]
Removing characters from indices within multiple lists
39,263,076
<p>Just a really quick question I cannot figure out for the life of me, although it seems simple...</p> <p>How do I delete the last 2 characters of each 4th index of a list, in a list? So in less confusing terms:</p> <pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append...
2
2016-09-01T05:08:37Z
39,263,278
<pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append(f) L.append(p) for i in L: i[3] = i[3].rstrip('\n') &gt;&gt;&gt; [['yes', 'no', 'tot', 'foop'], ['ick', 'throw', 'tamp', 'lap']] </code></pre>
0
2016-09-01T05:24:59Z
[ "python", "list" ]
Removing characters from indices within multiple lists
39,263,076
<p>Just a really quick question I cannot figure out for the life of me, although it seems simple...</p> <p>How do I delete the last 2 characters of each 4th index of a list, in a list? So in less confusing terms:</p> <pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append...
2
2016-09-01T05:08:37Z
39,263,357
<p>For getting each 4th element from the list use this part: <code>i[3::4]</code></p> <p>For removing last two symbols from item: <code>x[:-1]</code></p> <p>The output script:</p> <pre><code>for i in L: i[3::4] = [ x[:-1] for x in i[3::4]] </code></pre> <p>Result:</p> <blockquote> <p>[['yes', 'no', 'tot', 'f...
1
2016-09-01T05:31:19Z
[ "python", "list" ]
Removing characters from indices within multiple lists
39,263,076
<p>Just a really quick question I cannot figure out for the life of me, although it seems simple...</p> <p>How do I delete the last 2 characters of each 4th index of a list, in a list? So in less confusing terms:</p> <pre><code>f = ['yes', 'no', 'tot', 'foop\n'] p = ['ick', 'throw', 'tamp', 'lap\n'] L = [] L.append...
2
2016-09-01T05:08:37Z
39,265,504
<p>If you want to remove new lines and white space only from the 4th index with list comprehension:</p> <pre><code>&gt;&gt;&gt; f = ['yes', 'no', 'tot', 'foop\n'] &gt;&gt;&gt; p = ['ick', 'throw', 'tamp', 'lap\n'] &gt;&gt;&gt; [x[0:3]+[x[3].rstrip()] for x in [f]+[p]] [['yes', 'no', 'tot', 'foop'], ['ick', 'throw', 't...
1
2016-09-01T07:40:17Z
[ "python", "list" ]
Python 3 + Selenium: Find element by Xpath and text() doesn't work
39,263,091
<p>This is html code:</p> <pre><code>&lt;td&gt; &lt;a href="https://www.facebook.com/n/?confirmemail.php&amp;amp;e=myemail%40gmail.com&amp;amp;c=77438&amp;amp;cuid=AYh3nbnRpQs3d3S9QQ4e74G2jZzOBE69YqYVaWlnPtcs-SOpgHEFilr-khC8FsPUB5zzR6rvBQmgU54QxWdjn2jW9A5OhSaUal_KMcpvARnfDzPrmaOE3ObQrn-cfMk0MYFiR8fT0z8HVc3fX328oMpA&...
0
2016-09-01T05:10:25Z
39,263,190
<p>Try to check if the element contains the text instead of exact match</p> <pre><code>((By.XPATH, ".//*[contains(text(), 'Confirm Your Account')]")) </code></pre> <p>Or</p> <pre><code>((By.XPATH, ".//*[contains(., 'Confirm Your Account')]")) </code></pre>
0
2016-09-01T05:19:36Z
[ "python", "selenium", "xpath" ]
Python 3 + Selenium: Find element by Xpath and text() doesn't work
39,263,091
<p>This is html code:</p> <pre><code>&lt;td&gt; &lt;a href="https://www.facebook.com/n/?confirmemail.php&amp;amp;e=myemail%40gmail.com&amp;amp;c=77438&amp;amp;cuid=AYh3nbnRpQs3d3S9QQ4e74G2jZzOBE69YqYVaWlnPtcs-SOpgHEFilr-khC8FsPUB5zzR6rvBQmgU54QxWdjn2jW9A5OhSaUal_KMcpvARnfDzPrmaOE3ObQrn-cfMk0MYFiR8fT0z8HVc3fX328oMpA&...
0
2016-09-01T05:10:25Z
39,304,414
<p>you can use following xpath</p> <pre><code>driver.find_element_by_xpath("//td/a[1]") </code></pre>
0
2016-09-03T07:28:05Z
[ "python", "selenium", "xpath" ]
Argparse - Custom Action update to an dest dict
39,263,156
<p>I want to collect some options as a dict using <code>argparse</code>. I have wrote a custom Action class as follows. The problem is that the <code>__call__</code> method is never invoked. </p> <pre><code>#!/usr/bin/env python3 import argparse class UpdateDict(argparse.Action): def __init__(self, option_string...
0
2016-09-01T05:15:42Z
39,263,253
<p>Your <code>parse_args</code> function need to return the parser which it creates, as you need its <code>parse_args</code> method for the actual parsing. Also, you should source the arguments from <code>sys.argv[1:]</code>, basically the arguments except for the main program's argument (i.e. your script name). So y...
0
2016-09-01T05:23:52Z
[ "python", "argparse" ]
Argparse - Custom Action update to an dest dict
39,263,156
<p>I want to collect some options as a dict using <code>argparse</code>. I have wrote a custom Action class as follows. The problem is that the <code>__call__</code> method is never invoked. </p> <pre><code>#!/usr/bin/env python3 import argparse class UpdateDict(argparse.Action): def __init__(self, option_string...
0
2016-09-01T05:15:42Z
39,264,302
<p>With your script, simplified to focus on putting values in <code>mydict</code>:</p> <pre><code>import argparse class UpdateDict(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): adict = getattr(namespace, 'mydict') adict.update({self.dest: values}) def parse_...
0
2016-09-01T06:39:39Z
[ "python", "argparse" ]
C++ pointers in Cython
39,263,162
<p>I use Cython to wrap my C++ classes. Some of methods return sth. like <code>class_name*</code>. <code>class_name</code> may be some complicated class already described in pxd and pyx file (like it is mentioned here in extended answer <a href="http://stackoverflow.com/a/39116733/4881441">http://stackoverflow.com/a/39...
1
2016-09-01T05:16:09Z
39,285,634
<p>You can't directly return a pointer from a <code>def</code> method (only from a <code>cdef</code>).</p> <p>You'll need to write a Cython Wrapper class that stores the pointer you want to pass and you can return this Wrapper Object. If you want to execute methods on the C++ object you also have to use your Cython Wr...
1
2016-09-02T06:28:01Z
[ "python", "c++", "c++11", "pointers", "cython" ]
Make Some Tkinter Listbox Items Always Selected
39,263,298
<p>I have a tkinter listbox where some of the items in the listbox need to always be selected. In my app, these items are required by the user, whereas some other items in the listbox are optional (should be selectable/deselectable).</p> <p>Most examples bind a function using <code>'&lt;&lt;ListboxSelect&gt;&gt;'</cod...
1
2016-09-01T05:26:13Z
39,263,723
<p>Ok, nice question. Here is a workaround I managed to come up with, and it seems to work.</p> <p>First, create a list of indices you want to always keep selected:</p> <pre><code>items = ['apples', 'oranges', 'peaches', 'carrots', 'lettuce', 'grapes'] special_items = [0, 2, 4] for i,item in enumerate(items): .....
2
2016-09-01T06:01:11Z
[ "python", "tkinter", "listbox", "bind" ]
yaml exception in google app server "unable to add testProject to attribute application" regex issue?
39,263,309
<p>first day with google app engine.</p> <p>my yaml file includes the following:</p> <pre><code>application: testProgram version: 1 runtime: python api_version: 1 handlers: - url: /.* script: main.py libraries: - name: webapp2 version: "2.5.2" </code></pre> <p>my python file includes the following (just for gi...
2
2016-09-01T05:27:11Z
39,263,364
<p>It is most likely complaining about your applicationId, look at the regex, it accepts lowercased chars only.</p> <p>Change your applicationId to "testprogram" or "test-program"</p>
0
2016-09-01T05:31:58Z
[ "python", "google-app-engine", "yaml" ]
Pandas pop last row
39,263,411
<p>Is there any way to get and remove last row like <code>pop</code> method of python native list?</p> <p>I know I can do like below. I just want to make it one line.</p> <pre><code>df.ix[df.index[-1]] df = df[:-1] </code></pre>
1
2016-09-01T05:35:57Z
39,264,351
<p>Suppose sample dataframe:</p> <pre><code>In[51]:df Out[51]: a b 0 1 5 1 2 6 2 3 7 3 4 8 </code></pre> <p>you can do using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html" rel="nofollow">df.drop</a>:</p> <pre><code>In[52]:df,last_row=df.drop(df.tail(1).index),...
1
2016-09-01T06:42:31Z
[ "python", "pandas" ]
Sphinx custom template
39,263,486
<p>I want to add a "next" and "previous" button at the bottom of my page.</p> <p>I saw a similar question posted <a href="http://stackoverflow.com/questions/26260726/how-do-i-add-a-previous-chapter-and-next-chapter-link-in-documentation-gener">"here"</a></p> <p>But he doesn't explain which file to edit and where.</p>...
1
2016-09-01T05:42:05Z
39,263,666
<p>There are themes that provide that functionality out of the box. You could install Sphinx bootstrap theme, which is a nice looking theme with bootstrap integration. You can find it here: <a href="https://ryan-roemer.github.io/sphinx-bootstrap-theme/" rel="nofollow">https://ryan-roemer.github.io/sphinx-bootstrap-them...
2
2016-09-01T05:56:32Z
[ "python", "python-sphinx" ]
Django user login form user is none
39,263,527
<p>I'm having some trouble logging in users. I have the following views and template:</p> <p>views.py</p> <pre><code>def login(request): if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') user = auth.authenticate(username=username, ...
0
2016-09-01T05:44:55Z
39,263,961
<p>I suggest you make a forms.py file and in here make a class like so:</p> <pre><code>from django import forms from django.contrib.auth import authenticate, login, logout, get_user_model class LoginForm(forms.Form): username = forms.CharField() password = forms.CharField(widget=forms.PasswordInput) ...
0
2016-09-01T06:17:55Z
[ "python", "html", "django", "forms", "login" ]
Display missing values of specific column based on another specific column
39,263,536
<p>this is my problem</p> <p>Let's say I have 2 columns on the dataframe which look like this:</p> <pre><code> Type | Killed _______ |________ Dog 1 Dog nan Dog nan Cat 4 Cat nan Cow 1 Cow nan </code></pre> <p>I would like to display all missing value in Killed a...
4
2016-09-01T05:45:42Z
39,263,575
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.value_counts.html" rel="nofollow"><code>value_counts</code></a>:</p> <pre><code>print (d...
3
2016-09-01T05:48:47Z
[ "python", "pandas", "dataframe", "multiple-columns", null ]
Display missing values of specific column based on another specific column
39,263,536
<p>this is my problem</p> <p>Let's say I have 2 columns on the dataframe which look like this:</p> <pre><code> Type | Killed _______ |________ Dog 1 Dog nan Dog nan Cat 4 Cat nan Cow 1 Cow nan </code></pre> <p>I would like to display all missing value in Killed a...
4
2016-09-01T05:45:42Z
39,263,871
<p>I can get you both <code>isnull</code> and <code>notnull</code></p> <pre><code>isnull = np.where(df.Killed.isnull(), 'isnull', 'notnull') df.groupby([df.Type, isnull]).size().unstack() </code></pre> <p><a href="http://i.stack.imgur.com/qkD6N.png" rel="nofollow"><img src="http://i.stack.imgur.com/qkD6N.png" alt="en...
1
2016-09-01T06:11:56Z
[ "python", "pandas", "dataframe", "multiple-columns", null ]
Python to open ADODB recordset and add new record
39,263,563
<p>in my wxPython app which I am developing I have written a method which will add a new record into an access database (.accdb). I have procured this code from online search however am not able to make it work. Below is the code:-</p> <pre><code>def Allocate_sub(self, event): pth = os.getcwd() myDb = pth + '...
0
2016-09-01T05:48:01Z
39,309,654
<p>I figured the solution, posting here just in case someone refers to it... it's a small correction in line</p> <pre><code>cDataset.Open("Allocated_Subs", con, 3, 3, 1) </code></pre> <p>it should be:-</p> <pre><code>cDataset.Open("Allocated_Subs", con, 1, 3) </code></pre> <p>Regards, Premanshu</p>
0
2016-09-03T17:40:23Z
[ "python", "adodb", "recordset" ]
How can I read tar.gz file using pandas read_csv with gzip compression option?
39,263,929
<p>I have a very simple csv, with the following data, compressed inside the tar.gz file. I need to read that in dataframe using pandas.read_csv. </p> <pre><code> A B 0 1 4 1 2 5 2 3 6 import pandas as pd pd.read_csv("sample.tar.gz",compression='gzip') </code></pre> <p>However, I am getting error:</p> <pre...
1
2016-09-01T06:15:12Z
39,264,156
<pre><code>df = pd.read_csv('sample.tar.gz', compression='gzip', header=0, sep=' ', quotechar='"', error_bad_lines=False) </code></pre> <p>Note: <code>error_bad_lines=False</code> will ignore the offending rows. </p>
1
2016-09-01T06:30:57Z
[ "python", "csv", "pandas", "gzip", "tar" ]
Read .mat file in Python. But the shape of the data changed
39,264,196
<pre><code> % save .mat file in the matlab train_set_x=1:50*1*51*61*23; train_set_x=reshape(train_set_x,[50,1,51,61,23]); save(['pythonTest.mat'],'train_set_x','-v7.3'); </code></pre> <p>The data obtained in the matlab is in the size of (50,1,51,61,23).</p> <p>I load the .mat file in Python with the instruc...
6
2016-09-01T06:33:06Z
39,264,426
<p>You do not have any errors in the code. There is a fundamental difference between Matlab and python in the way they treat multi-dimensional arrays.<br> Both Matalb and python store all the elements of the multi-dim array as a single contiguous block in memory. The difference is the order of the elements:<br> <strong...
3
2016-09-01T06:47:02Z
[ "python", "matlab", "numpy", "file-io", "mat-file" ]
response.out.write in python, google app engine not displaying on local host
39,264,484
<p>my yaml file:</p> <pre><code>application: testprogram version: 1 runtime: python api_version: 1 handlers: - url: /.* script: main.py </code></pre> <p>my python file:</p> <pre><code>import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.reponse.headers['Content-Type'] = 'text/pl...
1
2016-09-01T06:49:49Z
39,276,599
<p>In the <code>.yaml</code> file, point the routing handler to main.app (not main.py).</p> <p>You also have have typo in your python file. response is missing the first 's':</p> <pre><code>self.reponse.headers['Content-Type'] = 'text/plain' </code></pre> <p>should be</p> <pre><code>self.response.headers['Content-T...
0
2016-09-01T16:29:22Z
[ "python", "google-app-engine", "localhost", "yaml" ]
response.out.write in python, google app engine not displaying on local host
39,264,484
<p>my yaml file:</p> <pre><code>application: testprogram version: 1 runtime: python api_version: 1 handlers: - url: /.* script: main.py </code></pre> <p>my python file:</p> <pre><code>import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.reponse.headers['Content-Type'] = 'text/pl...
1
2016-09-01T06:49:49Z
39,278,799
<p>You guys are going to laugh when you see this.</p> <p>Fixing the typo in self.response.headers was the fix.</p> <p>so originally my code was <code>self.reponse.headers['Content-Type'] = 'text/plain'</code></p> <p>and then I added this missing "s"</p> <p><code>self.response.headers['Content-Type'] = 'text/plain'...
-1
2016-09-01T18:46:08Z
[ "python", "google-app-engine", "localhost", "yaml" ]
response.out.write in python, google app engine not displaying on local host
39,264,484
<p>my yaml file:</p> <pre><code>application: testprogram version: 1 runtime: python api_version: 1 handlers: - url: /.* script: main.py </code></pre> <p>my python file:</p> <pre><code>import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.reponse.headers['Content-Type'] = 'text/pl...
1
2016-09-01T06:49:49Z
39,280,433
<p>You have a problem in <code>app.yaml</code> file in the handlers section:</p> <p>Yours:</p> <pre><code>application: testprogram version: 1 runtime: python api_version: 1 handlers: - url: /.* script: main.py </code></pre> <p>but you should have:</p> <pre><code>application: testprogram version: 1 runtime: pytho...
0
2016-09-01T20:33:37Z
[ "python", "google-app-engine", "localhost", "yaml" ]
Find and shows the highest record of the name list
39,264,545
<p>I'm new to Python. I've been given a task to write a Python program to read a name list which consist of people names and their height.</p> <p>Any suggestion or idea for coding to find out the highest height and show the record?</p> <p>For examples, the highest height is 180 and the result will show "Adam,180"</p>...
-5
2016-09-01T06:52:55Z
39,264,962
<p>We can use operator.itemgetter</p> <pre><code>import operator stats = {'Dave':179, 'Adam':180, 'Daniel': 170} max(stats.items(), key=operator.itemgetter(1)) </code></pre>
0
2016-09-01T07:13:48Z
[ "python" ]
Find and shows the highest record of the name list
39,264,545
<p>I'm new to Python. I've been given a task to write a Python program to read a name list which consist of people names and their height.</p> <p>Any suggestion or idea for coding to find out the highest height and show the record?</p> <p>For examples, the highest height is 180 and the result will show "Adam,180"</p>...
-5
2016-09-01T06:52:55Z
39,265,488
<pre><code>names = {'jason': 5.8, 'daniel': 5.0, 'rizwan': 6} &gt;&gt;&gt; sorted(names.items(), key=lambda value: value[1], reverse=True) [('rizwan', 6), ('jason', 5.8), ('daniel', 5.0)] &gt;&gt;&gt; max(sorted(names.items(), key=lambda value: value[1])) ('rizwan', 6) &gt;&gt;&gt; min(sorted(names.items(), key=lambd...
0
2016-09-01T07:39:19Z
[ "python" ]
Find and shows the highest record of the name list
39,264,545
<p>I'm new to Python. I've been given a task to write a Python program to read a name list which consist of people names and their height.</p> <p>Any suggestion or idea for coding to find out the highest height and show the record?</p> <p>For examples, the highest height is 180 and the result will show "Adam,180"</p>...
-5
2016-09-01T06:52:55Z
39,265,618
<p>if you have separate lists:</p> <pre><code>names = ['alireza','sarah','maryam','muhammad'] heights = [180,172,178,182] print(names[heights.index(max(heights))]) </code></pre> <p>if you want use dictionary:</p> <pre><code>names = {'alireza':180,'sarah':172,'maryam':178,'muhammad':182} max(names.keys(), key=name...
0
2016-09-01T07:45:46Z
[ "python" ]
Encoding issues in python how to fix it
39,264,757
<p>I get this error while writing data to csv file</p> <pre><code>import csv a = [u'eaTfxfwz', u'Edward', u'O\u2019Connell', u'[email protected]', u'Santa Clara', u'CA', 'UNITED STATES', u'150 Saratoga Avenue #306', u'', u'Santa Clara, CA', u'95051', u'', u'408-835-2209', u'None', u'', '', u'2012-010', u'pjOjJf...
0
2016-09-01T07:04:42Z
39,264,816
<p>You can use <code>utf-8</code> encoding.</p> <pre><code>import csv aenc=[] a = [u'eaTfxfwz', u'Edward', u'O\u2019Connell', u'[email protected]', u'Santa Clara', u'CA', 'UNITED STATES', u'150 Saratoga Avenue #306', u'', u'Santa Clara, CA', u'95051', u'', u'408-835-2209', u'None', u'', '', u'2012-010', u'pjOjJ...
0
2016-09-01T07:07:11Z
[ "python", "encoding", "utf" ]
finding the LCM using python
39,264,780
<p>def multiple(a, b): """so I'm trying to return the smallest number n that is a multiple of both a and b.</p> <p>for example:</p> <blockquote> <blockquote> <blockquote> <p>multiple(3, 4) 12 multiple(14, 21) 42 """</p> </blockquote> </blockquote> </blockquote...
-2
2016-09-01T07:05:36Z
39,264,825
<p>No need to find GCD, we can directly find LCM. Below code works</p> <pre><code>def lcmof(x,y): res=0 mx=max(x,y) mn=min(x,y) for i in range(1,mx+1,1): temp=mx*i try: if(temp%mn==0): res=temp break except ZeroDivisionError: ...
1
2016-09-01T07:07:34Z
[ "python", "lcm" ]
how to repeat / expand expressions in python
39,264,957
<p>What is the most pythonic way to repeat an expression in Python. </p> <p><strong>Context :</strong> A function is getting passed a dictionary (with possibly 20 elements) and I need to extract and use values from this dictionary <strong>if they exist</strong>. Something like this :</p> <pre><code>x = dict_name['key...
0
2016-09-01T07:13:46Z
39,265,147
<p>Whether there is an "equivalent" to <code>inline</code> in Python depends on who you ask, and what you check.</p> <p>For no equivalent, e.g.: <a href="http://stackoverflow.com/a/6442497/2707864">http://stackoverflow.com/a/6442497/2707864</a></p> <p>For equivalent, e.g.: <a href="https://www.safaribooksonline.com/l...
0
2016-09-01T07:22:06Z
[ "python", "inline" ]
How can I get more user information after allowing user sign up through Facebook in Django?
39,265,013
<p>I'm using <code>Python-social-auth</code>(<a href="https://github.com/omab/python-social-auth" rel="nofollow">https://github.com/omab/python-social-auth</a>) for user signing up through <code>Facebook</code>. </p> <p>Only defect is that I can't get more information about user if user sign up through <code>Facebook<...
1
2016-09-01T07:16:14Z
39,266,836
<p>Define in settings <code>SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS</code> with fields that interest you</p> <pre><code>SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = { 'fields': 'first_name, last_name, birthday' } </code></pre> <p>List of available fields you can see <a href="https://developers.facebook.com/docs/...
0
2016-09-01T08:48:49Z
[ "python", "django", "python-social-auth" ]
How to get the length of repeated numbers column wise?
39,265,221
<p>I am trying to get the length of repeated numbers in Python Numpy. For example, let's consider a simple ndarray</p> <pre><code>import numpy as np a = np.array([ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 1, 0, 0, 1, 1, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0, 0, 1, 0], [1, 1, 0, 0, 1, 1, 1, 1, 0, 0], ]) </code>...
1
2016-09-01T07:24:57Z
39,265,360
<p>With focus on performance, here's one generic approach for ndarrays -</p> <pre><code>ones_count = a.sum(-2) zeros_count = (a.shape[-2] - ones_count - a.argmax(-2))*a.any(-2) </code></pre> <p>One alternative to get <code>zeros_count</code> with selections using <code>np.where</code>, would be -</p> <pre><code>zero...
4
2016-09-01T07:31:54Z
[ "python", "numpy" ]
How to send celery all logs to a custom handler . in my case python-logstash handler
39,265,344
<p>In my Celery application I am getting 2 types of logs on the console i.e celery application logs and task level logs (inside task I am using logger.INFO(str) syntax for logging)</p> <p>I wanted to send both of them to a custom handler (in my case python-logstash handler )</p> <p>For django logs I was successfull, ...
2
2016-09-01T07:31:13Z
39,271,269
<pre><code>def initialize_logstash(logger=None,loglevel=logging.DEBUG, **kwargs): # logger = logging.getLogger('celery') handler = logstash.TCPLogstashHandler('localhost', 5959,tags=['worker']) handler.setLevel(loglevel) logger.addHandler(handler) # logger.setLevel(logging.DEBUG) return logger ...
0
2016-09-01T12:12:42Z
[ "python", "logging", "logstash", "django-celery", "celery-task" ]
How to specify metadata for dask.dataframe
39,265,396
<p>Providing metadata became very important in dask 0.11. The API provides some good examples, how to achieve that, but when it comes to picking the right dtypes for my dataframe, I still feel unsure.</p> <ul> <li>Could I do something like <code>meta={'x': int 'y': float, 'z': float}</code> instead of <code>meta={'x'...
3
2016-09-01T07:33:58Z
39,266,754
<p>The available basic data types are the ones which are offered through numpy. Have a look at the <a href="http://docs.scipy.org/doc/numpy-1.10.1/user/basics.types.html" rel="nofollow">documentation</a> for a list.</p> <p>Not included in this set are datetime-formats (e.g. <code>datetime64</code>), for which addition...
2
2016-09-01T08:44:50Z
[ "python", "pandas", "dask" ]
How to specify metadata for dask.dataframe
39,265,396
<p>Providing metadata became very important in dask 0.11. The API provides some good examples, how to achieve that, but when it comes to picking the right dtypes for my dataframe, I still feel unsure.</p> <ul> <li>Could I do something like <code>meta={'x': int 'y': float, 'z': float}</code> instead of <code>meta={'x'...
3
2016-09-01T07:33:58Z
39,271,481
<p>Both Dask.dataframe and Pandas use NumPy dtypes. In particular, anything within that you can pass to <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html" rel="nofollow">np.dtype</a>. This includes the following:</p> <ol> <li>NumPy dtype objects, like <code>np.float64</code></li> <li>Pyth...
2
2016-09-01T12:23:01Z
[ "python", "pandas", "dask" ]
Call RPC from component with different role Crossbar.io
39,265,582
<p>I need to call procedure in Crossbar component, with it everything ok. But I have such configuration:</p> <pre><code> { "name": "somerole", "permissions": [ { "uri": "com.example.api.sender", "match": "exact", "allow": { "call": true, "regi...
0
2016-09-01T07:44:02Z
39,266,999
<p>I found a solution. Created additional class </p> <pre><code>class APIBaseSession(ApplicationSession): instance = None @inlineCallbacks def onJoin(self, details): if not APIBaseSession.instance: APIBaseSession.instance = self else: raise ValueError("Instance of ...
0
2016-09-01T08:56:04Z
[ "python", "python-3.x", "autobahn", "crossbar" ]
How to display json value in django template?
39,265,646
<p>This is my View.py code... </p> <pre><code>import requests from django.http import HttpResponse from django.shortcuts import render import json def book(request): if request.method == 'POST': r = requests.post('http://api.railwayapi.com/cancelled/date/01-09-2016/apikey/mezxa1595/', params=request.POS...
0
2016-09-01T07:47:26Z
39,266,753
<p>That "js" should be a python dict not json object. You may need to:</p> <pre><code>return render(request,'book.html', {'js': json.loads(js)}) </code></pre> <p>Then you can use the variables in <code>book.html</code> template.</p>
-1
2016-09-01T08:44:50Z
[ "javascript", "python", "json", "django" ]
How to convert tar.gz file to zip using Python only?
39,265,680
<p>Does anybody has any code for converting tar.gz file into zip using only Python code? I have been facing many issues with tar.gz as mentioned in the <a href="http://stackoverflow.com/questions/39263929/how-can-i-read-tar-gz-file-using-pandas-read-csv-with-gzip-compression-option">How can I read tar.gz file using pan...
0
2016-09-01T07:48:49Z
39,265,752
<p>You would have to use the <a href="https://docs.python.org/3/library/tarfile.html" rel="nofollow">tarfile</a> module, with mode <code>'r|gz'</code> for reading. Then use <a href="https://docs.python.org/3/library/zipfile.html#module-zipfile" rel="nofollow">zipfile</a> for writing.</p> <pre><code>import tarfile, zip...
1
2016-09-01T07:52:46Z
[ "python", "zip", "tar" ]
asyncio "Task was destroyed but it is pending!" in pysnmp sample program
39,265,772
<p>I am testing pysnmp asyncio module and as the start used the <a href="http://pysnmp.sourceforge.net/_downloads/multiple-sequential-queries.py" rel="nofollow">sample program</a> provided along with the documentation. When I run the sample program, it gives the <code>Task was destroyed but it is pending!</code> error....
0
2016-09-01T07:53:56Z
39,437,074
<p>There is an internal timer function in pysnmp which is used for handling caches, retries etc. With asyncio transport that timer is driven by asyncio <code>Future</code>. The message you observe warns you about that Future object is still pending right before main loop is shut down.</p> <p>To fix that you need to ca...
0
2016-09-11T14:26:21Z
[ "python", "python-3.x", "python-asyncio", "pysnmp" ]
Comparing previous and next values in a list or in a dataframe
39,265,798
<p>I am new here and have, after a lot of research, not been able to crack this one.</p> <p>My List looks somewhat like this:</p> <pre><code>lister=["AB1","AB2","AB3","AB3-2","AB3-3","AB3-4","AB4","AB4-2","AB5"] </code></pre> <p>It is a list of existing folders and cannot be changed into something more practical. I ...
0
2016-09-01T07:54:59Z
39,266,032
<pre><code>gb = pd.Series(lister).str.split('-', 1, expand=True).groupby(0)[1].last().fillna('') </code></pre> <p>Gives you:</p> <pre><code>AB1 AB2 AB3 4 AB4 2 AB5 </code></pre> <p>Then:</p> <pre><code>gb.index + np.where(gb, '-' + gb, '') </code></pre> <p>Gives you:</p> <pre><code>['AB1', 'A...
5
2016-09-01T08:07:13Z
[ "python", "string", "list", "pandas" ]
Comparing previous and next values in a list or in a dataframe
39,265,798
<p>I am new here and have, after a lot of research, not been able to crack this one.</p> <p>My List looks somewhat like this:</p> <pre><code>lister=["AB1","AB2","AB3","AB3-2","AB3-3","AB3-4","AB4","AB4-2","AB5"] </code></pre> <p>It is a list of existing folders and cannot be changed into something more practical. I ...
0
2016-09-01T07:54:59Z
39,266,432
<p>this is <strong>not best</strong> answer and i think has <strong>bad performance</strong> but if someone need pure python without any module or use Cython(typed variables) this may help:</p> <pre><code>lister=["AB1","AB2","AB3","AB3-2","AB3-3","AB3-4","AB4","AB4-2","AB5"] resulter = list() i=0 while i&lt; len(list...
1
2016-09-01T08:28:32Z
[ "python", "string", "list", "pandas" ]
Python sys._getframe
39,265,823
<p>/mypath/test.py</p> <pre><code>import sys def test(): frame = sys._getframe(0) f = frame.f_code.co_filename print('f:', f) print('co_filename1:', frame.f_code.co_filename) while frame.f_code.co_filename == f: frame = frame.f_back print('co_filename2:', frame.f_code.co_filename) tes...
1
2016-09-01T07:56:09Z
39,266,128
<p>Whenever you run <code>frame = frame.f_back</code> you go back to the previous code frame. When you are on the topmost frame, however, <code>f_back</code> attribute contains None (as in "there is no previous frame") - so you should just break off the while loop at that point. Just add an extra condition to that, fo...
0
2016-09-01T08:11:57Z
[ "python" ]
Regex on bytestring in Python 3
39,265,923
<p>I am using RegEx to match BGP messages in a byte string. An example byte string is looking like this:</p> <p><code>b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x13\x04'</code></p> <p>\xff (8 times) is used as "mag...
3
2016-09-01T08:01:41Z
39,265,986
<p>I think you want to match 8 occurrences of <code>\xff</code>, not just 8 trailing <code>f</code>s (e.g. <code>\xfffffffff</code>):</p> <pre><code>messages = re.split(b'(?:\xff){8}', payload) ^^^ ^ </code></pre> <p>Also, there are just more than one 8 consecutive <code>\xff</code>s in your ...
1
2016-09-01T08:04:50Z
[ "python", "regex", "python-3.x", "bytestring" ]
How to draw recursive tree on tkinter
39,266,081
<p>I tried to draw recursive tree on python tkinter based on depth enter by user, here is my code so far:</p> <pre><code>from tkinter import * # Import tkinter import math #angleFactor = math.pi/5 #sizeFactor = 0.58 class Main: def __init__(self): window = Tk() # Create a window window.title("Rec...
0
2016-09-01T08:10:00Z
39,267,844
<p>Your main problem is that you messed up the args to the <code>drawLine</code> method. You defined it as </p> <pre><code>drawLine(self, x1,x2,y1,y2) </code></pre> <p>but you call it as </p> <pre><code>self.drawLine(x1,y1,x2,y2) </code></pre> <p>so the <code>y1</code> arg you pass it gets used for the <code>x2</co...
1
2016-09-01T09:32:43Z
[ "python", "recursion", "tkinter" ]
auto increment - internal reference odoo9
39,266,106
<p>I want to change the type of the field 'ref' (Internal Reference) to be auto incremented (for example every time I create a new contact my Internal Reference should increase by 1). So first contact should have Internal Reference 1, the second 2, the third 3 and so on...</p> <p>There are no errors but still the refe...
0
2016-09-01T08:11:08Z
39,266,450
<p>You don't need the unnecessary if statement, because as you stated in your question you want the reference to autoincrement every time a new user is created. the users can't change the field from the form, this is how you get the next reference in odoo.</p> <pre><code>@api.model def create(self, vals): vals['re...
0
2016-09-01T08:29:24Z
[ "python", "xml", "auto-increment", "odoo-9" ]
Suppose i have two lists in python a list of first names and a list of last names
39,266,197
<pre><code>firstName = ['abcd','efghi','jkl','mnopqr'] lastName = ['xyz','pqrst','uvw','klmn'] </code></pre> <p>my desired output is </p> <pre><code>abcd xyz [email protected] efghi pqrst [email protected] jkl uvw [email protected] mnopqr klmn [email protected] </code></pre> <p>I have tried various methods an...
-1
2016-09-01T08:15:12Z
39,266,259
<pre><code>for x, y in zip(firstName,lastName): print(x, y, "%s.%[email protected]"%(x[0], y)) </code></pre>
1
2016-09-01T08:19:09Z
[ "python" ]
Suppose i have two lists in python a list of first names and a list of last names
39,266,197
<pre><code>firstName = ['abcd','efghi','jkl','mnopqr'] lastName = ['xyz','pqrst','uvw','klmn'] </code></pre> <p>my desired output is </p> <pre><code>abcd xyz [email protected] efghi pqrst [email protected] jkl uvw [email protected] mnopqr klmn [email protected] </code></pre> <p>I have tried various methods an...
-1
2016-09-01T08:15:12Z
39,266,299
<pre><code>&gt;&gt;&gt; for x,y in zip(firstName,lastName): ... print("{0}\t{1}\t{2}".format(x,y,x[0]+'.'+y+'@example.com')) ... abcd xyz [email protected] efghi pqrst [email protected] jkl uvw [email protected] mnopqr klmn [email protected] </code></pre>
1
2016-09-01T08:21:16Z
[ "python" ]
Suppose i have two lists in python a list of first names and a list of last names
39,266,197
<pre><code>firstName = ['abcd','efghi','jkl','mnopqr'] lastName = ['xyz','pqrst','uvw','klmn'] </code></pre> <p>my desired output is </p> <pre><code>abcd xyz [email protected] efghi pqrst [email protected] jkl uvw [email protected] mnopqr klmn [email protected] </code></pre> <p>I have tried various methods an...
-1
2016-09-01T08:15:12Z
39,266,311
<pre><code>firstName = ['abcd','efghi','jkl','mnopqr'] lastName = ['xyz','pqrst','uvw','klmn'] for index in range(0, len(firstName)): first = firstName[index] last = lastName[index] email = first[0] + '.' + last + '@example.com' print first, last, email </code></pre>
0
2016-09-01T08:21:41Z
[ "python" ]
Suppose i have two lists in python a list of first names and a list of last names
39,266,197
<pre><code>firstName = ['abcd','efghi','jkl','mnopqr'] lastName = ['xyz','pqrst','uvw','klmn'] </code></pre> <p>my desired output is </p> <pre><code>abcd xyz [email protected] efghi pqrst [email protected] jkl uvw [email protected] mnopqr klmn [email protected] </code></pre> <p>I have tried various methods an...
-1
2016-09-01T08:15:12Z
39,266,314
<pre><code>for i,j in zip(firstName,lastName): print (i+" "+j+" "+i[0]+"."+j+"@example.com") </code></pre> <p>output </p> <pre><code>abcd xyz [email protected] efghi pqrst [email protected] jkl uvw [email protected] mnopqr klmn [email protected] </code></pre>
0
2016-09-01T08:21:55Z
[ "python" ]
Suppose i have two lists in python a list of first names and a list of last names
39,266,197
<pre><code>firstName = ['abcd','efghi','jkl','mnopqr'] lastName = ['xyz','pqrst','uvw','klmn'] </code></pre> <p>my desired output is </p> <pre><code>abcd xyz [email protected] efghi pqrst [email protected] jkl uvw [email protected] mnopqr klmn [email protected] </code></pre> <p>I have tried various methods an...
-1
2016-09-01T08:15:12Z
39,266,322
<p>This prints the output you're looking for. Did you really just want to print it ?</p> <pre><code>for x,y in zip(firstName,lastName): print (x,y, x[0] + r'.' + y + r'@example.com') </code></pre>
1
2016-09-01T08:22:07Z
[ "python" ]
Fit erf function to data
39,266,231
<p>So I have hysteresis loop. I want to use the erf function to fit it with my data.</p> <p>A portion of my loop is shown in black on the lower graph.</p> <p>I am trying to use the <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html" rel="nofollow"><code>scipy.optimize.curve_fi...
1
2016-09-01T08:17:12Z
39,267,369
<p>I suspect two things are needed for a good fit here. First, I believe you need to add <code>mFL</code> to your <code>erfunc</code> function, and second, as suggested by Glostas, you need to specify some initial guesses for your fitting parameters. I created some artificial data in an attempt to replicate your data. ...
2
2016-09-01T09:11:34Z
[ "python", "python-3.x", "numpy", "scipy" ]
transcrypt import in import
39,266,262
<p>Using Transcrypt for python to javascript compiling I have 2 modules that need each other. For example: </p> <p>myTest.py:</p> <pre><code>import myTest2 def test(): myTest2.test() someConstant = 1 </code></pre> <p>and myTest2.py:</p> <pre><code>import myTest def test(): console.log(myTest.someConstant) <...
1
2016-09-01T08:19:18Z
39,266,474
<p>Try importing from <code>myTest</code> as and when you need it.</p> <p>In <code>mytest2.py</code></p> <pre><code>def test(): from myTest import someConstant console.log(someConstant) </code></pre>
0
2016-09-01T08:30:21Z
[ "javascript", "python", "transcrypt" ]
transcrypt import in import
39,266,262
<p>Using Transcrypt for python to javascript compiling I have 2 modules that need each other. For example: </p> <p>myTest.py:</p> <pre><code>import myTest2 def test(): myTest2.test() someConstant = 1 </code></pre> <p>and myTest2.py:</p> <pre><code>import myTest def test(): console.log(myTest.someConstant) <...
1
2016-09-01T08:19:18Z
39,280,920
<p>In Transcrypt imports are resolved at compile time rather than runtime, since the compiler must know which modules to include in the generated JavaScript. Moreover, import resolution happens in one pass. This fact that resolution happens in a single pass means that mutual (or in general cyclic) imports are not suppo...
2
2016-09-01T21:12:04Z
[ "javascript", "python", "transcrypt" ]
write into file without reading all the file
39,266,351
<p>I have a template of a file (html) with the header and footer. I try to insert text into right after <code>&lt;trbody&gt;</code>. The way i'm doing it right now is with <code>fileinput.input()</code> </p> <pre><code>def write_to_html(self,path): for line in fileinput.input(path, inplace=1): line = re.sub(r'CUR...
0
2016-09-01T08:23:21Z
39,266,661
<p>5000 lines is nothing. Read the entire file using <code>f.readlines()</code> to get a list of lines:</p> <pre><code>with open(path) as f: lines = f.readlines() </code></pre> <p>Then process each line, and eventually join them to one string and write the entire thing back to the file.</p>
-2
2016-09-01T08:40:16Z
[ "python", "python-2.7" ]
write into file without reading all the file
39,266,351
<p>I have a template of a file (html) with the header and footer. I try to insert text into right after <code>&lt;trbody&gt;</code>. The way i'm doing it right now is with <code>fileinput.input()</code> </p> <pre><code>def write_to_html(self,path): for line in fileinput.input(path, inplace=1): line = re.sub(r'CUR...
0
2016-09-01T08:23:21Z
39,274,864
<p>Re-reading the question a couple more times, the following thought occurs. Could you split the writing into 3 blocks - one for the header, one for the table lines and another for the footer. It does rather seem to depend on what those three substitution lines are doing, but if I'm right, they can only update lines t...
1
2016-09-01T14:55:30Z
[ "python", "python-2.7" ]
How to delete directory containing .git in python
39,266,408
<p>I am not able to override/delete the folder containing .git in python. I am working on the below configuration:</p> <ul> <li>OS - Windows 8</li> <li>Python - 3.5.2</li> <li>Git - 2.9.2</li> </ul> <p>Any Help would be appreciated.</p>
0
2016-09-01T08:26:55Z
39,266,507
<p>You should be using shutil to remove a directory that's not empty. If <code>os.rmdir</code> is used on a directory that's not empty an exception is raised. </p> <pre><code>import shutil shutil.rmtree('/.git') </code></pre>
0
2016-09-01T08:32:25Z
[ "python", "git" ]
How to delete directory containing .git in python
39,266,408
<p>I am not able to override/delete the folder containing .git in python. I am working on the below configuration:</p> <ul> <li>OS - Windows 8</li> <li>Python - 3.5.2</li> <li>Git - 2.9.2</li> </ul> <p>Any Help would be appreciated.</p>
0
2016-09-01T08:26:55Z
39,266,520
<p>try this code</p> <pre><code>import shutil shutil.rmtree('/path/to/your/dir/') </code></pre>
0
2016-09-01T08:32:59Z
[ "python", "git" ]
Dynamic framesize in Python Reportlab
39,266,415
<p>I tried to generate a shipping list with <a href="/questions/tagged/reportlab" class="post-tag" title="show questions tagged &#39;reportlab&#39;" rel="tag">reportlab</a> in Python. I was trying to put all parts (like senders address, receivers address, a table) in place by using Platypus <code>Frames</code>.</p> <p...
1
2016-09-01T08:27:26Z
39,268,987
<p>Your use case is a really common one, so Reportlab has a system to help you out. </p> <p>If you read the user guide about <code>platypus</code> it will introduce you to 4 main concepts: </p> <blockquote> <p><code>DocTemplates</code> the outermost container for the document;</p> <p><code>PageTemplates</code>...
1
2016-09-01T10:24:02Z
[ "python", "pdf", "pdf-generation", "reportlab" ]
Django Admin showing Object - not working with __unicode__ OR __str__
39,266,629
<p>my Django admin panel is showing <code>object</code> instead of <code>self.name</code> of the object.</p> <p>I went through several similar questions here yet couldn't seem to resolve this issue. <code>__unicode__</code> and <code>__str__</code> bear the same results, both for books and for authors. I've changed th...
1
2016-09-01T08:38:32Z
39,266,725
<p>Your indentation is incorrect. You need to indent the code to make it a method of your model. It should be:</p> <pre><code>class Author(models.Model): name = models.CharField(max_length=100) def __str__(self): return self.name </code></pre> <p>If you are using Python 3, use <a href="https://docs.d...
3
2016-09-01T08:43:30Z
[ "python", "django", "postgresql" ]
Import module does not work through terminal, while it works through IDE
39,266,662
<p>I have a projects consisting of two packages like this:</p> <pre><code>MyProjectDir -Package1 --__init__.py --file1_1.py --file1_2.py --file1_3.py -Package2 --__init__.py --file2_1.py --file2_2.py --file2_3.py </code></pre> <p>Now, in the packages the files have some imports between files:</p> <p><strong>file2_3....
2
2016-09-01T08:40:17Z
39,267,022
<p>The issue is that the way in which you are running the program <em>is wrong</em>, PyCharm is aware on how to handle python submodules and thus executes the file correctly.</p> <p>If you have a package <code>package1</code> with a module <code>package1.my_module</code> you should run this using the <code>-m</code> s...
1
2016-09-01T08:57:14Z
[ "python", "windows", "import" ]
NameError: global name 'QContextMenuEvent' is not defined
39,266,682
<p>I want to add a right click menu.</p> <pre><code>def contextMenuEvent(self,event): global posX global posY global selections,scan_widget if event.reason() == QContextMenuEvent.Mouse: menu = QMenu(self) clear = menu.addAction('Clear') for i in selections: self.bu...
0
2016-09-01T08:41:39Z
39,267,282
<p>From what I googled, <code>QContextMenuEvent</code> class resides in the <code>QtGui</code> module which can be imported from <code>PyQt5</code></p> <pre><code>from PyQt5.QtGui import QContextMenuEvent </code></pre>
2
2016-09-01T09:07:52Z
[ "python", "menu", "pyqt5" ]
NameError: global name 'QContextMenuEvent' is not defined
39,266,682
<p>I want to add a right click menu.</p> <pre><code>def contextMenuEvent(self,event): global posX global posY global selections,scan_widget if event.reason() == QContextMenuEvent.Mouse: menu = QMenu(self) clear = menu.addAction('Clear') for i in selections: self.bu...
0
2016-09-01T08:41:39Z
39,268,067
<p>I replaced </p> <p><code>if event.reason() == QContextMenuEvent.Mouse:</code> </p> <p>with</p> <p><code>if event.button == Qt.RightButton:</code></p>
0
2016-09-01T09:42:52Z
[ "python", "menu", "pyqt5" ]
How to use sqlalchemy to query in many-to-many relation?
39,266,776
<p>To get a member list in current organization, i used following statement, </p> <pre><code>from ..members import members from flask.ext.login import current_user from app.common.database import db_session @members.route("/", methods=["GET"]) @login_required def index(): datas = db_session.query(Group_has_Person...
0
2016-09-01T08:46:02Z
39,340,319
<p>I've resolved my question by the following statement:</p> <pre><code>datas = db_session.query(Group_has_Person).join(Group).filter(Group.organization==current_user.organization).all() </code></pre>
0
2016-09-06T03:43:53Z
[ "python", "sqlalchemy" ]
Python multiprocessing pool freezes without reason
39,266,816
<p>I am pretty new to python and I hope someone here can help me.</p> <p>I started learning python some weeks ago and I tried to build a webcrawler.</p> <p>The idea is the following: The first part crawls the domains from a website (for each letter). The second part checks if the domain is valid (reachable and not pa...
0
2016-09-01T08:47:36Z
39,291,210
<p>After several hours debugging and testing I could fix the problem.</p> <p>Instead of the multiprocessing pool I've used the ThreadPoolExecutor (which is better for network applications)</p> <p>I've figured out that the requests.get() in the threaded function caused some troubles. I changed the timeout to 1.</p> <...
0
2016-09-02T11:25:37Z
[ "python", "web-crawler", "python-multiprocessing" ]
Multithreaded webserver in Python
39,266,927
<p>An example from a video lecture. Background: the lecturer gave a simplest web server in python. He created a socket, binded it, made listening, accepted a connection, received data, and send it back to the client in uppercase. Then he said that there is a drawback: this web server is single-threaded. Then let's fork...
0
2016-09-01T08:52:32Z
39,268,473
<p>The correct netstat usage is:</p> <pre><code>netstat -tanp </code></pre> <p>because you need the <code>-a</code> option to display listening sockets. Add grep to locate your program quickly:</p> <pre><code>netstat -tanp| grep 8080 </code></pre>
0
2016-09-01T10:00:41Z
[ "python", "multithreading", "webserver" ]
How can I use integer that I supply into tf.placeholder(tf.int32)?
39,266,944
<p>I need to initialize a dynamic list which has length given by an integer that I will put into a placeholder through feed_dict. </p> <p>I set up the graph through this code: </p> <pre><code>num_placeholder = tf.placeholder(tf.int32) input_data = list() for _ in range(num_placeholder): input_data.append(1) <...
0
2016-09-01T08:53:22Z
39,272,841
<p><code>num_placeholder</code> is a <code>Tensor</code> object, it can not be directly used as an <code>int</code>, it must be valuated first. See documentation on <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/io_ops.html#placeholder" rel="nofollow"><code>placeholder</code></a> method.</p> <p>If ...
1
2016-09-01T13:27:23Z
[ "python", "machine-learning", "tensorflow" ]
Python class inheritance - how to use this to connect to a mysql database
39,267,056
<p>I am using python 2.7 and I have written a set of python classes in order to upload data to my database. However I am not sure I am completely understanding how to use inheritance from class to class. What I have is a User and Database class - which searches for the users/ databases from a list:</p> <pre><code>cla...
1
2016-09-01T08:58:48Z
39,267,256
<p>If you are inheriting you dont need to create a User and Database instance. You can just create a DatabaseConnect object:</p> <pre><code>class DatabaseConnect(User, Database): def __init__(self, username, database): User.__init__(self, username) Database.__init__(self, database) def connec...
1
2016-09-01T09:06:56Z
[ "python", "mysql", "python-2.7", "class", "inheritance" ]
Python class inheritance - how to use this to connect to a mysql database
39,267,056
<p>I am using python 2.7 and I have written a set of python classes in order to upload data to my database. However I am not sure I am completely understanding how to use inheritance from class to class. What I have is a User and Database class - which searches for the users/ databases from a list:</p> <pre><code>cla...
1
2016-09-01T08:58:48Z
39,267,266
<p>By doing:</p> <pre><code>def __init__(self, username, database): self.username = User.username self.database = Database.database </code></pre> <p>you are not properly initialising the <code>User</code> and <code>Database</code> instances. You need to call their <code>__init__</code> function. There are sev...
0
2016-09-01T09:07:14Z
[ "python", "mysql", "python-2.7", "class", "inheritance" ]
Pandas - Multiindex Division [i.e. Division by Group]
39,267,126
<p><strong>Aim:</strong> I'm trying to divide each row in a multilevel index by the total number in each group.</p> <p><strong>More specifically:</strong> Given the following data, I want to divide the number of Red and Blue marbles by the total number in each group (i.e. the sum across Date, Country and Colour) </p> ...
1
2016-09-01T09:01:15Z
39,269,086
<p>A shorter version would be:</p> <pre><code>df.groupby(level=['Date', 'Country']).transform(lambda x: x/x.sum()) number Date Country Colour 2011 US Red 0.400 Blue 0.600 2012 IN Red 1.000 IE Red 0.500 Blue 0.500 2013 JP...
2
2016-09-01T10:27:50Z
[ "python", "pandas" ]
Can't upload any data to bigquery using table.insertall()
39,267,210
<p>This is the portion of my code that I'm having issues with.</p> <pre><code>table_data_insert_all_request_body = { "kind": "bigquery#tableDataInsertAllRequest", "skipInvalidRows": True, "ignoreUnknownValues": True, "templateSuffix": 'suffix', "rows": [ { "json": { ("one"): ("two"), ("th...
0
2016-09-01T09:05:19Z
39,290,878
<p>Even though its tough to tell without looking at your schema, I am pretty sure your json data is not correct. Here is what I use.</p> <pre><code>Bodyfields = { "kind": "bigquery#tableDataInsertAllRequest", "rows": [ { "json": { 'col_name_1...
1
2016-09-02T11:04:58Z
[ "python", "json", "python-2.7", "google-bigquery" ]
How to split a string in python based on dots, ignoring decimal values?
39,267,292
<p>I have the following string:</p> <blockquote> <p>s = 'This .is sparta 1.2 version. Please check.'</p> </blockquote> <p>I want to split it based on dots, while ignoring decimal figures. So, Required Output :</p> <blockquote> <p>['This ','is sparta 1.2 version','Please check']</p> </blockquote> <p>I tried foll...
1
2016-09-01T09:08:27Z
39,267,366
<p>Try splitting on</p> <pre><code>(?&lt;!\d)\.(?!\d) </code></pre> <p>It makes sure the dot isn't preceded, nor followed, by a digit.</p> <p><a href="https://regex101.com/r/iA0xQ2/1" rel="nofollow">See it here at regex101</a>.</p>
4
2016-09-01T09:11:29Z
[ "python", "regex" ]
How to split a string in python based on dots, ignoring decimal values?
39,267,292
<p>I have the following string:</p> <blockquote> <p>s = 'This .is sparta 1.2 version. Please check.'</p> </blockquote> <p>I want to split it based on dots, while ignoring decimal figures. So, Required Output :</p> <blockquote> <p>['This ','is sparta 1.2 version','Please check']</p> </blockquote> <p>I tried foll...
1
2016-09-01T09:08:27Z
39,267,476
<p>Since almost have what you want, you could parse the current output to remove Nones and empty strings.</p> <p>This can be done in one line using list comprehension:</p> <pre><code>FilteredList = [ itm for itm in UnfilteredList if itm is not None and len(itm)&gt;0] </code></pre>
0
2016-09-01T09:16:15Z
[ "python", "regex" ]
Replace rows in a Pandas df with rows from another df
39,267,372
<p>I have 2 Pandas dfs, A and B. Both have 10 columns and the index 'ID'. Where the IDs of A and B match, I want to replace the rows of B with the rows of A. I have tried to use pd.update, but no success yet. Any help appreciated.</p>
0
2016-09-01T09:11:45Z
39,272,096
<p>below code should do the trick</p> <pre><code>s1 = pd.Series([5, 1, 'a']) s2 = pd.Series([6, 2, 'b']) s3 = pd.Series([7, 3, 'd']) s4 = pd.Series([8, 4, 'e']) s5 = pd.Series([9, 5, 'f']) df1 = pd.DataFrame([list(s1), list(s2),list(s3),list(s4),list(s5)], columns = ["A", "B", "C"]) s1 = pd.Series([5, 6, 'p']) s...
0
2016-09-01T12:53:08Z
[ "python", "pandas", "dataframe" ]
How to work with Django inline forms?
39,267,386
<p>I have two models (Receipt and Ingredient) and want to create ingredients when creating receipt.</p> <p><strong>forms.py</strong></p> <pre><code>from django import forms from django.forms import ModelForm from django.forms.models import inlineformset_factory from .models import Receipt, Ingredient, CookingStep c...
0
2016-09-01T09:12:21Z
39,268,006
<p>Firstly, use some consistent names for your variables. Your <code>ReceiptForm</code> instance is a form, not a formset, so call it <code>form</code>. Let's call your <code>ReceiptFormSet</code> instance <code>formset</code> everywhere.</p> <p>Next, you need to include your form and formset in the template context w...
0
2016-09-01T09:40:25Z
[ "python", "django" ]
Advanced mailto use in Python
39,267,464
<p>I'm trying to send an email with custom recipient, subject and body in Python. This means I don't want to use <a href="http://stackoverflow.com/questions/6270782/how-to-send-an-email-with-python">Python's smtp packages</a>, but something like <a href="https://docs.python.org/2.7/library/webbrowser.html?highlight=web...
1
2016-09-01T09:15:40Z
39,268,665
<p>Use string concatenation.</p> <pre><code>recipient = '[email protected]' subject = 'mysubject' body = 'This is a message' webbrowser.open("mailto:?to='+ recipient + '&amp;subject=' + subject + "&amp;body=" + body, new=1) </code></pre>
0
2016-09-01T10:09:10Z
[ "python", "python-2.7", "email", "python-webbrowser" ]
Advanced mailto use in Python
39,267,464
<p>I'm trying to send an email with custom recipient, subject and body in Python. This means I don't want to use <a href="http://stackoverflow.com/questions/6270782/how-to-send-an-email-with-python">Python's smtp packages</a>, but something like <a href="https://docs.python.org/2.7/library/webbrowser.html?highlight=web...
1
2016-09-01T09:15:40Z
39,269,802
<p>I use the variables <strong>recipient</strong> and <strong>subject</strong> to store the relative values. Simply replace the example text between single quotes with your real value.</p> <pre><code>recipient = 'emailaddress' subject = 'mysubject' </code></pre> <p>The subject field can't contain white spaces, so the...
1
2016-09-01T11:02:22Z
[ "python", "python-2.7", "email", "python-webbrowser" ]
Comparing list of tuples within dictionary
39,267,495
<p>I have been cracking my head over this problem... I have a simplified dataset like such:<br> <code>dict = {'A': [('a', 1, 1), ('b', 2, 2), ('c', 3, 3)], 'B': [('b', 2, 2), ('a', 1, 1)], 'C': [('d', 4, 4)], 'D': [('c', 3, 3), ('e', 5, 5)]}</code><br> where the value represents a list of tuples. </p> <p>I need t...
0
2016-09-01T09:17:29Z
39,267,957
<p>You can use <a href="https://docs.python.org/2/library/sets.html" rel="nofollow">sets</a> to check whether one value is contained (<code>set.issubset(otherset)</code>) within one another. The below code demonstrates how you could implement this very easily. For each value every other value is checked for inclusion. ...
0
2016-09-01T09:38:12Z
[ "python", "dictionary" ]
Comparing list of tuples within dictionary
39,267,495
<p>I have been cracking my head over this problem... I have a simplified dataset like such:<br> <code>dict = {'A': [('a', 1, 1), ('b', 2, 2), ('c', 3, 3)], 'B': [('b', 2, 2), ('a', 1, 1)], 'C': [('d', 4, 4)], 'D': [('c', 3, 3), ('e', 5, 5)]}</code><br> where the value represents a list of tuples. </p> <p>I need t...
0
2016-09-01T09:17:29Z
39,268,173
<p>You could convert the values to set of frozensets, then filter out the duplicates and finally pick the dictionary items whose value is in the set:</p> <pre><code>d = { 'A': [('a', 1, 1), ('b', 2, 2), ('c', 3, 3)], 'B': [('b', 2, 2), ('a', 1, 1)], 'C': [('d', 4, 4)] } sets = {frozenset(v) for v in d.val...
0
2016-09-01T09:47:41Z
[ "python", "dictionary" ]
Comparing list of tuples within dictionary
39,267,495
<p>I have been cracking my head over this problem... I have a simplified dataset like such:<br> <code>dict = {'A': [('a', 1, 1), ('b', 2, 2), ('c', 3, 3)], 'B': [('b', 2, 2), ('a', 1, 1)], 'C': [('d', 4, 4)], 'D': [('c', 3, 3), ('e', 5, 5)]}</code><br> where the value represents a list of tuples. </p> <p>I need t...
0
2016-09-01T09:17:29Z
39,268,439
<p>Use <code>set</code> and <code>combinations</code>:</p> <pre><code>from itertools import combinations d = {'A': [('a', 1, 1), ('b', 2, 2), ('c', 3, 3)], 'B': [('b', 2, 2), ('a', 1, 1)], 'C': [('d', 4, 4)]} xs = set() for (ai, av), (bi, bv) in combinations(d.items(), 2): if set(av) &lt;= set(bv): xs.add(ai) ...
0
2016-09-01T09:59:36Z
[ "python", "dictionary" ]
Filter list of dicts by highest value of dict and taking reversed values into account
39,267,554
<p>Let's say i have data looking like this:</p> <pre><code>filter_data = [ {'sender_id': 1, 'receiver_id': 2, 'order': 1}, {'sender_id': 2, 'receiver_id': 1, 'order': 3}, {'sender_id': 3, 'receiver_id': 2, 'order': 5}, {'sender_id': 2, 'receiver_id': 3, 'order': 2}, ] # there must be a better way to g...
1
2016-09-01T09:19:41Z
39,267,938
<p>You can use a dictionary, mapping a <code>frozenset</code> of sender and receiver ID (so order does not matter) to the item with the currently highest order.</p> <pre><code>result = {} for item in filter_data: key = frozenset([item["sender_id"], item["receiver_id"]]) if key not in result or result[key]["ord...
1
2016-09-01T09:37:07Z
[ "python" ]
Filter list of dicts by highest value of dict and taking reversed values into account
39,267,554
<p>Let's say i have data looking like this:</p> <pre><code>filter_data = [ {'sender_id': 1, 'receiver_id': 2, 'order': 1}, {'sender_id': 2, 'receiver_id': 1, 'order': 3}, {'sender_id': 3, 'receiver_id': 2, 'order': 5}, {'sender_id': 2, 'receiver_id': 3, 'order': 2}, ] # there must be a better way to g...
1
2016-09-01T09:19:41Z
39,268,111
<p>Create an empty dictionary that will gather the new highest dictionary. We iterate through your <code>filter_data</code> and check the sum of <code>sender_id</code> and <code>receiver_id</code>, since you said that the order of those was irrelevant.</p> <pre><code>filter_data = [ {'sender_id': 1, 'receiver_id':...
0
2016-09-01T09:44:55Z
[ "python" ]
Filter list of dicts by highest value of dict and taking reversed values into account
39,267,554
<p>Let's say i have data looking like this:</p> <pre><code>filter_data = [ {'sender_id': 1, 'receiver_id': 2, 'order': 1}, {'sender_id': 2, 'receiver_id': 1, 'order': 3}, {'sender_id': 3, 'receiver_id': 2, 'order': 5}, {'sender_id': 2, 'receiver_id': 3, 'order': 2}, ] # there must be a better way to g...
1
2016-09-01T09:19:41Z
39,268,327
<p>Did I understand you now?</p> <pre class="lang-py prettyprint-override"><code>from itertools import groupby grp = groupby(filter_data, lambda x: (min(x["sender_id"], x["receiver_id"]), max(x["sender_id"], x["receiver_id"]))) l = [sorted(g, key = lambda x: -x["order"])[0] for k, g in grp] </code></pre>
1
2016-09-01T09:54:19Z
[ "python" ]
"CSV file does not exist" - Pandas Dataframe
39,267,614
<p>I am currently learning Pandas for data analysis and having some issues reading a csv file in Atom editor. </p> <p>When I am running the following code:</p> <pre><code>import pandas as pd df = pd.read_csv("FBI-CRIME11.csv") print(df.head()) </code></pre> <p>I get an error message, which ends with </p> <blockq...
1
2016-09-01T09:22:26Z
39,267,665
<p>Have you tried?</p> <pre><code>df = pd.read_csv("Users/alekseinabatov/Documents/Python/FBI-CRIME11.csv") </code></pre> <p>or maybe</p> <pre><code>df = pd.read_csv('Users/alekseinabatov/Documents/Python/"FBI-CRIME11.csv"') </code></pre> <p>(If the file name has quotes)</p>
1
2016-09-01T09:24:56Z
[ "python", "csv", "pandas", "atom" ]
"CSV file does not exist" - Pandas Dataframe
39,267,614
<p>I am currently learning Pandas for data analysis and having some issues reading a csv file in Atom editor. </p> <p>When I am running the following code:</p> <pre><code>import pandas as pd df = pd.read_csv("FBI-CRIME11.csv") print(df.head()) </code></pre> <p>I get an error message, which ends with </p> <blockq...
1
2016-09-01T09:22:26Z
39,267,769
<p>Just referring to the filename like</p> <pre><code>df = pd.read_csv("FBI-CRIME11.csv") </code></pre> <p>generally only works if the file is in the same directory as the script.</p> <p>If you are using windows, make sure you specify the path to the file as follows:</p> <pre><code>PATH = "C:\\Users\\path\\to\\file...
1
2016-09-01T09:29:43Z
[ "python", "csv", "pandas", "atom" ]
Why it is faster to return a tuple than multiple values in Python?
39,267,626
<p>I did a small test:</p> <pre><code>In [12]: def test1(): ...: return 1,2,3 ...: In [13]: def test2(): ...: return (1,2,3) ...: In [14]: %timeit a,b,c = test1() </code></pre> <p>The slowest run took 66.88 times longer than the fastest. This could mean that an intermediate result is being...
1
2016-09-01T09:22:53Z
39,267,734
<p>Both <code>test1</code> and <code>test2</code> results in same bytecode, so they have to perform in same speed. Your measurement conditions wasn't consistent (e.g. CPU load was increased for test2, due to additional background processes).</p> <pre><code>&gt;&gt;&gt; import dis &gt;&gt;&gt; def test1(): ... retu...
7
2016-09-01T09:28:12Z
[ "python", "performance", "tuples", "return-value", "benchmarking" ]
How to customized inline model view/form of Flask-Admin module?
39,267,649
<p>Suppose I have this parent model:</p> <pre><code>class GoogleAccount(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String, index=True) class GoogleAccountApi(db.Model): id = db.Column(db.Integer, primary_key=True) client_secret = db.Column(db.String) token = db.Co...
0
2016-09-01T09:23:59Z
39,273,457
<p>Found it <a href="http://stackoverflow.com/questions/34313253/flask-admin-inline-modelling-passing-form-arguments-throws-attributeerror">here</a>, so this is what you do:</p> <pre><code>inline_models = [(models.GoogleAccountApi, dict( column_descriptions=dict(client_secret='Retoken here') ))] </code></pre>
0
2016-09-01T13:55:11Z
[ "python", "flask", "flask-admin" ]
MongoDBForm error "ValueError:A document class must be provided"
39,267,793
<p>Hi i am creating a simple Sign Up form with django framework and mongodb. Following is my view:</p> <pre><code>class SignUpView(FormView): template_name='MnCApp/signup.html' form_class=EmployeeForm() succes_url='/success/' </code></pre> <p>Following is my model:</p> <pre><code>class Employee(Document)...
-1
2016-09-01T09:30:42Z
39,268,611
<p>I suspect that your inner class should be called <code>Meta</code>, not <code>meta</code>.</p>
0
2016-09-01T10:06:55Z
[ "python", "django", "mongodb", "mongoengine" ]
Can I get a trimmed mean of all columns in a dataframe with nan values?
39,267,848
<p>I seem to be going around in circles trying to solve this problem. I'd be very grateful for any help from the stackoverflow brains trust.</p> <p>The problem is that I want to get the trimmed mean of all the columns in a pandas dataframe (i.e. the mean of the values in a given column, excluding the max and the min v...
1
2016-09-01T09:32:48Z
39,272,879
<p>you colud use df.mean(skipna =True) <a href="http://pandas.pydata.org/pandas-docs/version/0.17.1/generated/pandas.DataFrame.mean.html" rel="nofollow">DataFrame.mean</a></p> <pre><code>df1 = pd.DataFrame([[5, 1, 'a'], [6, 2, 'b'],[7, 3, 'd'],[np.nan, 4, 'e'],[9, 5, 'f'],[5, 1, 'g']], columns = ["A", "B", "C"]) pri...
0
2016-09-01T13:28:44Z
[ "python", "pandas", "scipy", "code-statistics" ]
Can I get a trimmed mean of all columns in a dataframe with nan values?
39,267,848
<p>I seem to be going around in circles trying to solve this problem. I'd be very grateful for any help from the stackoverflow brains trust.</p> <p>The problem is that I want to get the trimmed mean of all the columns in a pandas dataframe (i.e. the mean of the values in a given column, excluding the max and the min v...
1
2016-09-01T09:32:48Z
39,274,068
<p>consider <code>df</code></p> <pre><code>np.random.seed() data = np.random.choice((0, 25, 35, 100, np.nan), (1000, 2), p=(.01, .39, .39, .01, .2)) df = pd.DataFrame(data, columns=list('AB')) </code></pre> <p>Construct your mean using sums and divide by relevant normal...
1
2016-09-01T14:19:55Z
[ "python", "pandas", "scipy", "code-statistics" ]
Why "TypeError: 'module' object is not callable" occurs on calling impala.dbapi.connect()?
39,267,946
<p>I am trying to connect to impala and I am following <a href="https://github.com/cloudera/impyla" rel="nofollow">impyla guide</a>. But I am getting this error as I execute connect(). The error is shown below:</p> <pre><code>In [27]: import impala.dbapi as connect In [28]: conn = connect(host="some798.xyz.something"...
0
2016-09-01T09:37:35Z
39,268,117
<p>I think what you wanted to do is: <code>from impala.dbapi import connect</code></p> <p>In your code you are using impala.dbapi (module) renamed as <code>connect</code>...</p>
2
2016-09-01T09:45:18Z
[ "python", "hadoop", "thrift", "impala" ]
Efficient use of numpy.random.choice with repeated numbers and alternatives
39,267,947
<p>I need to generate a large array with repeated elements, and my code is:</p> <pre><code>np.repeat(xrange(x,y), data) </code></pre> <p>However, data is a numpy array with type float64 (but it represent integeres, no 2.1 there) and I get the error</p> <pre><code>TypeError: Cannot cast array data from dtype('float64...
4
2016-09-01T09:37:36Z
39,271,543
<h2>Problem statement</h2> <p>Pretty interesting problem this one! Just to give the readers an idea about the problem without going into the minor data conversion issues, we have a range of values, let's say <code>a = np.arange(5)</code>, i.e.</p> <pre><code>a = np.array([0,1,2,3,4]) </code></pre> <p>Now, let's say ...
3
2016-09-01T12:25:46Z
[ "python", "python-2.7", "numpy", "casting", "repeat" ]
Efficient use of numpy.random.choice with repeated numbers and alternatives
39,267,947
<p>I need to generate a large array with repeated elements, and my code is:</p> <pre><code>np.repeat(xrange(x,y), data) </code></pre> <p>However, data is a numpy array with type float64 (but it represent integeres, no 2.1 there) and I get the error</p> <pre><code>TypeError: Cannot cast array data from dtype('float64...
4
2016-09-01T09:37:36Z
39,271,796
<p>For completion, I also have an alternative implementation. Given that we have <code>data</code>, we can use an hypergeometric sampling for each class:</p> <ul> <li>calculate reverse <code>data.cumsum()</code></li> <li>for each class draw <code>np.hypergeometric(data[pos], cumsum[pos]-data[pos], remain)</code></li> ...
1
2016-09-01T12:37:43Z
[ "python", "python-2.7", "numpy", "casting", "repeat" ]
Efficient use of numpy.random.choice with repeated numbers and alternatives
39,267,947
<p>I need to generate a large array with repeated elements, and my code is:</p> <pre><code>np.repeat(xrange(x,y), data) </code></pre> <p>However, data is a numpy array with type float64 (but it represent integeres, no 2.1 there) and I get the error</p> <pre><code>TypeError: Cannot cast array data from dtype('float64...
4
2016-09-01T09:37:36Z
39,277,021
<p>Lurking in the question is the <a href="https://en.wikipedia.org/wiki/Hypergeometric_distribution#Multivariate_hypergeometric_distribution" rel="nofollow">multivariate hypergeometric distribution</a>. In <a href="http://stackoverflow.com/questions/35734026/numpy-drawing-from-urn/35735195#35735195">Numpy drawing fro...
3
2016-09-01T16:54:32Z
[ "python", "python-2.7", "numpy", "casting", "repeat" ]
Python: decode 7bit or 8bit encoded email body
39,267,949
<p><a href="https://docs.python.org/2/library/email.encoders.html" rel="nofollow">https://docs.python.org/2/library/email.encoders.html</a> lists way to encode the email payload. Is there a way to decode the payload that was received over email?</p> <p>I need to decode the html body from the email encoded in base64 or...
0
2016-09-01T09:37:42Z
39,269,840
<p>Looks like the easiest way to decode 7bit data is to use the quopri module in python. Essentially quoted-printable is a format which is used to send 8bit data over a 7bit channel. The code below is working well for me:</p> <pre><code>import quopri quopri.decodestring(email_multipart_payload) # payload has 7bit enco...
0
2016-09-01T11:04:08Z
[ "python", "email", "encoding", "html-email" ]