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 |
|---|---|---|---|---|---|---|---|---|---|
I am receiving a syntax error for a character not in my code | 38,125,801 | <p>I am trying to recursively add column names for a long list and keep receiving a syntax error. There is a character at the beginning of each item that should not be included, hence the [1:].</p>
<pre><code>for i in range(0,len(stat_list)):
cur.execute( '''
ALTER TABLE PDB_id ADD {} TEXT '''.format(stat_list... | 0 | 2016-06-30T14:15:48Z | 38,126,379 | <p>The issue was one of the final items containing the '/'. Problem solved.</p>
| 0 | 2016-06-30T14:38:49Z | [
"python",
"sql",
"sqlite"
] |
Get href tags properly in BeautifulSoup | 38,125,807 | <p>I'm trying to get href links from a link. It looks like this </p>
<pre><code><div class="srTitleFull pcLink"><a style="display:block" name="000 Plus system requirements" title="000 Plus System Requirements" href="../games/index.php?g_id=21580&game=000 Plus">000 Plus</a></div><div c... | 1 | 2016-06-30T14:15:59Z | 38,125,874 | <p>The problem with your nested loops is that you are using the <code>soup.find_all()</code> in both outer and inner loop asking <code>BeautifulSoup</code> to search the entire tree. You meant to use the <code>x</code> loop variable to search links inside, to make a "context-specific" search, so to say:</p>
<pre><code... | 3 | 2016-06-30T14:18:21Z | [
"python",
"web-scraping",
"beautifulsoup",
"href",
"python-3.4"
] |
Select rows given 2 columns, if at least one value is below threshold | 38,125,815 | <p>I have a pandas dataframe </p>
<pre><code>NAME VALUE
A 2
A 1
B 4
A 3
C 2
B 8
</code></pre>
<p>I would like to add a column if values in column "Name" contain AT LEAST ONE value in "Values" below 3, corresponding to the name, such that:</p>
<pre><code>... | 2 | 2016-06-30T14:16:32Z | 38,125,940 | <p>You can use <code>groupby</code> on <code>NAME</code> and <code>apply</code> a lambda that tests your condition and take the <code>max</code> value which will be <code>True</code> if any meet the condition and assign using <code>map</code>:</p>
<pre><code>In [317]:
df['BELOW_THRESHOLD'] = df['NAME'].map(df.groupby(... | 4 | 2016-06-30T14:20:34Z | [
"python",
"pandas",
"select"
] |
Select rows given 2 columns, if at least one value is below threshold | 38,125,815 | <p>I have a pandas dataframe </p>
<pre><code>NAME VALUE
A 2
A 1
B 4
A 3
C 2
B 8
</code></pre>
<p>I would like to add a column if values in column "Name" contain AT LEAST ONE value in "Values" below 3, corresponding to the name, such that:</p>
<pre><code>... | 2 | 2016-06-30T14:16:32Z | 38,126,129 | <p>You can also use transform:</p>
<pre><code>df.groupby('NAME').transform('min') < 3
Out[47]:
VALUE
0 True
1 True
2 False
3 True
4 True
5 False
</code></pre>
<p>It returns a boolean array so if you need Y/N, you can pass it to np.where like EdChum did.</p>
| 3 | 2016-06-30T14:27:55Z | [
"python",
"pandas",
"select"
] |
Run Google App Engine application with microservice | 38,125,926 | <p>I have a one big monolith application, and now its time to separate some modules to micro services!
I read a lot about pub/sub and microservices in Google docs, but can't find answers to my questions:</p>
<ol>
<li>How app.yaml file looks like for my module(microservice)?</li>
<li>How app.yaml looks like for my app?... | 3 | 2016-06-30T14:20:04Z | 38,126,712 | <p>A monolithic app is really an app with a single module/service (the default one). The <code>app.yaml</code> config for such app (like the one you shown) is really the default module's config file - there is no "per-app" such config. The modules are "tied" together into one specific app by this line in their respecti... | 2 | 2016-06-30T14:53:34Z | [
"python",
"google-app-engine",
"publish-subscribe",
"microservices"
] |
Python: catching error + printing to file | 38,125,961 | <p>I wonder if there is a way to capture any (and all) type of error that crashes the script, but potentially without using <code>try</code> to catch a specific exception.</p>
<p>I have a webdriver script that does a lot of stuff, like clicks on links, sends keys and so on, but I cannot predict where it will crash. I ... | 1 | 2016-06-30T14:21:11Z | 38,126,265 | <p>You can use a plain <code>except</code> to catch any and all exceptions, like so:</p>
<pre><code>try:
some code here
except:
print 'whoops, something went wrong'
</code></pre>
<p>However this doesn't give you any information about the exception, so you probably don't want to do that.</p>
<p>You can also c... | 1 | 2016-06-30T14:33:59Z | [
"python",
"error-handling"
] |
Python: catching error + printing to file | 38,125,961 | <p>I wonder if there is a way to capture any (and all) type of error that crashes the script, but potentially without using <code>try</code> to catch a specific exception.</p>
<p>I have a webdriver script that does a lot of stuff, like clicks on links, sends keys and so on, but I cannot predict where it will crash. I ... | 1 | 2016-06-30T14:21:11Z | 38,127,160 | <p>It seems the trick you are looking for is redirecting the stderr to a file or stdout.</p>
<p>Python when having the exception will write the exception to stderr .
simply you need to redirect stderr to the same output file you have when running the python program</p>
<p>like this</p>
<blockquote>
<p>python file.... | 0 | 2016-06-30T15:11:36Z | [
"python",
"error-handling"
] |
Sympy never returns when processing complicated determinants | 38,126,043 | <p>At least this it how it appears. The following code behaved correctly for 3x3 and 6x6 matrices.</p>
<pre><code> deter = mat.det('method':'berkowitz')
#self.resultFileHandler.writeLogStr(str(deter))
a = sy_polys.Poly(deter, k)
</code></pre>
<p>For 3x3 it takes ~0.8s to execute this code, for 6x6 it takes... | 2 | 2016-06-30T14:24:45Z | 38,132,833 | <p><strong>The algorithm is just slow.</strong></p>
<p>Sympy explains <a href="http://docs.sympy.org/0.7.2/modules/matrices/matrices.html#sympy.matrices.matrices.MatrixBase.berkowitz" rel="nofollow">the Berkowitz method in its documentation</a>, and references <a href="http://www.sciencedirect.com/science/article/pii/... | 1 | 2016-06-30T20:38:37Z | [
"python",
"sympy"
] |
Sympy never returns when processing complicated determinants | 38,126,043 | <p>At least this it how it appears. The following code behaved correctly for 3x3 and 6x6 matrices.</p>
<pre><code> deter = mat.det('method':'berkowitz')
#self.resultFileHandler.writeLogStr(str(deter))
a = sy_polys.Poly(deter, k)
</code></pre>
<p>For 3x3 it takes ~0.8s to execute this code, for 6x6 it takes... | 2 | 2016-06-30T14:24:45Z | 38,331,077 | <p>OK, so I returned to this after reading literature and feeling (emphasis here) that the Berkowitz should perform between O(n^2) and O(n^3). </p>
<p>What I found was that the input type to the det and Poly makes a huge difference to the performance (I admit that the input type was not shown in my question). Wrapping... | 0 | 2016-07-12T14:00:21Z | [
"python",
"sympy"
] |
Django Rest Framework Tokens Are Not Being Automatically Generated | 38,126,052 | <p>I am (trying) to use Django Rest Framework's Token-based authentication. I have the following in my app's <strong>models.py</strong></p>
<pre><code>from django.db.models.signals import post_save
from django.dispatch import receiver
from rest_framework.authtoken.models import Token
from django.conf import settings
... | 0 | 2016-06-30T14:24:55Z | 38,126,622 | <p>Things to check:</p>
<ul>
<li>Is the receiver even running? Add a print or log inside to check that it is called in the first place</li>
<li>If <code>AUTH_USER_MODEL</code> is not defined, you may need to use <code>get_user_model()</code> instead</li>
<li>Make sure that this code is inside the <code>models.py</code... | 1 | 2016-06-30T14:49:43Z | [
"python",
"django",
"database",
"django-rest-framework",
"token"
] |
prevent OrderedDict from splitting single string value into characters during iteration | 38,126,060 | <p>I would like to make an <code>OrderedDict</code> with a string for each key and a list of strings for each value.</p>
<pre><code>from collections import OrderedDict
# Compare a dict with an OrderedDict
someDict = dict(a = ["foo","bar"], b = ["baz"])
someOrderedDict = OrderedDict([("a",("foo","bar")),("b",("baz"))]... | 0 | 2016-06-30T14:25:13Z | 38,126,131 | <p>This is because you're assigning a string (<code>("baz")</code>) to the <code>b</code> key, rather than a tuple (<code>("baz",)</code>) or list of strings.</p>
<p>Instead of</p>
<pre><code>someOrderedDict = OrderedDict([("a",("foo","bar")),("b",("baz"))])
</code></pre>
<p>try</p>
<pre><code>someOrderedDict = Ord... | 3 | 2016-06-30T14:28:05Z | [
"python",
"python-3.x",
"dictionary",
"ordereddictionary"
] |
prevent OrderedDict from splitting single string value into characters during iteration | 38,126,060 | <p>I would like to make an <code>OrderedDict</code> with a string for each key and a list of strings for each value.</p>
<pre><code>from collections import OrderedDict
# Compare a dict with an OrderedDict
someDict = dict(a = ["foo","bar"], b = ["baz"])
someOrderedDict = OrderedDict([("a",("foo","bar")),("b",("baz"))]... | 0 | 2016-06-30T14:25:13Z | 38,126,150 | <p>You can add a <code>,</code> after <code>"baz"</code> so it can get interpreted as a tuple instead of a single <code>str</code> during the <code>for</code> loop:</p>
<pre><code>someOrderedDict = OrderedDict([("a",("foo","bar")),("b",("baz",))])
</code></pre>
<p>Then, iteration works fine grabbing the single elemen... | 2 | 2016-06-30T14:28:48Z | [
"python",
"python-3.x",
"dictionary",
"ordereddictionary"
] |
Other options for PyInstaller console = False? | 38,126,063 | <p>I am using PyInstaller to build an windows exe distributable package for a Kivy application where docutils.rst is being used. When setting console = False in the PyInstaller .spec file a virus is reported. When console = True, everything runs smoothly. When excluding docutils in the package, no virus is reported at ... | 0 | 2016-06-30T14:25:18Z | 38,126,237 | <blockquote>
<p>Question 1: Does anybody know how to disable the console python console in an executable?</p>
</blockquote>
<p>pass <code>noconsole</code> as an argument @ CLI :</p>
<pre><code> pyinstaller --noconsole --onefile <filename>
</code></pre>
<blockquote>
<p>Question 2: what do you think is the b... | 0 | 2016-06-30T14:32:18Z | [
"python",
"kivy",
"pyinstaller",
"docutils"
] |
Python why is file path considered a directory | 38,126,159 | <p>I am working on a Django project where I want to replace a file on my server. One way of doing it is to remove the file if the filename already exists and saving the new file at its place. </p>
<p>My problem is that my file path that ends with /data.xlsx is considered a directory. In python, os.isfile(path) returns... | 0 | 2016-06-30T14:29:07Z | 38,126,299 | <p>A path name does not define whether something is a file or directory. You could name a file <code>"/tmp/my/directory"</code> and a directory <code>"/tmp/my/file.xls"</code> if you felt like it. Likewise, python doesn't <em>decide</em> whether a path corresponds to a file or a directory, it only checks. If python sa... | 0 | 2016-06-30T14:35:16Z | [
"python",
"path",
"directory",
"delete-file"
] |
Django password-only login | 38,126,185 | <p>I'm currently working on a project for which clients should be able to login to their account using only a single 'keycode' or password, without their username. Security is not really an issue, as the tool is mostly for internal use. The user passwords will be inserted by an admin, so there will be no login collisi... | -3 | 2016-06-30T14:30:11Z | 38,126,460 | <p>You can create all users with the same (hardcoded) password and then create a view for login which receives only the passcode (I.e. the username) and re-direct it to a real login form with the pre-defined password</p>
| 0 | 2016-06-30T14:42:06Z | [
"python",
"django"
] |
Django password-only login | 38,126,185 | <p>I'm currently working on a project for which clients should be able to login to their account using only a single 'keycode' or password, without their username. Security is not really an issue, as the tool is mostly for internal use. The user passwords will be inserted by an admin, so there will be no login collisi... | -3 | 2016-06-30T14:30:11Z | 38,126,537 | <p>for your login you can use the username instead of password if no security is needed. Then get a form in your template and in your Django view :</p>
<pre><code>if request.method == "POST":
form = ConnexionForm(request.POST)
if form.is_valid():
username = form.cleaned_data["Username"]
user = ... | 0 | 2016-06-30T14:45:49Z | [
"python",
"django"
] |
Subset Sum floats Elimations | 38,126,221 | <p>I will be happy to get some help. I have the following problem:
I'm given a list of numbers and a target number.</p>
<pre><code>subset_sum([11.96,1,15.04,7.8,20,10,11.13,9,11,1.07,8.04,9], 20)
</code></pre>
<p>I need to find an algorithm that will find all numbers that combined will sum target number ex: 20.
Firs... | 1 | 2016-06-30T14:31:40Z | 38,126,705 | <p>there are many ways to think about this problem.
If you do recursion make sure to identify your end cases first, then proceed with the rest of the program.</p>
<p>This is the first thing that comes to mind.</p>
<pre><code><?php
subset_sum([11.96,1,15.04,7.8,20,10,11.13,9,11,1.07,8.04,9], 20);
function subset... | 0 | 2016-06-30T14:53:15Z | [
"php",
"python",
"algorithm",
"dynamic-programming",
"subset-sum"
] |
Subset Sum floats Elimations | 38,126,221 | <p>I will be happy to get some help. I have the following problem:
I'm given a list of numbers and a target number.</p>
<pre><code>subset_sum([11.96,1,15.04,7.8,20,10,11.13,9,11,1.07,8.04,9], 20)
</code></pre>
<p>I need to find an algorithm that will find all numbers that combined will sum target number ex: 20.
Firs... | 1 | 2016-06-30T14:31:40Z | 38,126,773 | <p>This is possible solution, but it's not pretty:</p>
<pre><code>import itertools
import operator
from functools import reduce
def subset_num(array, num):
subsets = reduce(operator.add, [list(itertools.combinations(array, r)) for r in range(1, 1 + len(array))])
return [subset for subset in subsets if sum(sub... | 0 | 2016-06-30T14:56:27Z | [
"php",
"python",
"algorithm",
"dynamic-programming",
"subset-sum"
] |
Subset Sum floats Elimations | 38,126,221 | <p>I will be happy to get some help. I have the following problem:
I'm given a list of numbers and a target number.</p>
<pre><code>subset_sum([11.96,1,15.04,7.8,20,10,11.13,9,11,1.07,8.04,9], 20)
</code></pre>
<p>I need to find an algorithm that will find all numbers that combined will sum target number ex: 20.
Firs... | 1 | 2016-06-30T14:31:40Z | 38,135,446 | <p>DISCLAIMER: this is not a full solution, it is a way to just help you build the possible subsets. It does not help you to pick which ones go together (without using the same item more than once and getting the lowest remainder).</p>
<p>Using dynamic programming you can build all the subsets that add up to the given... | 0 | 2016-07-01T00:52:39Z | [
"php",
"python",
"algorithm",
"dynamic-programming",
"subset-sum"
] |
Subset Sum floats Elimations | 38,126,221 | <p>I will be happy to get some help. I have the following problem:
I'm given a list of numbers and a target number.</p>
<pre><code>subset_sum([11.96,1,15.04,7.8,20,10,11.13,9,11,1.07,8.04,9], 20)
</code></pre>
<p>I need to find an algorithm that will find all numbers that combined will sum target number ex: 20.
Firs... | 1 | 2016-06-30T14:31:40Z | 38,247,086 | <p>So I have a possbile solution:</p>
<pre><code> #compute difference between 2 list but keep duplicates
def list_difference(a, b):
count = Counter(a) # count items in a
count.subtract(b) # subtract items that are in b
diff = []
for x in a:
if count[x] > 0:
... | 0 | 2016-07-07T13:42:52Z | [
"php",
"python",
"algorithm",
"dynamic-programming",
"subset-sum"
] |
Over-riding Django-allauth login/ registration urls with custom url/ pages | 38,126,241 | <p>I have configured django-allauth for login through Facebook, Twitter and Google.</p>
<p>However, django-allauth accepts login request only at <code>/accounts/login/</code>, sign up request only at <code>/accounts/signup/</code> etc.
I have a modal form for login and registration on my home page and I want to use o... | 0 | 2016-06-30T14:32:40Z | 38,126,928 | <p>Well, it is pretty easy solution.</p>
<p>in urls.py do this:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>from allauth.account.views import LoginView, SignupView ... | 0 | 2016-06-30T15:02:39Z | [
"python",
"django",
"django-allauth"
] |
Over-riding Django-allauth login/ registration urls with custom url/ pages | 38,126,241 | <p>I have configured django-allauth for login through Facebook, Twitter and Google.</p>
<p>However, django-allauth accepts login request only at <code>/accounts/login/</code>, sign up request only at <code>/accounts/signup/</code> etc.
I have a modal form for login and registration on my home page and I want to use o... | 0 | 2016-06-30T14:32:40Z | 38,128,033 | <p>For using allauth's login or signup functionality, you do not have to override urls associated with it.</p>
<p>Just <em>submit</em> your form to the urls associated with the allauth like</p>
<pre><code><form action="/accounts/login/?next{{request.path}}" method="POST">
{% csrf_token %}
<!-- Your form ... | 0 | 2016-06-30T15:52:46Z | [
"python",
"django",
"django-allauth"
] |
Over-riding Django-allauth login/ registration urls with custom url/ pages | 38,126,241 | <p>I have configured django-allauth for login through Facebook, Twitter and Google.</p>
<p>However, django-allauth accepts login request only at <code>/accounts/login/</code>, sign up request only at <code>/accounts/signup/</code> etc.
I have a modal form for login and registration on my home page and I want to use o... | 0 | 2016-06-30T14:32:40Z | 38,141,973 | <p>I think you may want to call django-allauth's forms in your home view</p>
<p>In <code>views.py</code>:</p>
<pre><code>from django.allauth.account.forms import LoginForm, SignupForm
def home(request):
context = {
'login_form': LoginForm(),
'signup_form': SignupForm(),
}
return render(re... | 0 | 2016-07-01T09:35:10Z | [
"python",
"django",
"django-allauth"
] |
Over-riding Django-allauth login/ registration urls with custom url/ pages | 38,126,241 | <p>I have configured django-allauth for login through Facebook, Twitter and Google.</p>
<p>However, django-allauth accepts login request only at <code>/accounts/login/</code>, sign up request only at <code>/accounts/signup/</code> etc.
I have a modal form for login and registration on my home page and I want to use o... | 0 | 2016-06-30T14:32:40Z | 38,194,108 | <p>When trying to override the url in urls.py, did you place the override above or below the "url(r'^accounts/', include('allauth.urls'))"? When I tried to override allauth the first time, I placed my code below that line, which doesn't work--going above that line worked.</p>
| 0 | 2016-07-05T01:47:06Z | [
"python",
"django",
"django-allauth"
] |
Django TypeError:"User" object is not iterable pops up during serialization | 38,126,261 | <p>I'm having a problem with my django project. Im using django rest framework and seems like im doing something wrong during serialization. So here is the issue:</p>
<p>I have an APIview that should return a JSON to the user that should be auth by token. This json should contain the list of users classes for today.he... | 0 | 2016-06-30T14:33:39Z | 38,139,520 | <p>Your ProfileSerializer defines <code>user</code> with <code>many=True</code>, but there is only one user per profile.</p>
| 1 | 2016-07-01T07:28:29Z | [
"python",
"django",
"api",
"serialization",
"django-rest-framework"
] |
SyntaxError when parsing dict with single and double quotes? | 38,126,273 | <p>Let me start off by saying I'm a bit of a noob, so bare with me!</p>
<p>So, I'm retrieving a blog post from Tumblr using the pytumblr API. I want to retrieve a post and extract only the post content. <em>Technically</em> Tumblr sends it to me in a <code>dict</code>, but the format is very, very confusing. In additi... | 2 | 2016-06-30T14:34:15Z | 38,126,770 | <p>The syntax error is caused by your removal of the brackets. Somewhere inside the dictionary there's a list of tags, and the string you have goes:</p>
<pre><code>... u'title': None, u'tags': u'queued', u'suggestion', u'suggestion blog', ...
</code></pre>
<p>That is, it switches from dictionary notation to list nota... | 1 | 2016-06-30T14:56:18Z | [
"python",
"dictionary",
"abstract-syntax-tree",
"pytumblr"
] |
Handling array as form name in flask | 38,126,371 | <p>If I send a form like this:</p>
<pre><code><form method="POST" ...>
<input type="text" name="filters[price_from]">
<input type="text" name="filters[price_to]">
</form>
</code></pre>
<p>to PHP script it automatically creates an array and I can access variables like this:</p>
<pre><c... | 1 | 2016-06-30T14:38:38Z | 38,128,832 | <p>You cannot access a python array/list using a key, if you want to access your data using a key, store your <code>filters</code> as a <code>json</code> object, then you will be able to access the data by using a key.</p>
<pre><code><form method="POST" enctype="application/JSON">
<input type="text" name=... | 0 | 2016-06-30T16:34:18Z | [
"python",
"flask"
] |
pandas: how to sort a grouped dataframe by mean amount? | 38,126,375 | <p>I have a dataframe that looks like this:</p>
<pre><code>Speciality Amount
Greek 15
Greek 16
Italian 8
Italian 11
Italian 13
</code></pre>
<p>I have now aggregated the mean and count for each speciality:</p>
<pre><code>df_by_spec_count = df.groupby('Speciality').agg(['me... | 2 | 2016-06-30T14:38:43Z | 38,126,469 | <p>You have hierarchical columns so you need to pass a tuple to select the appropriate column level to sort on:</p>
<pre><code>In [324]:
df_by_spec_count.sort_values(by=('Amount','count'),ascending=False).head()
Out[324]:
Amount
mean count
Speciality
Italian ... | 1 | 2016-06-30T14:42:18Z | [
"python",
"pandas"
] |
pandas: how to sort a grouped dataframe by mean amount? | 38,126,375 | <p>I have a dataframe that looks like this:</p>
<pre><code>Speciality Amount
Greek 15
Greek 16
Italian 8
Italian 11
Italian 13
</code></pre>
<p>I have now aggregated the mean and count for each speciality:</p>
<pre><code>df_by_spec_count = df.groupby('Speciality').agg(['me... | 2 | 2016-06-30T14:38:43Z | 38,126,483 | <p>Another solution is remove top level by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.MultiIndex.droplevel.html" rel="nofollow"><code>MultiIndex.droplevel</code></a>:</p>
<pre><code>df_by_spec_count = df.groupby('Speciality').agg(['mean', 'count'])
df_by_spec_count.columns = df_by_spec_count... | 2 | 2016-06-30T14:43:17Z | [
"python",
"pandas"
] |
How I can divide values in a column by specific row in Python? | 38,126,434 | <p>I have a tab file and I want to divide features(upstream,downstrs,downupst,annotate or ...) of a gene to standard feature.
last two columns are the result columns for cond_a and cond_b that I want to produce.
I was writing a code to be able to save each line in a tuple and then search tuples and do the divisions bu... | 0 | 2016-06-30T14:41:09Z | 38,126,731 | <p>It's hard to tell exactly what you want (for future reference it's best to leave out technical details that are field-related and not programming related - makes it easier for those of us who know nothing about genes to help), and I can't tell how you're calculating those two columns exactly. However, this looks li... | 0 | 2016-06-30T14:54:15Z | [
"python"
] |
How I can divide values in a column by specific row in Python? | 38,126,434 | <p>I have a tab file and I want to divide features(upstream,downstrs,downupst,annotate or ...) of a gene to standard feature.
last two columns are the result columns for cond_a and cond_b that I want to produce.
I was writing a code to be able to save each line in a tuple and then search tuples and do the divisions bu... | 0 | 2016-06-30T14:41:09Z | 38,127,121 | <p>thank you, but this is not what I want to calculate, lets make the question clear, first 2/5 is dividing first row(2) to second row(5) (standard of gene A). 5/5 is division to itself because it is standard which is 1. last row (4/2) is dividing last row to row number 6<br>
A_____upstream_____2_____2/5<br>
A_... | 0 | 2016-06-30T15:10:19Z | [
"python"
] |
All indices of each unique element in a list python | 38,126,477 | <p>I'm working with a very large data set (about 75 million entries) and I'm trying to shorten the length of time that running my code takes by a significant margin (with a loop right now it will take a couple days) and keep memory usage extremely low.</p>
<p>I have two numpy arrays (<code>clients</code> and <code>uni... | 2 | 2016-06-30T14:43:00Z | 38,126,936 | <p>With <a href="http://pandas.pydata.org/" rel="nofollow">Pandas</a>, this can easily be done using the <a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html" rel="nofollow"><code>grouby()</code></a> function:</p>
<pre><code>import pandas as pd
# some fake data
df = pd.DataFrame({'clients': ['a', 'b', 'a... | 2 | 2016-06-30T15:03:00Z | [
"python",
"arrays",
"numpy",
"pandas",
"indexing"
] |
All indices of each unique element in a list python | 38,126,477 | <p>I'm working with a very large data set (about 75 million entries) and I'm trying to shorten the length of time that running my code takes by a significant margin (with a loop right now it will take a couple days) and keep memory usage extremely low.</p>
<p>I have two numpy arrays (<code>clients</code> and <code>uni... | 2 | 2016-06-30T14:43:00Z | 38,127,336 | <p>This is a typical group-by type operation, which can be performed elegantly and efficiently using the <a href="https://github.com/EelcoHoogendoorn/Numpy_arraysetops_EP" rel="nofollow">numpy-indexed</a> package (disclaimer: I am its author):</p>
<pre><code>import numpy_indexed as npi
unique_clients, units_per_client... | 1 | 2016-06-30T15:20:07Z | [
"python",
"arrays",
"numpy",
"pandas",
"indexing"
] |
Python - Deleting a sheet | 38,126,542 | <p>Is there any function that has been made to delete only a single sheet using xlwt, xlrd, xlutils, xlutils.filter, or pyexcel? Those are the only ones I have access to and I want to know how to delete a sheet.</p>
<p>Perhaps you could create a list with all the sheet names, remove the sheet name from that you want t... | 0 | 2016-06-30T14:46:16Z | 38,127,504 | <p>The answer that was given on the other question was this:</p>
<pre><code>write_book._Workbook__worksheets = [write_book._Workbook__worksheets[0]]
</code></pre>
<p>This removes everything but the first worksheet associated with a Workbook.</p>
| 0 | 2016-06-30T15:28:12Z | [
"python",
"excel",
"xlwt",
"xlutils",
"pyexcel"
] |
Initialize two Python classes with same arguments, get different results | 38,126,546 | <p><strong>Objective:</strong> understand strange behavior regarding two classes initialized with identical arguments, and producing different results. </p>
<p><strong>Background:</strong></p>
<p>My project involves a Raspberry Pi 3 communicating with various sensors on an Arduino MEGA via serial (through the USB por... | 1 | 2016-06-30T14:46:23Z | 38,130,213 | <p>It turned out to be the second hypothesis. There is apparently some non-printable character being included in the concatenation step of the hex bytes. Switching to the following order solved the problem. </p>
<p><strong>EDIT:</strong> I discovered that performing a <code>readline()</code> immediately after <code>wr... | 1 | 2016-06-30T17:57:07Z | [
"python",
"python-2.7",
"class",
"serial-port"
] |
Python: How to access outer class namespaces | 38,126,674 | <p>Consider this code:</p>
<pre><code>class A:
B = 42 # or whatever
class C:
a = B # wont find `B` here
</code></pre>
<p>That will not work because in <code>class C</code>, it wont find <code>B</code>.</p>
<p>You also cannot use <code>A.B</code> because also <code>A</code> is not kn... | 3 | 2016-06-30T14:51:53Z | 38,126,858 | <pre><code>class Constants:
a = 1
class A:
class B(Constants):
pass
class C(Constants):
pass
print(A.B.a, A.C.a)
</code></pre>
| 1 | 2016-06-30T14:59:48Z | [
"python",
"namespaces"
] |
Python: How to access outer class namespaces | 38,126,674 | <p>Consider this code:</p>
<pre><code>class A:
B = 42 # or whatever
class C:
a = B # wont find `B` here
</code></pre>
<p>That will not work because in <code>class C</code>, it wont find <code>B</code>.</p>
<p>You also cannot use <code>A.B</code> because also <code>A</code> is not kn... | 3 | 2016-06-30T14:51:53Z | 38,127,028 | <p>I'd perform the class variable assignments for the inner classes in the outer class <em>after</em> the inner class declarations are complete. It's very little more complicated, completely obvious and it works:</p>
<pre><code>class A:
class B:
a = 1
class C:
pass
C.a = B.a
print(A.B.a, A... | 1 | 2016-06-30T15:06:18Z | [
"python",
"namespaces"
] |
Python: How to access outer class namespaces | 38,126,674 | <p>Consider this code:</p>
<pre><code>class A:
B = 42 # or whatever
class C:
a = B # wont find `B` here
</code></pre>
<p>That will not work because in <code>class C</code>, it wont find <code>B</code>.</p>
<p>You also cannot use <code>A.B</code> because also <code>A</code> is not kn... | 3 | 2016-06-30T14:51:53Z | 38,127,064 | <p>What do you think about</p>
<pre><code>var = 1
class A:
class B:
a = var
class C:
a = var
</code></pre>
| 0 | 2016-06-30T15:07:52Z | [
"python",
"namespaces"
] |
Python: How to access outer class namespaces | 38,126,674 | <p>Consider this code:</p>
<pre><code>class A:
B = 42 # or whatever
class C:
a = B # wont find `B` here
</code></pre>
<p>That will not work because in <code>class C</code>, it wont find <code>B</code>.</p>
<p>You also cannot use <code>A.B</code> because also <code>A</code> is not kn... | 3 | 2016-06-30T14:51:53Z | 38,127,065 | <p>You can always work with temporary objects which you don't expose. Depending on how your non-trivial example looks, this may not be appropriate, however.</p>
<pre><code># foo module
ABC_ATTRIBUTE = 42
class A:
B = ABC_ATTRIBUTE
class C:
a = ABC_ATTRIBUTE
del ABC_ATTRIBUTE # no longer accessible as foo.ABC_... | 0 | 2016-06-30T15:07:55Z | [
"python",
"namespaces"
] |
how to implement an iteratation in flatMap function | 38,126,919 | <p>I'm reading a multi-line-record text file into an RDD. The underlying data is like this</p>
<pre><code>Time MHist::852-YF-007
2016-05-10 00:00:00 0
2016-05-09 23:59:00 0
2016-05-09 23:58:00 0
Time MHist::852-YF-008
2016-05-10 00:00:00 0
2016-05-09 23:59:00 0
2016-05-09 23:58:00 0
</code></pre>
<p>No I ... | 0 | 2016-06-30T15:02:12Z | 38,131,783 | <p><code>itemgetter</code> returns a function which accepts an object and calls <code>__getitem__</code> for each argument passed to <code>itemgetter</code>. So you have to call it on <code>lines</code>:</p>
<pre><code>itemgetter(0, slice(1, None))(lines)
</code></pre>
<p>which will be roughly equivalent to</p>
<pre... | 2 | 2016-06-30T19:32:43Z | [
"python",
"python-2.7",
"hadoop",
"iteration",
"pyspark"
] |
How to execute one python file for a certain amount of time and after that, run another? | 38,126,957 | <p>I have two scripts; the first mines a bunch of data and the second analyses it. I want the first file to run for ~2 hours or so, and after that the second to just run once.</p>
<p>I understand that <code>os.system()</code> is not a very safe way to go about this. I would also like to understand why is that?</p>
<p... | 0 | 2016-06-30T15:03:52Z | 38,127,051 | <p>If you are using a Linux environment, you can execute your scripts after adding them to a cron job.</p>
<p>To execute the main function, put your initial code after this (in python):</p>
<pre><code>if __name__ == '__main__':
#your code
</code></pre>
| 0 | 2016-06-30T15:07:25Z | [
"python",
"operating-system"
] |
How to execute one python file for a certain amount of time and after that, run another? | 38,126,957 | <p>I have two scripts; the first mines a bunch of data and the second analyses it. I want the first file to run for ~2 hours or so, and after that the second to just run once.</p>
<p>I understand that <code>os.system()</code> is not a very safe way to go about this. I would also like to understand why is that?</p>
<p... | 0 | 2016-06-30T15:03:52Z | 38,127,154 | <p>If you're on Windows and are lazy you could create a batch job that does </p>
<pre><code>python first_task.py
SLEEP 7200
python second_task.py
</code></pre>
| 0 | 2016-06-30T15:11:25Z | [
"python",
"operating-system"
] |
Python snippet duplicate lines I have chosen | 38,127,069 | <p>I want to grabs specified sections from several files.</p>
<p>All my files is structured as the following but have difference object data:</p>
<pre><code>some lines
ObjectAlias apple
some lines
Begin
some lines
End
some lines
ObjectAlias pear
some lines
Begin
some lines
End
...
</code></pre>
<p>Assume I have my a... | 0 | 2016-06-30T15:08:08Z | 38,127,476 | <p>You should have a <code>break</code> when you find an <code>obj</code> in the each rather than keep finding and concatenating the output</p>
<p><strong>update:</strong> since you need to filter out the lines between ObjectAlias and Begin, so you need one more <code>state</code> to record what is done during the pr... | 0 | 2016-06-30T15:26:50Z | [
"python"
] |
Strange typecasting when adding int to uint8? | 38,127,123 | <p>I am somewhat confused by the way python/numpy work when typecasting unsigned integers. </p>
<p>Example:</p>
<pre><code>import numpy as np
x = np.array([255], dtype=np.uint8)
y = x + 1
</code></pre>
<p>This gives the result:</p>
<pre><code>In[0]: y
Out[0]: array([0], dtype=uint8)
</code></pre>
<p>I understand t... | 4 | 2016-06-30T15:10:27Z | 39,253,434 | <p>This behaviour seems to stem from an understandable desire to keep array casting to an absolute minimum.</p>
<p>Consider </p>
<pre><code>z = np.uint8(255)
z + 1
# 256
type(z+1)
# numpy.int64
</code></pre>
<p>where the literal <code>1</code> has type <code>int</code>. It seems in that case both operands are cast t... | 2 | 2016-08-31T15:20:47Z | [
"python",
"numpy"
] |
Is everything a Tensor in TensorFlow, including operations? | 38,127,164 | <p>I've been reading the documentation <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/framework.html#core-graph-data-structures" rel="nofollow">on core graph structures</a> and it seems there is a disagreement with what TensorFlow actually does and the docs (unless I have a misunderstanding, which I ... | 0 | 2016-06-30T15:11:42Z | 38,128,067 | <p>tf.Varible is an tensor, and then you assign a value to it, that is an operation, an assign-operation. Or you use tf.mul() , that also an operation</p>
| 0 | 2016-06-30T15:54:42Z | [
"python",
"tensorflow"
] |
Is everything a Tensor in TensorFlow, including operations? | 38,127,164 | <p>I've been reading the documentation <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/framework.html#core-graph-data-structures" rel="nofollow">on core graph structures</a> and it seems there is a disagreement with what TensorFlow actually does and the docs (unless I have a misunderstanding, which I ... | 0 | 2016-06-30T15:11:42Z | 38,128,516 | <p>There are operations. You can get a list of all operations in the graph by <code>graph.get_operations()</code> (where you could get <code>graph</code> via <code>tf.get_default_graph()</code> or <code>sess.graph</code> or whatever is appropriate in your situation).</p>
<p>It's just that, in Python, things like <code... | 0 | 2016-06-30T16:17:00Z | [
"python",
"tensorflow"
] |
Is everything a Tensor in TensorFlow, including operations? | 38,127,164 | <p>I've been reading the documentation <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/framework.html#core-graph-data-structures" rel="nofollow">on core graph structures</a> and it seems there is a disagreement with what TensorFlow actually does and the docs (unless I have a misunderstanding, which I ... | 0 | 2016-06-30T15:11:42Z | 38,128,543 | <p>I am not an expert, but maybe this will clear things up a bit.</p>
<pre>
x = tf.constant(1, shape=[10, 10])
y = tf.constant(1, shape=[10, 10])
z = tf.matmul(x, y, name='operation')
# print(z)
# tf.Tensor 'operation:0' shape=(10, 10) dtype=int32
# z is a placeholder for the result of multiplication of x and y
# but ... | 0 | 2016-06-30T16:18:24Z | [
"python",
"tensorflow"
] |
Is everything a Tensor in TensorFlow, including operations? | 38,127,164 | <p>I've been reading the documentation <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/framework.html#core-graph-data-structures" rel="nofollow">on core graph structures</a> and it seems there is a disagreement with what TensorFlow actually does and the docs (unless I have a misunderstanding, which I ... | 0 | 2016-06-30T15:11:42Z | 38,128,782 | <p>I'm not very familiar with TensorFlow, but it seems to be a basic concept that <code>Wx</code> is a <em>symbolic handle</em> for the output of <code>tf.matmul(x, W)</code>. So you actually created an Operation, but accessing <code>Wx</code> will give you a representation of the result (even though it's not calculate... | 0 | 2016-06-30T16:31:16Z | [
"python",
"tensorflow"
] |
How to use groupby to concatenate strings in python pandas? | 38,127,209 | <p>I currently have dataframe at the top. Is there a way to use a groupby function to get another dataframe to group the data and concatenate the words into the format like further below using python pandas?</p>
<p>Thanks</p>
<p>[<img src="http://i.stack.imgur.com/ffFpH.png" alt="enter image description [1]"></p>
| -3 | 2016-06-30T15:14:13Z | 38,127,286 | <p>You can apply <code>join</code> on your column after <code>groupby</code>:</p>
<pre><code>df.groupby('index')['words'].apply(','.join)
</code></pre>
<p>Example:</p>
<pre><code>In [326]:
df = pd.DataFrame({'id':['a','a','b','c','c'], 'words':['asd','rtr','s','rrtttt','dsfd']})
df
Out[326]:
id words
0 a a... | 3 | 2016-06-30T15:17:56Z | [
"python",
"pandas",
"grouping"
] |
Extract the last part of a facebook page url | 38,127,225 | <p>Let's say we have different links for facebook pages. I want to extract the 'entity' in these links. For example:</p>
<p>In <a href="http://www.facebook.com/pages/Blue-Mountain-Aromatics/561694213861926" rel="nofollow">http://www.facebook.com/pages/Blue-Mountain-Aromatics/561694213861926</a>
I want to extract 'Blue... | 0 | 2016-06-30T15:14:51Z | 38,127,370 | <pre><code>try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse
links = [
'http://www.facebook.com/pages/Blue-Mountain-Aromatics/561694213861926',
'http://www.facebook.com/1905BocaJuniors',
'https://www.facebook.com/7upGuatemala?ref=br_tf',
'http://www.fb.com... | 1 | 2016-06-30T15:21:36Z | [
"python",
"regex",
"url",
"entity"
] |
Extract the last part of a facebook page url | 38,127,225 | <p>Let's say we have different links for facebook pages. I want to extract the 'entity' in these links. For example:</p>
<p>In <a href="http://www.facebook.com/pages/Blue-Mountain-Aromatics/561694213861926" rel="nofollow">http://www.facebook.com/pages/Blue-Mountain-Aromatics/561694213861926</a>
I want to extract 'Blue... | 0 | 2016-06-30T15:14:51Z | 38,127,455 | <p>The Python 3 version of @Robᵩs answer (and re-written to a funtion):</p>
<pre><code>from urllib.parse import urlparse
links = [
'http://www.facebook.com/pages/Blue-Mountain-Aromatics/561694213861926',
'http://www.facebook.com/1905BocaJuniors',
'https://www.facebook.com/7upGuatemala?ref=br_tf',
'h... | 1 | 2016-06-30T15:25:49Z | [
"python",
"regex",
"url",
"entity"
] |
Python: building a CCDF out of a list | 38,127,241 | <p>I have the following list, where the 1st element is a generic value and the second is the number of occurrences of that value:</p>
<pre><code>mylist=[(2, 45), (3, 21), (4, 12), (5, 7),
(6, 2), (7, 2), (8, 3), (9, 2),
(10, 1), (11, 1), (15, 1), (17, 2), (18, 1)]
</code></pre>
<p>and I want to compute the CCDF (Co... | -2 | 2016-06-30T15:15:46Z | 38,127,655 | <p>Your inner list comprehension is off.
There are two issues:</p>
<ol>
<li><p>The correct syntax for a conditional (list) comprehension is: <code>[x for x in someiterable if predicate(x)]</code></p></li>
<li><p>You are using the same variable names in both iterations. That is
confusing and error prone.</p></li>
</ol>... | 1 | 2016-06-30T15:34:19Z | [
"python",
"list-comprehension",
"find-occurrences",
"cdf"
] |
Python: building a CCDF out of a list | 38,127,241 | <p>I have the following list, where the 1st element is a generic value and the second is the number of occurrences of that value:</p>
<pre><code>mylist=[(2, 45), (3, 21), (4, 12), (5, 7),
(6, 2), (7, 2), (8, 3), (9, 2),
(10, 1), (11, 1), (15, 1), (17, 2), (18, 1)]
</code></pre>
<p>and I want to compute the CCDF (Co... | -2 | 2016-06-30T15:15:46Z | 38,127,973 | <pre><code>mylist = [
(2, 45), (3, 21), (4, 12), (5, 7), (6, 2),
(7, 2), (8, 3), (9, 2), (10, 1), (11, 1),
(15, 1), (17, 2), (18, 1)
]
def get_sum_of_values(_list):
return reduce(lambda a, b: a + b[1], _list, 0)
def calculate_ccdf(mylist):
sum_of_values = get_sum_of_values(mylist)
return [(... | 1 | 2016-06-30T15:50:02Z | [
"python",
"list-comprehension",
"find-occurrences",
"cdf"
] |
Can we make correlated queries with SQLAlchemy | 38,127,298 | <p>I'm trying to translate this SQL query into a Flask-SQLAlchemy call:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT *
FROM "ENVOI"
WHERE "ID_ENVOI" IN (SELECT d."ID_ENVOI"
FROM "DECLANCHEMENT" d
WHERE d."STATUS" = 0
AND d."DA... | 1 | 2016-06-30T15:18:14Z | 38,147,207 | <p>Yes, we can.</p>
<p>Have a look at the following example (especially the <code>correlate</code> method call):</p>
<pre><code>from sqlalchemy import select, func, table, Column, Integer
table1 = table('table1', Column('col', Integer))
table2 = table('table2', Column('col', Integer))
subquery = select(
[func.... | 1 | 2016-07-01T13:52:27Z | [
"python",
"postgresql",
"sqlalchemy"
] |
Can we make correlated queries with SQLAlchemy | 38,127,298 | <p>I'm trying to translate this SQL query into a Flask-SQLAlchemy call:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT *
FROM "ENVOI"
WHERE "ID_ENVOI" IN (SELECT d."ID_ENVOI"
FROM "DECLANCHEMENT" d
WHERE d."STATUS" = 0
AND d."DA... | 1 | 2016-06-30T15:18:14Z | 38,180,888 | <p>Based on the link from univerio's comment, I've done this code for my request:</p>
<pre class="lang-py prettyprint-override"><code>Declch = db.aliased(Declanchement)
maxdate_sub = db.select([db.func.max(Declanchement.date)])\
.where(Declanchement.id_envoi == Declch.id_envoi)
decs_sub = db.session.... | 0 | 2016-07-04T09:12:40Z | [
"python",
"postgresql",
"sqlalchemy"
] |
Pandas sorting multindex and reset | 38,127,418 | <p>I'm trying to go through a dataframe with 2 index levels.
I previously removed entries from the dataframe, so often the second level is not ascending. But I want it to be.
What's a good way of resetting the second level index to a sorted list?</p>
<p>e.g.</p>
<pre><code>a = [{'A':1, 'B':2, 'C':3, 'D':4}]
b = [{'A'... | 3 | 2016-06-30T15:23:47Z | 38,127,517 | <p>One possible solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.cumcount.html" rel="nofollow"><code>cumcount</code></a>:</p>
<pre><code>df = df[df['D']<=4]
df.reset_index('bar', drop=True, inplace=True)
df['bar'] = df.groupby(level='foo').cumcount()
df.set... | 1 | 2016-06-30T15:28:46Z | [
"python",
"sorting",
"pandas"
] |
Where are default django logging settings? | 38,127,430 | <p>This question has been <a href="http://stackoverflow.com/questions/19256919/location-of-django-logs-and-errors/19257221">asked</a> two years before, however, the answer seems to be incorrect as of at least <strong>django 1.9</strong>.</p>
<pre><code>django-admin startproject myproject
cat myproject/settings.py
#no ... | 0 | 2016-06-30T15:24:28Z | 38,127,524 | <p>As the documentation for the <a href="https://docs.djangoproject.com/en/1.9/ref/settings/#logging" rel="nofollow"><code>LOGGING</code></a> setting says, you can see the default logging configuration in <a href="https://github.com/django/django/blob/1.9.7/django/utils/log.py#L20" rel="nofollow"><code>django/utils/log... | 4 | 2016-06-30T15:29:13Z | [
"python",
"django",
"logging"
] |
Get iterable Tensor without running eval | 38,127,529 | <p>Is there a way to make a Tensor iterable without running <code>eval()</code> to get its numpy array?</p>
<p>I am trying to iterate through two parts of a tensor after using <code>split()</code> on it, but it happens within the construction of the hidden layers of my neural network, so it needs to happen before I am... | 4 | 2016-06-30T15:29:26Z | 38,129,418 | <p>No, there isn't; not directly.</p>
<p>It's easiest to think about Tensorflow programs as being split into two phases: a building Python phase that builds a computation graph, and a execution phase that runs the computation graph. Nothing actually runs during the building phase; all computation happens during the ex... | 0 | 2016-06-30T17:08:18Z | [
"python",
"numpy",
"tensorflow"
] |
Hide field odoo in python onchange method | 38,127,562 | <p>I have a small question, just to research.
I can hide a field based on attrs in odoo 8, but is there a way to do the same in python code. below is the code:</p>
<pre><code><field name="test" attrs="{'invisible':[('role', '=', 'testrole')]}" />
</code></pre>
<p>so this does the work ( means hides the field if... | 2 | 2016-06-30T15:30:53Z | 38,132,164 | <p>the answer to your question is in this link. But it's better to use invisible only in the XML code, otherwise it's not going to work properly.</p>
<p>http://stackoverflow.com/questions/31532390/invisible-true-false-parameter-exist-or-not-in-odoo-8</p>
| 0 | 2016-06-30T19:56:18Z | [
"python",
"openerp"
] |
Hide field odoo in python onchange method | 38,127,562 | <p>I have a small question, just to research.
I can hide a field based on attrs in odoo 8, but is there a way to do the same in python code. below is the code:</p>
<pre><code><field name="test" attrs="{'invisible':[('role', '=', 'testrole')]}" />
</code></pre>
<p>so this does the work ( means hides the field if... | 2 | 2016-06-30T15:30:53Z | 38,145,631 | <p>In this case you can create a new Boolean field and this field default set False and in your "rol" field invisible={'boolean_filed','=', True}
and onchange method also apply and you can apply onchange function the "boolean_field" value set True.</p>
<pre><code>bool = field.boolean('Boolean')
_default { 'bool': Fal... | 1 | 2016-07-01T12:37:20Z | [
"python",
"openerp"
] |
Hide field odoo in python onchange method | 38,127,562 | <p>I have a small question, just to research.
I can hide a field based on attrs in odoo 8, but is there a way to do the same in python code. below is the code:</p>
<pre><code><field name="test" attrs="{'invisible':[('role', '=', 'testrole')]}" />
</code></pre>
<p>so this does the work ( means hides the field if... | 2 | 2016-06-30T15:30:53Z | 38,149,395 | <p>I prefer the way with a second field, too, but i would choose a computed field instead, like:</p>
<pre class="lang-py prettyprint-override"><code>role = # your role field definition
hide = field.Boolean(string='Hide', compute="_compute_hide")
@api.depends('role')
def _compute_hide(self):
# simple logic, but yo... | 0 | 2016-07-01T15:46:36Z | [
"python",
"openerp"
] |
Python, nltk: Cannot import mkdtemp | 38,127,616 | <p>I got this error while trying to compile test.py that contains these two commands -</p>
<pre><code>import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
</code></pre>
<p>This is the error I got</p>
<pre><code>Traceback (most recent call last):
File "test.py", line 3, in <module>
... | 1 | 2016-06-30T15:33:08Z | 38,127,912 | <p>Make sure you don't have <code>tempfile.py</code> somewhere in python path; which prevents import of standard library <a href="https://docs.python.org/3/library/tempfile.html" rel="nofollow"><code>tempfile</code> module</a>.</p>
<p>Also make sure deleting <code>tempfile.pyc</code> if there it is.</p>
| 0 | 2016-06-30T15:48:02Z | [
"python",
"nltk"
] |
MakeHuman no running OpenGL error | 38,127,718 | <p>I've read all of the same error post on google, checked my python and opengl files then installed more python stuff (showing pertinent to this problem)</p>
<pre><code>python-2.7.12_1
python3.4-3.4.5_1
python3.5-3.5.2_1
python-enum34-1.1.6_1
python3.4-PyQt5-5.6_1
python3.4-PyQt5-opengl-5.6_1
python-PyQt5-open... | -2 | 2016-06-30T15:37:16Z | 38,135,085 | <p>You need to install the packages that provide the OpenGL libraries. Usually these are included in the development or library packages for your graphics card. It doesn't seem like Void Linux installs dependencies for you, so you'll need to install them yourself, and this will depend on the graphics driver you're usin... | 0 | 2016-07-01T00:04:04Z | [
"python",
"python-2.7",
"python-3.x",
"opengl"
] |
Running a python script in the background using child_process (node js) | 38,127,766 | <p>I have a python script <strong>test.py</strong> on a raspberry pi which needs to be running in the background. Using the CLI, I do this:</p>
<pre><code>python test.py &
</code></pre>
<p>But, how do I do the same using the child_process in node js.</p>
<pre><code>var spawn = require("child_process").spawn;
var... | 1 | 2016-06-30T15:40:40Z | 38,127,891 | <p>Don't use the <code>&</code> (ampersand) in the command line arguments. It is used by shell, not by python.</p>
<p>Use <code>{detached: true}</code> option so it will be able to live when your Node process exits:</p>
<pre><code>var spawn = require("child_process").spawn;
var p = spawn("python", ["/path/to/test... | 1 | 2016-06-30T15:47:09Z | [
"python",
"node.js",
"raspberry-pi",
"child-process"
] |
Running a python script in the background using child_process (node js) | 38,127,766 | <p>I have a python script <strong>test.py</strong> on a raspberry pi which needs to be running in the background. Using the CLI, I do this:</p>
<pre><code>python test.py &
</code></pre>
<p>But, how do I do the same using the child_process in node js.</p>
<pre><code>var spawn = require("child_process").spawn;
var... | 1 | 2016-06-30T15:40:40Z | 38,127,948 | <p>You shouldn't really be doing that. Processes should be handled by a real process manager.</p>
<p>If you want to run a background process, you should look into how to run services in Raspberry Pi. It depends on the Linux distribution that is being run on the Raspberry Pi (<a href="https://en.wikipedia.org/wiki/Upst... | 2 | 2016-06-30T15:49:16Z | [
"python",
"node.js",
"raspberry-pi",
"child-process"
] |
Python Pandas Unstacking Unique Column Values to Columns Of Their Own | 38,127,927 | <pre><code>df = pd.DataFrame({'Col1': ['label1', 'label1', 'label2', 'label2',
'label3', 'label3', 'label4'],
'Col2': ['a', 'd', 'b', 'e', 'c', 'f', 'q']}, columns=['Col1', 'Col2'])
</code></pre>
<p>Looks like this</p>
<pre><code> Col1 Col2
0 label1 a
1 label1 d
2 label2 b
3 label2 e
4 ... | 4 | 2016-06-30T15:48:41Z | 38,128,039 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.cumcount.html" rel="nofollow"><code>cumcount</code></a> for creating column for new <code>index</code> and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"... | 5 | 2016-06-30T15:53:09Z | [
"python",
"pandas",
"text",
"grouping"
] |
Dividing two columns of a different DataFrames | 38,128,014 | <p>I am using Spark to do exploratory data analysis on a user log file. One of the analysis that I am doing is average requests on daily basis per host. So in order to figure out the average, I need to divide the total request column of the DataFrame by number unique Request column of the DataFrame.</p>
<pre><code>tot... | 2 | 2016-06-30T15:51:49Z | 38,130,693 | <p>It is not possible to reference column from another table. If you want to combine data you'll have to <code>join</code> first using something similar to this:</p>
<pre><code>from pyspark.sql.functions import col
(total_req_per_day_df.alias("total")
.join(daily_hosts_df.alias("host"), ["day"])
.select(col("... | 13 | 2016-06-30T18:26:40Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql"
] |
Dividing two columns of a different DataFrames | 38,128,014 | <p>I am using Spark to do exploratory data analysis on a user log file. One of the analysis that I am doing is average requests on daily basis per host. So in order to figure out the average, I need to divide the total request column of the DataFrame by number unique Request column of the DataFrame.</p>
<pre><code>tot... | 2 | 2016-06-30T15:51:49Z | 38,163,715 | <p>Join the two data frames on column day, and then select the day and ratio of the count columns.</p>
<pre><code>total_req_per_day_df = logs_df.select(dayofmonth('time')
.alias('day')
).groupBy('day').count()
avg_daily_req_per_host_df = (
t... | 0 | 2016-07-02T19:25:27Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql"
] |
Dividing two columns of a different DataFrames | 38,128,014 | <p>I am using Spark to do exploratory data analysis on a user log file. One of the analysis that I am doing is average requests on daily basis per host. So in order to figure out the average, I need to divide the total request column of the DataFrame by number unique Request column of the DataFrame.</p>
<pre><code>tot... | 2 | 2016-06-30T15:51:49Z | 38,285,608 | <p>It's a question from an edX Spark course assignment. Since the solution is public now I take the opportunity to share another, slower one and ask whether the performance of it could be improved or is totally anti-Spark?</p>
<pre><code>daily_hosts_list = (daily_hosts_df.map(lambda r: (r[0], r[1])).take(30))
days_wit... | 1 | 2016-07-09T19:33:09Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql"
] |
Dividing two columns of a different DataFrames | 38,128,014 | <p>I am using Spark to do exploratory data analysis on a user log file. One of the analysis that I am doing is average requests on daily basis per host. So in order to figure out the average, I need to divide the total request column of the DataFrame by number unique Request column of the DataFrame.</p>
<pre><code>tot... | 2 | 2016-06-30T15:51:49Z | 38,459,088 | <p>Solution, based on zero323 answer, but correctly works as OUTER join. </p>
<pre><code>avg_daily_req_per_host_df = (
total_req_per_day_df.join(
daily_hosts_df, daily_hosts_df['day'] == total_req_per_day_df['day'], 'outer'
).select(
total_req_per_day_df['day'],
(total_req_per_day_df['count']/da... | 0 | 2016-07-19T12:48:35Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql"
] |
Corrupted nodes inside an HDF5 file | 38,128,061 | <p>I have an instance of a program running in a cluster, the program basically perform numerical computations reading and writing numerical arrays to an <strong>HDF5</strong> file using <a href="http://www.h5py.org/" rel="nofollow">h5py</a>. </p>
<p>When I try to run several instances of my code in different computing... | 0 | 2016-06-30T15:54:26Z | 38,142,072 | <p>According to the Book <strong>Python and HDF5</strong> by Andrew Collete,</p>
<blockquote>
<p>multiprocessing is a more recent built-in module available with Python, which provides support for basic fork()-based parallel processing. The main restriction is that your parallel processes canât share a single HDF5 ... | 0 | 2016-07-01T09:40:02Z | [
"python",
"hdf5",
"h5py"
] |
django smart-selects ajax configuration | 38,128,140 | <p>So I have finally implemented smart-selects (<a href="https://github.com/digi604/django-smart-selects" rel="nofollow">https://github.com/digi604/django-smart-selects</a>) on the admin side, but now when I try to get the actual filters to work on the user side, the filters don't work. I've tried to research a solutio... | 0 | 2016-06-30T15:57:40Z | 38,128,200 | <p><code>smart selects</code> has it's own form field types. You are overriding that for <code>category</code> right now in your form: </p>
<pre><code>## Pre-populated dropdown menu
category = forms.ModelChoiceField(
queryset=Category.objects.all(),
label = "Category"
)
</code></pre>
<p>Remove all the code ab... | 0 | 2016-06-30T16:01:02Z | [
"python",
"ajax",
"django",
"django-smart-selects"
] |
Django - Allowing super user to review all interactions to the database and generate reports | 38,128,263 | <p>I am designing an application where any member of staff can add items into the database (using SQLite3) and was wondering if there was a way to get it so that the admin (superuser) can review all these changes and additions to the database before they are displayed? The idea being if I'm logged in as the superuser a... | 0 | 2016-06-30T16:04:46Z | 38,128,404 | <p><a href="https://github.com/etianen/django-reversion" rel="nofollow"><code>django-reversion</code></a> is an app that allows for a few of the things you are looking for:</p>
<ul>
<li>Roll back to any point in a model instance's history. </li>
<li>Recover deleted model instances. </li>
<li>Simple admin integration.<... | 1 | 2016-06-30T16:11:34Z | [
"python",
"django",
"django-models"
] |
While loop break condition not working | 38,128,337 | <p>I am trying to read a file, which will break when gets a line starting with <code>"--------------------------"</code> as:</p>
<pre><code>#!/usr/bin/python3
def cinpt():
with open("test", 'r') as finp:
for line in finp:
if line.strip().startswith("start"):
while not line.start... | 0 | 2016-06-30T16:08:07Z | 38,129,071 | <p>You should read the liens form your file in a single place
As it is, you are fetching lines from your file both at <code>for line in finp:</code> line and at <code>sdata = finp.readline()</code> - this likely will be bad for you (as you have found out).</p>
<p>Keep your fiel data in a single place, and use aux... | 0 | 2016-06-30T16:47:22Z | [
"python",
"python-3.x"
] |
While loop break condition not working | 38,128,337 | <p>I am trying to read a file, which will break when gets a line starting with <code>"--------------------------"</code> as:</p>
<pre><code>#!/usr/bin/python3
def cinpt():
with open("test", 'r') as finp:
for line in finp:
if line.strip().startswith("start"):
while not line.start... | 0 | 2016-06-30T16:08:07Z | 38,129,247 | <p>It loops forever because your line variable does not change during the while loop. You should iterate line by line, its simple.</p>
<pre><code>#!/usr/bin/python3
def cinpt():
with open("test", 'r') as finp:
started = False
for line in finp:
if started:
if line.startsw... | 2 | 2016-06-30T16:57:23Z | [
"python",
"python-3.x"
] |
Search Pandas Column for Substring in other Column | 38,128,353 | <p>I have an example .csv, imported as df.csv, as follows:</p>
<pre><code> Ethnicity, Description
0 French, Irish Dance Company
1 Italian, Moroccan/Algerian
2 Danish, Company in Netherlands
3 Dutch, French
4 English, EnglishFrench
5 Irish, Irish-American
</code></pre>
<p>I'd like to check the pandas <c... | 3 | 2016-06-30T16:08:47Z | 38,128,453 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.contains.html" rel="nofollow"><code>str.contains</code></a> with values in column <code>Ethnicity</code> converted <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.tolist.html" rel="nofollow"><cod... | 2 | 2016-06-30T16:13:37Z | [
"python",
"string",
"pandas",
"dataframe",
"substring"
] |
Search Pandas Column for Substring in other Column | 38,128,353 | <p>I have an example .csv, imported as df.csv, as follows:</p>
<pre><code> Ethnicity, Description
0 French, Irish Dance Company
1 Italian, Moroccan/Algerian
2 Danish, Company in Netherlands
3 Dutch, French
4 English, EnglishFrench
5 Irish, Irish-American
</code></pre>
<p>I'd like to check the pandas <c... | 3 | 2016-06-30T16:08:47Z | 38,128,861 | <p>the ever popular double apply:</p>
<pre><code>df[df.Description.apply(lambda x: df.Ethnicity.apply(lambda y: y in x)).any(1)]
Ethnicity Description
0 French Irish Dance Company
3 Dutch French
4 English EnglishFrench
5 Irish Irish-American
</code></pre>
<hr>
<h3... | 2 | 2016-06-30T16:35:58Z | [
"python",
"string",
"pandas",
"dataframe",
"substring"
] |
How to make a Class return an object when the class is referenced after it has been initialized? | 38,128,359 | <p>How to make a class return an object in the following way:</p>
<pre><code>import numpy as np
a = np.array([(1,2),(3,4)])
</code></pre>
<p>Whenever <code>a</code> is referenced, it returns </p>
<pre><code>array([[1, 2],
[3, 4]])
</code></pre>
<p>However when I create a simple class:</p>
<pre><code>class ... | 1 | 2016-06-30T16:08:59Z | 38,128,417 | <p>Using Python's "magic methods", like the <code>__init__</code> you've already seen, we can make the class execute code when certain things happen. One of these is <code>__call__</code>, which executes when the class is called like a function.</p>
<p>Knowing this, you could use this code:</p>
<pre><code>import nump... | 2 | 2016-06-30T16:12:07Z | [
"python",
"python-3.x",
"oop"
] |
How to make a Class return an object when the class is referenced after it has been initialized? | 38,128,359 | <p>How to make a class return an object in the following way:</p>
<pre><code>import numpy as np
a = np.array([(1,2),(3,4)])
</code></pre>
<p>Whenever <code>a</code> is referenced, it returns </p>
<pre><code>array([[1, 2],
[3, 4]])
</code></pre>
<p>However when I create a simple class:</p>
<pre><code>class ... | 1 | 2016-06-30T16:08:59Z | 38,128,429 | <p>You should use <code>__repr__</code> in the following way:</p>
<pre><code>class Example:
def __init__(self, data):
self.nparray = np.array(data)
def __repr__(self):
return repr(self.nparray)
</code></pre>
<p>This returns the representation the <code>self.nparray</code> object within... | 2 | 2016-06-30T16:12:43Z | [
"python",
"python-3.x",
"oop"
] |
How to make a Class return an object when the class is referenced after it has been initialized? | 38,128,359 | <p>How to make a class return an object in the following way:</p>
<pre><code>import numpy as np
a = np.array([(1,2),(3,4)])
</code></pre>
<p>Whenever <code>a</code> is referenced, it returns </p>
<pre><code>array([[1, 2],
[3, 4]])
</code></pre>
<p>However when I create a simple class:</p>
<pre><code>class ... | 1 | 2016-06-30T16:08:59Z | 38,128,460 | <p>You can't return any data from a class <strong>init</strong> function. Have you tried something like:</p>
<pre><code>class Example(object):
nparray = None
def __init__(self, data):
self.nparray = np.array(data)
return
def getArray(self):
return(self.nparray)
</code></pre>
| 0 | 2016-06-30T16:13:52Z | [
"python",
"python-3.x",
"oop"
] |
I cant import sklearn | 38,128,380 | <p>I try to import scikit-learn, but there is an error. i installed sklearn, scipy on anaconda. i am using W10 and python 3.5.</p>
<pre><code>>>> import sklearn
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import sklearn
File "C:\Users\lenovo\AppData\Local\Pro... | 0 | 2016-06-30T16:10:08Z | 39,798,925 | <p>In linux there is <code>pip install <module></code> to install a module, and if you are using anaconda then <code>conda install <module></code>, I believe there would be something similar in windows.</p>
<p>If you are sure that you have installed <code>scipy</code> module, then probably the python path ... | 1 | 2016-09-30T19:36:56Z | [
"python"
] |
Use both matplotlib inline and qt in jupyter notebook | 38,128,640 | <p>I am using Jupyter (with IPython) to analyze research data, as well as export figures. I really like the notebook approach offered by Jupyter: when I revisit an experiment after a long time, I can easily see how the figures correspond to the data. This is of course using the inline backend.</p>
<p>However, when I w... | 0 | 2016-06-30T16:23:28Z | 38,129,646 | <p>This allows you to run QtConsole, plotting with the plotSin function, both inline and through the QtConsole.</p>
<pre><code>import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
</code></pre>
<p>..</p>
<pre><code>def plotChirp(Type, Exp, Rand):
# Orignal Chirp Funciton Fro... | 0 | 2016-06-30T17:22:34Z | [
"python",
"matplotlib",
"ipython",
"jupyter",
"jupyter-notebook"
] |
Best way to organize Django fieldsets | 38,128,666 | <p>So I am in the process of creating a django admin view with customizable fieldsets based on the user's permission level. What is the best way to organize the fieldsets to reduce code repetition? </p>
<p>Currently, for 2 different fieldsets I have it set up like this:</p>
<pre><code>standard_fieldsets = (
(... | 1 | 2016-06-30T16:24:40Z | 38,248,542 | <p>If fields inside a fieldset are always the same and in the same order, you can do something like this:</p>
<pre><code>class SomeAdmin(admin.ModelAdmin):
fieldsets = {
'base': (None, {'fields': ('email', 'password')}),
'permissions': (
_('Permissions'), {
'fields': ('i... | 1 | 2016-07-07T14:46:45Z | [
"python",
"django",
"django-admin"
] |
2's compliment of a Byte in python | 38,128,727 | <p>I am working on the following python code:</p>
<pre><code>import wave
from bitstring import BitArray
w = wave.open('file.wav','rb')
totalFrames = w.getnframes() #Total number of samples
bytesData = w.readframes(totalFrames)
binData = BitArray(bytesData)
bin2Data = (binData.bin)
</code></pre>
<p>The file.wa... | 0 | 2016-06-30T16:28:11Z | 38,128,807 | <p>You need to use</p>
<pre><code>int(binData.bin, 2)
</code></pre>
<p>To create an int, you can specify the base as a second parameter, otherwise it will just assume the value is in base 10. As you can see from the <a href="https://docs.python.org/2/library/functions.html#int" rel="nofollow">docs</a>, the default ba... | 0 | 2016-06-30T16:32:37Z | [
"python"
] |
Tox installs the wrong version of pip to it's virtual env | 38,128,764 | <p>I am using <a href="https://pypi.python.org/pypi/tox" rel="nofollow">tox</a> to manage some testing environments. I have a dependency (backports.ssl-match-hostname) that I cannot download using the latest version of pip, so I need to revert back to pip 8.0.3 to allow the install to work.</p>
<p>I have included the ... | 2 | 2016-06-30T16:30:08Z | 38,133,283 | <p>This was apparently the result of the "virtualenvs" python package containing a pre-selected group of python packages that it refers to, one of which was the latest and greatest pip.</p>
<p>I don't know if this is the preferred way of doing this, but I found success by running</p>
<pre><code>pip uninstall virtuale... | 1 | 2016-06-30T21:06:31Z | [
"python",
"linux",
"dependencies",
"pip",
"tox"
] |
Tox installs the wrong version of pip to it's virtual env | 38,128,764 | <p>I am using <a href="https://pypi.python.org/pypi/tox" rel="nofollow">tox</a> to manage some testing environments. I have a dependency (backports.ssl-match-hostname) that I cannot download using the latest version of pip, so I need to revert back to pip 8.0.3 to allow the install to work.</p>
<p>I have included the ... | 2 | 2016-06-30T16:30:08Z | 39,660,073 | <p>A workaround for this is here: <a href="https://github.com/pypa/pip/issues/3666" rel="nofollow">https://github.com/pypa/pip/issues/3666</a></p>
<p>Although to make it work I had to write "pip install pip==8.1.1" in my script. So to recap:</p>
<p>Add a pip.sh script to your project:</p>
<pre><code>#!/bin/bash
pip ... | 0 | 2016-09-23T11:50:34Z | [
"python",
"linux",
"dependencies",
"pip",
"tox"
] |
how django 'auto_now' ignore the update of specified field | 38,128,926 | <p>i have a model, like this:</p>
<pre><code> name = models.CharField(max_length=255)
modify_time = models.DateTimeField(auto_now=True)
chasha = models.CharField(max_length=255)
stat = models.CharField(max_length=255)
</code></pre>
<p>Usually, 'modify_time' will be updated when i update 'name', 'chasha... | 0 | 2016-06-30T16:39:18Z | 38,129,192 | <p>Use a custom save method to update the field by looking at a previous instance. </p>
<pre><code>from django.db import models
from django.utils import timezone as tz
class MyModel(models.Model):
name = models.CharField(max_length=255)
modify_time = models.DateTimeField(null=True, blank=True)
chasha = m... | 0 | 2016-06-30T16:53:38Z | [
"python",
"sql",
"django",
"model"
] |
NLTK panlex_lite giving me error | 38,128,935 | <p>I'm trying to use NLTK for my NLP learning in Python. </p>
<p>Certain package called "panlex_lite" keeps giving me error so I tried using the following:</p>
<pre><code>import nltk
nltk.download('all', halt_on_error = False)
</code></pre>
<p>and it gives me the following error:</p>
<pre><code>[nltk_data] | Dow... | 2 | 2016-06-30T16:40:10Z | 38,135,306 | <p>Here's a "dirty" hack:</p>
<pre><code>$ rm /Users/Harshil/nltk_data/corpora/panlex_lite.zip
$ rm -r /Users/Harshil/nltk_data/corpora/panlex_lite
$ python
>>> import nltk
>>> dler = nltk.downloader.Downloader()
>>> dler._update_index()
>>> dler._status_cache['panlex_lite'] = 'ins... | 5 | 2016-07-01T00:33:19Z | [
"python",
"nlp",
"nltk"
] |
Memory Error When Generating List of Odd Numbers | 38,129,000 | <p>Please take a look at the following code. It makes a list of all odd numbers from 1 - 100. It then takes that list and chunks it into sublists, each sublist one element larger than the last. </p>
<pre><code>mylist = list(range(1, 100, 2))
out = []
i = 1 # Start off with size 1, because we don't care about the initi... | 0 | 2016-06-30T16:43:21Z | 38,129,350 | <p>As this is a challenge, I'll point you in the right direction:</p>
<p>You don't need to store the triangle in memory. What you want is to figure out how to calculate what numbers are in the triangle at a specified line:</p>
<pre><code>1) 1
2) 2 3
3) 4 5 6
4) 7 8 9 10
</code></pre>
<p>If I want line 4, that ... | 1 | 2016-06-30T17:03:55Z | [
"python",
"list",
"function",
"python-3.x"
] |
Iterating through a pandas dataframe and inserting new values into an empty column | 38,129,027 | <p>I'm relatively new to Pandas and am having trouble iterating through the values in a given column in my dataset and finding those cells which contain a specific string.</p>
<pre><code>Address,City
['1234 Apple Drive', 'San Francisco', 'CA'],''
['4678 Bannana Street', 'Austin', 'TX'],''
</code></pre>
<p>For this ex... | 2 | 2016-06-30T16:45:12Z | 38,129,375 | <pre><code>df['street'] = df['Address'].str.replace('\[|\]','').str.split(',', expand=True)[0]
df['street_filtered'] = df.ix[df.street.str.contains('Street'),'street']
</code></pre>
<p>your welcome</p>
| 1 | 2016-06-30T17:05:31Z | [
"python",
"pandas",
"iteration"
] |
Iterating through a pandas dataframe and inserting new values into an empty column | 38,129,027 | <p>I'm relatively new to Pandas and am having trouble iterating through the values in a given column in my dataset and finding those cells which contain a specific string.</p>
<pre><code>Address,City
['1234 Apple Drive', 'San Francisco', 'CA'],''
['4678 Bannana Street', 'Austin', 'TX'],''
</code></pre>
<p>For this ex... | 2 | 2016-06-30T16:45:12Z | 38,129,456 | <p>Try this:</p>
<pre><code>import re
df = pd.DataFrame([['1234 Apple Drive', 'San Francisco', 'CA'],
['4678 Bannana Street', 'Austin', 'TX']],
columns=['Address', 'City', 'State'])
df['Street'] = df.Address.str.extract(r'([\S]+)\s+Street', flags=re.IGNORECASE)
print df
... | 3 | 2016-06-30T17:10:47Z | [
"python",
"pandas",
"iteration"
] |
How to install Theano for Python 3.5 on Windows 10 | 38,129,033 | <p>I can't find how one is supposed to install Theano for Python 3.5 (Windows 10) only for Python 2.7.</p>
<p>I don't want to have to downgrade to 2.7 so does anyone know how to install Theano for Python 3.5 (on Windows 10)?</p>
<p>A clear set of step-by-step instructions would be greatly appreciated, as well as othe... | 1 | 2016-06-30T16:45:19Z | 38,129,195 | <p>I know that this might be a grim answer, and I apologise if it is, but it is much harder to install Theano on Windows than it is to install Theano on Linux and / or Ubuntu.</p>
<p>With that being said, here are some links that could help you install Theano on Windows:</p>
<ul>
<li><p><a href="http://stackoverflow.... | 0 | 2016-06-30T16:53:41Z | [
"python",
"python-3.x",
"installation",
"anaconda",
"theano"
] |
How to install Theano for Python 3.5 on Windows 10 | 38,129,033 | <p>I can't find how one is supposed to install Theano for Python 3.5 (Windows 10) only for Python 2.7.</p>
<p>I don't want to have to downgrade to 2.7 so does anyone know how to install Theano for Python 3.5 (on Windows 10)?</p>
<p>A clear set of step-by-step instructions would be greatly appreciated, as well as othe... | 1 | 2016-06-30T16:45:19Z | 39,564,246 | <p>To make this question more self contained I find it worth to add this answer: </p>
<p><a href="https://winpython.github.io/" rel="nofollow">Winpython</a> is the best!!, actually it is the recommended installation over windows, <a href="http://deeplearning.net/software/theano/install_windows.html#scientific-python-d... | 0 | 2016-09-19T01:37:55Z | [
"python",
"python-3.x",
"installation",
"anaconda",
"theano"
] |
How to run python without including ~/.local/lib/pythonX.Y/site-packages in its module search path | 38,129,077 | <p>I have some packages installed under my <code>~/.local/lib/python2.7/site-packages/</code> subdir, which was for use with system python (/usr/bin/python). Now I have just installed Anaconda python (which is also python 2.7, but minor version 11). The whole idea of Anaconda distro is to have a self-containing python ... | 0 | 2016-06-30T16:47:49Z | 38,129,078 | <p>Well, there is a <code>-s</code> flag in python executable to disable searching the user site directory (`~/.local/lib/python2.7/site-packages etc). That solves the problem above!</p>
| 0 | 2016-06-30T16:47:49Z | [
"python",
"anaconda"
] |
Cython optimization | 38,129,097 | <p>I am writing a rather big simulation in Python and was hoping to get some extra performance from Cython. However, for the code below I don't seem to get all that much, even though it contains a rather large loop. Roughly 100k iterations.</p>
<p>Did I make some beginners mistake or is this loop-size simply to small ... | 3 | 2016-06-30T16:49:15Z | 38,164,065 | <p>You should use compiler directives. I wrote your function in Python</p>
<pre><code>import numpy as np
def example_python(a, A):
N = 100
B = np.zeros((3,N,N),dtype = np.complex)
aux = np.sqrt(A[0])
for n in range(N):
if aux[n] > 1:
for m in range(N):
B[0,n,m] =... | 4 | 2016-07-02T20:08:01Z | [
"python",
"numpy",
"optimization",
"cython"
] |
How to return an Excel from disk as an HttpResponse using Django | 38,129,236 | <p>I'm using Django to write a button on my web page to support download button, I've generated the Excel (.xls) files already and they're saved on the server. I don't need to use a csv writer to write rows and columns on the fly and then return the response, however, I just wanted to pass the excel file on my disk int... | 0 | 2016-06-30T16:56:36Z | 38,133,653 | <p>OK, problem solved, one of my coworkers helped me out:
I dont' need to be constrained to return an HttpResponse, instead I could just use <code><a href="RELATIVE_PATH_TO_MY_FILE" type="submit"></a></code> into the html button.
This way, I don't need to open the excel on the disk and read it into memory a... | 0 | 2016-06-30T21:33:59Z | [
"python",
"django",
"excel"
] |
SaltStack execution module unable to use cmd.run correctly | 38,129,320 | <p>I am attempting to create a salt execution module and I am having trouble using <code>cmd.run</code> correctly in the module.</p>
<p>If I run (using masterless minion):</p>
<pre><code>salt-call cmd.run "cat hey.txt | grep 'hey there'"
</code></pre>
<p>I get:</p>
<pre><code>[INFO ] Executing command 'cat hey.t... | 1 | 2016-06-30T17:02:09Z | 38,509,508 | <p>Turns out the reason for this is because python_shell, which lets you use shell features such as pipes, defaults to False for cmd.run in a module. Simply passing python_shell=True to cmd.run calls in the module solves the problem! </p>
| 0 | 2016-07-21T16:23:04Z | [
"python",
"grep",
"salt-stack"
] |
difflib.SequenceMatcher isjunk argument not considered? | 38,129,357 | <p>In the python difflib library, is the SequenceMatcher class behaving unexpectedly, or am I misreading what the supposed behavior is?</p>
<p>Why does the isjunk argument seem to not make any difference in this case?</p>
<pre><code>difflib.SequenceMatcher(None, "AA", "A A").ratio() return 0.8
difflib.SequenceMatche... | 2 | 2016-06-30T17:04:24Z | 38,199,334 | <p>This is happening because the <code>ratio</code> function uses total sequences' length while calculating the ratio, <strong>but it doesn't filter elements using <code>isjunk</code></strong>. So, as long as the number of matches in the matching blocks results in the same value (with and without <code>isjunk</code>), ... | 0 | 2016-07-05T09:04:58Z | [
"python",
"difflib",
"sequencematcher"
] |
conda env create failed? | 38,129,388 | <p>I tried to create a new environment for anaconda installation that I want to tweak apart from the original install. I found this not working:</p>
<pre><code>$ conda env create --name pandas018numpy111 pandas018test1
Using Anaconda Cloud api site https://api.anaconda.org
Error: Invalid name, try the format: user/pac... | 1 | 2016-06-30T17:06:17Z | 38,130,515 | <p>Ah, I found the answer. </p>
<p>What I need is the <code>conda create</code> command, actually,</p>
<pre><code>$ conda create -n pandas018numpy111 --clone root
</code></pre>
<p>Then I have the throw-away environment to modify, etc and later just toss. To switch then I will just use:</p>
<pre><code>$ source activ... | 1 | 2016-06-30T18:14:16Z | [
"python",
"anaconda"
] |
Can't Save PIL Image From Shell Command (PHP) | 38,129,562 | <p>I have a pretty simple python script that creates an image, writes some text, and finally outputs to a file. Running the script from terminal via ssh works fine and outputs the image as expected. However, if I attempt to run the command via php everything works up until I run the img.save() function. </p>
<p>The... | 0 | 2016-06-30T17:16:59Z | 38,129,804 | <p>Try to use an absolute path. Like this:</p>
<pre><code>background.save('/path/to/test/test.png')
</code></pre>
<p>or even this:</p>
<pre><code>import os
background.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.png'))
</code></pre>
<p>This will save file in the same directory as your script<... | 1 | 2016-06-30T17:31:41Z | [
"php",
"python",
"python-imaging-library"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.