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 |
|---|---|---|---|---|---|---|---|---|---|
Still having issues deploying flask app on Godaddy shared hosting | 37,692,882 | <p>I've been trying now for some time to deploy my flask app on a Godaddy hosting server. I have done extensive searches online and followed them but I'm still having issues. Right now my app is just displaying as ordinary html so I'm having things like {{my_var}} displayed on the page. My flask app works locally and t... | 0 | 2016-06-08T03:47:03Z | 38,015,467 | <p>I have similar problems. I understand that an <strong>index.htm</strong> file must be placed at <strong>public_html</strong>, but when you try to do <strong>render_template("index.htm")</strong>, Flask will look for this file in the <strong>templates</strong> folder. The rendering is not actually executed. The <stro... | 0 | 2016-06-24T14:10:57Z | [
"python",
".htaccess",
"flask",
"cgi",
"shared-hosting"
] |
Is it a good idea to call a staticmethod in python on self rather than the classname itself | 37,692,915 | <p>If I have the following class.</p>
<pre><code>class Foo:
@staticmethod
def _bar():
# do something
print "static method"
def instancemethod(self):
Foo._bar() # method 1
self._bar() # method 2
</code></pre>
<p>In this case, is method 1 a preferred way of calling staticme... | 4 | 2016-06-08T03:50:52Z | 37,692,960 | <p>Write the code that expresses what you want to do. If you want to call this method right here:</p>
<pre><code>class Foo:
@staticmethod
def _bar(): # <-- this one
# do something
print "static method"
</code></pre>
<p>then specify that particular method:</p>
<pre><code>Foo._bar()
</code>... | 4 | 2016-06-08T03:56:13Z | [
"python",
"python-2.7",
"python-3.x"
] |
Using console commands in python | 37,692,935 | <p>I am using console commands in python, however, it is not outputting the value I want. </p>
<p>The path is:</p>
<pre><code>#ifconfig -a | grep "HWaddr"
</code></pre>
<p>From this command I get:</p>
<pre><code>eth0 Link encap:Ethernet HWaddr 30:9E:D5:C7:1z:EF
eth1 Link encap:Ethernet HWaddr 30:0E:95:97:0A... | 0 | 2016-06-08T03:53:23Z | 37,693,161 | <p>The most robust and easy way in Linux to get the MAC address is to get it from <code>sysfs</code>, mounted on <code>/sys</code>.</p>
<p>For interface <code>etho</code>, the location would be <code>/sys/class/net/eth0/address</code>; Similarly for <code>eth1</code>, it would be <code>/sys/class/net/eth1/address</cod... | 1 | 2016-06-08T04:17:45Z | [
"python",
"linux",
"console",
"command",
"nic"
] |
Using console commands in python | 37,692,935 | <p>I am using console commands in python, however, it is not outputting the value I want. </p>
<p>The path is:</p>
<pre><code>#ifconfig -a | grep "HWaddr"
</code></pre>
<p>From this command I get:</p>
<pre><code>eth0 Link encap:Ethernet HWaddr 30:9E:D5:C7:1z:EF
eth1 Link encap:Ethernet HWaddr 30:0E:95:97:0A... | 0 | 2016-06-08T03:53:23Z | 37,693,239 | <p>Quoting from <a href="http://stackoverflow.com/a/159195/4104748">here</a>.</p>
<p>Python 2.5 includes an uuid implementation which (in at least one version) needs the mac address. You can import the mac finding function into your own code easily:</p>
<pre><code>from uuid import getnode as get_mac
mac = get_mac()
<... | 1 | 2016-06-08T04:25:49Z | [
"python",
"linux",
"console",
"command",
"nic"
] |
Using console commands in python | 37,692,935 | <p>I am using console commands in python, however, it is not outputting the value I want. </p>
<p>The path is:</p>
<pre><code>#ifconfig -a | grep "HWaddr"
</code></pre>
<p>From this command I get:</p>
<pre><code>eth0 Link encap:Ethernet HWaddr 30:9E:D5:C7:1z:EF
eth1 Link encap:Ethernet HWaddr 30:0E:95:97:0A... | 0 | 2016-06-08T03:53:23Z | 37,693,728 | <pre><code>import subprocess
def getmac(command):
return subprocess.check_output(command, shell=True)
command = "ifconfig -a | grep HWaddr"
print "%s" %(getmac(command).split()[9])
# or print out the entire list to see which index your HWAddr corresponds to
# print "%s" %(getmac(command).split())
</code></pre>
... | 0 | 2016-06-08T05:12:06Z | [
"python",
"linux",
"console",
"command",
"nic"
] |
How do I run a python/pygame script with command-line arguments? | 37,692,944 | <p>I'm not very experienced with python beyond the basics, but I'm trying to run a pygame written by someone else. However, the game uses some initial inputs set by sys.argv, which I've deduced are the command-line arguments. Because I don't know how to include these when running the script, they don't exist, and thus ... | -1 | 2016-06-08T03:54:27Z | 37,693,170 | <p>Command-line arguments are set simply by running the file from a <a href="http://www.computerhope.com/issues/chdos.htm" rel="nofollow">command prompt</a> and adding them in space-separated format:</p>
<pre><code>my_script.py myArg 77 "and so on..."
</code></pre>
| 0 | 2016-06-08T04:18:19Z | [
"python",
"pygame"
] |
Why does send_keys("string") place spaces in between each character? | 37,692,969 | <p>So I am automating search terms from a list of lists.
Right now I have:</p>
<pre><code>search_terms = KeyWordExtract(keyWord_List)
browser.find_element_by_id('terms').send_keys(search_terms)
def KeyWordExtract(keyWord_List):
myString = " ".join(keyWord_List)
return myString
</code></pre>
<p>If I have ... | 0 | 2016-06-08T03:56:56Z | 37,693,015 | <p>Your first list is <code>['nasa', 'rocket', 'hopkins']</code>. Your <code>KeyWordExtract</code> just takes a list and returns the concatenated strings separated by space.</p>
<p>To do what you want to do, replace</p>
<pre><code>myString = " ".join(keyWord_List)
</code></pre>
<p>with</p>
<pre><code>myString = ' '... | 0 | 2016-06-08T04:02:59Z | [
"python",
"selenium",
"web-scraping"
] |
How to print EC2 Tag name along with IP address? | 37,692,974 | <p>I have a code which prints the Public IP's for the running instances, </p>
<pre><code>regions = ['us-east-1','us-west-1','us-west-2','eu-west-1','sa-east-1','ap-southeast-1','ap-southeast-2','ap-northeast-1']
for region in regions:
client = boto3.client('ec2',aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SEC... | 0 | 2016-06-08T03:57:22Z | 37,693,734 | <p>Try the following code, it will give you a dictionary where the key is the <code>InstanceId</code> and the value is a list of <code>[PublicIP, Name]</code>.</p>
<pre><code>import boto3
def instance_info():
instance_information = {}
ip_dict = {}
client = boto3.client('ec2')
addresses_dict = client.d... | 1 | 2016-06-08T05:12:28Z | [
"python",
"amazon-ec2",
"boto3"
] |
Installing Flask using Pip | 37,693,098 | <p>I'm a first timer to Python and I'm trying to set up an easy quick backend with it. When trying to install Flask using Pip I run this and see the following error:</p>
<pre><code>Rutgers-MacBook-Pro:~ rutger$ pip install flask
Collecting flask
Downloading Flask-0.11.1-py2.py3-none-any.whl (80kB)
100% |âââ... | 0 | 2016-06-08T04:12:39Z | 37,693,139 | <p>As you can see in the output, the error is</p>
<p><code>
error: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/itsdangerous.py'
</code></p>
<p>You can try again with <code>sudo pip install flask</code> which lets you run the original command as the root user.</p>
| 2 | 2016-06-08T04:15:44Z | [
"python",
"python-2.7",
"pip"
] |
Conduct DBSCAN on radian distance matrix with sklearn? | 37,693,119 | <p>I wish to conduct clustering on several timestamps(in minutes).
So what i've done so far is:</p>
<p>1) Convert points to radian</p>
<pre><code>#points containing time value in minutes
points = [100, 200, 600, 659, 700]
def convert_to_radian(x):
return((x / (24 * 60)) * 2 * pi)
rad_function = np.vectorize(con... | 0 | 2016-06-08T04:14:15Z | 37,805,986 | <p>Okay so after much digging i realized that i could simply just set DBSCAN metric to 'precomputed', use the <code>.fit()</code> method and pass in my distance matrix. For those that are interested here is the source:</p>
<pre><code>import numpy as np
from math import pi
from sklearn.cluster import DBSCAN
#points co... | 0 | 2016-06-14T07:47:29Z | [
"python",
"numpy",
"scipy",
"scikit-learn",
"data-mining"
] |
how to subtract one column data from 2nd row to 1st row in csv files using python | 37,693,129 | <p>I have CSV file with data like<br></p>
<pre><code>data,data,10.00
data,data,11.00
data,data,12.00
</code></pre>
<p>I need to update this as</p>
<pre><code>data,data,10.00
data,data,11.00,1.00(11.00-10.00)
data,data,12.30,1.30(12.30-11.00)
</code></pre>
<p>could you help me to update the <code>csv file</code> usi... | -2 | 2016-06-08T04:14:56Z | 37,697,470 | <p>You can use <code>pandas</code> and <code>numpy</code>. <code>pandas</code> reads/writes the csv and <code>numpy</code> does the calculations:</p>
<pre><code>import pandas as pd
import numpy as np
data = pd.read_csv('test.csv', header=None)
col_data = data[2].values
diff = np.diff(col_data)
diff = np.insert(diff, ... | 0 | 2016-06-08T08:43:12Z | [
"python",
"csv"
] |
How to use virtualenv inside a folder? | 37,693,154 | <p>I try to use <code>virtualenv</code> inside a folder using the command <code>virtualenv .</code> and getting the error <code>-bash: virtualenv: command not found</code>. However, I installed <code>virtualenv</code> using pip <code>pip installed virtualenv</code> and also, upgraded it earlier with <code>sudo pip inst... | 0 | 2016-06-08T04:17:09Z | 37,693,496 | <p>This is pretty simple<br>Just goto environment folder<br>
Try: <code>Scripts/activate</code><br>
This will activate the environment<br>
Try:<code>Scripts/deactivate</code><br>
This will deactivate current environment</p>
| 0 | 2016-06-08T04:50:13Z | [
"python",
"virtualenv"
] |
Change a value using mouse click with pygame | 37,693,300 | <p>I am trying to create a nice and simple game just for practice with pygame, and I was trying to change a value using mouse click and I can't find out what to do</p>
<pre><code>global item
ev = pygame.event.get()
item = 0
while True:
for event in ev:
if event.type == QUIT:
pygame.quit()
sys.exi... | 0 | 2016-06-08T04:30:41Z | 37,695,374 | <p>Welcome to stackoverflow.</p>
<p>A simple script where clicking in the window increments <code>item</code> by 1 and prints it:</p>
<pre><code>import pygame
pygame.init()
screen = pygame.display.set_mode((400,400))
clock = pygame.time.Clock()
item = 0
done = False
while not done:
for event in pygame.event.... | 0 | 2016-06-08T07:00:45Z | [
"python",
"pygame",
"mouseclick-event"
] |
wait a process to finish in Python script | 37,693,372 | <p>I'm writing a Python script to run several executables one by one on Windows. I need to wait a program to finish before starting the next.</p>
<p>So the script will be like this.</p>
<pre><code>1: launch a.exe
2: wait till a.exe finishes running
3: launch b.exe
4: wait till b.exe finishes
</code></pre>
<p>Anyone... | 0 | 2016-06-08T04:37:12Z | 37,693,472 | <p>If you wish to wait for your launched process, you can simply use subprocess.call() . This method executes the command in args and waits for it to complete. For reference, see <a href="https://docs.python.org/2/library/subprocess.html" rel="nofollow">this</a></p>
<pre><code>import subprocess
subprocess.call(('somep... | 3 | 2016-06-08T04:46:59Z | [
"python",
"subprocess"
] |
sort Python list with two keys but only one in reverse order | 37,693,373 | <p>I was wondering what would be a Pythonic way of sorting a list of tuples by two keys whereby sorting with one (and only one) key would be in a reverse order and sorting with the the other would be case insensitive.
More specifically, I have a list containing tuples like:</p>
<pre><code>myList = [(ele1A, ele2A),(ele... | 3 | 2016-06-08T04:37:23Z | 37,693,603 | <p>Two keys will be used when we need to sort a list with two constraints one in ascending order and other in descending in the same list or any
<br>In your example <br><code>sortedList = sorted(myList, key = lambda y: (y[0].lower(), y[1]))</code> can sort entire list only in one order
<br>you can try these and check w... | 2 | 2016-06-08T05:00:11Z | [
"python",
"sorting"
] |
sort Python list with two keys but only one in reverse order | 37,693,373 | <p>I was wondering what would be a Pythonic way of sorting a list of tuples by two keys whereby sorting with one (and only one) key would be in a reverse order and sorting with the the other would be case insensitive.
More specifically, I have a list containing tuples like:</p>
<pre><code>myList = [(ele1A, ele2A),(ele... | 3 | 2016-06-08T04:37:23Z | 37,693,791 | <p>Sometimes there is little alternative but to use a comparator function. There was a <code>cmp</code> argument to <code>sorted</code> from its introduction to 2.4, but it was removed from Python 3 in favour of the more efficient <code>key</code> function. In 3.2, <code>cmp_to_key</code> was added to <code>functools</... | 1 | 2016-06-08T05:18:29Z | [
"python",
"sorting"
] |
sort Python list with two keys but only one in reverse order | 37,693,373 | <p>I was wondering what would be a Pythonic way of sorting a list of tuples by two keys whereby sorting with one (and only one) key would be in a reverse order and sorting with the the other would be case insensitive.
More specifically, I have a list containing tuples like:</p>
<pre><code>myList = [(ele1A, ele2A),(ele... | 3 | 2016-06-08T04:37:23Z | 37,693,792 | <h1>Method 1</h1>
<p>A simple solution, but might not be the most efficient is to sort twice: the first time using the second element, the second using the first element:</p>
<pre><code>sortedList = sorted(sorted(myList, key=lambda (a,b):b, reverse=True), key=lambda(a,b):a)
</code></pre>
<p>Or break down:</p>
<pre>... | 0 | 2016-06-08T05:18:29Z | [
"python",
"sorting"
] |
ImportError: No module named _smbus_cffi | 37,693,459 | <p>Okay, I'am programming a robot with pi2go.py imported to my program. I'am running Linux debian on Raspberry pi (Linux raspberrypi 4.1.19-v7+). Pi2go imports pca9685.py that imports smbus. First of all, the smbus was not installed on my system so I got a smbus-cffi package for python. Ok, now I copied the smbus direc... | 0 | 2016-06-08T04:45:53Z | 37,710,903 | <p>Well, it appeared that I was using a wrong package.
Here is what I did:</p>
<p>I followed the instructions on this site:</p>
<p>Here are these commands: <a href="https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=99980" rel="nofollow">https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=99980</a></... | 0 | 2016-06-08T19:07:52Z | [
"python",
"linux",
"debian"
] |
Flask: Nothing matches the given URI | 37,693,488 | <p>I'm trying to upload a file using Flask.
Here is my HTML code</p>
<pre class="lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
<head>
<title>Python Starter Application</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel... | -1 | 2016-06-08T04:49:06Z | 37,695,417 | <p>like you are using flask i think that the best solution would be a flask solution like:</p>
<pre><code>def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(reque... | -1 | 2016-06-08T07:03:16Z | [
"python",
"python-2.7",
"http",
"flask",
"request"
] |
how to add specific elements of a tuple | 37,693,497 | <p>I have:</p>
<pre><code>([(5,2),(7,2)],[(5,1),(7,3),(11,1)])
</code></pre>
<p>I need to add the second elements having the same first element.</p>
<p>output:<code>[(5,3),(7,5),(11,1)]</code></p>
| 0 | 2016-06-08T04:50:27Z | 37,693,567 | <p>This is a great use-case for <code>collections.Counter</code>...</p>
<pre><code>from collections import Counter
tup = ([(5,2),(7,2)], [(5,1),(7,3),(11,1)])
counts = sum((Counter(dict(sublist)) for sublist in tup), Counter())
result = list(counts.items())
print(result)
</code></pre>
<p>One downside here is that yo... | 1 | 2016-06-08T04:56:41Z | [
"python",
"list",
"tuples"
] |
how to add specific elements of a tuple | 37,693,497 | <p>I have:</p>
<pre><code>([(5,2),(7,2)],[(5,1),(7,3),(11,1)])
</code></pre>
<p>I need to add the second elements having the same first element.</p>
<p>output:<code>[(5,3),(7,5),(11,1)]</code></p>
| 0 | 2016-06-08T04:50:27Z | 37,693,624 | <p>Try this code: (Brute force, may be..)</p>
<pre><code>dt = {}
tp = ([(5,2),(7,2)],[(5,1),(7,3),(11,1)])
for ls in tp:
for t in ls:
dt[t[0]] = dt[t[0]] + t[1] if t[0] in dt else t[1]
print dt.items()
</code></pre>
<hr>
<p>The approach taken here is to loop through the list of tuples and store the tuple's dat... | 1 | 2016-06-08T05:03:16Z | [
"python",
"list",
"tuples"
] |
How to make kafka-python or pykafka work as an async producer with uwsgi and gevent? | 37,693,563 | <p>My Stack is uwsgi with gevents. I am trying to wrap my api end points with a decorator to push all request data (url, method, body and response) to a kafka topic, But its not working. My theory is because I am using gevents, and I am trying to run these in async mode, the async thread which actually pushes to kafka,... | 1 | 2016-06-08T04:56:08Z | 39,453,666 | <p>I have more experience with pykafka so I can answer that section. pykafka uses a pluggable thread handler and gevent support is built in. You need to instantiate the KafkaClient with <code>use_greenlets=True</code>. Docs <a href="http://pykafka.readthedocs.io/en/latest/api/client.html#pykafka.client.KafkaClient" rel... | 0 | 2016-09-12T15:18:21Z | [
"python",
"apache-kafka",
"uwsgi",
"gevent",
"pykafka"
] |
returning a list of strings separated by a delimiter | 37,693,564 | <p>Im having some problems trying to solve this question. Its from a practice exam and I just can't seem to get it right. Im supposed to write a python function that takes in a string and a delimiter, and return a list back with the string stripped of the delimiter. We are not allowed to use the split function or "any ... | 1 | 2016-06-08T04:56:08Z | 37,693,691 | <p>simply use join operator this will join entire list with a given delimiter.
Here in this you can use empty delimiter ''.
try:</p>
<pre><code>a=['T', 'h', 'i', 's', ' ', 'i', 's', ' ', 's', 'o', ' ', 'f', 'u', 'n', ' ', 'I', ' ', 'l', 'o', 'v', 'e', ' ', 'i', 't']
''.join(a)
</code></pre>
<p>output will be</p>
<pr... | -1 | 2016-06-08T05:09:22Z | [
"python",
"split"
] |
returning a list of strings separated by a delimiter | 37,693,564 | <p>Im having some problems trying to solve this question. Its from a practice exam and I just can't seem to get it right. Im supposed to write a python function that takes in a string and a delimiter, and return a list back with the string stripped of the delimiter. We are not allowed to use the split function or "any ... | 1 | 2016-06-08T04:56:08Z | 37,693,693 | <p>If you join all the elements in the list you will get a single string which may not be what you are looking for.</p>
<p>Create a string before append it to the list like;</p>
<pre><code>>>> def StringToken(string, tmp):
newStrlist = []
newStr = ''
for i in range(len(string)):
if string... | 3 | 2016-06-08T05:09:27Z | [
"python",
"split"
] |
returning a list of strings separated by a delimiter | 37,693,564 | <p>Im having some problems trying to solve this question. Its from a practice exam and I just can't seem to get it right. Im supposed to write a python function that takes in a string and a delimiter, and return a list back with the string stripped of the delimiter. We are not allowed to use the split function or "any ... | 1 | 2016-06-08T04:56:08Z | 37,693,766 | <p>See comments in the code for a description. </p>
<pre><code>def StringToken(string, tmp):
newStr = "" # A string to build upon
lst = [] # The list to return
for c in string: # Iterate over the characters
if tmp == c: # Check for the character to strip
if newStr != "": # Prev... | 0 | 2016-06-08T05:16:06Z | [
"python",
"split"
] |
returning a list of strings separated by a delimiter | 37,693,564 | <p>Im having some problems trying to solve this question. Its from a practice exam and I just can't seem to get it right. Im supposed to write a python function that takes in a string and a delimiter, and return a list back with the string stripped of the delimiter. We are not allowed to use the split function or "any ... | 1 | 2016-06-08T04:56:08Z | 37,693,777 | <p>Instead of looping over the all the letters in the string, you can use <code>find</code> to get the index of the next occurrence of the delimiter and then build your list accordingly:</p>
<pre><code>def tokenizer(string, delim):
new_list = []
while True:
index = string.find(delim) # use find to nex... | 0 | 2016-06-08T05:17:05Z | [
"python",
"split"
] |
returning a list of strings separated by a delimiter | 37,693,564 | <p>Im having some problems trying to solve this question. Its from a practice exam and I just can't seem to get it right. Im supposed to write a python function that takes in a string and a delimiter, and return a list back with the string stripped of the delimiter. We are not allowed to use the split function or "any ... | 1 | 2016-06-08T04:56:08Z | 37,693,891 | <p>Here's an alternative that's a little shorter than the current answers:</p>
<pre><code>def StringToken(string, tmp):
newStr = []
start = 0
for ind, char in enumerate(string):
if char == tmp:
newStr.append(string[start:ind])
start = ind + 1
return newStr
</code></pre>
... | 0 | 2016-06-08T05:27:19Z | [
"python",
"split"
] |
how to sort dataframe based on particular (string)columns using python pandas? | 37,693,600 | <p>My dataframe contains following data</p>
<pre><code>product,values
a1,10
a5,20
a10,15
a2,45
a3,12
a6,67
</code></pre>
<p>I have to sort dataframe based on product column.
I need output like:</p>
<pre><code>product,values
a10,15
a6,67
a5,20
a3,12
a2,45
a1,10
</code></pre>
<p>I am facing following error:</p>
<blo... | 1 | 2016-06-08T04:59:45Z | 37,693,650 | <p>You can first <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.extract.html" rel="nofollow"><code>extract</code></a> <code>digits</code> and cast to <code>int</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.astype.html" rel="nofollow"><code>astyp... | 0 | 2016-06-08T05:04:52Z | [
"python",
"python-2.7",
"sorting",
"pandas",
"dataframe"
] |
Convert string column to DateTime format | 37,693,677 | <p>I have a DataFrame column where value is of string type 'June 6, 2016, 6' and I want to convert it into DataTime as 'YYYY-MM-DD HH:MM' format.</p>
<p>When tried convert by just taking value , I could able to convert it into right format.</p>
<pre><code>import datetime
stringDate = "June 6, 2016, 11"
dateObject = d... | 1 | 2016-06-08T05:07:52Z | 37,693,704 | <p>I think you need add parameter <code>format</code> to <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>to_datetime</code></a>:</p>
<pre><code>print (pd.to_datetime('June 6, 2016, 11', format='%B %d, %Y, %H'))
2016-06-06 11:00:00
</code></pre>
<p>It works ... | 2 | 2016-06-08T05:10:08Z | [
"python",
"string",
"datetime",
"pandas",
"dataframe"
] |
Concatenating two data frames on large no. of columns | 37,693,702 | <p>I have to Use concatenate function for large no. of columns. Let say this my function.</p>
<pre><code>pd.concat([mdf1[['user','tag1','tag2','tag3','tag4']].groupby(['user']).agg(sum)
</code></pre>
<p>Here I have large no. of tags so I want my function to take all the columns say after 'tag1' how can I do that?
mdf... | 1 | 2016-06-08T05:10:01Z | 37,694,106 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> and aggregating <a href="http://pandas.... | 1 | 2016-06-08T05:42:36Z | [
"python",
"pandas",
"dataframe",
"concatenation"
] |
Running python program on linux | 37,693,750 | <p>I'm not very familiar with linux as well as python. I'm taking this class that have example code of a inverted index program on python. I would like to know how to run and test the code. Here's the code that was provided to me.</p>
<p>This is the code for the mapping file. (inverted_index_map.py)</p>
<pre><code>im... | 0 | 2016-06-08T05:14:39Z | 37,693,821 | <p>You'll need to run the script using the <code>python</code> command to invoke the python interpreter and pass the path to your script as an argument. Check out this article, I think it will help get you started:</p>
<p><a href="http://pythoncentral.io/execute-python-script-file-shell/" rel="nofollow">http://pythonc... | 1 | 2016-06-08T05:21:54Z | [
"python",
"linux",
"mapreduce",
"inverted-index"
] |
Running python program on linux | 37,693,750 | <p>I'm not very familiar with linux as well as python. I'm taking this class that have example code of a inverted index program on python. I would like to know how to run and test the code. Here's the code that was provided to me.</p>
<p>This is the code for the mapping file. (inverted_index_map.py)</p>
<pre><code>im... | 0 | 2016-06-08T05:14:39Z | 37,693,896 | <p>You need to pass the file in as standard input like so</p>
<pre><code>python inverted_index_map.py < testfilename.txt
</code></pre>
<p>or prefix the python file with <code>#!/usr/bin/python</code> or <code>#!/usr/bin/env python</code> then <code>chmod +x</code> it and you can run</p>
<pre><code>.\inverted_inde... | 1 | 2016-06-08T05:27:44Z | [
"python",
"linux",
"mapreduce",
"inverted-index"
] |
Running python program on linux | 37,693,750 | <p>I'm not very familiar with linux as well as python. I'm taking this class that have example code of a inverted index program on python. I would like to know how to run and test the code. Here's the code that was provided to me.</p>
<p>This is the code for the mapping file. (inverted_index_map.py)</p>
<pre><code>im... | 0 | 2016-06-08T05:14:39Z | 37,693,990 | <p>These two programs are written as command-line tools, meaning they take their input from the stdin and display it to stdout. By default, that means that they take input from the keyboard and display output on the screen. In most Linux shells, you can change where input comes from and output goes to by using <code>&l... | 2 | 2016-06-08T05:34:40Z | [
"python",
"linux",
"mapreduce",
"inverted-index"
] |
Unable to connect to Jupyter Notebook Remode Server on Ubuntu | 37,693,755 | <p>I'm trying to setup a remote Jupyter Notebook server on an AWS Ubuntu machine.
I followed this blog: <a href="http://blog.impiyush.me/2015/02/running-ipython-notebook-server-on-aws.html" rel="nofollow">http://blog.impiyush.me/2015/02/running-ipython-notebook-server-on-aws.html</a> </p>
<p>I'm able to do a <code>wg... | 0 | 2016-06-08T05:15:09Z | 37,744,960 | <p>Posting here for future reference.</p>
<p>Found the issue. The AWS Security Group settings were not configured to allow incoming connections on either HTTPS (443) or 8888. I added those rules in to the AWS console and it started working.</p>
| 1 | 2016-06-10T09:41:41Z | [
"python",
"ubuntu",
"jupyter-notebook"
] |
How can i group data based on range of values | 37,693,805 | <p>I have data like</p>
<pre><code>[312.281,
370.401,
254.245,
272.256,
312.325,
286.243,
271.231, ...]
</code></pre>
<p>then I want to group them by the range of value by</p>
<pre><code>for i in data:
if i in range(200,300):
data_200_300.append(i)
elif i in range(300,400):
data_300_40... | 1 | 2016-06-08T05:20:17Z | 37,693,846 | <p><a href="https://docs.python.org/2/library/functions.html#range" rel="nofollow"><code>range</code></a> returns a list of integers between two numbers while your data contains floating point numbers. You can directly use <a href="https://docs.python.org/2/library/stdtypes.html#comparisons" rel="nofollow">Comparisons<... | 3 | 2016-06-08T05:23:54Z | [
"python",
"python-2.7"
] |
How can i group data based on range of values | 37,693,805 | <p>I have data like</p>
<pre><code>[312.281,
370.401,
254.245,
272.256,
312.325,
286.243,
271.231, ...]
</code></pre>
<p>then I want to group them by the range of value by</p>
<pre><code>for i in data:
if i in range(200,300):
data_200_300.append(i)
elif i in range(300,400):
data_300_40... | 1 | 2016-06-08T05:20:17Z | 37,694,192 | <p>@AKS answered it right as an alternative you can also try it with <strong>lambda expressions</strong> something like this.</p>
<pre><code>result = filter(lambda x: 200 < x < 300, data)
</code></pre>
<p>and you can use this like it to process your data</p>
<pre><code>filtered_data = []
for i in range(200,400... | 0 | 2016-06-08T05:49:01Z | [
"python",
"python-2.7"
] |
How can i group data based on range of values | 37,693,805 | <p>I have data like</p>
<pre><code>[312.281,
370.401,
254.245,
272.256,
312.325,
286.243,
271.231, ...]
</code></pre>
<p>then I want to group them by the range of value by</p>
<pre><code>for i in data:
if i in range(200,300):
data_200_300.append(i)
elif i in range(300,400):
data_300_40... | 1 | 2016-06-08T05:20:17Z | 37,697,846 | <p>If you have a lot of such values and the possibility to import <code>numpy</code>, there is a faster option than a string of if-conditions or lambda-filter. It's using logical indexing:</p>
<pre><code>def indexingversion(data, bin_start, bin_end, bin_step):
x = np.array(data)
bin_edges = np.arange(bin_start... | 0 | 2016-06-08T08:59:24Z | [
"python",
"python-2.7"
] |
Run pyQT GUI main app in seperate Thread | 37,693,818 | <p>I am trying to add a PyQt GUI console in my already established application. But the PyQt GUI blocks the whole application making it unable to do rest of the work. I tried using QThread, but that is called from the mainWindow class. What I want is to run the MainWindow app in separate thread. </p>
<pre><code>def ma... | 0 | 2016-06-08T05:21:27Z | 37,694,109 | <p>One way of doing this is</p>
<pre><code>import threading
def main()
app = QtGui.QApplication(sys.argv)
ex = Start_GUI()
app.exec_() #<---------- code blocks over here !
#After running the GUI, continue the rest of the application task
t = threading.Thread(target=main)
t.daemon = True
t.star... | 1 | 2016-06-08T05:42:48Z | [
"python",
"multithreading",
"user-interface",
"pyqt",
"pyqt4"
] |
How to fetch data from link tag in django? | 37,694,004 | <p>In my models I have a class called "Add_prod",I have created few columns like book,author,price and so on.In the templates I have created two hyperlinks for sorting data in ascending/descending order of price."name" attribute is not supporting in anchor tag.I also tried with id attribute instead of name,but still no... | 0 | 2016-06-08T05:35:31Z | 37,694,366 | <p>You need to append the URLs with the <code>query parameters</code> you are expecting in the view:</p>
<pre><code><a name="low_price" href="{% url 'welcome_user' %}?low_price">Low Price</a>
<a name="high_price" href="{% url 'welcome_user' %}?high_price">High Price</a>
</code></pre>
| 1 | 2016-06-08T06:01:10Z | [
"python",
"django",
"django-templates"
] |
How to fetch data from link tag in django? | 37,694,004 | <p>In my models I have a class called "Add_prod",I have created few columns like book,author,price and so on.In the templates I have created two hyperlinks for sorting data in ascending/descending order of price."name" attribute is not supporting in anchor tag.I also tried with id attribute instead of name,but still no... | 0 | 2016-06-08T05:35:31Z | 37,694,612 | <p>there are two way:</p>
<p>1 as @AKS answer.</p>
<p>2</p>
<pre><code>def welcome_user(request,type):
if 'low_price' == type:
my_products = Add_prod.objects.all().order_by('price')
if 'high_price' == type:
my_products = Add_prod.objects.all().order_by('-price')
else:
my_product... | 1 | 2016-06-08T06:16:25Z | [
"python",
"django",
"django-templates"
] |
How can I run onclick function on python | 37,694,056 | <p>How can I run <code>onclick</code> on selected row?<br>
To run a javascript <code>onClick</code> event with python,
I tried something like this:</p>
<pre><code>driver.find_element_by_id('fastforward').click()
</code></pre>
<p><a href="http://i.stack.imgur.com/SZuAS.jpg" rel="nofollow">page code on site (selected ... | 0 | 2016-06-08T05:38:59Z | 37,694,505 | <p>If you want to click on <code><td></code>, try:</p>
<pre><code>driver.find_element_by_xpath('//td[contains(@onclick,"{'page': 'fastforward'}")]').click()
</code></pre>
<p>If you want to click on its parent <code><tr></code> element:</p>
<pre><code>driver.find_element_by_xpath('//td[contains(@onclick,"... | 0 | 2016-06-08T06:09:34Z | [
"python",
"selenium",
"selenium-webdriver",
"web-scraping"
] |
How can I run onclick function on python | 37,694,056 | <p>How can I run <code>onclick</code> on selected row?<br>
To run a javascript <code>onClick</code> event with python,
I tried something like this:</p>
<pre><code>driver.find_element_by_id('fastforward').click()
</code></pre>
<p><a href="http://i.stack.imgur.com/SZuAS.jpg" rel="nofollow">page code on site (selected ... | 0 | 2016-06-08T05:38:59Z | 37,718,244 | <p>You can Use following xpath:</p>
<p>driver.find_element_by_xpath("//td[contains(text(),'Put Text Of TD')]").click()</p>
| 0 | 2016-06-09T06:21:02Z | [
"python",
"selenium",
"selenium-webdriver",
"web-scraping"
] |
Extract data of a column by matching data of other column in Python | 37,694,062 | <p>I want to extract all MaxTemp for year 2010</p>
<pre><code>Year Month Day MaxTemp MinTemp
2010 1 1 -19.9 -37.2
2010 1 2 -13.8 -20
2010 1 3 -13.1 -15.9
2010 1 4 -12 -22.3
2010 1 5 -11.8 -14.4
2010 1 6 -14.3 -32.5
2010 1 7 -28.2 -37.3
2011 1 8 -... | 2 | 2016-06-08T05:39:27Z | 37,694,245 | <p>You can do it like this, then <code>data</code> will be a list of MaxTemps from 2010:</p>
<pre><code>with open('data/'+file_name, "rU") as files:
data = list()
for line in csv.reader(files):
if int(line[0])==2010:
data.append(line[3])
</code></pre>
<p>Better would be to use something li... | 0 | 2016-06-08T05:52:01Z | [
"python",
"csv",
"row",
"extract"
] |
Extract data of a column by matching data of other column in Python | 37,694,062 | <p>I want to extract all MaxTemp for year 2010</p>
<pre><code>Year Month Day MaxTemp MinTemp
2010 1 1 -19.9 -37.2
2010 1 2 -13.8 -20
2010 1 3 -13.1 -15.9
2010 1 4 -12 -22.3
2010 1 5 -11.8 -14.4
2010 1 6 -14.3 -32.5
2010 1 7 -28.2 -37.3
2011 1 8 -... | 2 | 2016-06-08T05:39:27Z | 37,694,284 | <p>As rofls said, but with comprehensions</p>
<pre><code>with open('data/'+file_name, "rU") as files:
data = [x[3] for x in csv.reader(files) if str(x[0]) == '2010']
</code></pre>
| 1 | 2016-06-08T05:54:31Z | [
"python",
"csv",
"row",
"extract"
] |
Extract data of a column by matching data of other column in Python | 37,694,062 | <p>I want to extract all MaxTemp for year 2010</p>
<pre><code>Year Month Day MaxTemp MinTemp
2010 1 1 -19.9 -37.2
2010 1 2 -13.8 -20
2010 1 3 -13.1 -15.9
2010 1 4 -12 -22.3
2010 1 5 -11.8 -14.4
2010 1 6 -14.3 -32.5
2010 1 7 -28.2 -37.3
2011 1 8 -... | 2 | 2016-06-08T05:39:27Z | 37,694,517 | <pre><code>Here you go:
maxList = list()
for row in val:
rowInStr = ''.join(row)
rowSplitList = rowInStr.split(" ")
if rowSplitList[0] == "2010":
rowSplitList = filter(lambda a: a!='', rowSplitList)
maxList.append(rowSplitList[-2])
Output:
['-19.9', '-13.8', '-13.1', '-12', '-11.8', '-14.3',... | 0 | 2016-06-08T06:10:22Z | [
"python",
"csv",
"row",
"extract"
] |
How to join array more than one array in python | 37,694,134 | <p>I have 4 arrays like this:</p>
<pre><code>temp1 = ['a' , 'b' , 'c']
temp2 = ['d' , 'e' ,'' ]
temp3 = ['f']
temp4 = ['g']
</code></pre>
<p>I want output:</p>
<pre><code>adfg
aefg
afg
bdfg
befg
bfg
cdfg
cefg
cfg
</code></pre>
<p>and I solved it using following:</p>
<pre><code>temp1 = ['a' , 'b' , 'c']
temp2 = ['d... | 1 | 2016-06-08T05:44:46Z | 37,694,206 | <p>Use Python Comprehensions. They are cleaner and more elegant.</p>
<pre><code>temp1 = ['a' , 'b' , 'c']
temp2 = ['d' , 'e' ,'' ]
temp3 = ['f']
temp4 = ['g']
templist = [i+j+k+l for i in temp1 for j in temp2 for k in temp3 for l in temp4]
# Result - ['adfg', 'aefg', 'afg', 'bdfg', 'befg', 'bfg', 'cdfg', 'cefg', 'cf... | 0 | 2016-06-08T05:49:38Z | [
"python",
"arrays"
] |
How to join array more than one array in python | 37,694,134 | <p>I have 4 arrays like this:</p>
<pre><code>temp1 = ['a' , 'b' , 'c']
temp2 = ['d' , 'e' ,'' ]
temp3 = ['f']
temp4 = ['g']
</code></pre>
<p>I want output:</p>
<pre><code>adfg
aefg
afg
bdfg
befg
bfg
cdfg
cefg
cfg
</code></pre>
<p>and I solved it using following:</p>
<pre><code>temp1 = ['a' , 'b' , 'c']
temp2 = ['d... | 1 | 2016-06-08T05:44:46Z | 37,694,230 | <p>You can use <a href="https://docs.python.org/2/library/itertools.html#itertools.product" rel="nofollow"><code>itertools.product</code></a>:</p>
<pre><code>>>> from itertools import product
>>> result = product(temp1, temp2, temp3, temp4)
>>> ["".join(item) for item in result]
['adfg', 'ae... | 5 | 2016-06-08T05:51:11Z | [
"python",
"arrays"
] |
How to join array more than one array in python | 37,694,134 | <p>I have 4 arrays like this:</p>
<pre><code>temp1 = ['a' , 'b' , 'c']
temp2 = ['d' , 'e' ,'' ]
temp3 = ['f']
temp4 = ['g']
</code></pre>
<p>I want output:</p>
<pre><code>adfg
aefg
afg
bdfg
befg
bfg
cdfg
cefg
cfg
</code></pre>
<p>and I solved it using following:</p>
<pre><code>temp1 = ['a' , 'b' , 'c']
temp2 = ['d... | 1 | 2016-06-08T05:44:46Z | 37,694,258 | <p>Use <a href="https://docs.python.org/2/library/itertools.html#itertools.product" rel="nofollow"><code>itertools.product()</code></a>. </p>
<pre><code>>>> import itertools
>>> result = [''.join(i) for i in itertools.product(temp1,temp2,temp3,temp4)]
>>> result
['adfg', 'aefg', 'afg', 'bdf... | 1 | 2016-06-08T05:52:53Z | [
"python",
"arrays"
] |
remove certain elements from numpy array without destroying the structure | 37,694,199 | <p>I have a numpy array as below, I want to remove all zeros. </p>
<pre><code> a = [[ 5 2 0 9 4]
[ 2 0 9 4 2]
[ 0 9 4 2 6]
[ 9 4 2 6 8]
[ 4 2 6 8 0]
[ 2 6 8 0 3]
[ 6 8 0 3 11]
[ 8 0 3 11 7]
[ 0 3 11 7 1]
[ 3 11 7 1 5]
[11 7 1 5 21]
[ 7 1 5 21 8]
[ 1 5 21 8 0]
[... | 3 | 2016-06-08T05:49:20Z | 37,694,493 | <p>The result array cannot be a numpy array, because its shape is not constant. Therefore a possible solution would be doing it the standard pythonic way:</p>
<pre><code>b = [row[row>0] for row in a]
</code></pre>
| 2 | 2016-06-08T06:09:06Z | [
"python",
"arrays",
"numpy"
] |
remove certain elements from numpy array without destroying the structure | 37,694,199 | <p>I have a numpy array as below, I want to remove all zeros. </p>
<pre><code> a = [[ 5 2 0 9 4]
[ 2 0 9 4 2]
[ 0 9 4 2 6]
[ 9 4 2 6 8]
[ 4 2 6 8 0]
[ 2 6 8 0 3]
[ 6 8 0 3 11]
[ 8 0 3 11 7]
[ 0 3 11 7 1]
[ 3 11 7 1 5]
[11 7 1 5 21]
[ 7 1 5 21 8]
[ 1 5 21 8 0]
[... | 3 | 2016-06-08T05:49:20Z | 37,695,350 | <p>It seems you want to remove zeros if there's exactly the same numbers of zeros in each column. Note, in your example this is not (yet) possible.</p>
<pre><code>b=np.hstack([y.reshape((len(y),1)) for y in [x[x>0] for x in [a[:,i] for i in range(a.shape[1])]]])
</code></pre>
| 1 | 2016-06-08T06:59:07Z | [
"python",
"arrays",
"numpy"
] |
How to add details to a table created as the result of a many2many field using create function in odoo | 37,694,265 | <p>I have a custom model <em>csm</em> in my application. I have a <em>many2many</em> field as <em>product_multi</em> reffering to <em>product.product</em> . This many2many field resulted in the creation of another table named <strong>csm_product_product_rel</strong>. Now i need to create records in this table from acco... | 0 | 2016-06-08T05:53:11Z | 37,694,737 | <p>This is how you have to write the create function. Look at the sample code below and try </p>
<pre><code>def create(self, cr, uid, values, context=None):
partner_id=values.get('partner_id')
if partner_id:
emp_ids=values.get('employee_ids')
if emp_ids:
... | 2 | 2016-06-08T06:24:12Z | [
"python",
"odoo-8"
] |
How to add details to a table created as the result of a many2many field using create function in odoo | 37,694,265 | <p>I have a custom model <em>csm</em> in my application. I have a <em>many2many</em> field as <em>product_multi</em> reffering to <em>product.product</em> . This many2many field resulted in the creation of another table named <strong>csm_product_product_rel</strong>. Now i need to create records in this table from acco... | 0 | 2016-06-08T05:53:11Z | 37,698,416 | <p>This is because the model <code>csm_product_product_rel</code> doesn't exists. Exists the table in the database but not the model in python code.</p>
<p>You have defined a relation from <code>csm</code> model to <code>product.product</code> model. If you want to add a new relation record you need to do this
by the ... | 2 | 2016-06-08T09:24:46Z | [
"python",
"odoo-8"
] |
how can we write the program by using multiprocessing module of Python? | 37,694,534 | <pre><code># -*- coding: utf-8 -*-
from __future__ import print_function
import os, codecs, re, string, mysql
import mysql.connector
'''Reading files with txt extension'''
y_ = ""
for root, dirs, files in os.walk("/Users/Documents/source-document/part1"):
for file in files:
if file.endswith(".txt"):
... | 0 | 2016-06-08T06:11:22Z | 37,694,783 | <p>there's an example in the <a href="https://docs.python.org/3.5/library/multiprocessing.html" rel="nofollow">python docs</a> which demonstrates the use of <code>multiprocessing</code>:</p>
<pre><code>from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
with Pool(5) as p:
p... | 1 | 2016-06-08T06:27:22Z | [
"python",
"parallel-processing",
"multiprocessing"
] |
Using proxy middleware to scrape Amazon | 37,694,883 | <pre><code>class HttpProxyMiddleware(object):
###never retry these errors
def __init__(self, settings):
socket.setdefaulttimeout(3)
self.proxies = []
self.proxy_index = 1
##plant proxies
self.proxy_list = settings.get('PROXY_LIST')
fin = open(self.proxy_list)
... | 0 | 2016-06-08T06:33:36Z | 37,868,234 | <p>You could use the Proxicity.io APIs available at <a href="https://www.proxicity.io/api" rel="nofollow">https://www.proxicity.io/api</a> to serve you the proxies and user-agent headers (if you need them) instead of the proxy list, as that will get stale. They have free and paid APIs, but still pretty cheap. Try Out t... | 0 | 2016-06-16T19:50:57Z | [
"python",
"scrapy",
"web-crawler"
] |
Failed to remove â ' ' despite using re from text | 37,694,908 | <p>I tried remove â and ' ' from the next but I am unable to remove. </p>
<p>My coding is as follows:</p>
<pre><code>import re
with open('NoSpace.text') as f1:
with open('NoSymbol.text', 'w')as f2:
lines = f1.readlines()
for line in lines:
str = line
regex = re.compile('[,\.!... | 0 | 2016-06-08T06:35:00Z | 37,695,412 | <p>The dash in your text is an en dash (<a href="http://www.fileformat.info/info/unicode/char/2013/index.htm" rel="nofollow">U+2013</a>; a Unicode character), not the ASCII minus sign.</p>
<p>In addition to that, there are some mistakes in your code.</p>
<p>In a character class (inside of <code>[...]</code> in a rege... | 1 | 2016-06-08T07:02:50Z | [
"python",
"regex",
"python-2.7"
] |
Why are there so many improper underlines when I debugging python code in Visual Studio Code | 37,694,916 | <p>I have been writing my python code in VSCode with a python extension named 'python' on Ubuntu for many days. It has been very nice.</p>
<p>However, today I meet some problems as shown in the picture:</p>
<p><img src="http://i.stack.imgur.com/7Y85Z.png"></p>
<p>I have write the correct code which can be run proper... | 0 | 2016-06-08T06:35:21Z | 37,874,860 | <p>I'm the author of the extension. An updated was pushed out on the 9th of June. It is possible you hadn't updated for a while. To get rid of these messages you could either fix the corresponding errors or just turn off linting by going into the settings.json file and adding the following setting:</p>
<pre><code>"pyt... | 2 | 2016-06-17T06:46:50Z | [
"python",
"ubuntu",
"vscode"
] |
Python: How to prevent python dictionary from putting quotes around my json? | 37,694,940 | <p>I am using requests to create a post request on a contractor's API. I have a JSON variable <code>inputJSON</code> that undergoes formatting like so:</p>
<pre><code>def dolayoutCalc(inputJSON):
inputJSON = ast.literal_eval(inputJSON)
inputJSON = json.dumps(inputJSON)
url='http://xxyy.com/API'
payload... | 0 | 2016-06-08T06:36:46Z | 37,695,589 | <p>inputJSON gets quotes around it because it's a string. When you call json.dumps() on something a string will come out, and then when it's converted to JSON it will get quotes around it. e.g.:</p>
<pre><code>>>> import json
>>> json.dumps('this is a string')
>>> '"this is a string"'
</code... | 0 | 2016-06-08T07:12:53Z | [
"python",
"json",
"http",
"python-requests"
] |
Cannot get a checked checkbox [FLASK + HTML] | 37,694,967 | <p>First of all, apologize if this question may have been asked before. I am relatively new in web programming, especially using Flask and HTML. I've seen a similar question (with the answer) <a href="http://stackoverflow.com/questions/20941539/how-to-get-if-checkbox-is-checked-on-flask">here</a>, however, I still coul... | -1 | 2016-06-08T06:38:33Z | 37,696,962 | <p>Your <code>checkbox</code> and <code>Button</code> are in different <code>forms</code>. Make it in a single <code>from</code>. It will work.</p>
| 0 | 2016-06-08T08:20:16Z | [
"python",
"html",
"flask"
] |
How to add counter column in django-tables2? | 37,694,971 | <p>I'm trying to add a counter on the first column of a table using django-tables2, but the solution below is only showing all 0 under the # column. How should I add a column that will have a column that numbers the rows?</p>
<p>tables.py:</p>
<pre><code>import django_tables2 as tables
from profiles.models import Tr... | 1 | 2016-06-08T06:38:43Z | 37,695,336 | <p>From the documentation of <a href="http://django-tables2.readthedocs.io/en/latest/pages/api-reference.html#column" rel="nofollow"><code>Column</code></a></p>
<blockquote>
<p><strong><code>default (str or callable)</code>:</strong></p>
<p>The default value for the column. This can be a value or a callable obj... | 2 | 2016-06-08T06:58:31Z | [
"python",
"django",
"django-tables2"
] |
How to add counter column in django-tables2? | 37,694,971 | <p>I'm trying to add a counter on the first column of a table using django-tables2, but the solution below is only showing all 0 under the # column. How should I add a column that will have a column that numbers the rows?</p>
<p>tables.py:</p>
<pre><code>import django_tables2 as tables
from profiles.models import Tr... | 1 | 2016-06-08T06:38:43Z | 37,720,905 | <p>Other answers all have the <code>itertools.count</code> instance in the toplevel scope of the <code>tables.py</code> file. This makes the counter persist between page loads, it will only be reset when the server is restarted. A better solution is to add the counter as instance variable on the table like this:</p>
<... | 1 | 2016-06-09T08:40:35Z | [
"python",
"django",
"django-tables2"
] |
Fetch a 'return'd value from an executemany statement | 37,695,004 | <p>Using Postgresql 9.5 with psycopg2.</p>
<p>Using 'returning', I can retrieve the 'id' of a single row I insert.</p>
<pre><code>sql = "insert into %s (%s) values (%s) returning id" % (table_name, columns, values_template)
values = tuple(row_dict[key] for key in keys)
cur.execute(sql, values)
id_new_row = cu... | 0 | 2016-06-08T06:40:36Z | 37,695,496 | <p>I think that what you're trying to do is impossible.</p>
<p>For a start, you are already on dodgy ground as far as PEP 249 is concerned. Specifically it says this about executemany.</p>
<blockquote>
<p>Use of this method for an operation which produces one or more result sets constitutes undefined behavior, and... | 1 | 2016-06-08T07:07:56Z | [
"python",
"postgresql",
"psycopg2"
] |
Why does GLPK produce the error `cannot execute glpsol.exe` while the default PuLP solver works perfectly? | 37,695,065 | <p>While trying to solve a Binary Integer Programming Problem with PuLP and using GLPK as the solver, I get the following error. I have installed GLPK on Windows, set the path as well. The result of <code>pulp.pulpTestAll()</code> shows <code>Solver <class 'pulp.solvers.GLPK_CMD'> passed</code></p>
<pre><code>Tr... | 0 | 2016-06-08T06:43:33Z | 38,583,599 | <p>Actually this is not an answer. I was planning to add this as a comment. But I cannot write a comment since I don't have 50 reputation now. So I'll just put it as an answer here.
I feel the problem is not in your program. Your program should be fine. But could be some issue in environment variables or permissions. I... | 0 | 2016-07-26T07:27:26Z | [
"python",
"mathematical-optimization",
"linear-programming",
"pulp"
] |
python: selectively split and combine alphanumeric strings in a file | 37,695,218 | <p>I am trying to replicate certain lines in a file and strip certain substrings from certain replicas. Each line is a string which I get through a fileobject.readline()</p>
<pre><code>Input:
Line1 : a -> b,c;
Line2 : d -> e,f,g;
Line3 : h -> i,j;
Line4 : k -> l;
Output:
Line1 : a -> b;
Line2 : a ->... | 0 | 2016-06-08T06:52:19Z | 37,695,474 | <p>As far as I understand your question, you can simply replace ',' characters with the '\w ' pattern. It's more like a trick than a solution.</p>
<p>I wrote a simple function that can 'replicate' a line into multiple line follows your requirement. Note that this is for 1 line only.</p>
<pre><code>def replicateALine... | 2 | 2016-06-08T07:06:27Z | [
"python",
"string",
"file",
"strip"
] |
python: selectively split and combine alphanumeric strings in a file | 37,695,218 | <p>I am trying to replicate certain lines in a file and strip certain substrings from certain replicas. Each line is a string which I get through a fileobject.readline()</p>
<pre><code>Input:
Line1 : a -> b,c;
Line2 : d -> e,f,g;
Line3 : h -> i,j;
Line4 : k -> l;
Output:
Line1 : a -> b;
Line2 : a ->... | 0 | 2016-06-08T06:52:19Z | 37,695,567 | <pre><code>s = "a -> b,c;"
s = s.replace(";","")
a = s.split(" -> ")
b = a[1].split(',')
for i in range(len(b)):
print('{} -> {};'.format(a[0],b[i]))
</code></pre>
<p>Read more about Python split and other string methods <a href="https://docs.python.org/2/library/string.html#string-functions" rel="nofollo... | 0 | 2016-06-08T07:11:56Z | [
"python",
"string",
"file",
"strip"
] |
Python: Identifying a State Space Model for a System | 37,695,253 | <p>I am looking to obtain a state space model for a system I have, using python.</p>
<p>I have tested the actual system, so I have the inputs to it and I have measured the outputs. so I have sets of corresponding inputs and outputs.</p>
<p>Is there a function somewhere, for python, where I can supply the function wit... | 0 | 2016-06-08T06:53:36Z | 37,695,463 | <p>try reading this article: <a href="http://pages.uoregon.edu/cfulton/posts/state_space_python.html" rel="nofollow">state space model</a> and <a href="http://pages.uoregon.edu/cfulton/posts/state_space_mh.html" rel="nofollow">this state space model2</a>
the latter uses other py packages to create a model, you can use ... | 0 | 2016-06-08T07:05:52Z | [
"python",
"state-space",
"control-theory",
"system-identification"
] |
Python How to allocate and restrict memory space to an array containing data? | 37,695,299 | <p>I am required to transmit a <strong>BYTE</strong> array containing hexadecimal values of size no more than 250 bytes in the following format: </p>
<pre><code>header|no of data structures|Data/Payload
</code></pre>
<p>Now, I have read multiple posts on stackoverflow regarding memory allocation to a an array but i d... | 1 | 2016-06-08T06:56:28Z | 37,696,983 | <p>sys.getsizeof(newdata) is returning the internal representation of your data structure, and is system dependent. Refer to <a href="https://docs.python.org/2/library/sys.html" rel="nofollow">sys â System-specific parameters and functions</a></p>
<p>Try this link: <a href="http://stackoverflow.com/questions/4013230... | 0 | 2016-06-08T08:21:33Z | [
"python",
"arrays",
"memory"
] |
Python How to allocate and restrict memory space to an array containing data? | 37,695,299 | <p>I am required to transmit a <strong>BYTE</strong> array containing hexadecimal values of size no more than 250 bytes in the following format: </p>
<pre><code>header|no of data structures|Data/Payload
</code></pre>
<p>Now, I have read multiple posts on stackoverflow regarding memory allocation to a an array but i d... | 1 | 2016-06-08T06:56:28Z | 38,713,056 | <p>Declaring a byte array of size 250 makes a byte array that is equal to 250 bytes, however python's memory management is programmed in such a way that it acquires more space for an integer or a character as compared to C or other languages where you can assign an integer to be short or long. The sys.getsizeof() comma... | 0 | 2016-08-02T06:19:44Z | [
"python",
"arrays",
"memory"
] |
How can a "dead man's switch" be written in Python, something that monitors for an interaction in a specified time? | 37,695,364 | <p>I want to have a Python script running that looks for someone to interact with it in a specified time period (say, a week). If someone interacts with it, it continues to another loop of looking for an interaction. If someone does not interact with it, then it starts performing some actions.</p>
<p>I have started su... | 0 | 2016-06-08T07:00:16Z | 37,701,032 | <p>You can simply write:</p>
<pre><code>import signal
TIMEOUT = 20 * 60 # secs to wait for interaction
def interrupted(signum, frame):
"called when read times out"
print('Exiting')
signal.signal(signal.SIGALRM, interrupted)
def i_input():
try:
print('You have 20 minutes to interact or this s... | 1 | 2016-06-08T11:19:31Z | [
"python",
"input",
"timeout",
"signals"
] |
Python and OpenCV - getting the duration time of a video at certain points | 37,695,376 | <p>Let say I have made a program to detect a green ball in a video. Whenever there is a green ball detected, I want to print out the duration of video at the time the green ball is detected. Is it possible?</p>
| 0 | 2016-06-08T07:00:54Z | 37,695,497 | <p>In <a href="http://stackoverflow.com/a/25359361/1150303">this answer</a>, you will find a solution to determine the frames per second.</p>
<p>so you'd want to use:</p>
<pre><code>fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
</code></pre>
<p>and count the number of frames you're at. Then you can compute the video time wi... | 2 | 2016-06-08T07:07:56Z | [
"python",
"opencv",
"video"
] |
Python - delete object that points to another object | 37,695,472 | <p>I have a list of tuples like below:</p>
<pre><code>In [136]: z
Out[136]:
[(0, array([ 0.71428571, 2.92857143, 1.64285714, 1.07142857])),
(1, array([ 2.89473684, 1.68421053, 0.52631579, 3.21052632])),
(2, array([ 1.03571429, 1.5 , 2.75 , 2.96428571])),
(3, array([ 3.35714286, 2.07142857, 3.... | 0 | 2016-06-08T07:06:24Z | 37,695,624 | <p>I didn't try but probably something like (where <code>k</code> is the key to be removed; in your example <code>k=0</code>):</p>
<pre><code>z = [ (e[0] - (e[0]>k), e[1]) for e in z if e[0] != k ]
</code></pre>
<p><strong>Explanations:</strong> you can have a filter effect in a list comprehension with the syntax ... | 2 | 2016-06-08T07:14:16Z | [
"python",
"list",
"filter"
] |
what is the difference between "def on_data(self, data):" and "def on_status(self, status):" in tweepy streamListener? | 37,695,529 | <p>what is the difference between "def on_data(self, data):" and "def on_status(self, status):" in tweepy streamListener ? </p>
<p>hi, in the <a href="http://docs.tweepy.org/en/v3.5.0/streaming_how_to.html" rel="nofollow">tweepy documentation</a>
they use <strong>def on_status</strong> for streaming:</p>
<pre><code>... | 0 | 2016-06-08T07:09:28Z | 37,695,679 | <p>Read the first link. The "difference" is that one happens before the other. </p>
<blockquote>
<p>The <code>on_data</code> method of Tweepyâs StreamListener conveniently passes data from statuses to the <code>on_status</code> method. </p>
</blockquote>
| 0 | 2016-06-08T07:17:13Z | [
"python",
"nlp",
"web-crawler",
"tweepy",
"twitter-streaming-api"
] |
Error installing Django: syntax error | 37,695,603 | <p>I made a few experimentations upgrading from python 2.6.5 to python 2.7.11 in order to get Django to work properly. Then I had to uninstall python 2.7.11 and get back to python 2.6.5 (compatibility issues with other projects). Now, when I try to install django 1.2.1 using <code>pip install django==1.2.1</code> I get... | 0 | 2016-06-08T07:13:30Z | 37,696,079 | <p>Python 2.6 does not have set literals.</p>
<pre><code> # in python 2.6 only this will work
fasttypes = set(int, str, frozenset, type(None))
# in python 2.7+ this will work as well
fasttypes = {int, str, frozenset, type(None)}
</code></pre>
<p>The version of Django you are using is not compatible with python 2.... | 1 | 2016-06-08T07:35:03Z | [
"python",
"django"
] |
Error installing Django: syntax error | 37,695,603 | <p>I made a few experimentations upgrading from python 2.6.5 to python 2.7.11 in order to get Django to work properly. Then I had to uninstall python 2.7.11 and get back to python 2.6.5 (compatibility issues with other projects). Now, when I try to install django 1.2.1 using <code>pip install django==1.2.1</code> I get... | 0 | 2016-06-08T07:13:30Z | 37,696,254 | <p>You can have multiple version of Python installed on Windows (what you seem to be using) without any problems. You just have to make sure the default version of Python is set correctly for your situation.</p>
<p>Instead of using an extremely outdated version of django, install the latest version of Python - just ch... | 2 | 2016-06-08T07:43:27Z | [
"python",
"django"
] |
Error installing Django: syntax error | 37,695,603 | <p>I made a few experimentations upgrading from python 2.6.5 to python 2.7.11 in order to get Django to work properly. Then I had to uninstall python 2.7.11 and get back to python 2.6.5 (compatibility issues with other projects). Now, when I try to install django 1.2.1 using <code>pip install django==1.2.1</code> I get... | 0 | 2016-06-08T07:13:30Z | 37,725,568 | <p>The problem was solved by installing the Django version I need - 1.2.1 not using pip but downloading the files and manually running:
<code>python setup.py install</code> .</p>
| 0 | 2016-06-09T12:07:29Z | [
"python",
"django"
] |
Using SQLALCHEMY in my Python script | 37,695,689 | <p>While using SQLalchemy engine APIs in my python script, I want to select few columns from a table with a where clause on the other columns. My query looks like following. I have successfully connected the engine. I know I am making some small mistake, please help</p>
<pre><code>connection = engine.connect()
data=co... | -2 | 2016-06-08T07:17:48Z | 37,696,177 | <p>Try this:</p>
<pre><code>from sqlalchemy.sql import text
connection = engine.connect()
s = text("select *
FROM Table1
WHERE Table1.Country = 'India'")
data=connection.execute(s)
</code></pre>
| 0 | 2016-06-08T07:39:37Z | [
"python",
"api",
"sqlalchemy"
] |
How to get offset position of a text in html page in python | 37,695,780 | <p>I am doing a webscraping to extract some text using beautiful soup. </p>
<p>I am successfully extracting the required text from the webpage but my new requirement is along with the text I need to extract the offset number/position where the text actually started and ended in the document. </p>
<p>Is there any poss... | 0 | 2016-06-08T07:21:53Z | 37,696,413 | <p>Try to use following code</p>
<pre><code>import re
DATA = "This is test message"
for match in re.finditer(r'(?s)((?:[^\n][\n]?)+)', DATA):
print match.start(), match.end()
</code></pre>
<p>Output </p>
<p>0 20</p>
| -1 | 2016-06-08T07:51:45Z | [
"python",
"web-scraping",
"beautifulsoup"
] |
Extract a dictionary objects to a list | 37,696,094 | <p>i need a small help to put the content returned from dictionary to 2 different list.</p>
<p>The code is :</p>
<pre><code>for region in regions:
instance_information = {}
ip_dict = {}
client = boto3.client('ec2',aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SECRET_KEY,region_name=region,)
addre... | 0 | 2016-06-08T07:35:48Z | 37,696,128 | <p>You may simple iterate over all the values in the given dictionary and select the first element as the IP to append it in a new list.</p>
<pre><code>ip_list = [i[0]for i in instance_information.values()]
>> ['52.113.42.171', '52.26.21.83', '52.13.84.44', '5.33.81.148', '52.3.173.116']
</code></pre>
<p>Or if ... | 1 | 2016-06-08T07:37:27Z | [
"python",
"list",
"dictionary"
] |
Extract a dictionary objects to a list | 37,696,094 | <p>i need a small help to put the content returned from dictionary to 2 different list.</p>
<p>The code is :</p>
<pre><code>for region in regions:
instance_information = {}
ip_dict = {}
client = boto3.client('ec2',aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SECRET_KEY,region_name=region,)
addre... | 0 | 2016-06-08T07:35:48Z | 37,696,142 | <p>List comprehension is your tool:</p>
<pre><code>iplist = [v[0] for v in instance_information.values()]
</code></pre>
<p>EDIT:
As you need, make a function that returns you the ips</p>
<pre><code>def getIpFromRegions(regions):
for region in regions:
instance_information = {}
ip_dict = {}
client... | 3 | 2016-06-08T07:37:56Z | [
"python",
"list",
"dictionary"
] |
print the selected choice name as well | 37,696,184 | <p>I am unable to place the print command for printing the name of selected choice. The code is as follows:</p>
<pre><code>import dpkt
from dpkt.ip import IP
from dpkt.ethernet import Ethernet
import struct
import socket
import csv
def ip_to_str(address):
return socket.inet_ntoa(address)
f = open('ipp.pcap', 'rb'... | 0 | 2016-06-08T07:39:56Z | 37,697,051 | <p>Add this code after the line <code>choice = ch.split(',')</code></p>
<pre><code>dict = {'1':'Ver', '2':'HeaderLength', '3':'TotalLength'}
print(', '.join([dict[i] for i in choice if i in dict.keys()]))
</code></pre>
<p>I would recommend you replace your while loop with the following:</p>
<pre><code>while loop:
... | 2 | 2016-06-08T08:24:46Z | [
"python",
"python-2.7"
] |
How to get an windows executable from my kivy app (Pyinstaller)? | 37,696,206 | <p>I've done a kivy app and I packaged to an .apk with buildozer. The fact is that now I want to package in a .exe for windows with Pyinstaller but I have realised that this two programs (buildozer and Pyinstaller), don't work in the same way. I've been looking for a good tutorial that could help me to get the file, bu... | 0 | 2016-06-08T07:40:44Z | 37,700,197 | <p>The Kivy documentation for this is <a href="https://kivy.org/docs/guide/packaging-windows.html" rel="nofollow">here</a>.</p>
<p>You probably do have to run this in Windows if you want to create a package for that platform.</p>
| 0 | 2016-06-08T10:40:40Z | [
"python",
"linux",
"package",
"kivy",
"pyinstaller"
] |
How to get an windows executable from my kivy app (Pyinstaller)? | 37,696,206 | <p>I've done a kivy app and I packaged to an .apk with buildozer. The fact is that now I want to package in a .exe for windows with Pyinstaller but I have realised that this two programs (buildozer and Pyinstaller), don't work in the same way. I've been looking for a good tutorial that could help me to get the file, bu... | 0 | 2016-06-08T07:40:44Z | 37,823,174 | <p>You have to run PyInstaller yourfile.spec on a windows environment.
I can share a spec file I am using just as an example.</p>
<pre><code># -*- mode: python -*-
import os
from os.path import join
from kivy import kivy_data_dir
from kivy.deps import sdl2, glew
from kivy.tools.packaging import pyinstaller_hooks as ... | 0 | 2016-06-14T22:29:00Z | [
"python",
"linux",
"package",
"kivy",
"pyinstaller"
] |
PyQt: Window stops responding when listening to ip, port | 37,696,431 | <p>I am trying to make a simple chat application with sockets, When i tried a simple thing, making a loop and listening to my hostname and port, GUI would start freezing and would not respond at all.</p>
<p>However, i also tried a <code>QTimer()</code>, since it is designed for PyQt, but it would bring a same result a... | 0 | 2016-06-08T07:52:33Z | 37,696,934 | <p>Most probably the problem is occuring because you connecting the socket in the main application only which is stalling the whole process including the GUI.
So the solution is better you run socket function and chat function in a separate process using <a href="https://docs.python.org/2/library/subprocess.html" rel=... | 1 | 2016-06-08T08:18:32Z | [
"python",
"sockets",
"pyqt",
"qtimer"
] |
PyQt: Window stops responding when listening to ip, port | 37,696,431 | <p>I am trying to make a simple chat application with sockets, When i tried a simple thing, making a loop and listening to my hostname and port, GUI would start freezing and would not respond at all.</p>
<p>However, i also tried a <code>QTimer()</code>, since it is designed for PyQt, but it would bring a same result a... | 0 | 2016-06-08T07:52:33Z | 37,697,116 | <p>You need to do the GUI and the communication in different threads. When the socket is for example waiting for some data, the GUI is blocked. You can connect the two threads using signal/slots of QT.</p>
<p>For example, Example is the class for GUI. MyThread will run in another thread and call a slot of Example ever... | 0 | 2016-06-08T08:27:33Z | [
"python",
"sockets",
"pyqt",
"qtimer"
] |
How to get rid of \x00 in my array of bytes? | 37,696,463 | <p>Here is the example of my array:</p>
<blockquote>
<p><code>b'[\x00{\x00"\x00s\x00u\x00b\x00i\x00d\x00"\x00:\x006\x002\x008\x003\x007\x00,\x00"\x00n\x00a\x00m\x00e\x00"\x00:\x00"\x00B\x00e\x00y\x00o\x00n\x00d\x00\x00E\x00y\x00e\x00s\x00"\x00,\x00"\x00p\x00r\x00i\x00c\x00e\x00"\x00:\x00"\x001\x001\x008\x00\x00p\x00... | 0 | 2016-06-08T07:54:05Z | 37,696,618 | <p>Decode it to text. Or open the file with the correct encoding in the first place.</p>
<pre><code>>>> b'[\x00{\x00"\x00s\x00u\x00b\x00'.decode('utf-16le')
'[{"sub'
</code></pre>
| 1 | 2016-06-08T08:02:03Z | [
"python"
] |
How to get the Style name of a paragraph in a libreoffice document with a python macro? | 37,696,554 | <p>I'm in need to create a python macro for some odt and ods documents.</p>
<p>I need to find the style name of a line and do some specific work for every style i found.</p>
<p>I can open the documents, get the line but not the style.
I've searched on internet and here but I found nothing.</p>
<p>Can someone help me... | 0 | 2016-06-08T07:59:11Z | 37,704,423 | <p>Read the <a href="https://www.openoffice.org/api/docs/common/ref/com/sun/star/style/ParagraphProperties.html#ParaStyleName" rel="nofollow">ParaStyleName</a>:</p>
<pre><code>style_name = cursor.getPropertyValue("ParaStyleName")
</code></pre>
| 1 | 2016-06-08T13:49:10Z | [
"python",
"python-3.x",
"macros",
"libreoffice"
] |
Django and one-time links with data | 37,696,582 | <p>I think I have a simple case here but I'm not finding good examples of the implementation ( or probably failing to understand).</p>
<p>After the user (not logged in) types his username to a form, Django would generate a unique URL based of this data (encoded in URL?) for the user that can be accessed once and withi... | 0 | 2016-06-08T08:00:20Z | 37,697,234 | <p>If you don't need that url you could save data to the session and send the user to a specific url.
The view connected to the url generates content depending on the (anonymous) users session. The user can see the content as long as you sessions last or you implement a time stamp an check this before delivering conten... | 0 | 2016-06-08T08:33:30Z | [
"python",
"django",
"forms"
] |
python won't execute second condition if elif | 37,696,605 | <p>i have this on my script</p>
<pre><code>for x in test:
extra_data_list = ast.literal_eval(x['extra_data'][3])
if extra_data_list.has_key('first_name') == True:
if extra_data_list['email_address'] == current_user['email']:
linked.append('Linkedin')
elif is_google == current_user['emai... | -6 | 2016-06-08T08:01:15Z | 37,696,688 | <p>You are missing a tab before the elif. It referers to the external if</p>
| 1 | 2016-06-08T08:05:33Z | [
"python"
] |
python won't execute second condition if elif | 37,696,605 | <p>i have this on my script</p>
<pre><code>for x in test:
extra_data_list = ast.literal_eval(x['extra_data'][3])
if extra_data_list.has_key('first_name') == True:
if extra_data_list['email_address'] == current_user['email']:
linked.append('Linkedin')
elif is_google == current_user['emai... | -6 | 2016-06-08T08:01:15Z | 37,696,710 | <p>Because the first if condition is true your code cannot execute the elif!</p>
<p>You can just use a normal if statement:</p>
<pre><code>for x in test:
extra_data_list = ast.literal_eval(x['extra_data'][3])
if extra_data_list.has_key('first_name') == True:
if extra_data_list['email_address'] == curr... | 0 | 2016-06-08T08:06:39Z | [
"python"
] |
xhtml2pdf not picking image | 37,696,620 | <p>i am creating pdf from html and it gets converted but without image. i have tried the absolute urls also but it still doesn't work
pdf function:</p>
<pre><code>def test_pdf(request):
template = get_template('../templates/index.html')
html = template.render(Context(data))
filename = 'pdfs/'+str(random.r... | 0 | 2016-06-08T08:02:05Z | 37,699,520 | <p>Could not even imagine the error :
in my css i have written :</p>
<pre><code>.main{width:75%;}
</code></pre>
<p>because of this images were not visible. I just removed it randomly and images started displaying </p>
| 0 | 2016-06-08T10:10:05Z | [
"python",
"django",
"xhtml2pdf"
] |
how to find difference in dates in pandas dataframe in Azure ML | 37,696,630 | <p>Is Azure uses some other Syntax for finding difference in dates and time.<br>
or<br>
Any package is missing in Azure.<br>
how to find difference in dates in pandas data-frame in Azure ML.
<br>I have 2 columns in a dataframe and I have to find the difference of two and have to kept in third column ,the problem is thi... | 0 | 2016-06-08T08:02:16Z | 38,239,034 | <p>Per my experience, it seems that the issue was caused by your code without the <code>dataframe_service</code> which indicates that the function operations on a data frame, please see <a href="https://github.com/Azure/Azure-MachineLearning-ClientLibrary-Python#dataframe_service" rel="nofollow">https://github.com/Azur... | 0 | 2016-07-07T06:45:22Z | [
"python",
"azure",
"pandas",
"machine-learning",
"azure-machine-learning"
] |
Comparing two DataFrames elements with different DataFrame | 37,696,640 | <p>I have a DataFrame which has multiple samples </p>
<pre><code>df1 = [[ 0 1 2 3 4 5 6 7 8 9 10 11 \
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 13.4 5.2 7.7 -2.1 1.6 -4.1 -0.5 8.2 15.9 12.9 11.8 9.3
2 -3.1 -0.... | 2 | 2016-06-08T08:02:50Z | 37,697,088 | <p>OK I think the following should work:</p>
<pre><code>In [208]:
# load some data
t="""1 13.4 5.2 7.7 -2.1 1.6 -4.1 -0.5 8.2 15.9 12.9 11.8 9.3
2 -3.1 -0.6 -5.1 -0.5 -4.1 0.5 -3.6 -5.6 -9.7 -3.6 -4.7 -5.7
3 -10.3 -1.0 -9.8 0.5 -3.6 1.0 -1.5 -1.6 -5.1 -4.6 -13.3 -10.7
... | 2 | 2016-06-08T08:26:47Z | [
"python",
"pandas"
] |
Comparing two DataFrames elements with different DataFrame | 37,696,640 | <p>I have a DataFrame which has multiple samples </p>
<pre><code>df1 = [[ 0 1 2 3 4 5 6 7 8 9 10 11 \
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 13.4 5.2 7.7 -2.1 1.6 -4.1 -0.5 8.2 15.9 12.9 11.8 9.3
2 -3.1 -0.... | 2 | 2016-06-08T08:02:50Z | 37,697,205 | <h3>Setup</h3>
<pre><code>import pandas as pd
import numpy as np
np.random.seed([3,1415])
df1 = pd.DataFrame(np.random.choice(range(10), (20, 10)))
df2 = pd.Series(np.random.choice(range(10), (10,)))
</code></pre>
<p>try:</p>
<pre><code>1 * (df1 > df2) - (df1 < df2)
0 1 2 3 4 5 6 7 8 9
0 -1 1... | 2 | 2016-06-08T08:32:30Z | [
"python",
"pandas"
] |
How to prevent admin superusers from causing "Site matching query does not exist" errors? | 37,696,755 | <p>There are many SO questions about the Django errormessage <code>Site matching query does not exist.</code>:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/11814059/site-matching-query-does-not-exist">Site matching query does not exist</a></li>
<li><a href="http://stackoverflow.com/questions/16068518/djang... | 0 | 2016-06-08T08:08:57Z | 37,697,316 | <p>Create a custom admin class like so:</p>
<pre><code>class DeleteNotAllowedModelAdmin(admin.ModelAdmin):
# Other stuff here
def has_delete_permission(self, request, obj=None):
return False
</code></pre>
<p>If you only want to prevent deletion of say the last site and allow when there are more than o... | 1 | 2016-06-08T08:36:53Z | [
"python",
"django",
"high-availability"
] |
QTabWidget tabs shelf as eclipse | 37,696,759 | <p>I am trying to achieve tabs shelf when the number of max tabs is increasing.</p>
<p>For Example:</p>
<p>Max_Tabs = 5</p>
<p>if number of open tabs is getting greater than 5 then the oldest one should popout to the shelf.</p>
<p>Can I use setcornerwidget for this?
If yes then which widget I should Consider using?... | 0 | 2016-06-08T08:09:09Z | 37,718,058 | <p>Yes, you can use <code>setCornerWidget</code> for this. You'll probably want to use a <code>QToolButton</code> with a <code>QMenu</code> for the widget.</p>
| 1 | 2016-06-09T06:08:43Z | [
"python",
"pyqt",
"pyqt4",
"qtabwidget"
] |
Complex non-greedy matching with regular expressions | 37,696,928 | <p>I'm trying to parse rows from a HTML table with cells containing specific values with regular expressions in Python. My aim in this (contrived) example is to get the rows with "cow". </p>
<pre><code>import re
response = '''
<tr class="someClass"><td></td><td>chicken</td></tr>
&l... | 5 | 2016-06-08T08:18:17Z | 37,697,113 | <p>If your 'response' string always contains newlines then you can do what you need without regex. Use the built-in <code>split</code> function to create a list of each line. Then iterate over the list and see if 'cow' is in the line:</p>
<pre><code>response = '''
<tr class="someClass"><td></td><t... | 0 | 2016-06-08T08:27:31Z | [
"python",
"regex",
"non-greedy"
] |
Complex non-greedy matching with regular expressions | 37,696,928 | <p>I'm trying to parse rows from a HTML table with cells containing specific values with regular expressions in Python. My aim in this (contrived) example is to get the rows with "cow". </p>
<pre><code>import re
response = '''
<tr class="someClass"><td></td><td>chicken</td></tr>
&l... | 5 | 2016-06-08T08:18:17Z | 37,697,175 | <p>You don't really need regex for this at all.</p>
<p>As soon as you add the ? quantifier to your expression, you've made the token lazy (non-greedy).</p>
<p>Anyway, you could just do:</p>
<pre><code>for line in example:
if 'cow' in line:
print(line)
</code></pre>
<p>no regex required.</p>
<p>If you w... | 0 | 2016-06-08T08:31:01Z | [
"python",
"regex",
"non-greedy"
] |
Complex non-greedy matching with regular expressions | 37,696,928 | <p>I'm trying to parse rows from a HTML table with cells containing specific values with regular expressions in Python. My aim in this (contrived) example is to get the rows with "cow". </p>
<pre><code>import re
response = '''
<tr class="someClass"><td></td><td>chicken</td></tr>
&l... | 5 | 2016-06-08T08:18:17Z | 37,697,494 | <p>If the input string contains each tag on a separate line, <a href="http://stackoverflow.com/a/37697097/1925388">Moses Koledoye's answer</a> would work.<br>
However, if the tags are spread out over multiple lines, the following would be needed:</p>
<pre><code>import re
response = '''
<tr class="someClass
">&... | 2 | 2016-06-08T08:43:56Z | [
"python",
"regex",
"non-greedy"
] |
Complex non-greedy matching with regular expressions | 37,696,928 | <p>I'm trying to parse rows from a HTML table with cells containing specific values with regular expressions in Python. My aim in this (contrived) example is to get the rows with "cow". </p>
<pre><code>import re
response = '''
<tr class="someClass"><td></td><td>chicken</td></tr>
&l... | 5 | 2016-06-08T08:18:17Z | 37,704,148 | <p>Your problem isn't related to the greediness but to the fact that the regex engine tries to succeed at each position in the string from left to right. That's why you will always obtain the <strong>leftmost</strong> result and using a non-greedy quantifier will not change the starting position!</p>
<p>If you write s... | 4 | 2016-06-08T13:38:43Z | [
"python",
"regex",
"non-greedy"
] |
how to call the python method inside xml template using odoo 9 module | 37,697,107 | <p>i have a piece of code having variable in .py file but i don't know how to call the varibale inside xml template </p>
<p>.xml file</p>
<pre><code> <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="menu_secondary" name="group_js menu" inherit_id="web.menu_secondary">... | 0 | 2016-06-08T08:27:22Z | 38,181,043 | <p>If it is in the same model then you can replace your template using the following code.</p>
<pre><code> <template id="menu_secondary" name="group_js menu" inherit_id="web.menu_secondary">
<xpath expr="." position="inside">
<span t-esc="o.test()" />
</xpath>
</template>... | 0 | 2016-07-04T09:19:27Z | [
"python",
"xml",
"odoo-9"
] |
Calculation occurance random numbers in csv file | 37,697,154 | <p>I have a csv file with the columns: recipe_name (index), apple, citrus, banana, melon, ... (and more columns with fruits).
For each recipe there is a row with the weight percentages of each fruit. But not all recipes contain all fruits. These are empty spaces in the csv file.
It looks like this: </p>
<blockquote>... | 1 | 2016-06-08T08:29:32Z | 37,697,242 | <p>call <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.count.html" rel="nofollow"><code>count</code></a> on the cols of interest and pass param <code>axis=1</code>:</p>
<pre><code>In [217]:
df['count'] = df.ix[:,'apple':].count(axis=1)
df
Out[217]:
recipe_name apple citrus banana... | 2 | 2016-06-08T08:33:55Z | [
"python",
"excel",
"csv",
"pandas"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.