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 |
|---|---|---|---|---|---|---|---|---|---|
PyQt5 module "QtQuick" is not installed | 37,843,212 | <p>I'm trying to get a basic PyQt5 QML project going using either Windows or Linux. I first tried Linux and with no luck am trying Windows now. My issue is whenever I try and run it via python main.py it will complain that "module "QtQuick" is not installed" and "module "QtQuick.Window" is not installed".</p>
<p>I fee... | 2 | 2016-06-15T18:33:25Z | 37,845,134 | <p>Turns out I needed to add the following Environment Variable:</p>
<pre><code>QML2_IMPORT_PATH
</code></pre>
<p>with the value in my case being:</p>
<pre><code>C:\Python35\Lib\site-packages\PyQt5\qml
</code></pre>
| 2 | 2016-06-15T20:25:24Z | [
"python",
"linux",
"windows",
"qt",
"pyqt5"
] |
Use scipy.integrate to get integral over a partial set of variables | 37,843,330 | <p>I have a function,</p>
<pre><code>f = lambda a,b,c,d: <some equation of a,b,c,d>
</code></pre>
<p>I want to integrate f from a = 0 to 1, and b = 0 to 2 such that I get a function in c and d. How can I do this with scipy.integrate ?</p>
<p>Example - </p>
<pre><code>>>> f = lambda a,b,c,d: a+b+c+d
&... | 3 | 2016-06-15T18:39:55Z | 37,843,643 | <p>You can do this as shown in <a href="http://stackoverflow.com/questions/28099892/how-to-evaluate-single-integrals-of-multivariate-functions-with-pythons-scipy-i">this answer</a>, just use <code>dblquad</code> in place of <code>quad</code>. If you want a function of <code>c</code> and <code>d</code> use the <code>arg... | 1 | 2016-06-15T18:55:49Z | [
"python",
"scipy"
] |
Use scipy.integrate to get integral over a partial set of variables | 37,843,330 | <p>I have a function,</p>
<pre><code>f = lambda a,b,c,d: <some equation of a,b,c,d>
</code></pre>
<p>I want to integrate f from a = 0 to 1, and b = 0 to 2 such that I get a function in c and d. How can I do this with scipy.integrate ?</p>
<p>Example - </p>
<pre><code>>>> f = lambda a,b,c,d: a+b+c+d
&... | 3 | 2016-06-15T18:39:55Z | 37,843,660 | <p>Numeric integeation only works if the function returns a number. Therefore, you either define a function of c and d which inegrates on each invocation, or tabulate this functipn on a grid of c and d and interpolate.</p>
| 1 | 2016-06-15T18:57:00Z | [
"python",
"scipy"
] |
Use scipy.integrate to get integral over a partial set of variables | 37,843,330 | <p>I have a function,</p>
<pre><code>f = lambda a,b,c,d: <some equation of a,b,c,d>
</code></pre>
<p>I want to integrate f from a = 0 to 1, and b = 0 to 2 such that I get a function in c and d. How can I do this with scipy.integrate ?</p>
<p>Example - </p>
<pre><code>>>> f = lambda a,b,c,d: a+b+c+d
&... | 3 | 2016-06-15T18:39:55Z | 37,862,784 | <p>Here I propose a solution which implements fixed Gauss-Legendre quadrature for any number of parameters through a class. You create an instance of the class with a function and parameters: a string for a normal parameter, and a list of 2 numbers if you want to integrate over this variable. Then the <code>__init__</c... | 1 | 2016-06-16T14:58:53Z | [
"python",
"scipy"
] |
I really messed up my python install | 37,843,368 | <p>I recently went to upgrade python on my ubuntu 14.04 from 2.7 to 2.7.11.
Afterwards, I noticed that I kept getting errors on importing modules like Requests. I made sure to pip install requests and upgrade but to no avail. I went ahead and uninstalled python and reinstalled with a few other random things.</p>
<p>La... | 0 | 2016-06-15T18:42:28Z | 37,844,076 | <p>Ah I some how fixed it. </p>
<p><a href="http://stackoverflow.com/questions/25607837/pip-install-not-installing-into-correct-directory">Pip Install not installing into correct directory?</a></p>
<p>Went there and tried running:</p>
<pre><code>export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin/pytho... | 0 | 2016-06-15T19:22:33Z | [
"python",
"python-2.7"
] |
How to get all items in a list of strings in Python | 37,843,398 | <p>I got the following code:</p>
<pre><code>import re
dump_final = re.findall(r"\btext=[\w]*", dump5)
</code></pre>
<p>Which returns a list, e.g. <code>['Apple', 'Banana', 'Lemon']</code>.</p>
<p>It turns out that I need to get all the elements of this list and call another function using those elements.</p>
... | -2 | 2016-06-15T18:43:53Z | 37,844,701 | <p>I don't know how you get your list, but if you have a list:</p>
<pre><code>dump_final = ["Apple", "Banana", "Lemon"]
</code></pre>
<p>It is more pythonic to do this:</p>
<pre><code>for d in dump_final:
devM.goToApp(d) # Another Function that opens the apps are listed in dump_final
</code></pre>
<p>There is n... | 0 | 2016-06-15T20:02:13Z | [
"python",
"python-2.7"
] |
How can I get the information in the table using BeautifulSoup? | 37,843,411 | <p>I'm trying to get the information in the table from this website: <a href="http://indiawater.gov.in/IMISReports/Reports/WaterQuality/rpt_WQM_LaboratoryInformation_S.aspx?Rep=0&RP=Y" rel="nofollow">http://indiawater.gov.in/IMISReports/Reports/WaterQuality/rpt_WQM_LaboratoryInformation_S.aspx?Rep=0&RP=Y</a></p... | 1 | 2016-06-15T18:44:42Z | 37,843,526 | <p>You can use the table id to get the table but the <code>oddrowcolor</code> etc.. is dynamically added so it is not in the source:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
url = "http://indiawater.gov.in/IMISReports/Reports/WaterQuality/rpt_WQM_LaboratoryInformation_S.aspx?Rep=0&RP=Y"
r = req... | 2 | 2016-06-15T18:49:59Z | [
"python",
"beautifulsoup"
] |
Appending tabs to all print statements in Python | 37,843,554 | <p>I'm writing a Python console application, and I would like its output to be tabbed one tab over to set it apart from the command line. </p>
<p>Is there a single-command way to have tabs in front of all print statements without having to type each one explicitly?</p>
<p>Thank you!</p>
| 0 | 2016-06-15T18:51:02Z | 37,843,656 | <p>What you'll want to do is just create an alternate print command for this specific use. It might look something like this:</p>
<pre class="lang-py prettyprint-override"><code>from __future__ import print_function
def print_tabbed(str_to_print):
print('\t{}'.format(str_to_print))
</code></pre>
| 1 | 2016-06-15T18:56:52Z | [
"python",
"formatting"
] |
Appending tabs to all print statements in Python | 37,843,554 | <p>I'm writing a Python console application, and I would like its output to be tabbed one tab over to set it apart from the command line. </p>
<p>Is there a single-command way to have tabs in front of all print statements without having to type each one explicitly?</p>
<p>Thank you!</p>
| 0 | 2016-06-15T18:51:02Z | 37,843,680 | <p>There isn't any setting in Python to be able to do that, the easiest way would be to create a new function like so.</p>
<pre><code>def printTab(*args):
args = ("\t",)+args
print(*args)
</code></pre>
<blockquote>
<p>Comment on other answers:</p>
<p>If you let your new function take a single argument,... | 2 | 2016-06-15T18:57:49Z | [
"python",
"formatting"
] |
Appending tabs to all print statements in Python | 37,843,554 | <p>I'm writing a Python console application, and I would like its output to be tabbed one tab over to set it apart from the command line. </p>
<p>Is there a single-command way to have tabs in front of all print statements without having to type each one explicitly?</p>
<p>Thank you!</p>
| 0 | 2016-06-15T18:51:02Z | 37,843,691 | <p>While there may be a way to do what you ask <a href="http://stackoverflow.com/questions/4573727/self-modifying-python-how-can-i-redirect-all-print-statements-within-a-function">(see this link if that's really what you want)</a>, I think it's a bad idea and you could improve a bit on this solution.</p>
<p>If you def... | 0 | 2016-06-15T18:58:30Z | [
"python",
"formatting"
] |
Telling Python to save a .txt file to a certain directory on linux | 37,843,635 | <p>I am trying to save a file in the QCTestFiles directory, but my script is not writing the files to the specified directory. Is my path file correct for Linux and if it is not how can I change my code to write and save a file in a different directory? My current script is running in the brperez location.</p>
<pre><c... | -3 | 2016-06-15T18:55:23Z | 37,843,701 | <p>I don't think that path is correct for linux. I can't remember ever preceding a linux path with 'c:', it's been a while since I spent a lot of time in a true linux env, but I suppose it could depend on what you are doing.</p>
<p>Do you have access to the machine? Navigate to the folder in terminal and type 'pwd' to... | 0 | 2016-06-15T18:59:03Z | [
"python",
"linux"
] |
Telling Python to save a .txt file to a certain directory on linux | 37,843,635 | <p>I am trying to save a file in the QCTestFiles directory, but my script is not writing the files to the specified directory. Is my path file correct for Linux and if it is not how can I change my code to write and save a file in a different directory? My current script is running in the brperez location.</p>
<pre><c... | -3 | 2016-06-15T18:55:23Z | 37,843,714 | <p>No, it is not correct for linux. There is no concept of a 'c:' drive in linux. You should only have to specify the path, e.g. '/usr/local/home/brperez/QCTestFiles'</p>
<p>For more information about drive naming in linux, take a look at this question, and the links in the top answer: <a href="http://askubuntu.com/qu... | 0 | 2016-06-15T18:59:38Z | [
"python",
"linux"
] |
Telling Python to save a .txt file to a certain directory on linux | 37,843,635 | <p>I am trying to save a file in the QCTestFiles directory, but my script is not writing the files to the specified directory. Is my path file correct for Linux and if it is not how can I change my code to write and save a file in a different directory? My current script is running in the brperez location.</p>
<pre><c... | -3 | 2016-06-15T18:55:23Z | 37,843,724 | <p>Since you are using Linux, your path will not have a drive letter, it will just be something like /usr/local/home/brperez.</p>
<p>Hope that helps.</p>
| 0 | 2016-06-15T19:00:28Z | [
"python",
"linux"
] |
Telling Python to save a .txt file to a certain directory on linux | 37,843,635 | <p>I am trying to save a file in the QCTestFiles directory, but my script is not writing the files to the specified directory. Is my path file correct for Linux and if it is not how can I change my code to write and save a file in a different directory? My current script is running in the brperez location.</p>
<pre><c... | -3 | 2016-06-15T18:55:23Z | 37,843,816 | <p>giving that you're running your script in the <code>brperez</code> location, you can replace your snippet with the following one:</p>
<pre><code>filename = (GPN + '_' + inspector + '_' + date + '.txt')
save_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'QCTestFiles')
complete_name = os.path.join(... | 0 | 2016-06-15T19:06:18Z | [
"python",
"linux"
] |
python_2_unicode_compatible error; python 2.7, django 1.9 | 37,843,723 | <p>I am using Python 2.7 and Django 1.9.7. I am trying to add a string method to models.py but I'm getting an error.
When I run "python manage.py runserver", I get the following:</p>
<p>ValueError: @python_2_unicode_compatible cannot be applied to Languages because it doesn't define __ str__().</p>
<pre><code>from d... | 0 | 2016-06-15T19:00:26Z | 37,844,268 | <p>When you are writing</p>
<pre><code> def __str__(self):
return self.lname
</code></pre>
<p>Then you are over-riding the in-built 'str' method.
So whenever str is used, your defined method is called instead of the in-built one.</p>
<p>So if you all you want to do is to return the "lname" of the object o... | 1 | 2016-06-15T19:34:53Z | [
"python",
"django",
"python-2.7",
"unicode-string"
] |
How to get all power plants from Open Street Map using overpass api with python? | 37,843,782 | <p>This is the code I'm using: </p>
<pre><code>import overpass
api = overpass.API(timeout=900)
response = api.Get('node["power" = "plant"]')
print(response)
</code></pre>
<p>I'm getting a nested dictionary of power plants, but only 187. I suspect there must be many more. Does anyone know a better way to query? I ev... | 0 | 2016-06-15T19:03:51Z | 37,852,050 | <p>You are only fetching <a href="https://wiki.openstreetmap.org/wiki/Node" rel="nofollow">nodes</a>. According to <a href="https://taginfo.openstreetmap.org/keys/power" rel="nofollow">taginfo</a> about 7% of power plants are mapped as <a href="https://wiki.openstreetmap.org/wiki/Way" rel="nofollow">ways</a> (and very ... | 1 | 2016-06-16T07:03:30Z | [
"python",
"openstreetmap",
"overpass-api"
] |
find and count repeated occurances within a list - python | 37,843,809 | <p>this is a challange</p>
<p>looking for a one liner solution:</p>
<p>assume we have a list:</p>
<pre><code>a = [1,-1,1,-1,-1,-1]
</code></pre>
<p>idea is to get dynamic solution to find number of -1 within a list, but from the end to the start AND stop counting it when first value (from end to start) is 1.</p>
<... | -3 | 2016-06-15T19:05:59Z | 37,844,281 | <p>One solution is</p>
<pre><code> a[::-1].index(1) if 1 in a else len(a)
</code></pre>
<p><code>a[::-1]</code> reverses the list.</p>
<p><code>index(1)</code> finds the first occurrence of 1 in the reversed list</p>
<p>Since you mentioned there's only <code>1</code>'s and <code>-1</code>'s this is sufficient fo... | 1 | 2016-06-15T19:35:55Z | [
"python",
"python-3.x"
] |
Joining CSV or Tables | 37,843,833 | <p>I have two csv fies with different columns.
Table1</p>
<pre><code>title stage jan time
darn 3.001 0.421 5/23/2016 13:14
darn 2.054 0.1213 5/24/2016 14:14
ok 2.829 1.036 5/23/2016 14:14
five 1.115 1.146 5/23/2016 17:14
three 2 5 5/23/2016 21:14
</code></pre>
<p>Ta... | 1 | 2016-06-15T19:06:56Z | 37,843,910 | <p>assuming your time and date variables are recognized as such by Pandas,
just add</p>
<pre><code>merged = merged[merged.date == (merged.time - pd.Timedelta('1 hours'))]
</code></pre>
| 1 | 2016-06-15T19:12:13Z | [
"python",
"sql",
"oracle",
"csv",
"pandas"
] |
Joining CSV or Tables | 37,843,833 | <p>I have two csv fies with different columns.
Table1</p>
<pre><code>title stage jan time
darn 3.001 0.421 5/23/2016 13:14
darn 2.054 0.1213 5/24/2016 14:14
ok 2.829 1.036 5/23/2016 14:14
five 1.115 1.146 5/23/2016 17:14
three 2 5 5/23/2016 21:14
</code></pre>
<p>Ta... | 1 | 2016-06-15T19:06:56Z | 37,844,564 | <p>I would create a dummy column (to match "time" in <code>df</code>):</p>
<pre><code>In [11]: df1["time"] = df1["date"] + pd.offsets.Hour(1)
</code></pre>
<p>Now you can merge cleanly:</p>
<pre><code>In [12]: df.merge(df1)
Out[12]:
title stage jan time mar apr may jun ... | 0 | 2016-06-15T19:53:13Z | [
"python",
"sql",
"oracle",
"csv",
"pandas"
] |
AssertionError When I stack Autoencoder with TimeDistributed Layer using Keras | 37,843,847 | <p>I'm using Keras to implement an auto-encoder followed by a <code>TimeDistributed</code> layer. However, I met with an <code>AssertionError</code>. </p>
<p>Traceback Log:</p>
<pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
File "test3.py", line 115, in <module>
model... | 0 | 2016-06-15T19:07:57Z | 39,562,091 | <p>I had the same error message. Code for part of the network looks roughly like this. As you can see, I am also using Convolution1D. </p>
<pre><code>qenc = Sequential()
qenc.add(Embedding(output_dim=WORD2VEC_EMBED_SIZE, input_dim=vocab_size,
input_length=seq_maxlen,
weights=[embe... | 0 | 2016-09-18T19:58:42Z | [
"python",
"deep-learning",
"keras"
] |
How to control index returned by pandas groupby with rolling summary function | 37,843,864 | <p>I have data with a MultiIndex, like this:</p>
<pre><code>import itertools
idx1 = list('XYZ')
idx2 = range(3)
idx = pd.MultiIndex.from_tuples(list(itertools.product(idx1,idx2)))
df = pd.DataFrame(np.random.rand(9,4), columns=list('ABCD'), index=idx)
A B C D
first second ... | 1 | 2016-06-15T19:09:19Z | 37,844,037 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>group_keys=False</code></a>:</p>
<pre><code>In [43]: df.groupby(level=0, group_keys=False).rolling(2).sum()
Out[43]:
A B C D
X 0 NaN NaN NaN ... | 2 | 2016-06-15T19:20:04Z | [
"python",
"pandas"
] |
gae bigquery works from dev_appserver but credential errors during tests | 37,843,867 | <p>I have a gae app and it has a view that does this:</p>
<pre><code>from apiclient.discovery import build
from oauth2client.client import GoogleCredentials
# Grab the application's default credentials from the environment.
oCredentials = GoogleCredentials.get_application_default()
# Construct the service object for i... | 1 | 2016-06-15T19:09:31Z | 37,844,156 | <p>I'm going to poke at this, not sure how helpful it will be. Apologies. Is your app not authenticating with GAE in this instance or just big query? </p>
<p>I struggled against a lot of the auth issues dealing with BT and App Engine. I'm trying to dig up my notes from when I dealt with it. The Google BigQuery analyti... | 0 | 2016-06-15T19:27:39Z | [
"python",
"unit-testing",
"google-app-engine",
"google-bigquery"
] |
Getting style of <tr> tag using BeautifulSoup | 37,843,903 | <p>I'm scraping a page and from a table on that page I'm getting all <code><tr></code> elements like so:</p>
<pre><code>r = requests.get("http://lol.esportswikis.com/wiki/G2_Esports/Match_History")
s = BeautifulSoup(r.content, "lxml")
tr = s.find_all("table", class_="wikitable sortable")[0].find_all("tr")[3:]
p... | 1 | 2016-06-15T19:11:38Z | 37,843,954 | <p>Just access the attribute using <code>tag["attribute"]</code>:</p>
<pre><code>In [28]: soup = BeautifulSoup('<tr style="pretty"></tr>', 'html.parser')
In [29]: print soup.find("tr")["style"]
pretty
</code></pre>
<p>If you only want the tr tags with style attributes an to get them all:</p>
<pre><code>... | 1 | 2016-06-15T19:14:36Z | [
"python",
"beautifulsoup",
"python-requests"
] |
Using Regular Expressions to extract numerical quantities from a file and find the sum | 37,843,984 | <p>I am a beginner and learning python. The problem is that I have to extract numbers from a file (in which numbers can be anywhere. can be multiple times in the same line. some lines may not have numbers and some lines may be new lines) and find their sum. I did know how to solve it, and this was my code</p>
<pre><co... | 0 | 2016-06-15T19:16:11Z | 37,844,544 | <p>Your regular expression has <code>([0-9]*)</code> which will find all words with <em>zero</em> or more numbers. You probably want <code>([0-9]+)</code> instead.</p>
| 0 | 2016-06-15T19:52:07Z | [
"python",
"regex",
"python-3.x"
] |
Using Regular Expressions to extract numerical quantities from a file and find the sum | 37,843,984 | <p>I am a beginner and learning python. The problem is that I have to extract numbers from a file (in which numbers can be anywhere. can be multiple times in the same line. some lines may not have numbers and some lines may be new lines) and find their sum. I did know how to solve it, and this was my code</p>
<pre><co... | 0 | 2016-06-15T19:16:11Z | 37,844,627 | <p>Hello you made a mistake in the regular expression by adding the "*", like this should work:</p>
<pre><code>y=re.findall('([0-9])',line)
</code></pre>
| 0 | 2016-06-15T19:57:28Z | [
"python",
"regex",
"python-3.x"
] |
Using Regular Expressions to extract numerical quantities from a file and find the sum | 37,843,984 | <p>I am a beginner and learning python. The problem is that I have to extract numbers from a file (in which numbers can be anywhere. can be multiple times in the same line. some lines may not have numbers and some lines may be new lines) and find their sum. I did know how to solve it, and this was my code</p>
<pre><co... | 0 | 2016-06-15T19:16:11Z | 37,845,093 | <p>Expanding on wind85's answer, you might want to fine tune your regular expression depending on what kind of numbers you expect to find in your file. For example, if your numbers might have a decimal point in them, then you might want something like <code>[0-9]+(?:\.[0-9]+)?</code> (one or more digits optionally fol... | 0 | 2016-06-15T20:23:21Z | [
"python",
"regex",
"python-3.x"
] |
How can I change a string's letters while trying to disguise a password? | 37,844,012 | <p>I'm trying to create a simple username and password script in Python 3.5.1, and I cannot figure out how to make the user input a password, and then for it to be covered up with an asterisk so it cannot be read.</p>
<p>This is my code so far:</p>
<pre><code>import time
print ("Hello!")
time.sleep(1)
print ("Welcome... | -1 | 2016-06-15T19:17:32Z | 37,844,365 | <p>Use the <a href="https://docs.python.org/3/library/getpass.html" rel="nofollow"><code>getpass</code></a> module for this. <code>getpass.getpass()</code> allows the user to enter input without echoing (printing to the terminal).</p>
<p>You may also want to look at <a href="https://docs.python.org/3/library/getpass.h... | 1 | 2016-06-15T19:40:30Z | [
"python",
"passwords"
] |
Plot dataframe grouped by one column, and hue by another column | 37,844,014 | <p>I have the following <a href="https://gist.github.com/silviutofan92/5a6ec2b82931831e164f81613ba76903" rel="nofollow">DataFrame</a> and would like to create separate line graphs (1 for each "Cluster"), where x-axis is "Week", y-axis is "Slot Request" and hue is "Group".</p>
<p>To get the data that I want to plot, I ... | 0 | 2016-06-15T19:17:41Z | 37,844,328 | <p>Try something like this:</p>
<pre><code>summed = full_df.groupby(["Group", "Cluster", "Week"])["Slot Request"].sum().reset_index() #reset_index turns this back into a normal dataframe
g = sns.FacetGrid(summed, col="Group") #create a new grid for each "Group"
g.map(sns.pointplot, 'Week', 'Slot Request') #map a point... | 2 | 2016-06-15T19:38:36Z | [
"python",
"pandas",
"dataframe",
"seaborn"
] |
Plot dataframe grouped by one column, and hue by another column | 37,844,014 | <p>I have the following <a href="https://gist.github.com/silviutofan92/5a6ec2b82931831e164f81613ba76903" rel="nofollow">DataFrame</a> and would like to create separate line graphs (1 for each "Cluster"), where x-axis is "Week", y-axis is "Slot Request" and hue is "Group".</p>
<p>To get the data that I want to plot, I ... | 0 | 2016-06-15T19:17:41Z | 37,847,216 | <p>Thank you very much @Sam for the idea. I would've posted in comments, but code formatting was not clear. </p>
<p>Using the following:</p>
<pre><code>summed = full_df.groupby(["Group", "Cluster", "Week"])["Slot Request"].sum().reset_index()
g = sns.FacetGrid(summed, row ="Cluster", hue = "Cluster", sharex = False)
... | 0 | 2016-06-15T23:00:50Z | [
"python",
"pandas",
"dataframe",
"seaborn"
] |
Iterating over a variable sized lists in Python dict | 37,844,054 | <p>I have a dict that looks like the following:</p>
<pre><code>myDict = {'a':['1','2','3'],'b':['1','2'],'c':['1','2','3','4']}
</code></pre>
<p>I'm trying to iterate through all its values like the following:</p>
<pre><code>for i in myDict.iterkeys():
for j in range(0,len(myDict[i])):
print myDict[i][j]... | 0 | 2016-06-15T19:21:00Z | 37,844,094 | <p>You can just say</p>
<pre><code>for sub_list in myDict.values():
for item in sub_list:
print(item)
</code></pre>
<p>But that doesn't really answer your loop in a loop question. There isn't going to be a solution for nested iteration given a dictionary that contains lists.</p>
| 2 | 2016-06-15T19:23:30Z | [
"python",
"dictionary"
] |
Iterating over a variable sized lists in Python dict | 37,844,054 | <p>I have a dict that looks like the following:</p>
<pre><code>myDict = {'a':['1','2','3'],'b':['1','2'],'c':['1','2','3','4']}
</code></pre>
<p>I'm trying to iterate through all its values like the following:</p>
<pre><code>for i in myDict.iterkeys():
for j in range(0,len(myDict[i])):
print myDict[i][j]... | 0 | 2016-06-15T19:21:00Z | 37,844,129 | <p>You can just get the values from the dictionary, and the values from the sublist, no need to key or index:</p>
<pre><code>for sublist in myDict.values():
for value in sublist:
print(value)
</code></pre>
| 1 | 2016-06-15T19:25:30Z | [
"python",
"dictionary"
] |
Iterating over a variable sized lists in Python dict | 37,844,054 | <p>I have a dict that looks like the following:</p>
<pre><code>myDict = {'a':['1','2','3'],'b':['1','2'],'c':['1','2','3','4']}
</code></pre>
<p>I'm trying to iterate through all its values like the following:</p>
<pre><code>for i in myDict.iterkeys():
for j in range(0,len(myDict[i])):
print myDict[i][j]... | 0 | 2016-06-15T19:21:00Z | 37,844,168 | <p>Here is a solution with one for loop. </p>
<pre><code>for i in reduce(lambda x, y: x+y, myDict.values()):
print i
</code></pre>
<p><code>myDict.values</code> it's a list of list. </p>
<pre><code>In [33]: myDict.values()
Out[33]: [['1', '2', '3'], ['1', '2', '3', '4'], ['1', '2']]
</code></pre>
<p>With using ... | 2 | 2016-06-15T19:28:06Z | [
"python",
"dictionary"
] |
suds.TypeNotFound when acessing webservice | 37,844,079 | <p>Using suds to consume a ASMX webservice (created with ASP.NET), it throws the <code>suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'</code> error:</p>
<pre><code>def consume_webservice():
url = 'http://telemetriaws1.ana.gov.br/ServiceANA.asmx?wsdl'
imp = Import('http://www.w... | 0 | 2016-06-15T19:22:38Z | 37,911,426 | <p>Could you give <a href="https://github.com/mvantellingen/python-zeep" rel="nofollow">https://github.com/mvantellingen/python-zeep</a> a try (using the master branch). It's a new soap library i wrote and it should handle this.</p>
| 0 | 2016-06-19T20:17:03Z | [
"python",
"web-services",
"suds"
] |
Dropping the columns that contain NaN | 37,844,081 | <p>I have a DataFrame similar to this one</p>
<pre><code> A M DM BYN Z
2015-01-02 3. 7. NaN 2. 8.
2015-01-03 1. NaN 2. 8. 3.
...
2016-06-14 3. 1. 7. NaN 2.
2016-06-15 1. NaN 2. 8. 3.
</code></pre>
<p>My actual DataFrame contains more than 500 columns ... | 1 | 2016-06-15T19:22:45Z | 37,844,225 | <p>pandas has a method just for this <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dropna.html" rel="nofollow"><code>dropna</code></a>:</p>
<pre><code>In [21]: df.dropna(axis=1, how='any')
Out[21]:
A Z
2015-01-02 3.0 8.0
2015-01-03 1.0 3.0
2016-06-14 3.0 2.0
201... | 4 | 2016-06-15T19:31:46Z | [
"python",
"numpy",
"pandas"
] |
Dropping the columns that contain NaN | 37,844,081 | <p>I have a DataFrame similar to this one</p>
<pre><code> A M DM BYN Z
2015-01-02 3. 7. NaN 2. 8.
2015-01-03 1. NaN 2. 8. 3.
...
2016-06-14 3. 1. 7. NaN 2.
2016-06-15 1. NaN 2. 8. 3.
</code></pre>
<p>My actual DataFrame contains more than 500 columns ... | 1 | 2016-06-15T19:22:45Z | 37,844,264 | <p>To only keep columns where the last row has no missing values, ie dropping those that do, you can create a <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean index</code></a> on the columns using a negated <code>.isnull()</code> (or <code>.notnull()</cod... | 2 | 2016-06-15T19:34:40Z | [
"python",
"numpy",
"pandas"
] |
ZMQ in Python: New socket object for each incoming connection | 37,844,090 | <p>Sockets in ZMQ are simply bound to an interface and are then able to receive messages right away, like this:</p>
<pre><code>socket.bind("tcp://*:5555")
message = socket.recv()
</code></pre>
<p>Since multiple connections can send data to that socket simultaneously, <strong>how to distinguish the different senders?<... | 0 | 2016-06-15T19:23:21Z | 37,846,749 | <p>How to distinguish the different clients depends on what socket type your using as your 'server', the explanations below will hopefully answer the 2nd question too.</p>
<p><code>REQ</code> - Will reply to the client that sent the request, a <code>recv</code> call on a <code>REQ</code> socket must be followed by a <... | 0 | 2016-06-15T22:18:07Z | [
"python",
"sockets",
"zeromq"
] |
How to simulate GCS for offline testing | 37,844,119 | <p>I have a Python Google App Engine app which reads files from Google Cloud Storage, and I can test it offline with the local development server (dev_appserver.py), which is great.</p>
<p>I also have a .NET tool which dumps files into the cloud storage bucket for the App Engine app to retrieve, using <code>Google.Api... | 0 | 2016-06-15T19:25:03Z | 38,381,185 | <p>GAE GCS emulation uses the <a href="https://github.com/GoogleCloudPlatform/appengine-gcs-client/blob/master/python/src/cloudstorage/common.py" rel="nofollow">github project called appengine-gcs-client</a>. It includes a check in a function called local_run() (inside common.py), which lets the api know if it is runn... | 0 | 2016-07-14T18:03:09Z | [
"c#",
"python",
"google-app-engine",
"google-cloud-storage"
] |
Choose the number of clusters and vertices in python igraph | 37,844,149 | <p>I have a <strong>complete weighted graph</strong> as you can see in the image below:</p>
<p><a href="http://i.stack.imgur.com/LnFOF.png" rel="nofollow"><img src="http://i.stack.imgur.com/LnFOF.png" alt="enter image description here"></a></p>
<p><strong>The Goal:</strong>
My goal is to be able to choose the number ... | 2 | 2016-06-15T19:27:07Z | 37,884,067 | <p>Both methods are just returning a single cluster. This tells me that there's no clear separation between your vertices: they're just a big tangle, so there's no reasonable way to pull them apart.</p>
<p>If I edit the edge weights to have clear separations, like in <code>10_g2.ncol</code> below, then the clustering ... | 0 | 2016-06-17T14:25:12Z | [
"python",
"graph",
"cluster-analysis",
"graph-theory",
"igraph"
] |
What is the right way to create a SSECustomerKey for boto3 file encryption in python? | 37,844,349 | <p>I am using boto3 with my django application to upload media to S3. But I am having trouble encrypting the files on server using "Server Side Encryption using Customer Provided Encryption Keys"</p>
<p>I'm using boto3's object.put() api to upload files and specify the encryption keys. But I am getting the following e... | 0 | 2016-06-15T19:39:39Z | 37,982,559 | <p>The right way to do is to use <code>os.urandom</code></p>
<pre><code>import os
secret_key = os.urandom(32) # The key needs to be 32 character long.
</code></pre>
<p>and one doesn't need to provide <code>SSECustomerKeyMD5</code> as boto3 calculates it for you.</p>
<p>and also SSE-C doesn't work right in <code>key.... | 0 | 2016-06-23T04:49:34Z | [
"python",
"encryption",
"amazon-s3",
"boto",
"boto3"
] |
Complex parsing of a string in Python | 37,844,430 | <p>I want to parse a string with a format like this:</p>
<pre><code>[{text1}]{quantity}[{text2}]
</code></pre>
<p>This rule means that at the beginning there is some text that can optionally be there or not, followed by a {quantity} whose syntax I describe just below, followed by more optional text.</p>
<p>The {quan... | 2 | 2016-06-15T19:45:01Z | 37,844,733 | <p>Pyparsing let's you build up a parser by stitching together smaller parsers using '+' and '|' operators (among others). You can also attach names to the individual elements in the parser, to make it easier to get at the values afterward.</p>
<pre><code>from pyparsing import (pyparsing_common, CaselessKeyword, Optio... | 2 | 2016-06-15T20:04:35Z | [
"python",
"string",
"parsing"
] |
Complex parsing of a string in Python | 37,844,430 | <p>I want to parse a string with a format like this:</p>
<pre><code>[{text1}]{quantity}[{text2}]
</code></pre>
<p>This rule means that at the beginning there is some text that can optionally be there or not, followed by a {quantity} whose syntax I describe just below, followed by more optional text.</p>
<p>The {quan... | 2 | 2016-06-15T19:45:01Z | 37,844,913 | <p>I don't know if you want to use <code>re</code>, but here's a regular expression which I think works. You can change the <code>str</code> value to test it. The match returns a tuple which has the three values [{text1}]{quantity}[{text2}]. The first and last items in the tuple will be empty if text1 and text2 are mis... | 1 | 2016-06-15T20:13:56Z | [
"python",
"string",
"parsing"
] |
Complex parsing of a string in Python | 37,844,430 | <p>I want to parse a string with a format like this:</p>
<pre><code>[{text1}]{quantity}[{text2}]
</code></pre>
<p>This rule means that at the beginning there is some text that can optionally be there or not, followed by a {quantity} whose syntax I describe just below, followed by more optional text.</p>
<p>The {quan... | 2 | 2016-06-15T19:45:01Z | 37,845,471 | <p>Here's a rules processor using regex to match your two cases. I create a custom match result class to hold relevant extracted values from the input string. The rules processor tries the following rules in succession:</p>
<ul>
<li>rule1 - tries to match {n} followed by one of pc, pc., pcs, or pcs.</li>
<li>rule2 -... | 0 | 2016-06-15T20:47:15Z | [
"python",
"string",
"parsing"
] |
Change dataframe row names | 37,844,522 | <p>I have a df which looks like:</p>
<pre><code>BBG.LON.123.S_CAR_ADJ_DPS 343.94325
BBG.LON.436.S_CAR_ADJ_DPS 236.51530
</code></pre>
<p>I am trying to rename the row names (removing the '_CAR_ADJ_DPS' element of each row name and rename the column 'id' so my resulting df looks like:</p>
<pre><code> ... | 3 | 2016-06-15T19:50:58Z | 37,844,603 | <p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.split.html" rel="nofollow"><code>str.split</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#changes-to-rename" rel="nofollow"><code>rename_axis</code></a> (new in <code>pandas</code>... | 2 | 2016-06-15T19:55:20Z | [
"python",
"pandas",
"dataframe",
"split",
"rename"
] |
Change dataframe row names | 37,844,522 | <p>I have a df which looks like:</p>
<pre><code>BBG.LON.123.S_CAR_ADJ_DPS 343.94325
BBG.LON.436.S_CAR_ADJ_DPS 236.51530
</code></pre>
<p>I am trying to rename the row names (removing the '_CAR_ADJ_DPS' element of each row name and rename the column 'id' so my resulting df looks like:</p>
<pre><code> ... | 3 | 2016-06-15T19:50:58Z | 37,844,689 | <p>You may also be interested in <a href="http://pandas.pydata.org/pandas-docs/stable/text.html#extracting-substrings" rel="nofollow">str.extract</a> to pull out the entries as columns:</p>
<pre><code>In [11]: df[0].str.extract('(?P<A>.*)\.(?P<B>.*)\.(?P<C>\d+)\.(?P<D>.)_.*', expand=True)
Out[1... | 1 | 2016-06-15T20:00:58Z | [
"python",
"pandas",
"dataframe",
"split",
"rename"
] |
Avoid 'Memory Error" when dealing with large arrays | 37,844,596 | <p>I'm facing sometimes <code>Memory Error</code>, sometimes it goes through fine and sometimes it pops up.. Specifically when trying to subtract large array by one. I tried many ways to do this subtraction, is there any way to avoid this? and is my other code parts will also sometime arise this error?</p>
<p>Here is ... | 0 | 2016-06-15T19:54:55Z | 37,845,747 | <p>Not sure, but in the incriminated line you use numpy.asmatrix(dtm_lsa), which is a function call that allocates some memory.</p>
<p>You're doing it twice so it creates twice too much memory (that's before it's garbage collected, but it's too late in some cases)</p>
<p>(not patronizing you at all: That's the common... | 0 | 2016-06-15T21:04:35Z | [
"python",
"arrays",
"numpy",
"memory",
"out-of-memory"
] |
Mechanize: TypeError: 'NoneType' object does not support item assignment | 37,844,626 | <p>Trying to fill in a form in order to get the average prices of goods in a city. </p>
<pre><code>basket = br.open('http://www.numbeo.com/cost-of-living/')
read_it = basket.read()
# Select form
for form in br.forms():
print '%r %r %s' % (form.name, form.attrs.get('id'), form.action)
for control in form.cont... | 0 | 2016-06-15T19:57:20Z | 37,869,585 | <p>You're doing it wrongly. You need to select a <code>form</code>, only then can you assign values to the form controls.</p>
<p>Do you have a <code>menu_dispatch_form</code>? Then use <code>br.select_form("menu_dispatch_form")</code> to select the form. To add data to the form, you should assign values to the form co... | 1 | 2016-06-16T21:25:19Z | [
"python",
"mechanize"
] |
Getting Wrong answer on codechef | 37,844,631 | <p>Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US. Calculate Pooja's account ba... | -2 | 2016-06-15T19:57:37Z | 37,845,640 | <p>You are not handling this case:</p>
<p><em>Input:</em> 10 10.01</p>
<p><em>Output:</em> -0.4900000000000002</p>
<p><code>y>x</code> is not sufficient for testing for account underflow.</p>
<p>Also, if you are submitting your code as Python2, <code>input()</code> behaves differently in Python2 than Python3.</p... | 0 | 2016-06-15T20:57:45Z | [
"python"
] |
create a loop inside a loop in python | 37,844,637 | <p>i am trying to use this program to get a list (phi0ex) of 211 arrays each array contains 251*251 elements
all what i get is a list of arrays of 251 elements, please help</p>
<pre><code>data=loadtxt('data.csv',delimiter=',')
data1=data.transpose()
ngrains=loadtxt('nombre_grain.csv',delimiter=',')
phi0ex1=211*[zeros... | -6 | 2016-06-15T19:58:07Z | 37,857,742 | <p>i found the solution thank you guys for showing intrest, accully the function where() do the iteration it self (that i did'nt know) there is no need to put it in an other loop, only the loop over "ngrains will do the trick.</p>
<pre><code>data=loadtxt('data.csv',delimiter=',')
data1=data.transpose()
ngrains=loadtxt... | 0 | 2016-06-16T11:23:16Z | [
"python",
"arrays",
"csv"
] |
Flask SQLAlchemy sessions out of sync | 37,844,704 | <p>I have a Flask REST API, running with a gunicorn/nginx stack. There is global SQLAlchemy session set up once for each thread that the API runs on. I set up an endpoint /test/ for running the unit tests for the API. One test makes a POST request to add something to the database, then has a finally: clause to clean... | 0 | 2016-06-15T20:02:18Z | 37,845,889 | <p>Please use flask-sqlalchemy if you're using flask, it takes care of the lifecycle of the session for you.</p>
<p>If you insist on doing it yourself, the correct pattern is to create a session for each request instead of having a global session. You should be doing</p>
<pre><code>Session = scoped_session(session_fa... | 1 | 2016-06-15T21:14:59Z | [
"python",
"multithreading",
"session",
"sqlalchemy",
"gunicorn"
] |
Flask SQLAlchemy sessions out of sync | 37,844,704 | <p>I have a Flask REST API, running with a gunicorn/nginx stack. There is global SQLAlchemy session set up once for each thread that the API runs on. I set up an endpoint /test/ for running the unit tests for the API. One test makes a POST request to add something to the database, then has a finally: clause to clean... | 0 | 2016-06-15T20:02:18Z | 37,886,182 | <p>Figured it out. What I did was to add a setup and teardown to the request in my app's __init__.py:</p>
<pre><code>@app.before_request
def startup_session():
db.session = db.connectSQLAlchemy()
@app.teardown_request
def shutdown_session(exception=None):
db.session.close()
</code></pre>
<p>still using the... | 0 | 2016-06-17T16:21:40Z | [
"python",
"multithreading",
"session",
"sqlalchemy",
"gunicorn"
] |
How can I fix this batch file to write in a text file in spaces? | 37,844,762 | <p>I need help with fixing my code. I don't know whats wrong with it but it gives me an invalid syntax error on the else: command, Please be as simple as possible, and not be too complicated, I'm new to this. </p>
<pre><code>def myName(my_name): #What does this do?
myName = input("What is my name? ")
if... | -1 | 2016-06-15T20:05:40Z | 37,844,928 | <ul>
<li>Your code is a python script, not a batch file.</li>
<li><code>#{my_name}</code> is meaningless in Python (it is from Ruby)</li>
<li><code>def variable()</code> def-ines a function called <code>variable</code>.</li>
</ul>
<p>Replace <code>#{my_name}</code> with <code>my_name</code> in your <code>if</code> sta... | 1 | 2016-06-15T20:14:37Z | [
"python",
"syntax"
] |
How can I fix this batch file to write in a text file in spaces? | 37,844,762 | <p>I need help with fixing my code. I don't know whats wrong with it but it gives me an invalid syntax error on the else: command, Please be as simple as possible, and not be too complicated, I'm new to this. </p>
<pre><code>def myName(my_name): #What does this do?
myName = input("What is my name? ")
if... | -1 | 2016-06-15T20:05:40Z | 37,845,099 | <p>This works for me:</p>
<pre><code> def myName(my_name): #What does this do?
myName = input("What is my name? ")
if myName == my_name:
print "Correct!"
else: #Gives invalid syntax error!
print "In-Correct!"
myName('Jacob')
</code></pre>
<p>I'm never done P... | 0 | 2016-06-15T20:23:53Z | [
"python",
"syntax"
] |
How can I fix this batch file to write in a text file in spaces? | 37,844,762 | <p>I need help with fixing my code. I don't know whats wrong with it but it gives me an invalid syntax error on the else: command, Please be as simple as possible, and not be too complicated, I'm new to this. </p>
<pre><code>def myName(my_name): #What does this do?
myName = input("What is my name? ")
if... | -1 | 2016-06-15T20:05:40Z | 37,845,343 | <p>You are on the right track, but like the alert says, the syntax is invalid.</p>
<p>First, in python the end of an if-conditional is denoted by a colon(:)</p>
<p>Second, hashtags(pound symbol, etc.) are always interpreted as the start of a single line comment.</p>
<p>Finally, using the <code>def</code> keyword den... | 0 | 2016-06-15T20:39:09Z | [
"python",
"syntax"
] |
Only one thread is starting python | 37,844,857 | <pre><code>def pingGetterLoop():
while(1):
pingGetter()
def mainLoop():
root.mainloop()
print("thread two")
threadTwo = Thread(target = mainLoop())
print("thread one")
threadOne = Thread(target = pingGetterLoop())
threadOne.start()
threadTwo.start()
</code></pre>
<p>for some reason threadTwo never ... | 0 | 2016-06-15T20:10:51Z | 37,844,919 | <p>The problem is how you pass the functions to the threads. You call them instead of passing the callable. You can fix that by removing the brackets <code>()</code>:</p>
<pre><code>print("thread two")
threadTwo = Thread(target=mainLoop)
print("thread one")
threadOne = Thread(target=pingGetterLoop)
</code></pre>
<p>A... | 1 | 2016-06-15T20:14:17Z | [
"python",
"multithreading",
"python-3.x"
] |
Getting name from the email address in python | 37,844,870 | <p>I have a text file in which there are email addresses in the following format:</p>
<pre><code>some.name@somehost.com
</code></pre>
<p>or</p>
<pre><code>some_name@somehost
</code></pre>
<p>How can I split the string to get some & name? I tried the following code, but it appears I can only use one character (j... | -3 | 2016-06-15T20:11:35Z | 37,845,000 | <p>Use the following:</p>
<pre><code>email = "some.name@somehost.com"
name, _, _ = email.partition("@") # returns before @, @, and after @
splitname = name.split(".") # splits on .
print(splitname)
</code></pre>
<p><code>["some", "name"]</code></p>
| 4 | 2016-06-15T20:18:42Z | [
"python"
] |
how to use returned seperated lists of function in python? | 37,844,874 | <p>hi i have a function which returns a list and a dictionary.
if functions renturns one thing i know how to use that.
but how i can use returned list and dict of function?</p>
<p>my code is :</p>
<pre><code>def links(url):
__url = str(url) # find_dl_url()
__page = requests.get(__url)
__page_content = bs... | 0 | 2016-06-15T20:11:59Z | 37,844,888 | <p>You can <a href="https://stackoverflow.com/questions/354883/how-do-you-return-multiple-values-in-python">unpack</a> the returned variables</p>
<pre><code>lst, dct = links(url)
</code></pre>
| 3 | 2016-06-15T20:12:55Z | [
"python",
"python-3.x"
] |
Python: How to create a 16 character long digest using hashlib.md5 algorithm? | 37,844,962 | <p><a href="http://php.net/manual/en/function.md5.php" rel="nofollow">Php's md5 function</a> takes an optional second argument which, if true, returns a smaller hash of length 16 instead of the normal 32 character long hash.</p>
<p>How can we do the same using python's <code>hashlib.md5</code>.</p>
| -1 | 2016-06-15T20:16:19Z | 37,845,128 | <p><em>"an optional second argument which, if true, returns a smaller hash of length 16 instead of the normal 32 character long hash."</em></p>
<p>This is not true: The second parameter <a href="http://php.net/manual/en/function.md5.php" rel="nofollow"><code>$raw_output</code></a> specifies whether the output should b... | 5 | 2016-06-15T20:25:07Z | [
"python",
"md5",
"hashlib"
] |
sys.argv[0] is not showing the name of file in python | 37,844,969 | <p>If I understand correctly, When typing sys.argv[0] it shows the name of the .py file one is working on. But when I do this, it shows me a different name: </p>
<pre><code>sys.argv[0]
'C:\\Anaconda\\lib\\site-packages\\spyderlib\\widgets\\externalshell\\start_ipython_kernel.py'
</code></pre>
<p>The real name of th... | 2 | 2016-06-15T20:16:42Z | 37,845,591 | <p><code>argv</code> contain a list of command line arguments passed to python script. <code>argv[0]</code> is the script name. <a href="https://docs.python.org/2/library/sys.html#sys.argv" rel="nofollow">doc</a></p>
<p>IDE like Spyder / PyCharm doesn't run the script direct. It's run the wrapper that run Your script.... | 1 | 2016-06-15T20:54:21Z | [
"python",
"anaconda",
"spyder"
] |
Load data on startup | 37,845,130 | <p>I have a file with a bunch of data common between several projects. The data needs to be loaded into the Django database. The file doesn't change that much, so loading it once on server start is sufficient. Since the file is shared between multiple projects, I do not have full control over the format, so I cannot co... | 1 | 2016-06-15T20:25:15Z | 37,864,661 | <p>It seems that what I am looking for doesn't exist. Django trusts the user to deal with migrations and such and doesn't check the database on load. So there is no place in the system where you can load some data on system start and be sure that you can actually load it. What I ended up doing is loading the data in re... | 0 | 2016-06-16T16:27:23Z | [
"python",
"django"
] |
Static files on Openshift with Django | 37,845,189 | <p>I can't found my static files like css, js and picture. I get 404 error page.</p>
<p>In my <strong>settings django</strong> I have</p>
<pre><code>STATIC_ROOT = '/var/lib/openshift/*id*/app-root/repo/*project*/*app*'
STATIC_URL = '/static/'
</code></pre>
<p>and my filesystem are</p>
<pre><code> - project
- ap... | 1 | 2016-06-15T20:29:07Z | 37,845,388 | <p>in your settings.py make sure you have: </p>
<pre><code>import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static_files'),
) # create static_files dir and place there your static
# fi... | 0 | 2016-06-15T20:41:59Z | [
"python",
"django",
"http-status-code-404",
"openshift",
"wsgi"
] |
Static files on Openshift with Django | 37,845,189 | <p>I can't found my static files like css, js and picture. I get 404 error page.</p>
<p>In my <strong>settings django</strong> I have</p>
<pre><code>STATIC_ROOT = '/var/lib/openshift/*id*/app-root/repo/*project*/*app*'
STATIC_URL = '/static/'
</code></pre>
<p>and my filesystem are</p>
<pre><code> - project
- ap... | 1 | 2016-06-15T20:29:07Z | 37,867,675 | <p>You also need to make sure your manage.py is modified to be:</p>
<pre><code>import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
</code... | 0 | 2016-06-16T19:17:48Z | [
"python",
"django",
"http-status-code-404",
"openshift",
"wsgi"
] |
Static files on Openshift with Django | 37,845,189 | <p>I can't found my static files like css, js and picture. I get 404 error page.</p>
<p>In my <strong>settings django</strong> I have</p>
<pre><code>STATIC_ROOT = '/var/lib/openshift/*id*/app-root/repo/*project*/*app*'
STATIC_URL = '/static/'
</code></pre>
<p>and my filesystem are</p>
<pre><code> - project
- ap... | 1 | 2016-06-15T20:29:07Z | 38,139,439 | <p>In the <strong>wsgi.py</strong> I have to have
<code>
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR']))
os.environ['DJANGO_SETTINGS_MODULE' ] = 'project.settings.app'
</code>
and in my <strong>settings.py</strong>
<code>
STATIC_ROOT = os.path.join(os.getenv('OPENSHIFT_REPO_DIR'), 'wsgi/static', )
STATI... | 0 | 2016-07-01T07:24:07Z | [
"python",
"django",
"http-status-code-404",
"openshift",
"wsgi"
] |
Python indentation in Spacemacs with hard tabs is off | 37,845,243 | <p>Let me preface by saying that I am a relatively new emacs/spacemacs convert from vim, so my my knowledge is still pretty basic.</p>
<p>I have spacemacs set up with the python layer, with the additional package of dtrt-indent listed in dotspacemacs-additional-packages. And setting</p>
<pre><code>(dtrt-indent-mode t... | 1 | 2016-06-15T20:32:47Z | 37,870,728 | <p>Try <code>M-x whitespace-mode</code> and repeat this experiment. What do you see? Did you indent with spaces or with tabs?</p>
<p>I'm guessing you'll see something like this:</p>
<pre><code>def·func():
········
» print·'line'
</code></pre>
<p>This would mean you have <code>python-indent-offset</code>... | 2 | 2016-06-16T23:01:06Z | [
"python",
"emacs",
"spacemacs"
] |
Plotting a point cloud and moving the camera | 37,845,256 | <p>I have a list of points given by their x, y, z coordinates. I would like to plot these points on a computer. I have managed to do this with gnuplot and with the python library matplotlib separately. However for these two solutions, it seems hard to change the 'viewing point', or the point from which the projection o... | 1 | 2016-06-15T20:33:25Z | 37,850,158 | <p>When you change the viewing angles it's like moving your head on an equidistant shell seeing continuously the center of the image/screen/object.</p>
<p>What you said is moving your head in the x-y plane looking fixedly ahead so the content (the screen/object) shifts out from your sight. It is easy in <code>Gnuplot<... | 1 | 2016-06-16T04:55:36Z | [
"python",
"matplotlib",
"gnuplot",
"visualization"
] |
Plotting a point cloud and moving the camera | 37,845,256 | <p>I have a list of points given by their x, y, z coordinates. I would like to plot these points on a computer. I have managed to do this with gnuplot and with the python library matplotlib separately. However for these two solutions, it seems hard to change the 'viewing point', or the point from which the projection o... | 1 | 2016-06-15T20:33:25Z | 37,890,119 | <p>No, gnuplot cannot <em>really</em> move the viewing point, for the good reason that the viewing point is at infinity: all you can do is set an angle and magnification (using <code>set view</code>) and an offset within the viewing window (with <code>set origin</code>). That means, you can move the viewing point on a... | 0 | 2016-06-17T20:43:33Z | [
"python",
"matplotlib",
"gnuplot",
"visualization"
] |
Pygame: paint a Class polygon from a different module | 37,845,269 | <p><strong>History:</strong>
<em>Achievement not understand what is wrong with my code, first time you use a class to create a figure.</em></p>
<p><em>I have a module where is the Polygon class in it have the following code:</em></p>
<pre><code>import pygame
class Polygon:
def __init__(self,):
self.list... | 1 | 2016-06-15T20:34:40Z | 37,845,916 | <p>You need to create an instance of the <code>Polygon</code> class, not just try to call methods on the class directly:</p>
<pre><code>poly = Polygon() # call the class to create an instance; put this in your setup code
poly.draw() # put this in your main loop
</code></pre>
| 0 | 2016-06-15T21:16:40Z | [
"python",
"pygame"
] |
Pygame: paint a Class polygon from a different module | 37,845,269 | <p><strong>History:</strong>
<em>Achievement not understand what is wrong with my code, first time you use a class to create a figure.</em></p>
<p><em>I have a module where is the Polygon class in it have the following code:</em></p>
<pre><code>import pygame
class Polygon:
def __init__(self,):
self.list... | 1 | 2016-06-15T20:34:40Z | 37,846,731 | <p>Classes only define a "template" for a certain type of object. To actually create an object (or "instance") of that type, the class must be called and passed any data needed to complete its definition as arguments. Not hardcoding the data into the class itself will allow you to create more than one instance of the c... | 1 | 2016-06-15T22:16:38Z | [
"python",
"pygame"
] |
Why is my call to a variable that exists in the local scope not working in Python? | 37,845,273 | <p>This code is part of a function. When I run the function line by line with the proper arguments, it runs fine, but when I call the function it doesn't seem to work. The following three lines of code and their output are from the function call:</p>
<pre><code>print(locals().keys())
dict_keys(['allpost', 'allpre', 'p... | 1 | 2016-06-15T20:34:53Z | 37,845,321 | <p>Try whitout [] in your print</p>
<pre><code>print(locals()[k] for k in ['allpre'])
</code></pre>
| 0 | 2016-06-15T20:37:40Z | [
"python"
] |
Why is my call to a variable that exists in the local scope not working in Python? | 37,845,273 | <p>This code is part of a function. When I run the function line by line with the proper arguments, it runs fine, but when I call the function it doesn't seem to work. The following three lines of code and their output are from the function call:</p>
<pre><code>print(locals().keys())
dict_keys(['allpost', 'allpre', 'p... | 1 | 2016-06-15T20:34:53Z | 37,845,572 | <p>You're on Python 3, where a list comprehension has its own scope with its own local variables. <code>allpre</code> is not one of the comprehension's local variables.</p>
| 0 | 2016-06-15T20:53:20Z | [
"python"
] |
Why is my call to a variable that exists in the local scope not working in Python? | 37,845,273 | <p>This code is part of a function. When I run the function line by line with the proper arguments, it runs fine, but when I call the function it doesn't seem to work. The following three lines of code and their output are from the function call:</p>
<pre><code>print(locals().keys())
dict_keys(['allpost', 'allpre', 'p... | 1 | 2016-06-15T20:34:53Z | 37,845,576 | <p>Calling <code>locals</code> from within a list comprehension won't work the way you expect it to (in Python 3). That's because the main body of the list comprehension gets run within its own local namespace, just like it was a function returning a list. You can see this in your traceback, where <code><listcopy>... | 1 | 2016-06-15T20:53:35Z | [
"python"
] |
Why is my call to a variable that exists in the local scope not working in Python? | 37,845,273 | <p>This code is part of a function. When I run the function line by line with the proper arguments, it runs fine, but when I call the function it doesn't seem to work. The following three lines of code and their output are from the function call:</p>
<pre><code>print(locals().keys())
dict_keys(['allpost', 'allpre', 'p... | 1 | 2016-06-15T20:34:53Z | 37,845,709 | <p>List comprehensions have their local scope since Python 3.0. This was to prevent <a href="http://stackoverflow.com/a/4199355/1238367">scope leak</a>.</p>
<p><a href="https://docs.python.org/3.0/whatsnew/3.0.html" rel="nofollow">https://docs.python.org/3.0/whatsnew/3.0.html</a></p>
<blockquote>
<p>[...] note that... | 2 | 2016-06-15T21:02:08Z | [
"python"
] |
number of rows in two files different--> make equal by deleting from end | 37,845,301 | <pre><code> with open(filename,"r") as f:
reader = csv.reader(f,delimiter = ",")
data = list(reader)
rownum = len(data)
with open(filename2,"r") as f:
reader2 = csv.reader2(f,delimiter = ",")
data2 = list(reader2)
rownum2 = len(data)
if rownum > rownum2:
delete(row... | 0 | 2016-06-15T20:36:32Z | 37,845,468 | <p>It's pretty simple.</p>
<pre><code>data = data[:max(rownum, rownum2)]
data2 = data2[:max(rownum, rownum2)]
</code></pre>
| 0 | 2016-06-15T20:47:01Z | [
"python",
"python-2.7",
"rows"
] |
number of rows in two files different--> make equal by deleting from end | 37,845,301 | <pre><code> with open(filename,"r") as f:
reader = csv.reader(f,delimiter = ",")
data = list(reader)
rownum = len(data)
with open(filename2,"r") as f:
reader2 = csv.reader2(f,delimiter = ",")
data2 = list(reader2)
rownum2 = len(data)
if rownum > rownum2:
delete(row... | 0 | 2016-06-15T20:36:32Z | 37,845,504 | <p>Do you need to save the new data? If so this will do the job and the files must not even be in csv format:</p>
<pre><code>with open(filename1, "rb") as f:
f1lines = f.readlines()
with open(filename2, "rb") as f:
f2lines = f.readlines()
length = min(len(f1lines), len(f2lines))
f1lines = f1lines[:length]
f2... | 0 | 2016-06-15T20:49:14Z | [
"python",
"python-2.7",
"rows"
] |
Pandas MultiIndex groupby retaining index levels | 37,845,306 | <p>After research I have found no similar questions on this or any other forum.</p>
<p>I'm grouping a MultiIndex dataframe by its inner level. The thing is, after grouping by I still want to know which were the "chosen values" on this inner index. </p>
<p>So I have something of the sort</p>
<pre><code>df = pd.DataFr... | 3 | 2016-06-15T20:37:06Z | 37,845,567 | <p>This will get it done:</p>
<pre><code>def get_slice(df):
l0, l1 = df.index.levels
b0, b1 = df.index.labels
n = len(l0)
myslice = range(n)
for i in myslice:
myslice[i] = (l0[i], l1[b1[b0 == i][-1]])
return df.loc[myslice]
</code></pre>
<p>Timed</p>
<pre><code>%%timeit
get_slice(d... | 1 | 2016-06-15T20:53:09Z | [
"python",
"performance",
"pandas"
] |
Pandas MultiIndex groupby retaining index levels | 37,845,306 | <p>After research I have found no similar questions on this or any other forum.</p>
<p>I'm grouping a MultiIndex dataframe by its inner level. The thing is, after grouping by I still want to know which were the "chosen values" on this inner index. </p>
<p>So I have something of the sort</p>
<pre><code>df = pd.DataFr... | 3 | 2016-06-15T20:37:06Z | 37,846,647 | <p>Try This:: <code>reset_index()</code></p>
<pre><code>df = pd.DataFrame([['A', 1, 3],
['A', 2, 4],
['A', 3, 6],
['B', 1, 9],
['B', 2, 10],
['B', 4, 6]],
columns=pd.Index(['Name', 'Date', 'Value'], name='C... | 1 | 2016-06-15T22:10:26Z | [
"python",
"performance",
"pandas"
] |
Pandas MultiIndex groupby retaining index levels | 37,845,306 | <p>After research I have found no similar questions on this or any other forum.</p>
<p>I'm grouping a MultiIndex dataframe by its inner level. The thing is, after grouping by I still want to know which were the "chosen values" on this inner index. </p>
<p>So I have something of the sort</p>
<pre><code>df = pd.DataFr... | 3 | 2016-06-15T20:37:06Z | 37,846,655 | <p>By using <code>tail(1)</code> instead of <code>last()</code> on the groupby object, you get the desired behaviour:</p>
<pre><code>In [22]: df.groupby(level='Name').tail(1)
Out[22]:
ColumnName Value
Name Date
A 3 6
B 4 6
</code></pre>
<p>This is because <code>tail</code> acts like a 'filter... | 4 | 2016-06-15T22:10:51Z | [
"python",
"performance",
"pandas"
] |
Changing time from UTC to PDT | 37,845,327 | <p>This is what I have:</p>
<pre><code>pat = '%Y-%m-%d %H:%M:%S +0000'
my_time = time.strptime(task_time, pattern)
</code></pre>
<p>But, how can I change the timezone from:</p>
<pre><code> my_time:
2016-06-15 23:27:52 +0000
</code></pre>
<p>to a different timezone:</p>
<pre><code>PDT
</code></pre>
<p>or</p>
<pr... | 2 | 2016-06-15T20:37:55Z | 37,845,780 | <p>Using the python package <a href="http://crsmithdev.com/arrow/" rel="nofollow"><code>arrow</code></a> this simple script can be used:</p>
<pre><code>import arrow
fmt = "YYYY-MM-DD HH:mm:ss Z"
time = arrow.get("2016-06-15 23:27:52 +0000", fmt)
time = time.to("US/Pacific")
print(time.format(fmt))
</code></pre>
<p... | 2 | 2016-06-15T21:06:57Z | [
"python"
] |
yield(x) vs. (yield(x)): parentheses around yield in python | 37,845,338 | <p>Using Python 3.4, I get <code>SyntaxError: invalid syntax</code> here:</p>
<pre><code>>>> xlist = [1,2,3,4,5]
>>> [yield(x) for x in xlist]
SyntaxError: invalid syntax
</code></pre>
<p>But this generates a generator object:</p>
<pre><code>>>> [(yield(x)) for x in xlist]
<generator ob... | 2 | 2016-06-15T20:38:42Z | 37,845,447 | <p>The <a href="https://docs.python.org/3/reference/simple_stmts.html#the-yield-statement" rel="nofollow"><code>yield</code> keyword</a> can be used in two ways: As a statement, and as an expression.</p>
<p>The most common use is as a statement within generator functions, usually on its own line and all. It can be use... | 4 | 2016-06-15T20:46:15Z | [
"python",
"python-3.x"
] |
Django User-Login and authentication is not working | 37,845,352 | <p>I am creating a simple user-login page using Django and after get login redirecting to home page.But its always redirecting to unauthorized option given in app's views.py (i.e Invalid Details). Please check and help me.</p>
<p>Project name:login and App name: index</p>
<pre><code>views.py
from django.shortcuts i... | -3 | 2016-06-15T20:39:31Z | 37,847,190 | <p>Im going to share another approach to manage authentication in django assuming you already have a login html template (with username and password inputs inside a form with post action) , a user form and a home template , this would be the authentication views .py :</p>
<pre><code>from django.shortcuts import render... | 0 | 2016-06-15T22:57:57Z | [
"python",
"django",
"user-interface",
"authentication"
] |
Django User-Login and authentication is not working | 37,845,352 | <p>I am creating a simple user-login page using Django and after get login redirecting to home page.But its always redirecting to unauthorized option given in app's views.py (i.e Invalid Details). Please check and help me.</p>
<p>Project name:login and App name: index</p>
<pre><code>views.py
from django.shortcuts i... | -3 | 2016-06-15T20:39:31Z | 37,856,025 | <p>Change from </p>
<pre><code>username = request.GET.get('username', '')
password = request.GET.get('password', '')
</code></pre>
<p>to</p>
<pre><code>username = request.POST.get('username', '')
password = request.POST.get('password', '')
</code></pre>
| 0 | 2016-06-16T10:05:04Z | [
"python",
"django",
"user-interface",
"authentication"
] |
how to pass city and country to geocode | 37,845,361 | <p>I want to make sure I get the lat and lng for right city. For e.g there is Sydney in Australia and Sydney in Canada. This works fine</p>
<pre><code>for d in listofobjs:
location = geolocator.geocode(d['city'])
d2 = {
'username': d['username'],
'latitude': location.latitude,
'longitud... | 1 | 2016-06-15T20:40:10Z | 37,845,606 | <p>In the documentation it is stated that geolocator.geocode can return 0,1 or more values.
The method can return a list, hence the error message when you try to access it as a single structure element.
Or iterate through the list and append to listofobjs2 as much as needed.</p>
<p>You cannot be sure of getting exactl... | 0 | 2016-06-15T20:55:12Z | [
"python",
"geopy"
] |
Removing function from randomly shuffled list using random.shuffle (Python) | 37,845,380 | <p>So, recently I've had trouble getting random.shuffle to randomly pick and execute a function from a list. I've been able to get that process working but now I want the questions to be removed from the list once they're picked. I'll show you the code that should work in theory, but just randomly picks questions and r... | 2 | 2016-06-15T20:41:25Z | 37,845,449 | <p>You're recreating the <code>questionList</code> every time round the loop!</p>
<p>Try this:</p>
<pre><code>questionList = [Question1, Question2, Question3, Question4, Question5]
random.shuffle(questionList)
for q in questionList:
print(q())
</code></pre>
| 1 | 2016-06-15T20:46:19Z | [
"python",
"function"
] |
Removing function from randomly shuffled list using random.shuffle (Python) | 37,845,380 | <p>So, recently I've had trouble getting random.shuffle to randomly pick and execute a function from a list. I've been able to get that process working but now I want the questions to be removed from the list once they're picked. I'll show you the code that should work in theory, but just randomly picks questions and r... | 2 | 2016-06-15T20:41:25Z | 37,845,490 | <p>The problem is that you always set the <code>questionList</code> in the while loop, replacing it each time with a freshly filled version with all questions. If you move it out of the loop it should work fine.</p>
<p>Also, shuffling once is enough, so you can also move that out of the loop too.</p>
<p>In addition, ... | 1 | 2016-06-15T20:48:42Z | [
"python",
"function"
] |
Get a queryset from a queryset | 37,845,389 | <p>I have a queryset from <code>Picture.objects.filter(user_ID=user)</code>. The Picture model has "contest_ID" as a foreign key. </p>
<p>I'm looking to get a queryset of Contests which have Pictures, so from the queryset I already have, how do I pull a list of Contest objects?</p>
| 1 | 2016-06-15T20:42:02Z | 37,845,897 | <p>I assume that your models look something like this</p>
<pre>
class Contest(Model):
... something ...
class Picture(Model):
user = ForeignKey(User)
contest = ForeignKey(Contest)
... something ...
</pre>
<p>So, <code>Picture.objects.filter(user=user)</code> gives you pictures by a particular user (d... | 0 | 2016-06-15T21:15:28Z | [
"python",
"django",
"python-3.x"
] |
Get a queryset from a queryset | 37,845,389 | <p>I have a queryset from <code>Picture.objects.filter(user_ID=user)</code>. The Picture model has "contest_ID" as a foreign key. </p>
<p>I'm looking to get a queryset of Contests which have Pictures, so from the queryset I already have, how do I pull a list of Contest objects?</p>
| 1 | 2016-06-15T20:42:02Z | 37,846,465 | <p>You just need to follow the <a href="https://docs.djangoproject.com/en/1.9/topics/db/queries/#lookups-that-span-relationships" rel="nofollow">reverse relations</a>.</p>
<pre><code>user_contests = Contest.objects.filter(picture__user=user)
</code></pre>
| 2 | 2016-06-15T21:55:11Z | [
"python",
"django",
"python-3.x"
] |
Having trouble accessing certain information from my database with many to many relationships with django | 37,845,480 | <p>I'm working with Django REST Framework and a SQL database that has some many to many relationships, which is making hard to display information from the database in my app. The relevant tables are:</p>
<p>user: id, password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, dat... | 2 | 2016-06-15T20:47:55Z | 37,846,048 | <p>When you see <code>[<Project: ___ >]</code>, you're seeing a list of projects. You need to iterate over them or flatten them somehow.</p>
<p>Turn this into a <code><ul></code></p>
<pre><code><ul>
{% for project in profile.projects.all %}
<li>{{ project.name }}</li>
{% endfor %}
&... | 1 | 2016-06-15T21:25:38Z | [
"python",
"mysql",
"django"
] |
Python 3 how to add text to chosen line in a txt document using append | 37,845,489 | <p>In my document I would like to add scores to a chosen line using:</p>
<pre><code>file = open('scores.txt', 'a')
</code></pre>
<p>because I don't want to add all the lines to a list and change that one line.
I'm basically asking if you can add something to <code>.write()</code> or <code>.writelines()</code> to choo... | 0 | 2016-06-15T20:48:41Z | 37,846,061 | <p>The best way to store data to store some kind of user informations is Serialization. You have several modules including Pickle (which serialize the object into a binary file, and later can deserialize this object by reading the file, giving you the exact same object as it was before serialization), or Json.</p>
<p>... | 1 | 2016-06-15T21:26:24Z | [
"python",
"file",
"python-3.x"
] |
wxPython: Attribute Error *class* has no attribute *class_object* | 37,845,520 | <p>I am aware this might be considered a 'repeat question' however, I haven't found a similar question that answers my predicament, all the other folks with the same error had different looking code organization than mine.</p>
<p>I made a class for my dateFrame window and put a button in it, and OnClick() I want to ca... | 1 | 2016-06-15T20:50:15Z | 37,846,158 | <p>As pointed out by @user2357112, I had failed to use 'self' correctly to reference the objects within my Class. </p>
<p>For more information, see the link provided by @rrauenza in the comments section above.</p>
| 0 | 2016-06-15T21:33:21Z | [
"python",
"class",
"wxpython",
"attributeerror"
] |
list iteration using index of the list element | 37,845,582 | <p>I want to access list items in a specific way. for an example</p>
<pre><code>l1 =[1,2,3,4,5]
</code></pre>
<p>now i want to access 3rd element in the list i.e 4 but i want the result in specific way.</p>
<p>I want program to get the 2nd element i.e 3 and using its index i want to find 3rd element.</p>
<p>in shor... | -4 | 2016-06-15T20:54:05Z | 37,845,769 | <p>Here's an approach using <a href="https://docs.python.org/3/library/functions.html#enumerate" rel="nofollow"><code>enumerate</code></a>:</p>
<pre><code>>>> l1 = [1, 2, 3, 4, 5]
>>> for i, elem in enumerate(l1):
... print 'Current', elem
... try:
... print 'Next', l1[i+1]
... ex... | 0 | 2016-06-15T21:06:03Z | [
"python"
] |
list iteration using index of the list element | 37,845,582 | <p>I want to access list items in a specific way. for an example</p>
<pre><code>l1 =[1,2,3,4,5]
</code></pre>
<p>now i want to access 3rd element in the list i.e 4 but i want the result in specific way.</p>
<p>I want program to get the 2nd element i.e 3 and using its index i want to find 3rd element.</p>
<p>in shor... | -4 | 2016-06-15T20:54:05Z | 37,845,841 | <blockquote>
<p>I want program to get the 2nd element i.e 3 and using its index i want to find 3rd element.</p>
</blockquote>
<pre><code>i = 1 # Get the 2nd element
print l1[i+1] # Using its index find the 3rd element.
</code></pre>
| 1 | 2016-06-15T21:11:29Z | [
"python"
] |
Group by interval of datetime using pandas | 37,845,617 | <p>I have data </p>
<pre><code>data id url size domain subdomain
13/Jun/2016:06:27:26 30055 https://api.weather.com/v1/geocode/55.740002/37.610001/aggregate.json?apiKey=e45ff1b7c7bda231216c7ab7c33509b8&products=conditionsshort,fcstdaily10short,fcsthourly24short,nowlinks 3929 weather.com api.weathe... | 4 | 2016-06-15T20:56:06Z | 37,845,918 | <p>you need to <code>set_index</code> first
check that <code>df.index</code> is a <strong>Datetimeindex</strong>. If not, that's the cause of the error</p>
| 0 | 2016-06-15T21:16:57Z | [
"python",
"datetime",
"pandas"
] |
Group by interval of datetime using pandas | 37,845,617 | <p>I have data </p>
<pre><code>data id url size domain subdomain
13/Jun/2016:06:27:26 30055 https://api.weather.com/v1/geocode/55.740002/37.610001/aggregate.json?apiKey=e45ff1b7c7bda231216c7ab7c33509b8&products=conditionsshort,fcstdaily10short,fcsthourly24short,nowlinks 3929 weather.com api.weathe... | 4 | 2016-06-15T20:56:06Z | 37,845,960 | <p>You need to parse <code>data</code> using <code>pd.to_datetime()</code> with appropriate <code>format</code> settings and use the result as <code>index</code>. Then <code>.groupby()</code> while resampling to <code>5Min</code> intervals:</p>
<pre><code>df.index = pd.to_datetime(df.data, format='%d/%b/%Y:%H:%M:%S')
... | 1 | 2016-06-15T21:19:33Z | [
"python",
"datetime",
"pandas"
] |
Group by interval of datetime using pandas | 37,845,617 | <p>I have data </p>
<pre><code>data id url size domain subdomain
13/Jun/2016:06:27:26 30055 https://api.weather.com/v1/geocode/55.740002/37.610001/aggregate.json?apiKey=e45ff1b7c7bda231216c7ab7c33509b8&products=conditionsshort,fcstdaily10short,fcsthourly24short,nowlinks 3929 weather.com api.weathe... | 4 | 2016-06-15T20:56:06Z | 37,846,118 | <p>Note to convert to datetime you can pass the following format:</p>
<pre><code>df['data'] = pd.to_datetime(df['data'], format="%d/%b/%Y:%H:%M:%S")
</code></pre>
<p>Now you can use the groupby:</p>
<pre><code>In [11]: df1 = df.set_index("data")
In [12]: df1.groupby(pd.TimeGrouper("5Min")).sum()
Out[12]:
... | 1 | 2016-06-15T21:30:12Z | [
"python",
"datetime",
"pandas"
] |
How to change opacity of image and merge with another image in Python | 37,845,689 | <p>I've been looking up on how to put two picture together, turning the top one to around 50% transparent.</p>
<p>So far, I managed to find this:</p>
<pre><code>from PIL import Image
def merge():
background = Image.open("ib.jpg")
background = background .convert('L') #only foreground color matters
foregr... | 0 | 2016-06-15T21:00:30Z | 37,845,893 | <p>You have to use <code>blend</code> function from <code>PIL.Image</code>:</p>
<pre><code>from PIL import Image
bg = Image.open("1.jpg")
fg = Image.open("2.jpg")
# set alpha to .7
Image.blend(bg, fg, .7).save("out.png")
</code></pre>
<p><a href="http://i.stack.imgur.com/QR1Nk.png" rel="nofollow"><img src="http://i.s... | 0 | 2016-06-15T21:15:13Z | [
"python",
"python-imaging-library"
] |
Python: Unique list (based on part of file path) | 37,845,819 | <p>Sorry; I know there are a thousand 'make unique list' threads. I've tried to solve this on my own, or to hack another "make unique list" solution, but I've been unsuccessful with my not amazing python skills.</p>
<p>I have a list of video file names (these are shots in a movie). For any given shot I want to remove... | 0 | 2016-06-15T21:09:50Z | 37,845,981 | <p>One way would be to create a dictionary and keep reassigning the keys, so you only end up with the last value in the directory:</p>
<pre><code>import os
raw_list1 = [
'D:\\\\de05\\de05_019\\postvis\\tk_2\\blasts\\tb205_de05_019.POSTVIS.mov',
'D:\\\\de05\\de05_019\\postvis\\tk_3\\blasts\\tb205_de05_019.POST... | 1 | 2016-06-15T21:20:56Z | [
"python",
"list"
] |
Python sqlite3 not using index with LIKE | 37,845,854 | <p>I have a table with a single column, which I query in two ways:</p>
<ul>
<li><code>SELECT * FROM sequences WHERE seqs="blablabla"</code></li>
<li><code>SELECT * FROM sequences WHERE seqs LIKE "blablabla%"</code></li>
</ul>
<p>For these queries to use an index I seem to need two indices (one for each query type), a... | 0 | 2016-06-15T21:12:26Z | 37,854,143 | <p>The <a href="http://www.sqlite.org/optoverview.html#like_opt" rel="nofollow">documentation</a> says:</p>
<blockquote>
<p>If the right-hand side is a <a href="http://www.sqlite.org/lang_expr.html#varparam" rel="nofollow">parameter</a> that is bound to a string, then this optimization is only attempted if the <a hr... | 1 | 2016-06-16T08:43:54Z | [
"python",
"indexing",
"sqlite3"
] |
Variable step in a for loop | 37,845,872 | <p>I am trying to loop between 0.01 and 10, but between 0.01 and 0.1 use 0.01 as the step, then between 0.1 and 1.0 use 0.1 as step, and between 1.0 and 10.0 use 1.0 as step.</p>
<p>I have the while loop code written, but want to make it more pythonic.</p>
<pre><code>i = 0.01
while i < 10:
# do something
pri... | 17 | 2016-06-15T21:14:00Z | 37,846,008 | <p>You could have a nested loop, the outer one that iterates over the precision and inner one that is just <code>range(1,10)</code>:</p>
<pre><code>for precision in (0.01, 0.1, 1):
for i in range(1,10):
i*=precision
print(i)
</code></pre>
<p>However floats are probably not going to work in this ca... | 2 | 2016-06-15T21:22:29Z | [
"python",
"for-loop"
] |
Variable step in a for loop | 37,845,872 | <p>I am trying to loop between 0.01 and 10, but between 0.01 and 0.1 use 0.01 as the step, then between 0.1 and 1.0 use 0.1 as step, and between 1.0 and 10.0 use 1.0 as step.</p>
<p>I have the while loop code written, but want to make it more pythonic.</p>
<pre><code>i = 0.01
while i < 10:
# do something
pri... | 17 | 2016-06-15T21:14:00Z | 37,846,010 | <p>One approach would be to use two loops: one for the order of magnitude, and one for the values from 1 to 9:</p>
<pre><code>for exp in range(-2, 1):
for i in range(1, 10):
print("{:.2f}".format(i * 10 ** exp))
</code></pre>
| 2 | 2016-06-15T21:22:35Z | [
"python",
"for-loop"
] |
Variable step in a for loop | 37,845,872 | <p>I am trying to loop between 0.01 and 10, but between 0.01 and 0.1 use 0.01 as the step, then between 0.1 and 1.0 use 0.1 as step, and between 1.0 and 10.0 use 1.0 as step.</p>
<p>I have the while loop code written, but want to make it more pythonic.</p>
<pre><code>i = 0.01
while i < 10:
# do something
pri... | 17 | 2016-06-15T21:14:00Z | 37,846,018 | <p>A special-purse generator function might be the right way to go. This would effectively separate the boring part (getting the list of numbers right) from the interesting part (the <code># do something</code> in your example).</p>
<pre><code>def my_range():
for j in .01, .1, 1.:
for i in range(1, 10, 1):... | 19 | 2016-06-15T21:23:21Z | [
"python",
"for-loop"
] |
Variable step in a for loop | 37,845,872 | <p>I am trying to loop between 0.01 and 10, but between 0.01 and 0.1 use 0.01 as the step, then between 0.1 and 1.0 use 0.1 as step, and between 1.0 and 10.0 use 1.0 as step.</p>
<p>I have the while loop code written, but want to make it more pythonic.</p>
<pre><code>i = 0.01
while i < 10:
# do something
pri... | 17 | 2016-06-15T21:14:00Z | 37,846,054 | <p>You could do something like:</p>
<pre><code>import numpy as np
list1 = np.arange(0.01, 0.1, 0.01)
list2 = np.arange(0.1, 1, 0.1)
list3 = np.arange(1, 10, 1)
i_list = np.concatenate((list1, list2, list3)) # note the double parenthesis
for i in i_list:
...
</code></pre>
<p>Basically you create the entire list o... | 1 | 2016-06-15T21:25:59Z | [
"python",
"for-loop"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.