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 |
|---|---|---|---|---|---|---|---|---|---|
Python Selenium how extract text after element | 37,892,691 | <p>Here is the HTML code that I am trying to extract the text from</p>
<pre><code><fieldset>
<div class="grid-3-12 form-no-lbl">
<label class="form-lbl">CNPJ:</label>011234560083
</div>
<div class="grid-3-12 form-no-lbl">
<label class="form-lbl... | 1 | 2016-06-18T02:29:03Z | 37,892,781 | <p>If you have the luxury of having both <code>selenium</code> and <code>lxml</code> available, you could use <code>selenium</code> for navigating to the desired page(s), and then using <code>lxml</code> to parse the HTML. For example,</p>
<pre><code>import lxml.html as LH
# content = browser.page_source
content = '''... | 0 | 2016-06-18T02:50:22Z | [
"python",
"selenium",
"selenium-webdriver"
] |
Python Selenium how extract text after element | 37,892,691 | <p>Here is the HTML code that I am trying to extract the text from</p>
<pre><code><fieldset>
<div class="grid-3-12 form-no-lbl">
<label class="form-lbl">CNPJ:</label>011234560083
</div>
<div class="grid-3-12 form-no-lbl">
<label class="form-lbl... | 1 | 2016-06-18T02:29:03Z | 38,106,966 | <p>It seems really odd that your code doesn't work. I haven't run into a case quite like this. I think the code below should work. Basically I grab the text inside the <code>LABEL</code> and prepend it to the text you are already finding. The combination should get you the text you are looking for.</p>
<pre><code>line... | 0 | 2016-06-29T18:00:58Z | [
"python",
"selenium",
"selenium-webdriver"
] |
Using Keras & Tensorflow with AMD GPU | 37,892,784 | <p>I'm starting to learn Keras, which I believe is a layer on top of Tensorflow and Theano. However, I only have access to AMD GPUs such as the AMD R9 280X.</p>
<p>How can I setup my Python environment such that I can make use of my AMD GPUs through Keras/Tensorflow support for OpenCL?</p>
<p>I'm running on OSX.</p>... | 1 | 2016-06-18T02:51:00Z | 37,903,676 | <p>Theano <strong>does have</strong> support for OpenCL but it is still in its early stages. Theano itself is not interested in OpenCL and relies on <a href="https://github.com/Theano/libgpuarray/issues/189#issuecomment-224691193" rel="nofollow">community support</a>.</p>
<p><a href="https://github.com/Theano/Theano/i... | 1 | 2016-06-19T03:26:45Z | [
"python",
"python-2.7",
"opencl",
"tensorflow",
"keras"
] |
one way to merge two files with same "column name" and "different rows" using pandas in python | 37,892,796 | <p>I have two datafiles <code>a.csv</code> and <code>b.csv</code> which can be obtained from pastebin:
<a href="http://pastebin.com/nzjXESYn" rel="nofollow">http://pastebin.com/nzjXESYn</a><br>
<a href="http://pastebin.com/PDV5Ah64" rel="nofollow">http://pastebin.com/PDV5Ah64</a> </p>
<p>First file <code>a.csv</code>... | 0 | 2016-06-18T02:53:55Z | 37,892,821 | <p>If you want to merge the two datasets, you should use<code>.merge()</code> method, rather than <code>.append()</code>. </p>
<pre><code>result = pd.merge(df1,df2,on='wave')
</code></pre>
<p>The former joins two dataframes (similar to a SQL join), while the latter stacks the two dataframes on top of one another.</p>... | 1 | 2016-06-18T02:59:18Z | [
"python",
"csv",
"pandas",
"merge"
] |
Split and Join Series in Pandas | 37,892,936 | <p>I have two series in the dataframe below. The first is a string which will appear in the second, which will be a url string. What I want to do is change the first series by concatenating on extra characters, and have that change applied onto the second string. </p>
<pre><code>import pandas as pd
#import urlparse
d... | 1 | 2016-06-18T03:28:32Z | 37,893,062 | <p>apply isn't really designed to apply to multiple columns in the same row. What you can do is to change your function so that it takes in a series instead and then assigns source_col, dest_col to the appropriate value in the series. One way of doing it is as below:</p>
<pre><code>def trial(x):
source_col = x["Or... | 2 | 2016-06-18T03:52:54Z | [
"python",
"pandas",
"join",
"split",
"series"
] |
Split and Join Series in Pandas | 37,892,936 | <p>I have two series in the dataframe below. The first is a string which will appear in the second, which will be a url string. What I want to do is change the first series by concatenating on extra characters, and have that change applied onto the second string. </p>
<pre><code>import pandas as pd
#import urlparse
d... | 1 | 2016-06-18T03:28:32Z | 37,893,121 | <p>Instead of using <code>split</code>, you can use the <code>replace</code> method to prepend the <code>angry_</code> to the corresponding source:</p>
<pre><code>def trial(row):
row.WordinUrl = row.WordinUrl.replace(row.OrigWord, "angry_" + row.OrigWord)
row.OrigWord = "angry_" + row.OrigWord
return row
... | 1 | 2016-06-18T04:02:52Z | [
"python",
"pandas",
"join",
"split",
"series"
] |
Split and Join Series in Pandas | 37,892,936 | <p>I have two series in the dataframe below. The first is a string which will appear in the second, which will be a url string. What I want to do is change the first series by concatenating on extra characters, and have that change applied onto the second string. </p>
<pre><code>import pandas as pd
#import urlparse
d... | 1 | 2016-06-18T03:28:32Z | 37,906,014 | <p>here is an alternative approach:</p>
<pre><code>df['WordinUrl'] = (df.apply(lambda x: x.WordinUrl.replace(x.OrigWord,
'angry_' + x.OrigWord), axis=1))
In [25]: df
Out[25]:
OrigWord WordinUrl
0 bunny http://www.animal.... | 1 | 2016-06-19T10:01:52Z | [
"python",
"pandas",
"join",
"split",
"series"
] |
how to point towards a method given variable python | 37,893,005 | <pre><code>possibleRequests = ['test', 'test1']
def inboxReader():
global inbox
tempInbox = []
tempInbox = inbox.inboxMessage #inboxMesage remains filled?
print(inbox.inboxMessage, 'inboxReader')
i = 0
while (i < len(tempInbox)):
if (tempInbox[i] in possib... | 1 | 2016-06-18T03:41:34Z | 37,893,107 | <p>You can first create a dictionary of functions then refer to it with tempInbox[i]. Example code below:</p>
<pre><code>def func_a(x):
return x
def func_b(x):
return x*10
tempInbox = (2,3)
fn_dict = {"a":func_a,"b":func_b}
print fn_dict["a"](tempInbox[0]) # returns 2
print fn_dict["b"](tempInbox[1]) # retu... | 2 | 2016-06-18T04:00:34Z | [
"python",
"methods"
] |
I can't find PIL in python | 37,893,014 | <p>I have installed Pillow and can see where it is installed but from PIL import Image doesn't work. Says no module called PIL. Have tried the 'import image' instead as well and still not result? </p>
<pre><code>from tkinter import *
from tkinter import ttk
from PIL import Image
root = Tk()
root.title("Something")
... | -1 | 2016-06-18T03:43:07Z | 38,245,737 | <p>I think if your installation is right then it will create a PIL directory in your Pyhton3x/Lib/site_packges/PIL.If it is not there then try to clean Pillow from site_packages and install it again.</p>
| 0 | 2016-07-07T12:40:59Z | [
"python"
] |
Python - IF for a column in panda datafram | 37,893,097 | <p>I would like to turn <code>NaN</code> values in the column <code>GP</code> in the dataframe <code>draft</code> (which has 22 rows) into <code>0</code>. I tried these lines but they dont work</p>
<pre><code>import pandas as pd
draft = pd.read_csv('Draft year.csv')
if draft['GP'].isnull():
draft['GP'] = 0
</cod... | 0 | 2016-06-18T03:58:13Z | 37,893,119 | <p>You can use list comprehension and replace the <code>NaN</code>s with zeros.</p>
<pre><code>draft['GP'] = [0 if np.isnan(x) else x for x in draft.GP]
</code></pre>
| 2 | 2016-06-18T04:02:45Z | [
"python",
"pandas"
] |
Python - IF for a column in panda datafram | 37,893,097 | <p>I would like to turn <code>NaN</code> values in the column <code>GP</code> in the dataframe <code>draft</code> (which has 22 rows) into <code>0</code>. I tried these lines but they dont work</p>
<pre><code>import pandas as pd
draft = pd.read_csv('Draft year.csv')
if draft['GP'].isnull():
draft['GP'] = 0
</cod... | 0 | 2016-06-18T03:58:13Z | 37,893,125 | <p>The .fillna function works for this, you can specify the 'draft' series first if u only want to fillna with 0 for that column. Example below:</p>
<pre><code>import pandas as pd
print data3
data3 = pd.read_csv("data2.csv")
data3["Name"].fillna(0, inplace = True)
data3
Name Name2 Time
0 NaN NaN 1
1 NaN ... | 5 | 2016-06-18T04:04:44Z | [
"python",
"pandas"
] |
Simple script hangs creating and/or saving figure with matplotlib | 37,893,241 | <p>I'm running Python 2.7.11+ and <code>matplotlib</code> 1.5.1 on Ubuntu 16.04 64 bit.</p>
<p>The very simple script shown below hangs at either of the three lines marked. If I leave all lines un-commented, it will hang on the first one. If I comment it out, it will hang on the second one. Same with the third one.</p... | 0 | 2016-06-18T04:27:45Z | 37,899,536 | <p>As mentioned in the comments, this was an issue with the backend. I'm not sure why though, since I never had to mess with this after a new installation like this one</p>
<p>I tried the solution mentioned here: <a href="http://www.pyimagesearch.com/2015/08/24/resolved-matplotlib-figures-not-showing-up-or-displaying/... | 0 | 2016-06-18T17:02:44Z | [
"python",
"matplotlib"
] |
Using globals in Python exec | 37,893,257 | <p>I'm trying to create a custom python interpreter type application. I'm using exec statement (in Python 2.7.6) to execute given code but globals aren't working quite as expected. Could someone explain why this does not work:</p>
<pre><code>def print_x():
print(x)
g = {'x': 10, 'print_x': print_x}
l = {}
exec(... | 3 | 2016-06-18T04:30:40Z | 37,893,388 | <p>The <code>x</code> inside the function is picked up from the globals of the namespace where the function is defined. However, you're calling it in a different namespace. This isn't too different from having multiple modules:</p>
<pre><code># foo.py
def print_x():
print(x)
</code></pre>
<p>and then trying to ... | 3 | 2016-06-18T04:52:41Z | [
"python"
] |
Appending the list with each unique solution to the Queens Puzzle. I don't know why the last solution is the only solution appended to the list? | 37,893,365 | <p>I am trying to save each individual solution to the N-Queens Puzzle to a list. However, when I try to add each list as a sub-list, only the last solution is added to the list (10 times), as opposed to the 10 individual solutions. My goal is to ensure that each time I run the board only new solutions, which have not ... | 0 | 2016-06-18T04:49:14Z | 37,893,446 | <p>Just change </p>
<pre><code>solutions.append(bd)
</code></pre>
<p>to </p>
<pre><code>solutions.append(list(bd))
</code></pre>
<p>which creates a copy of your current solution.
Your problem with having the same solution 10 times in the list is because you add a reference to <code>bd</code> in your result list but... | 0 | 2016-06-18T05:05:05Z | [
"python",
"n-queens"
] |
Class name is not defined | 37,893,464 | <pre><code>class MyClass:
sample=0
w=0
b=0
g=0
o=0
color_list=['black','white','gray']
def __init__(self):
print("Enter Your Name")
MyClass.name=input()
print("What's the color of ur car?")
MyClass.color=input()
MyClass.sample=MyClass.sample+1
de... | -3 | 2016-06-18T05:08:55Z | 37,893,476 | <p>use <code>self</code> instead of MyClass inside your class</p>
| 0 | 2016-06-18T05:10:38Z | [
"python",
"class"
] |
Class name is not defined | 37,893,464 | <pre><code>class MyClass:
sample=0
w=0
b=0
g=0
o=0
color_list=['black','white','gray']
def __init__(self):
print("Enter Your Name")
MyClass.name=input()
print("What's the color of ur car?")
MyClass.color=input()
MyClass.sample=MyClass.sample+1
de... | -3 | 2016-06-18T05:08:55Z | 37,893,708 | <p>You are referencing your class in your classbody:</p>
<pre><code>class Myclass:
...
mylist = []
mylist.append(Myclass)
</code></pre>
<p>but the term <code>Myclass</code> is not defined while executing your class body.</p>
<p>It seems like you mixed up the indentation and it <em>should be</em></p>
<p... | 0 | 2016-06-18T05:49:20Z | [
"python",
"class"
] |
Class name is not defined | 37,893,464 | <pre><code>class MyClass:
sample=0
w=0
b=0
g=0
o=0
color_list=['black','white','gray']
def __init__(self):
print("Enter Your Name")
MyClass.name=input()
print("What's the color of ur car?")
MyClass.color=input()
MyClass.sample=MyClass.sample+1
de... | -3 | 2016-06-18T05:08:55Z | 37,894,815 | <p>The problem is the indenting of the last section of code â the way it is, it's being made a part of <code>Myclass</code>, which is in the process of being defined and doesn't exist yet!</p>
<p>To fix that issue just unindent it by one level:</p>
<pre><code>class MyClass:
sample=0
w=0
b=0
...
... | 0 | 2016-06-18T08:15:02Z | [
"python",
"class"
] |
Tensorflow set CUDA_VISIBLE_DEVICES within jupyter | 37,893,755 | <p>I have two GPUs and would like to run two different networks via ipynb simultaneously, however the first notebook always allocates both GPUs. </p>
<p>Using CUDA_VISIBLE_DEVICES, I can hide devices for python files, however I am unsure of how to do so within a notebook.</p>
<p>Is there anyway to hide different GPUs... | 3 | 2016-06-18T05:55:39Z | 37,901,914 | <p>You can set environment variables in the notebook using <code>os.environ</code>. Do the following before initializing TensorFlow to limit TensorFlow to first GPU.</p>
<pre><code>import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
</code></pre>
<p>You can double check that you have the correct devices visible to TF</p... | 4 | 2016-06-18T21:43:43Z | [
"python",
"environment-variables",
"tensorflow"
] |
Pandas extract multiple columns | 37,893,773 | <p>Using Pandas I am adding new columns to a DataFrame:</p>
<pre><code>df["Year"] = df["concat"].str.extract("(\d\d\d\d$)", expand=False)
df["Month"] = df["concat"].str.extract("(\d\d)\_\d\d\d\d$", expand=False)
df["Measure"] = df["concat"].str.extract("^(.*)\_\d\d\_\d\d\d\d$", expand=False)
</code></pre>
<p>This wor... | 0 | 2016-06-18T05:58:41Z | 37,894,923 | <p>You are passing in 3 separate values into your df reference as <code>df["Measure", "Year", "Month"]</code>. <code>"Measure"</code>, <code>"Year"</code> and <code>"Month"</code> instead of a single array <code>["Measure","Year","Month"]</code>. It should look like <code>df[["Measure", "Year", "Month"]]</code> instead... | 0 | 2016-06-18T08:31:21Z | [
"python",
"pandas",
"dataframe"
] |
Match Regex command to check one and only one occurrence of [+,-,/,*,U,D] | 37,893,800 | <p>I have a scenario where i need to identify using match_regex whether the characters given below occurs only once and inputs should not contain any other characters or numbers apart form the given list <code>[+-/*UD]</code>. Should treat each as separate characters.</p>
<p>Made up by only one occurrence of <code>[+,... | 1 | 2016-06-18T06:02:32Z | 37,893,854 | <p>You can use <a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow">negative look ahead assertion</a> with <a href="http://www.regular-expressions.info/brackets.html" rel="nofollow">captured group value</a>. The following regex will check that each character is following by same or not. Only str... | 1 | 2016-06-18T06:10:57Z | [
"javascript",
"python",
"regex"
] |
Concat str to 3 digits | 37,893,924 | <p>What is attempted to achieve is to sort a column in the changelist_view. The column consists of numbers with either 001-001-001 or 001-001-A-001 type. Used to @property method to build these numbers from integer fields, from several models.</p>
<p>Now, sorting is quite cumbersome. After research on this site / djan... | 0 | 2016-06-18T06:20:33Z | 37,927,213 | <p>Thanks again, solarissmoke. Did not restructure the model, but indeed came to the conclusion i was walking the wrong path with get_queryset. Solved it with a list filter, which does exactly what is needed, albeit without column sorting. </p>
<pre><code>class AssetListFilter(admin.SimpleListFilter):
title = 'Asset'... | 0 | 2016-06-20T16:13:29Z | [
"python",
"django",
"sorting",
"concatenation"
] |
Python selenium Can't access cookies | 37,893,959 | <p>I am trying to access a webpage using python, selenium and phantomjs. I get the page using <code>driver.get</code> and login to page. It said that I should enable cookies for that. </p>
<p>So I tried accessing cookies like:</p>
<pre><code>self.driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true', ... | 2 | 2016-06-18T06:25:24Z | 37,895,993 | <p>Cookies are enabled by default with PhantomJS, so I don't think there is anything wrong with what you're doing.</p>
<p>I believe the issue lies with Amazon not supporting "Phantomjs/(..*)" in the useragent. Have you tried other site's with this code? When you say you've tried it with FireFox, is that through <code>... | 0 | 2016-06-18T10:34:02Z | [
"python",
"selenium",
"cookies",
"selenium-webdriver",
"phantomjs"
] |
How to make pandas dataframe str.contains search faster | 37,894,003 | <p>I'm searching for a substring or multiple substrings in the dataframe of 4 million rows. </p>
<pre><code>df[df.col.str.contains('Donald',case=True,na=False)]
</code></pre>
<p>or</p>
<pre><code>df[df.col.str.contains('Donald|Trump|Dump',case=True,na=False)]
</code></pre>
<p>DataFrame(df) looks like below (with 4 ... | 2 | 2016-06-18T06:31:26Z | 37,894,064 | <p>If the number of substrings is small, it may be faster to search for one at a time, because you can pass the <code>regex=False</code> argument to <code>contains</code>, which speeds it up.</p>
<p>On a sample DataFrame of about 6000 rows that I tested it with on two sample substrings, <code>blah.contains("foo", rege... | 3 | 2016-06-18T06:39:47Z | [
"python",
"pandas",
"dataframe"
] |
How to make pandas dataframe str.contains search faster | 37,894,003 | <p>I'm searching for a substring or multiple substrings in the dataframe of 4 million rows. </p>
<pre><code>df[df.col.str.contains('Donald',case=True,na=False)]
</code></pre>
<p>or</p>
<pre><code>df[df.col.str.contains('Donald|Trump|Dump',case=True,na=False)]
</code></pre>
<p>DataFrame(df) looks like below (with 4 ... | 2 | 2016-06-18T06:31:26Z | 37,894,380 | <p>You could converting it to a list. It seems that searching in a list rather than applying string methods to a series is significantly faster.</p>
<p>Sample code:</p>
<pre><code>import timeit
df = pd.DataFrame({'col': ["very definition of the American success story, continually setting the standards of excellence i... | 2 | 2016-06-18T07:17:50Z | [
"python",
"pandas",
"dataframe"
] |
Returning multiple valuables and then calling those valuables separately | 37,894,036 | <p>I'm having issue with allowing a function to call on variables set by another function. I believe I know how to do this with single variables, but my code requires it be done with multiple variables, a challenge I've struggled with for hours. I've read much about ways others seem to have done this but I can't find s... | 1 | 2016-06-18T06:36:40Z | 37,894,325 | <p>ask() is a function which will return 4 values. So,</p>
<pre><code>returnValues = ask()
draw = draw(*returnValues)
or simply, draw = draw(*ask())
</code></pre>
<p>Also, end = ' ' is not correct. Instead of that you can just use print(c_,'').
Include Validations wherever necessary. Like what if I type "hi" for "Ho... | 1 | 2016-06-18T07:11:09Z | [
"python"
] |
Returning multiple valuables and then calling those valuables separately | 37,894,036 | <p>I'm having issue with allowing a function to call on variables set by another function. I believe I know how to do this with single variables, but my code requires it be done with multiple variables, a challenge I've struggled with for hours. I've read much about ways others seem to have done this but I can't find s... | 1 | 2016-06-18T06:36:40Z | 37,894,350 | <p>I was able to get <code>draw()</code> to accept the inputs from your <code>ask()</code> function (in Python IDLE) just by changing the last line of your code to this:</p>
<pre><code>draw(*ask())
</code></pre>
<p>The <code>*</code> will unpack the variables from the <code>ask()</code> call and pass that along to <c... | 1 | 2016-06-18T07:14:23Z | [
"python"
] |
Getting checkbutton variables values on every notebook tabs Tkinter Python | 37,894,096 | <p>On every Tkinter notebook tab, there is a list of checkbuttons and the variables get saved to their corresponding v[ ] (i.e. cb.append(Checkbuttons(.., variables = v[x],..)).</p>
<p>For now, I am encountering this error:</p>
<pre><code>File "/home/pass/OptionsInterface.py", line 27, in __init__
self.ntbk_render(f ... | 0 | 2016-06-18T06:43:14Z | 37,904,371 | <p>Alright, so thereâs a bit more (⦠alright, maybe a little more than a bitâ¦) here than I intended, but Iâll leave it on the assumption that youâll simply take away from it what you need or find of value.</p>
<p>The short answer is that when your Checkbutton calls cb_check, itâs passing the arguments like... | 1 | 2016-06-19T05:52:31Z | [
"python",
"arrays",
"list",
"checkbox",
"tkinter"
] |
Trouble with extracting data from a CSV file, sorting it and then writing that sorted list into another CSV file | 37,894,104 | <p>I'm trying to read data from a CSV file, sort it in python and then write it into another CSV file. I'm unsure of how to split the list I've sorted into the correct columns.</p>
<p>The output file prints out the complete list and I don't know how to split the list and output it into the csv file for each column.</p... | 1 | 2016-06-18T06:44:15Z | 37,894,405 | <p>Instead of <code>csv.DictWriter</code>, you could use <code>csv.writer</code>. The loop would look like below</p>
<pre><code> with S as csvfile:
fieldnames = ['Name', 'Gender', 'Year']
csv2 = csv.writer(csvfile,quoting=csv.QUOTE_ALL)
csv2.writerow(fieldnames)
csv2.writerow(sort)
</code></pr... | 1 | 2016-06-18T07:21:03Z | [
"python",
"sorting",
"csv"
] |
Trouble with extracting data from a CSV file, sorting it and then writing that sorted list into another CSV file | 37,894,104 | <p>I'm trying to read data from a CSV file, sort it in python and then write it into another CSV file. I'm unsure of how to split the list I've sorted into the correct columns.</p>
<p>The output file prints out the complete list and I don't know how to split the list and output it into the csv file for each column.</p... | 1 | 2016-06-18T06:44:15Z | 37,894,451 | <p>Instead of <code>sort[0]</code>, etc.:</p>
<pre><code> for eachline in sort:
csv2.writerow({'Name': sort[0], 'Gender': sort[1], 'Year': sort[2]})
</code></pre>
<p>you meant <code>eachline[0]</code>, etc.:</p>
<pre><code> for eachline in sort:
csv2.writerow({'Name': eachline[0], 'Gender': ea... | 1 | 2016-06-18T07:26:36Z | [
"python",
"sorting",
"csv"
] |
Storing the input from a Text Field in Tkinter | 37,894,183 | <p>I want to invoke the method <code>delImg</code> when the button delete is called. I used the following code segment for it. But the method parameters are highlighted as wrong. I used Tkinter.How to correct it ?</p>
<pre><code>import Tkinter
import sys
from Tkinter import *
from tkFileDialog import askopenfilename... | 2 | 2016-06-18T06:55:15Z | 37,894,285 | <p>The <strong><code>mtext</code></strong> and <strong><code>name</code></strong> variables exist only in the scope of <code>Hello</code> and <code>Callback</code> functions, respectively. </p>
<p>This means that even though you do have an <code>mtext</code> variable, it is inside the <code>Hello</code> function, and ... | 3 | 2016-06-18T07:06:50Z | [
"python",
"tkinter"
] |
Tilted grid network plotting in Basemap | 37,894,224 | <p>Here is an example figure as illustration. </p>
<p><a href="http://i.stack.imgur.com/39pQe.png" rel="nofollow"><img src="http://i.stack.imgur.com/39pQe.png" alt="enter image description here"></a> </p>
<p>This plot present the satellite SO2 column data for part of Europe. </p>
<p>Due to the difference between... | 1 | 2016-06-18T07:00:01Z | 37,896,175 | <p>Look on different examples from this page: <a href="http://www.uvm.edu/~jbagrow/dsv/heatmap_basemap.html" rel="nofollow">http://www.uvm.edu/~jbagrow/dsv/heatmap_basemap.html</a></p>
<p>Main idea of a sample is plot a <code>pcolormesh</code> on a <code>basemap</code>:</p>
<pre><code>import csv
import numpy as np
fr... | 1 | 2016-06-18T10:56:16Z | [
"python",
"matplotlib",
"matplotlib-basemap"
] |
How to find an item in a list (without using "in" method)? | 37,894,253 | <p>I am trying to find an item in a list without using "in" method. I tried to do it using loop. The code executed successfully, but giving collective result for both (item found as well as item not found). I tried to fix it using break statement. It somehow worked. But still not getting result as expected.</p>
<p>The... | 0 | 2016-06-18T07:03:33Z | 37,894,318 | <p>You're trying to convert the string to an <code>int</code> when you do this:</p>
<pre><code>num = int(input("Enter the number you want to search in list: "))
</code></pre>
<p>When the input isn't a number, this will throw an exception.</p>
<p>Instead, why don't you just do the same thing you did in the first part... | 1 | 2016-06-18T07:10:27Z | [
"python",
"list",
"python-3.x",
"search"
] |
How to find an item in a list (without using "in" method)? | 37,894,253 | <p>I am trying to find an item in a list without using "in" method. I tried to do it using loop. The code executed successfully, but giving collective result for both (item found as well as item not found). I tried to fix it using break statement. It somehow worked. But still not getting result as expected.</p>
<p>The... | 0 | 2016-06-18T07:03:33Z | 37,894,656 | <p>There's really no need to differentiate between integers and strings â they're both just <em>values</em> that Python can handle the same way to do what you want <strong>in this case</strong>. Given that fact, you could rewrite your code along the following lines (which includes several other techniques you could u... | 0 | 2016-06-18T07:53:35Z | [
"python",
"list",
"python-3.x",
"search"
] |
How to find an item in a list (without using "in" method)? | 37,894,253 | <p>I am trying to find an item in a list without using "in" method. I tried to do it using loop. The code executed successfully, but giving collective result for both (item found as well as item not found). I tried to fix it using break statement. It somehow worked. But still not getting result as expected.</p>
<p>The... | 0 | 2016-06-18T07:03:33Z | 37,894,881 | <p>Since this is a learning exercise, I'll submit this as a search avoiding <code>in</code>. Others will claim it is a dirty rotten cheat. Why?</p>
<pre><code>def search(inlist, item):
print(item, end="")
if inlist.__contains__(item):
print(" found")
else:
print(" not found")
mylist = []... | 0 | 2016-06-18T08:25:09Z | [
"python",
"list",
"python-3.x",
"search"
] |
How to find an item in a list (without using "in" method)? | 37,894,253 | <p>I am trying to find an item in a list without using "in" method. I tried to do it using loop. The code executed successfully, but giving collective result for both (item found as well as item not found). I tried to fix it using break statement. It somehow worked. But still not getting result as expected.</p>
<p>The... | 0 | 2016-06-18T07:03:33Z | 37,897,671 | <p>Use :</p>
<pre><code>def seach(l, elm):
try:
l.index(elm)
print "found"
except:
print "not found"
</code></pre>
<p>It is way more pythonic than a custom loop.</p>
<p>PS : As you are in your learning phase, do not try to find way to perform a task. The 'in' keyword is made for it.</... | 0 | 2016-06-18T13:45:23Z | [
"python",
"list",
"python-3.x",
"search"
] |
Flask - 405, Method not allowed | 37,894,263 | <p>I'm trying to send this simple form data to MySQL database using POST method. but same error "Method not allowed", I don't know what's wrong with that. Please help me out here. </p>
<p>HTML Codes:</p>
<pre><code><form role="form" action='/updateabbprof' method="POST">
<div class="form-group">... | 0 | 2016-06-18T07:04:58Z | 37,894,612 | <p>Check the methods that are accepted by <code>/userprofile</code>. Probably this view function is set up to accept post requests only?</p>
<p>The redirect from <code>updateaprof()</code> will cause the browser to issue a <code>GET</code> request to the new location <code>/userprofile</code>, which if it doesn't acce... | 0 | 2016-06-18T07:48:54Z | [
"python",
"mysql",
"python-2.7",
"flask",
"flask-admin"
] |
Using django custom permission on view defs | 37,894,444 | <p>I have written a custom permission </p>
<pre><code>class IsObjectOwner(permissions.BasePermission):
def has_permission(self, request, view):
if ...
.....
return False
else:
return True
</code></pre>
<p>And I am trying to apply this on a few particular view d... | 0 | 2016-06-18T07:25:49Z | 38,084,419 | <p>Set the permissions_classes to the entire viewset and not just to the functions.</p>
<pre><code>class GameView(viewsets.ModelViewSet):
permission_classes = (IsObjectOwner,)
queryset = GameModel.objects.all()
serializer_class = GameSerializer
def get_available_pieces(self,request,*args,**kwargs):
... | 0 | 2016-06-28T19:10:24Z | [
"python",
"django",
"permissions",
"django-rest-framework"
] |
delete fulfilling condition row from a file | 37,894,532 | <p>I have a file</p>
<pre><code>chrM 1114 A A 555 G 52 9.8 xyz
chrM 1256 A A 555 G 0 inf xac
chrM 1184 A A 400 G 50 8 cxv
chrM 1148 p q 500 G 100 5 asad
chrM 2500 x x 555 v 0 inf dad
</code></pre>
<p>here the 2nd last column is the ratio of $5/$6
I want to do delete those line where
$3=$4 and $8=inf if this who... | -1 | 2016-06-18T07:38:24Z | 37,894,596 | <p>Use awk simply like:</p>
<pre><code>awk '{if ($3 != $4 && $8 != "Inf") { print $0 } }' myfile.txt
</code></pre>
| 1 | 2016-06-18T07:47:16Z | [
"python",
"perl",
"shell"
] |
delete fulfilling condition row from a file | 37,894,532 | <p>I have a file</p>
<pre><code>chrM 1114 A A 555 G 52 9.8 xyz
chrM 1256 A A 555 G 0 inf xac
chrM 1184 A A 400 G 50 8 cxv
chrM 1148 p q 500 G 100 5 asad
chrM 2500 x x 555 v 0 inf dad
</code></pre>
<p>here the 2nd last column is the ratio of $5/$6
I want to do delete those line where
$3=$4 and $8=inf if this who... | -1 | 2016-06-18T07:38:24Z | 37,894,641 | <p>A python solution to this would be:</p>
<pre><code>file = open("myfile.txt")
file2 = open("myfile2.txt", "a")
for i, line in enumerate(file)
strList = line.split()
if not (strList[2] == strList[3] and strList[7] == "inf"):
file2.write(line)
file.close()
file2.close()
</code></pre>
<p>this assumes t... | 0 | 2016-06-18T07:52:10Z | [
"python",
"perl",
"shell"
] |
delete fulfilling condition row from a file | 37,894,532 | <p>I have a file</p>
<pre><code>chrM 1114 A A 555 G 52 9.8 xyz
chrM 1256 A A 555 G 0 inf xac
chrM 1184 A A 400 G 50 8 cxv
chrM 1148 p q 500 G 100 5 asad
chrM 2500 x x 555 v 0 inf dad
</code></pre>
<p>here the 2nd last column is the ratio of $5/$6
I want to do delete those line where
$3=$4 and $8=inf if this who... | -1 | 2016-06-18T07:38:24Z | 37,898,359 | <pre><code>awk '!$3==$4||$8!~/inf/' file
chrM 1114 A A 555 G 52 9.8 xyz
chrM 1184 A A 400 G 50 8 cxv
chrM 1148 p q 500 G 100 5 asad
</code></pre>
<p>Made a mistake hopefully corrected now.</p>
| -1 | 2016-06-18T15:00:17Z | [
"python",
"perl",
"shell"
] |
delete fulfilling condition row from a file | 37,894,532 | <p>I have a file</p>
<pre><code>chrM 1114 A A 555 G 52 9.8 xyz
chrM 1256 A A 555 G 0 inf xac
chrM 1184 A A 400 G 50 8 cxv
chrM 1148 p q 500 G 100 5 asad
chrM 2500 x x 555 v 0 inf dad
</code></pre>
<p>here the 2nd last column is the ratio of $5/$6
I want to do delete those line where
$3=$4 and $8=inf if this who... | -1 | 2016-06-18T07:38:24Z | 37,898,926 |
<p>In Perl, the solution is pretty much a transcription of your question</p>
<pre class="lang-none prettyprint-override"><code>perl -ane 'print unless $F[2] eq $F[3] and $F[7] eq "inf"' data.txt
</code></pre>
<h3>output</h3>
<pre class="lang-none prettyprint-override"><code>chrM 1114 A A 555 G 52 9.8 xyz
chrM 1184... | 1 | 2016-06-18T15:59:07Z | [
"python",
"perl",
"shell"
] |
How to import material_ui | 37,894,551 | <p>I recently installed material_ui using pip. I wish to be able to import and use the flatui for my kivy app but I can't seem to figure out how to import it correctly.
After installing this was the code I used to try and import </p>
<pre><code>from material_ui.flatui.flatui import FloatingAction
</code></pre>
<p>Thi... | 0 | 2016-06-18T07:41:34Z | 37,895,123 | <p>Here are a few suggestions as to what could be wrong:</p>
<p>1- check if material_ui is on in a path directory (get the list of path directories using <code>sys.path</code>)</p>
<p>2- <code>from material_ui.flatui.flatui import FloatingAction</code> could mean two things:</p>
<ol>
<li>Import the module (.py file)... | 2 | 2016-06-18T08:54:45Z | [
"python",
"kivy",
"material-ui"
] |
How to merge dataframes using pandas python? | 37,894,654 | <p>I have following two dataframes</p>
<p>data1</p>
<pre><code>company,values
a,76
b,56
c,78
d,56
</code></pre>
<p>dataframe2</p>
<pre><code>company,comp_id
a,a1
b,b1
</code></pre>
<p>I need output like following format</p>
<pre><code>company,value,comp_id
a,76,a1
b,56,b1
c,78
d,56
</code></pre>
<p>how to me... | 1 | 2016-06-18T07:53:19Z | 37,894,666 | <p>You're looking for the pandas.concat() function. Have a look at the documentation <a href="http://pandas.pydata.org/pandas-docs/stable/merging.html" rel="nofollow">here</a>.</p>
| 1 | 2016-06-18T07:55:10Z | [
"python",
"python-2.7",
"pandas"
] |
How to merge dataframes using pandas python? | 37,894,654 | <p>I have following two dataframes</p>
<p>data1</p>
<pre><code>company,values
a,76
b,56
c,78
d,56
</code></pre>
<p>dataframe2</p>
<pre><code>company,comp_id
a,a1
b,b1
</code></pre>
<p>I need output like following format</p>
<pre><code>company,value,comp_id
a,76,a1
b,56,b1
c,78
d,56
</code></pre>
<p>how to me... | 1 | 2016-06-18T07:53:19Z | 37,894,679 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.fillna.html" rel="nofollow"><code>fillna</code></a>:</p>
<pre><code>#fillna only column comp_id
print (pd.m... | 4 | 2016-06-18T07:56:19Z | [
"python",
"python-2.7",
"pandas"
] |
How to merge dataframes using pandas python? | 37,894,654 | <p>I have following two dataframes</p>
<p>data1</p>
<pre><code>company,values
a,76
b,56
c,78
d,56
</code></pre>
<p>dataframe2</p>
<pre><code>company,comp_id
a,a1
b,b1
</code></pre>
<p>I need output like following format</p>
<pre><code>company,value,comp_id
a,76,a1
b,56,b1
c,78
d,56
</code></pre>
<p>how to me... | 1 | 2016-06-18T07:53:19Z | 37,894,694 | <p>Use <code>pd.merge()</code></p>
<pre><code>>>> pd.merge(dataframe1, dataframe2, on='company', how='outer')
</code></pre>
| 3 | 2016-06-18T07:57:55Z | [
"python",
"python-2.7",
"pandas"
] |
How to merge dataframes using pandas python? | 37,894,654 | <p>I have following two dataframes</p>
<p>data1</p>
<pre><code>company,values
a,76
b,56
c,78
d,56
</code></pre>
<p>dataframe2</p>
<pre><code>company,comp_id
a,a1
b,b1
</code></pre>
<p>I need output like following format</p>
<pre><code>company,value,comp_id
a,76,a1
b,56,b1
c,78
d,56
</code></pre>
<p>how to me... | 1 | 2016-06-18T07:53:19Z | 37,897,253 | <p>You can use pd.concat() for this.</p>
<p>I am adding an example for a better understanding.</p>
<pre><code>In [25]: grouped_data
Out[25]:
Yield
monthyear Facility Date
Dec 15 CCM2 2015-12-01 2550.000000
Feb 16 CCM2 2016-02-01 4250.000000
Jan ... | 2 | 2016-06-18T13:01:14Z | [
"python",
"python-2.7",
"pandas"
] |
parsing issues in corrupted json using python | 37,894,729 | <p>I have a corrupted json, like following:</p>
<pre><code>{'a': 'b', 'c': "abcd'efgh ijklm"}
</code></pre>
<p>Before using python json.loads, i need to do 2 things:</p>
<ol>
<li>replace single quote inside double quote with <code>\'</code></li>
<li>replace all other single quote, except <code>\'</code> with double ... | 0 | 2016-06-18T08:02:51Z | 37,895,289 | <p>Actually you can't use the <a href="https://docs.python.org/3.5/library/json.html#json.loads" rel="nofollow"><code>json.loads</code></a> function to deserialize your string because the string doesn't contain a valid JSON document. Instead, you should consider to use the <a href="https://docs.python.org/3.5/library/a... | 1 | 2016-06-18T09:14:04Z | [
"python",
"json",
"quotes"
] |
Lookup values with different column names in pandas | 37,894,807 | <p>I have 2 pandas dataframes <code>df1</code> and <code>df2</code></p>
<pre><code>Name No
A 1
A 2
B 5
Player Gender
A F
B M
C F
</code></pre>
<p>I would like to create a new column <code>sex</code> in the <code>df1</code> dataframe, using corresponding values from the column <code>ge... | 1 | 2016-06-18T08:13:41Z | 37,894,837 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow"><code>map</code></a> by <code>df2</code> where is <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.set_index.html" rel="nofollow"><code>set_index</code></a> from column <code>Player</... | 1 | 2016-06-18T08:18:23Z | [
"python",
"dictionary",
"pandas",
"dataframe"
] |
I want to change the format of my DataFrame in pandas. How can I do this? | 37,894,809 | <p>My current dataframe looks like this:</p>
<pre><code>In [40]: result
Out[40]:
monthyear Facility Date Yield Planned
0 Dec 15 CCM2 2015-12-01 2550.000000 0.0
1 Feb 16 CCM2 2016-02-01 4250.000000 0.0
2 Jan 16 CCM1 2016-01-01 1540.000000 0.0
3 Jan 16 CCM2 ... | 3 | 2016-06-18T08:14:05Z | 37,895,061 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"><code>pivot_table</code></a> and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> by <code>index</code> with aggregating... | 4 | 2016-06-18T08:47:49Z | [
"python",
"pandas",
"group-by",
"pivot-table"
] |
How to run a .bat file in DOSbox with Python? | 37,894,821 | <p>I need to use <a href="https://www.dosbox.com" rel="nofollow">DOSbox</a> emulator to run a .bat file</p>
<p>But I do not know to implement all the steps that I have to follow in python. This was my try:</p>
<pre><code>import os
commands = ['""C:\Program Files (x86)\DOSBox-0.73\dosbox.exe""',
'mount c c... | 0 | 2016-06-18T08:16:12Z | 37,895,130 | <p>You actually don't even need Python for this. You need to run Dosbox passing in a -conf parameter which points to a configuration file with your required commands in an auto exec section.</p>
<p>So if you create a configuration file called something like run_t2d.conf in the same directory as the batch file which lo... | 2 | 2016-06-18T08:55:24Z | [
"python",
"windows",
"dosbox"
] |
How to run a .bat file in DOSbox with Python? | 37,894,821 | <p>I need to use <a href="https://www.dosbox.com" rel="nofollow">DOSbox</a> emulator to run a .bat file</p>
<p>But I do not know to implement all the steps that I have to follow in python. This was my try:</p>
<pre><code>import os
commands = ['""C:\Program Files (x86)\DOSBox-0.73\dosbox.exe""',
'mount c c... | 0 | 2016-06-18T08:16:12Z | 37,899,169 | <p>You can use the <a href="https://www.dosbox.com/wiki/Usage" rel="nofollow"><code>-c</code> option to DOSBox</a> to specify commands to run as arguments without having to create configuration file. For example:</p>
<pre><code>import subprocess
dosbox_exe = r'C:\Program Files (x86)\DOSBox-0.73\dosbox.exe'
dosbox_arg... | 2 | 2016-06-18T16:26:55Z | [
"python",
"windows",
"dosbox"
] |
How to assign value to a scalar variable in numpy array? | 37,894,892 | <p>I wrote a <code>for-loop</code> and wished to assign the value to the first variable in the part of an array that equals to <code>-inf</code>. The complete code is as below:</p>
<pre><code>cList = np.full((5), -np.inf)
for i in range(5):
newest = another_array[i][1]
cList[cList==-np.inf][0] = newest
</code>... | 0 | 2016-06-18T08:26:26Z | 37,894,915 | <p>This:</p>
<pre><code>cList[cList==-np.inf]
</code></pre>
<p>makes a copy of the selected data, not a view, so this:</p>
<pre><code>cList[cList==-np.inf][0] = newest
</code></pre>
<p>modifies the copy, leaving <code>cList</code> unchanged.</p>
<p>Repeatedly searching <code>cList</code> for instances of <code>-in... | 0 | 2016-06-18T08:30:16Z | [
"python",
"arrays",
"numpy"
] |
How to rename a column which have a same name with another one | 37,894,900 | <p>I have an data - frame as below...</p>
<pre><code> AA BB CC DD EE ... LL MM NN NN
0 a0 b0 c0 d0 e0 ... l0 m0 x0 y0
1 a1 b1 c1 d1 e1 ... l1 m1 x1 y1
2 a2 b2 c2 d2 e2 ... l2 m2 x2 y2
3 a3 b3 c3 d3 e3 ... l3 m3 x3 y3
</code></pre>
<p>I would like to change the name of 'NN' which is in right edge.</p>
<p>Somebody sa... | 1 | 2016-06-18T08:27:20Z | 37,894,932 | <p>You can slice all column names without last, create new <code>list</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.tolist.html" rel="nofollow"><code>tolist</code></a>, add new name <code>['ZZ']</code> and reassign back to <code>df.columns</code>:</p>
<pre><code>df.columns = d... | 0 | 2016-06-18T08:32:49Z | [
"python",
"list",
"pandas",
"dataframe",
"rename"
] |
How to rename a column which have a same name with another one | 37,894,900 | <p>I have an data - frame as below...</p>
<pre><code> AA BB CC DD EE ... LL MM NN NN
0 a0 b0 c0 d0 e0 ... l0 m0 x0 y0
1 a1 b1 c1 d1 e1 ... l1 m1 x1 y1
2 a2 b2 c2 d2 e2 ... l2 m2 x2 y2
3 a3 b3 c3 d3 e3 ... l3 m3 x3 y3
</code></pre>
<p>I would like to change the name of 'NN' which is in right edge.</p>
<p>Somebody sa... | 1 | 2016-06-18T08:27:20Z | 37,894,973 | <p>Copy the columns to a new list, modify the last index of the list, and reassign back to <code>df.columns</code>:</p>
<pre><code>>>> col = list(df.columns)
>>> col
['z', 'z']
>>> col[-1] = 'ZZ'
>>> df.columns = col
>>> df
z ZZ
0 1 10
1 2 20
</code></pre>
| 0 | 2016-06-18T08:38:57Z | [
"python",
"list",
"pandas",
"dataframe",
"rename"
] |
Beautiful Soup scrape for "Worldwide" | 37,894,975 | <p>I'm trying to scrape some Box Office Mojo pages for <strong>Worldwide</strong> box office gross figures using Beautiful Soup.My code below will grab the <strong>Domestic</strong> figures just fine, won't work when I sub in "Worldwide" for "Domestic Total Gross." Maybe because "Worldwide" show's up on the page more t... | 1 | 2016-06-18T08:39:06Z | 37,895,695 | <p>Use the table inside the <code>div.mp_box</code> structure to get what you want:</p>
<pre><code>In [1]: from bs4 import BeautifulSoup
In [2]: import requests
In [3]: r = requests.get("http://www.boxofficemojo.com/movies/?id=rainman.htm").content
In [4]: soup = BeautifulSoup(r,"lxml")
In [5]: table = soup.select_... | 0 | 2016-06-18T09:59:51Z | [
"python",
"beautifulsoup",
"scrape"
] |
how to create url column dataframe using two column values in python pandas? | 37,895,097 | <p>I have following dataframe.</p>
<pre><code>company,compid,secid
a,a1,a2
b,b1,b2
</code></pre>
<p>I need output like following format</p>
<pre><code>company,compid,secid,url
a,a1,a2,http://www.cssss.com/companydetails.aspx?compid=a1&secid=a2
b,b1,b2,http://www.cssss.com/companydetails.aspx?compid=b1&secid=... | 1 | 2016-06-18T08:52:05Z | 37,895,138 | <p>Use:</p>
<pre><code>df['url'] = 'http://www.cssss.com/companydetails.aspx?compid=' +
df.compid + '&secid=' + df.secid
print (df)
company compid secid url
0 a a1 a2 http://www.cssss.com/companydetails.aspx?compi...
1 b b1 b2... | 1 | 2016-06-18T08:55:50Z | [
"python",
"python-2.7",
"pandas",
"dataframe",
"concatenation"
] |
Python doesn't recognize cv2 when running under sudo | 37,895,111 | <p>I've installed opencv with python 2.7 <a href="http://www.pyimagesearch.com/2015/07/27/installing-opencv-3-0-for-both-python-2-7-and-python-3-on-your-raspberry-pi-2/" rel="nofollow">using this tutorial</a>. I've created a test python file and everything works fine. But when I try to run it as sudo, it throws an erro... | 0 | 2016-06-18T08:53:50Z | 38,001,535 | <p>This problem was caused because when I installed opencv I created it in a virtual env. Making a link to the opencv file from outside the env to the opencv library folder fixed it.</p>
| 0 | 2016-06-23T20:46:07Z | [
"python",
"opencv",
"raspberry-pi",
"sudo"
] |
How can I return an XML file with Spyne? | 37,895,243 | <p>I have <strong>Flask-Spyne</strong> server (web service) and I want to return (return to client after he will ask) a <strong>XML file</strong>.</p>
<p><strong>I want to do this:</strong></p>
<ul>
<li>I will put some things from database to XML. (<strong>solved</strong>)</li>
<li>I have that XML saved on server (we... | 0 | 2016-06-18T09:07:08Z | 37,907,837 | <p>If you want to return it as a regular string inside a document, you must set your _return type to <code>Unicode</code>.</p>
<p>If you want to return it as an xml document, you must parse it (<code>etree.parse("Databaze.xml")</code>) and return the resulting ElementTree instance. Your return type in this case should... | 0 | 2016-06-19T13:40:05Z | [
"python",
"xml",
"web-services",
"return",
"spyne"
] |
Regex avoid "rest of string" split results | 37,895,352 | <p>I have this code to split a complicated CSV file into chunks. The hard bit is that commas may also appear within "" and thus those must not be split on. The regex I am using to find commas not within "" works fine: <code>comma_re = re.compile(r',(?=([^"]*""[^"]*"")*[^"]*$)')</code></p>
<p>Demo: <a href="http://pyth... | 0 | 2016-06-18T09:21:29Z | 37,896,375 | <pre><code>(?<!"),(?![^",]+")|,(?=[^"]*$)
</code></pre>
<p>Will work for the example you gave, although it won't work if the input differs from that format.</p>
<pre><code>input = 'Test1,Test2,"",Test3,Test4"",Test5'
output = re.split(r'(?<!"),(?![^",]+")|,(?=[^"]*$)', input)
print(output)
# ['Test1', 'Test2',... | 1 | 2016-06-18T11:22:35Z | [
"python",
"regex",
"csv",
"split",
"match"
] |
Refer "sudo pip" to anaconda pip | 37,895,358 | <p>I have <a href="https://www.continuum.io/downloads" rel="nofollow">anaconda</a> installed in my ubuntu system. </p>
<p>If I use <code>sudo pip</code> in terminal, it seems that it refers to system pip, not to anaconda pip. I run <code>sudo which pip</code> to verify it.</p>
<p>The <code>sudo which pip</code> gave ... | 1 | 2016-06-18T09:22:04Z | 37,895,429 | <p>Which instance of <code>pip</code> is used when you type <code>pip</code> is determined by the contents of your <code>$PATH</code> environment variable. Your environment variables are normally replaced - as a security measure - by <code>sudo</code>. You can change this so as to keep your existing <code>$PATH</cod... | 2 | 2016-06-18T09:31:24Z | [
"python",
"linux",
"ubuntu"
] |
Object variable of a class as a tuple | 37,895,361 | <p>I am trying to define an <strong>object variable of a class so that it would be a tuple</strong> as seen below:</p>
<pre><code>class MyClass(object):
def __init__(self):
self.results = ? # tuple
def generate_results(self, a):
# tuple to hold the 3 result integers
self.results = (sel... | 0 | 2016-06-18T09:22:08Z | 37,895,840 | <p>You can optionally code this:</p>
<pre><code>def __init__(self):
self.results = ()
</code></pre>
<p>If I judge just from your code, I may say it is not important because inside <code>generate_results()</code> you overrided <code>self.results</code>.</p>
<p>It can be useful to initialize the empty tuple on... | 2 | 2016-06-18T10:15:33Z | [
"python",
"class",
"python-3.x",
"object",
"initialization"
] |
fastest method to read big data files in python | 37,895,404 | <p>I have got some (about 60) huge (>2 gig) CSV files which I want to loop through to to make subselections (e.g. each file contains data of 1 month of various financial products, i want to make 60-month time series of each product) .</p>
<p>Reading an entire file into memory (e.g. by loading the file in excel or matl... | 0 | 2016-06-18T09:27:57Z | 37,896,257 | <p>I would test <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">pandas.read_csv</a> mentioned in <a href="http://softwarerecs.stackexchange.com/questions/7463/fastest-python-library-to-read-a-csv-file">http://softwarerecs.stackexchange.com/questions/7463/fastest-pytho... | 0 | 2016-06-18T11:07:00Z | [
"python",
"performance",
"memory",
"split",
"iteration"
] |
fastest method to read big data files in python | 37,895,404 | <p>I have got some (about 60) huge (>2 gig) CSV files which I want to loop through to to make subselections (e.g. each file contains data of 1 month of various financial products, i want to make 60-month time series of each product) .</p>
<p>Reading an entire file into memory (e.g. by loading the file in excel or matl... | 0 | 2016-06-18T09:27:57Z | 37,896,339 | <p>For a project I have to read multiple csv file and my solution after some benchmark was something like that:</p>
<p>-the try/except was faster than a if/else</p>
<p>-the mmap module is useful to earn time when you access to data</p>
<pre><code>import sys
import os
import mmap
with open("yourCSVFile", "r+b") as f... | -1 | 2016-06-18T11:19:03Z | [
"python",
"performance",
"memory",
"split",
"iteration"
] |
How to find documents from the list by term in the query (if atleast one query term exists in the documents of list) | 37,895,449 | <p>I've list of queries and list of documents like this</p>
<pre><code>queries = ['drug dosage form development Society', 'new drugs through activity evaluation of some medicinally used plants', ' Evaluation of drugs available on market for their quality, effectiveness']
docs = ['A Comparison of Urinalysis Technolog... | 0 | 2016-06-18T09:33:36Z | 37,895,765 | <p>Your code(<code>for i in query:</code>) is searching for sentence not words.
To search for words, first you have to split query sentence into words.</p>
<pre><code>for q in queries:
for word in q.strip().split(" "):
print word
</code></pre>
<p>Complete code:</p>
<pre><code>for q in queries:
for wo... | 0 | 2016-06-18T10:06:42Z | [
"python"
] |
How to find documents from the list by term in the query (if atleast one query term exists in the documents of list) | 37,895,449 | <p>I've list of queries and list of documents like this</p>
<pre><code>queries = ['drug dosage form development Society', 'new drugs through activity evaluation of some medicinally used plants', ' Evaluation of drugs available on market for their quality, effectiveness']
docs = ['A Comparison of Urinalysis Technolog... | 0 | 2016-06-18T09:33:36Z | 37,914,435 | <p>An efficient way of doing this would be to build an Inverted Index. The one I've implemented below is a dirty inverted index.</p>
<pre><code>words = {}
for index, doc in enumerate(docs):
for word in doc.split(" "):
if not word or word==" ":
pass
elif not word in words: words[word]=[... | 0 | 2016-06-20T03:56:51Z | [
"python"
] |
Why am I not getting any results with this scrapy crawler? | 37,895,542 | <p>This is my test project tree:</p>
<pre><code>âââ test11
â  âââ __init__.py
â  âââ items.py
â  âââ pipelines.py
â  âââ settings.py
â  âââ spiders
â  âââ __init__.py
â  âââ basic.py
â  âââ easy.py
âââ scrap... | 0 | 2016-06-18T09:42:21Z | 37,896,367 | <p>You just need to set the <code>allowed_domains</code> appropriately:</p>
<pre><code>allowed_domains = ['amazon.cn']
</code></pre>
| 2 | 2016-06-18T11:21:25Z | [
"python",
"scrapy"
] |
How to create a tuple of an empty tuple in Python? | 37,895,568 | <p>How can I create a tuple consisting of just an empty tuple, i.e. <code>(())</code>? I have tried <code>tuple(tuple())</code>, <code>tuple(tuple(tuple()))</code>, <code>tuple([])</code> and <code>tuple(tuple([]))</code> which all gave me <code>()</code>.</p>
<p>The reason that I use such a thing is as follows: Assum... | 3 | 2016-06-18T09:45:22Z | 37,895,685 | <p>The empty tuple is <code>()</code>, and a tuple with just one item (such as the integer <code>1</code>), called a singleton (see <a href="https://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences">here</a> and <a href="https://docs.python.org/2/library/stdtypes.html?highlight=tuple#sequence-types-s... | 6 | 2016-06-18T09:58:37Z | [
"python",
"tuples"
] |
How to create a tuple of an empty tuple in Python? | 37,895,568 | <p>How can I create a tuple consisting of just an empty tuple, i.e. <code>(())</code>? I have tried <code>tuple(tuple())</code>, <code>tuple(tuple(tuple()))</code>, <code>tuple([])</code> and <code>tuple(tuple([]))</code> which all gave me <code>()</code>.</p>
<p>The reason that I use such a thing is as follows: Assum... | 3 | 2016-06-18T09:45:22Z | 37,895,687 | <p>I'm not surprise this didn't work: <code>(())</code> since the outer parens get interpreted as that: parentheses. so <code>(()) == ()</code> just like <code>(2) == (2)</code>. This should work, however:</p>
<pre><code>((),)
</code></pre>
| 2 | 2016-06-18T09:58:56Z | [
"python",
"tuples"
] |
appending to a list in recursive function | 37,895,718 | <p>I wrote the following recursive program which finds the combination of numbers which can be added to make the target value:</p>
<pre><code>arr = [1, 2, 2, 3, 5]
target = 8
def comb_sum(arr, current_index, target, result, ans):
if target == 0:
print result
ans.append(result)
return 0
... | 2 | 2016-06-18T10:01:54Z | 37,895,830 | <p>Make a copy of the result list and pass like below</p>
<pre><code>comb_sum(arr, current_index+1, target - arr[current_index], result[:], ans)
</code></pre>
<p>There is only one copy of result flowing through the program. So whenever <code>result</code> changes, it also reflects in <code>ans</code>. That's why copy... | 0 | 2016-06-18T10:14:21Z | [
"python",
"recursion",
"combinations"
] |
appending to a list in recursive function | 37,895,718 | <p>I wrote the following recursive program which finds the combination of numbers which can be added to make the target value:</p>
<pre><code>arr = [1, 2, 2, 3, 5]
target = 8
def comb_sum(arr, current_index, target, result, ans):
if target == 0:
print result
ans.append(result)
return 0
... | 2 | 2016-06-18T10:01:54Z | 37,896,067 | <pre><code>import copy
arr = [1, 2, 2, 3, 5]
target = 8
def comb_sum(arr, current_index, target, result, ans):
if target == 0:
print result
ans.append(copy.deepcopy(result) )
return 0
if target < 0:
return 1
if current_index == len(arr):
return 1
result.append(arr[current_index])
comb_sum(arr, ... | 2 | 2016-06-18T10:43:38Z | [
"python",
"recursion",
"combinations"
] |
Unable to run unittest's main function in ipython/jupyter notebook | 37,895,781 | <p>I am giving an example which throws an error in ipython/jupyter notebook, but runs fine as an individual script.</p>
<pre><code>import unittest
class Samples(unittest.TestCase):
def testToPow(self):
pow3 = 3**3
assert pow3==27
if __name__ == '__main__':
unittest.main()
</code></pre>
<p>T... | 2 | 2016-06-18T10:08:18Z | 38,012,249 | <p><code>unittest.main</code> looks at <code>sys.argv</code> by default, which is what started IPython, hence the error about the kernel connection file not being a valid attribute. You can pass an explicit list to <code>main</code> to avoid looking up sys.argv.</p>
<p>In the notebook, you will also want to include <c... | 5 | 2016-06-24T11:23:31Z | [
"python",
"python-2.7",
"ipython-notebook",
"jupyter-notebook",
"python-unittest"
] |
Google App Engine and Cloud SQL: Lost connection to MySQL server at 'reading initial communication packet' SQL 2nd Gen | 37,896,030 | <p>I'm getting an error similar to other posts in this subject.
I tried switching from 1st gen to 2nd gen SQL server (both on us-central1), but it still doesn't work.</p>
<p>I copied my CLOUDSQL_PROJECT from the url on the top of my project.<br>
I copied my CLOUDSQL_INSTANCE from the proprieties part in the SQL page.<... | 1 | 2016-06-18T10:38:19Z | 37,900,685 | <p>The documentation is slightly outdated. You should be able to always use the "Instance connection name" property from the SQL properties page to construct the unix socket path; just append that value after the "/cloudsql/" prefix.</p>
<p>For second generation, the connection format is project:region:name. In your e... | 1 | 2016-06-18T19:09:53Z | [
"python",
"python-2.7",
"google-app-engine",
"google-cloud-sql"
] |
quesrions regarding hurst exponent code in python 3 | 37,896,038 | <p>When I run this code in Python 3ï¼why it shows name âlagsâ not definedï¼</p>
<pre><code>from numpy import log,sqrt,std,subtract,cumsum,polyfit
def hurst(ts):
# Create the range of lag values
lags = range(2, 100)
# Calculate the array of the variances of the lagged differences
tau = [sqrt(std(... | 0 | 2016-06-18T10:39:21Z | 37,896,166 | <p>It looks like you didnt import numpy correctly.</p>
<p>Add this to the top of your code:</p>
<pre><code>import numpy as np
</code></pre>
<p>and then change all calls to be:</p>
<pre><code>np.polyfit(...)
np.sqrt(...)
</code></pre>
<p>or if you only want to import the ones you need:</p>
<pre><code>from numpy im... | 1 | 2016-06-18T10:55:38Z | [
"python"
] |
How to represent a 3D .obj object as a 3D array? | 37,896,090 | <p>Is there any way by which 3D models can be represented as 3D arrays? Are there any libraries that take .obj or .blend files as input and give an array representation of the same?</p>
<p>I thought that I would slice object and export the slices to an image. I would then use those images in opencv to build arrays for... | 3 | 2016-06-18T10:46:26Z | 37,896,517 | <p><a href="http://pygame.org/wiki/OBJFileLoader" rel="nofollow">PyGame</a> has an OBJFileLoader class.
<a href="https://pypi.python.org/pypi/PyWavefront/0.1" rel="nofollow">PyWavefront</a> has a 3D object model.</p>
| 1 | 2016-06-18T11:42:20Z | [
"python",
"c++",
"arrays",
"opencv",
"3d"
] |
How to represent a 3D .obj object as a 3D array? | 37,896,090 | <p>Is there any way by which 3D models can be represented as 3D arrays? Are there any libraries that take .obj or .blend files as input and give an array representation of the same?</p>
<p>I thought that I would slice object and export the slices to an image. I would then use those images in opencv to build arrays for... | 3 | 2016-06-18T10:46:26Z | 37,902,814 | <p>If I understand correctly, you want to create a voxel representation of 3D models? Something like the visible human displays?</p>
<p>I would use one of the OBJ file loaders recommended above to import the model into an OpenGL program. Rotate and scale to whatever alignment you want along XYZ.</p>
<p>Then draw the ... | 1 | 2016-06-19T00:22:34Z | [
"python",
"c++",
"arrays",
"opencv",
"3d"
] |
How to represent a 3D .obj object as a 3D array? | 37,896,090 | <p>Is there any way by which 3D models can be represented as 3D arrays? Are there any libraries that take .obj or .blend files as input and give an array representation of the same?</p>
<p>I thought that I would slice object and export the slices to an image. I would then use those images in opencv to build arrays for... | 3 | 2016-06-18T10:46:26Z | 37,936,160 | <p><a href="http://www.patrickmin.com/binvox/" rel="nofollow">Binvox</a> can be used to generate a voxel representation of a 3D model from a <em>.obj</em> file.</p>
<p><a href="https://github.com/dimatura/binvox-rw-py" rel="nofollow">Binvox-rw-py</a> can be used to read and parse the <em>.binvox</em> file generated ab... | 1 | 2016-06-21T05:21:12Z | [
"python",
"c++",
"arrays",
"opencv",
"3d"
] |
Cannot run bash script from crontab when it runs from command line bash | 37,896,144 | <p>My bash script(myfile.sh) is:</p>
<pre><code>#!/bin/sh
cd shivangi
cd hunt3
source bin/activate
cd backend_repo
sudo python manage.py runcrons
</code></pre>
<p>I am using Ubuntu 15.04</p>
<p>My crontab is :</p>
<pre><code>*/1 * * * * /home/shivangi/myfile.sh
</code></pre>
| 0 | 2016-06-18T10:52:20Z | 37,896,229 | <p>Use absolute paths in your script:</p>
<pre><code># /home/shivangi/myfile.sh
#!/usr/bin/env bash
/home/shivangi/hunt3/bin/python /home/shivangi/hunt3/manage.py runcrons
</code></pre>
| 1 | 2016-06-18T11:03:11Z | [
"python",
"django",
"bash",
"ubuntu",
"crontab"
] |
Error using cx_freeze and PyInstaller to make an .exe file in Python (which includes xlwings) | 37,896,236 | <p><a href="http://stackoverflow.com/questions/37889467/how-to-make-python-change-xlsx-files-when-excel-app-is-opened">Yesterday</a> I asked a question about using Excel and Python simultaneously. The solution was found: using <code>xlwings</code> package.</p>
<p>However, there is another problem connected with that -... | 2 | 2016-06-18T11:03:54Z | 37,897,694 | <p>At least in the case of cx_freeze an explanation can be found: <a href="https://bitbucket.org/anthony_tuininga/cx_freeze/issues/127/collectionssys-error" rel="nofollow">https://bitbucket.org/anthony_tuininga/cx_freeze/issues/127/collectionssys-error</a></p>
<p>Unfortunately <a href="https://pypi.python.org/pypi" re... | 1 | 2016-06-18T13:48:10Z | [
"python",
"excel",
"pyinstaller",
"cx-freeze",
"xlwings"
] |
How to get file extension correctly? | 37,896,386 | <p>I know that this question is asked many times on this website. But I found that they missed an important point: only file extension with one period was taken into consider like <code>*.png *.mp3</code>, but how do I deal with these filename with two period like <code>.tar.gz</code>.</p>
<p>The basic code is:</p>
<... | 2 | 2016-06-18T11:24:41Z | 37,896,418 | <p>Here is a in build module in <code>os</code>. More about <a href="https://docs.python.org/2/library/os.path.html#os.path.splitext" rel="nofollow"><code>os.path.splitext</code></a>.</p>
<pre><code>In [1]: from os.path import splitext
In [2]: file_name,extension = splitext('/home/lancaster/Downloads/a.ppt')
In [3]: e... | 3 | 2016-06-18T11:29:02Z | [
"python"
] |
How to get file extension correctly? | 37,896,386 | <p>I know that this question is asked many times on this website. But I found that they missed an important point: only file extension with one period was taken into consider like <code>*.png *.mp3</code>, but how do I deal with these filename with two period like <code>.tar.gz</code>.</p>
<p>The basic code is:</p>
<... | 2 | 2016-06-18T11:24:41Z | 37,896,436 | <p>One possible way is:</p>
<ol>
<li>Slice at "." => <code>tmp_ext = filename.split('.')[1:]</code></li>
</ol>
<p>Result is a list = <code>['tar', 'gz']</code></p>
<ol start="2">
<li>Join them together => <code>extention = ".".join(tmp_ext)</code></li>
</ol>
<p>Result is your extension as string = <code>'tar.gz'</c... | 1 | 2016-06-18T11:31:17Z | [
"python"
] |
How to get file extension correctly? | 37,896,386 | <p>I know that this question is asked many times on this website. But I found that they missed an important point: only file extension with one period was taken into consider like <code>*.png *.mp3</code>, but how do I deal with these filename with two period like <code>.tar.gz</code>.</p>
<p>The basic code is:</p>
<... | 2 | 2016-06-18T11:24:41Z | 37,896,458 | <pre><code>filename = '/home/lancaster/Downloads/a.tar.gz'
extention = filename.split('/')[-1]
if '.' in extention:
extention = extention.split('.')[-1]
if len(extention) > 0:
extention = '.'+extention
print extention
</code></pre>
| -2 | 2016-06-18T11:33:56Z | [
"python"
] |
How to get file extension correctly? | 37,896,386 | <p>I know that this question is asked many times on this website. But I found that they missed an important point: only file extension with one period was taken into consider like <code>*.png *.mp3</code>, but how do I deal with these filename with two period like <code>.tar.gz</code>.</p>
<p>The basic code is:</p>
<... | 2 | 2016-06-18T11:24:41Z | 37,896,488 | <p><strong>Simplest One:</strong></p>
<pre><code>import os.path
print os.path.splitext("/home/lancaster/Downloads/a.ppt")[1]
# '.ppt'
</code></pre>
| 0 | 2016-06-18T11:37:56Z | [
"python"
] |
How to get file extension correctly? | 37,896,386 | <p>I know that this question is asked many times on this website. But I found that they missed an important point: only file extension with one period was taken into consider like <code>*.png *.mp3</code>, but how do I deal with these filename with two period like <code>.tar.gz</code>.</p>
<p>The basic code is:</p>
<... | 2 | 2016-06-18T11:24:41Z | 37,896,568 | <p>The role of a file extension is to tell the viewer (and sometimes the computer) which application to use to handle the file.</p>
<p>Taking your worst-case example in your comments (<code>a.ppt.tar.gz</code>), this is a PowerPoint file that has been tar-balled and then gzipped. So you need to use a gzip-handling pro... | 3 | 2016-06-18T11:47:00Z | [
"python"
] |
How do I create a wheel from a django app? | 37,896,434 | <p>The reusable app docs (<a href="https://docs.djangoproject.com/en/1.9/intro/reusable-apps/">https://docs.djangoproject.com/en/1.9/intro/reusable-apps/</a>) tells you to list template and static files in <code>MANIFEST.in</code>, but it doesn't look like <code>python setup.py bdist_wheel</code> looks at that file at ... | 10 | 2016-06-18T11:31:03Z | 38,232,945 | <p>The <code>MANIFEST.in</code> file needs to be changed to:</p>
<pre><code>recursive-include myapp *
</code></pre>
<p>This includes everything under <code>myapp/myapp</code> with the correct paths. In particular, this includes <code>myapp/myapp/templates</code>, which is necessary.</p>
<p>The declaration above also... | 1 | 2016-07-06T20:13:50Z | [
"python",
"django",
"setuptools"
] |
Optimisation of Shadow Casting Python | 37,896,498 | <p>I have been working on a Shadow Caster for a small RPG I'm doing.</p>
<p>The trouble I have is that when I use it in my game it is just way way way to slow and induces a horrible lag.</p>
<p>Please do not be too frighten by the lenght of the post. It is fairly straightforward but so that you can run the code I inc... | 0 | 2016-06-18T11:40:16Z | 37,916,666 | <p>Your lag issue appears to be coming from the method <code>Night_Mask.apply_shadows(self, obstacles)</code>. This appears to be due to the pure amount of iterations the nested for loop needs to go through.</p>
<p>Reducing the value of <code>range_</code> in the constructor of <code>Light_Source(x, y, range_)</code> ... | 0 | 2016-06-20T07:21:56Z | [
"python",
"optimization",
"pygame",
"shadow",
"bresenham"
] |
pass multiple parameters to function in multiple tuple sets - python | 37,896,509 | <p>essentially I have a function which I need to pass to a bunch of values in two different moments (here skipped for practical reasons), hence, I thought need to split all the parameters in two tuple sets after which I'd pass the first set and then the second thinking - mistakenly - that python would allocate all the ... | 0 | 2016-06-18T11:41:30Z | 37,896,538 | <p>A very simple way is to concatenate the tuples and then unpack them as you pass them to your function:</p>
<pre><code>print(example_F_2(*(e+r)))
</code></pre>
| 2 | 2016-06-18T11:44:12Z | [
"python",
"function",
"functional-programming",
"tuples"
] |
pass multiple parameters to function in multiple tuple sets - python | 37,896,509 | <p>essentially I have a function which I need to pass to a bunch of values in two different moments (here skipped for practical reasons), hence, I thought need to split all the parameters in two tuple sets after which I'd pass the first set and then the second thinking - mistakenly - that python would allocate all the ... | 0 | 2016-06-18T11:41:30Z | 37,896,601 | <p>Perhaps you can use something like this:</p>
<pre><code>def example_F_2(e=None, r=None):
first_term = 0
second_term = 0
if e is not None:
first_term = e[0] * e[1]
if r is not None:
second_term = r[0] * r[1]
return first_term + second_term
e = (1, 2)
r = (3, 4)
print example_F_2... | 0 | 2016-06-18T11:51:25Z | [
"python",
"function",
"functional-programming",
"tuples"
] |
Flask: Mock call to external component returns a non serializable object for a HTTP response | 37,896,590 | <p>I'm trying to learn how to use the Mock library in python.</p>
<p>I have a Flask application which is connected to Redis via redis-py package.</p>
<p>In the '/myapp/version' API of my app, I call a info() from redis-py, and format a HTTP response back where the JSON data includes also the return data from the info... | 0 | 2016-06-18T11:49:23Z | 37,899,064 | <p>The best way to mock <code>redis-py</code> package is ti use <code>mockredis</code>. You need to simply patch your method using: <code>@patch('redis.StrictRedis', mock_strict_redis_client)</code>. More info can be found on the project <a href="https://github.com/locationlabs/mockredis" rel="nofollow">page</a>.</p>
... | 1 | 2016-06-18T16:14:39Z | [
"python",
"json",
"flask",
"redis",
"mocking"
] |
How to make only specific user getting a newsletter-mail (Django) | 37,896,634 | <p>I am trying to implement a newsletter and added a choice field to my UserProfile class, to let users select if they want to get an newsletter or not:</p>
<pre><code>class UserProfile(models.Model):
user = models.OneToOneField(User)
YES = 'YS'
NO = 'NO'
NEWS_CHOICES = (
(YES, 'Yes'),
... | 0 | 2016-06-18T11:55:32Z | 37,896,781 | <p>As the error indicates, <code>reader</code>, is a queryset, but you seem to be treating it as an single instance of <code>UserProfile</code>. This should work to add all the recipients to the list:</p>
<pre><code>to_list = [r.user.email for r in reader]
</code></pre>
<p>Do note however the <a href="https://docs.dj... | 1 | 2016-06-18T12:11:57Z | [
"python",
"django",
"django-models",
"django-views"
] |
Expecting value on the json.loads | 37,896,768 | <p>in my app am calling a php script which will return a json encoded string</p>
<pre><code> output = str(subprocess.check_output(["php","-f" , "../connector/somefile.php" ,"code_string:"+code_string]));
print(output)
</code></pre>
<p>here is my print(output)</p>
<pre><code>b'{"success":"1","code":"pewcndIi... | -1 | 2016-06-18T12:09:22Z | 37,896,898 | <p><code>'b</code> stands for byte-string, if you decode it, it should work </p>
<pre><code>json.loads(output.decode('utf-8'))
{'code': 'pewcndIiD8WcB5MdH+8JOAVJ03xlt92sIUYgs2m2tIGtLohnDHjBP8s8x9/YroJnyrCLcyN6Brwicn9/DS4j9kH8a6gcOKFS1
bpmvdKxJSrmgT0aOz0u16npbt1ldklXx16WEybEN4gKG0DI=', 'success': '1'}
</code></pre>
| 1 | 2016-06-18T12:23:36Z | [
"python",
"json",
"django"
] |
django get context from external app in main template | 37,896,785 | <p>I have integrated <a href="https://github.com/nephila/djangocms-blog" rel="nofollow">djangocms blog</a> in my project. In homepage sidebar i want to display latest blog posts. Problem is, my homepage is django-cms page and i can't get blog post objects. urls.py: </p>
<pre><code>urlpatterns = i18n_patterns('',
u... | 1 | 2016-06-18T12:12:36Z | 37,898,725 | <p>Use either an <code>assignment_tag</code> or an <code>inclusion_tag</code>:</p>
<h3>Templatetag</h3>
<pre><code># templatetags/blog_tags.py
from django import template
from djangocms_blog.models import Post
register = template.Library()
@register.assignment_tag()
def latest_posts_as(limit=5):
return Post.obj... | 1 | 2016-06-18T15:38:55Z | [
"python",
"django"
] |
django get context from external app in main template | 37,896,785 | <p>I have integrated <a href="https://github.com/nephila/djangocms-blog" rel="nofollow">djangocms blog</a> in my project. In homepage sidebar i want to display latest blog posts. Problem is, my homepage is django-cms page and i can't get blog post objects. urls.py: </p>
<pre><code>urlpatterns = i18n_patterns('',
u... | 1 | 2016-06-18T12:12:36Z | 37,905,318 | <p>Came up with other solution. Created new django-cms plugin:</p>
<pre><code>class BlogLatestEntriesPluginNav(BlogLatestEntriesPlugin):
name = _('Navigition latest blog entries')
render_template = 'latest_entries_nav.html'
plugin_pool.register_plugin(BlogLatestEntriesPluginNav)
</code></pre>
<p>where <code>... | 0 | 2016-06-19T08:26:17Z | [
"python",
"django"
] |
PyPDF module doesn' t make valid pdf file | 37,896,821 | <p>i'm trying to make some program in python to manipulate my pdf beamer presentations. Professor use on click dynamic transition so one page has several click transitions. I want to print those presentations but i have around 5000 pages. So i want to use just the last click transition page, so i will minimize number o... | 0 | 2016-06-18T12:16:17Z | 37,897,492 | <p><code>from pyPdf import PdfFileWriter, PdfFileReader</code> pyPdf is discontinued already and is succeeded by PyPDF2. I am not sure about Python 2, but in Python 3 you should <code>import PyPDF2</code>. </p>
<ol>
<li>No need to <code>import os, sys</code>. However, you can call <code>python3 xyz.py some_arg</code> ... | 0 | 2016-06-18T13:26:12Z | [
"python",
"file",
"pdf",
"pypdf2"
] |
problems with if in a function | 37,896,874 | <p>I am doing a simple program just to the program say if a number is even or not and to when the raw_input isn't a number, the program will complain about it:</p>
<pre><code>def f():
t = raw_input('Enter a number and we will send an inormation: ')
if t != type(int):
print 'is this a number?'
elif int(t) % ... | -4 | 2016-06-18T12:21:58Z | 37,896,988 | <p>Many errors here.</p>
<p>First, use <code>isintance</code> to test if a variable is an int. Do not use <code>type(t) != int</code>.</p>
<p>Then you do the <code>int(t)</code> operation multiple times.</p>
<p>In addition, it seems that t is a global var, which is not recommended to use, especially for beginners.</... | 1 | 2016-06-18T12:32:09Z | [
"python",
"function",
"if-statement"
] |
problems with if in a function | 37,896,874 | <p>I am doing a simple program just to the program say if a number is even or not and to when the raw_input isn't a number, the program will complain about it:</p>
<pre><code>def f():
t = raw_input('Enter a number and we will send an inormation: ')
if t != type(int):
print 'is this a number?'
elif int(t) % ... | -4 | 2016-06-18T12:21:58Z | 37,897,020 | <p>You can use <code>if t.isdigit():</code></p>
<p><code>type(int)</code> returns the type of the object which will never be a value. So it will always be false.</p>
| 0 | 2016-06-18T12:35:24Z | [
"python",
"function",
"if-statement"
] |
problems with if in a function | 37,896,874 | <p>I am doing a simple program just to the program say if a number is even or not and to when the raw_input isn't a number, the program will complain about it:</p>
<pre><code>def f():
t = raw_input('Enter a number and we will send an inormation: ')
if t != type(int):
print 'is this a number?'
elif int(t) % ... | -4 | 2016-06-18T12:21:58Z | 37,897,109 | <p>This is caused by the fact that raw_input always returns a string, even if there is only numbers used. You need to type cast it as int and then check if it is odd or even, and catch an exception if it is not able to be converted to int. This is how you should do it:</p>
<pre><code>def f():
try:
t = int... | 0 | 2016-06-18T12:45:21Z | [
"python",
"function",
"if-statement"
] |
How to display image result on window in python openCV | 37,896,999 | <p>I intend to show the optical flow result and difference image between every pair of images, but the image window always display the result from the last pair even I can see the images have been written correctly.<br>
cv2.imshow('flow',bgr)
cv2.imshow('diff',diff)
Could someone shed a light on this, thanks!</... | 0 | 2016-06-18T12:33:25Z | 37,897,097 | <p>You need to put the <code>waitKey()</code> inside the <code>while</code> loop:</p>
<pre><code>import numpy as np
import cv2
dirOC = 'ImgDir_OriC\\'
dirTC = 'ImgDir_TransC\\'
suffix = '.bmp'
fCount = 11
count = 0
MAX = 10
while(count < MAX ):
fNameO = dirOC + str(fCount) + suffix
fNameT = dirTC + str(... | 1 | 2016-06-18T12:43:41Z | [
"python",
"opencv"
] |
Appending elements generated by a for loop into an array | 37,897,025 | <p>I want to generate an array containing all the elements produced by a for loop. I haven't found anything relevant or helpful in the NumPy manual or stackoverflow. This is the problematic part of the code.</p>
<pre><code>import numpy as np
for i in range(0,26):
d = np.random.uniform(i,i+1.75)
empty = np.arr... | 2 | 2016-06-18T12:36:00Z | 37,897,437 | <p>Your <code>all</code> should be placed outside the loop, so you can avoid overwriting previously written values and the value should be updated and not reassigned to a new append with <code>empty</code>:</p>
<pre><code>import numpy as np
all = np.array([])
for i in range(0,26):
d = np.random.uniform(i,i+1.75)... | 1 | 2016-06-18T13:21:28Z | [
"python",
"arrays",
"python-2.7",
"numpy",
"for-loop"
] |
Appending elements generated by a for loop into an array | 37,897,025 | <p>I want to generate an array containing all the elements produced by a for loop. I haven't found anything relevant or helpful in the NumPy manual or stackoverflow. This is the problematic part of the code.</p>
<pre><code>import numpy as np
for i in range(0,26):
d = np.random.uniform(i,i+1.75)
empty = np.arr... | 2 | 2016-06-18T12:36:00Z | 37,897,537 | <p>@Moses's answer works fine, but you can achieve this directly in numpy. <code>np.random.uniform</code> also takes a size parameter. <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.uniform.html" rel="nofollow">See documentation</a>. Your code can therefore be simplified to:</p>
<pre><code>a... | 1 | 2016-06-18T13:30:48Z | [
"python",
"arrays",
"python-2.7",
"numpy",
"for-loop"
] |
How to re-order my Pandas dataframe other than using the "columns.tolist()" method? I want a particular column to appear last always | 37,897,029 | <p>my dataframe is like this:</p>
<pre><code>In [57]: final_data
Out[57]:
monthyear Date Planned CCM1 CCM2
0 Dec 15 2015-12-01 0.0 0.000000 2550.000000
1 Feb 16 2016-02-01 0.0 0.000000 4250.000000
2 Jan 16 2016-01-01 0.0 1540.0000... | 1 | 2016-06-18T12:36:24Z | 37,897,280 | <p>you can do something like this: </p>
<pre><code> df
Out[17]:
monthyear Date Planned CCM1 CCM2
0 Dec 15 2015-12-01 0 0.000000 2550.000000
1 Feb 16 2016-02-01 0 0.000000 4250.000000
2 Jan 16 2016-01-01 0 1540.000000 6800.000000
3 Nov 15 ... | 2 | 2016-06-18T13:04:37Z | [
"python",
"pandas"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.