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: Is there anyway to read messages from a tcp port without knowing the sent message size? | 39,574,683 | <p>I'm trying to do write a python script that should work as a tcp server. I receive messages of different sizes from a client whose message format cannot be changed, so my server script is the one that, somehow, should get adapted to the received messages. Together with this, the server can't send back any kind of ac... | -1 | 2016-09-19T13:40:59Z | 39,576,008 | <p>TCP is a data stream protocol which means that there are no inherent message boundaries. The concept of a message can only be defined by the application. This is typically done by defining a message boundary or by prefixing the message with its size. Since the message is thus defined at the application level you wil... | 1 | 2016-09-19T14:46:06Z | [
"python",
"tcp"
] |
'int' object not subscriptable error | 39,574,702 | <pre><code>while 1 == 1:
import csv
from time import sleep
import sys
bill = 0
with open('list2.txt') as csvfile:
readCSV = csv.reader(csvfile, delimiter = ",")
GTINs = []
products = []
prices = []
for row in readCSV:
GTIN = row[0]
... | -1 | 2016-09-19T13:42:03Z | 39,574,835 | <p>For your loops <code>if confirmation == ("YES") or ("Yes") or ("yes"):</code></p>
<p>That's never going to work in Python because you are basically asking <code>if confirmation is equal to "YES" or if ("Yes") or if ("yes")</code> ; and <code>if ("Yes")</code> is true because it's valid and not None or 0 or empty. Y... | 4 | 2016-09-19T13:48:31Z | [
"python",
"python-3.x",
"csv"
] |
'int' object not subscriptable error | 39,574,702 | <pre><code>while 1 == 1:
import csv
from time import sleep
import sys
bill = 0
with open('list2.txt') as csvfile:
readCSV = csv.reader(csvfile, delimiter = ",")
GTINs = []
products = []
prices = []
for row in readCSV:
GTIN = row[0]
... | -1 | 2016-09-19T13:42:03Z | 39,574,981 | <p>In relation with the 'if' comparison issue, I would recommend you to firstly remove the Upper format from the string and then compare. It would be then more idiomatic and also youre problem would be solved:</p>
<pre><code>if anythingelse.lower() == ("yes"):
x = 1
elif anythingelse.lower() == ("no"):
... | 0 | 2016-09-19T13:55:37Z | [
"python",
"python-3.x",
"csv"
] |
Replace newline in python when reading line for line | 39,574,730 | <p>I am trying to do a simple parsing on a text in python which I have no issues with in bash using tr '\n' ' '. Basically to get all of the lines on a single line. In python print line is a bit different from what I understand. re.sub cannot find my new line because it doesn't exist even though when I print to an ou... | 0 | 2016-09-19T13:43:36Z | 39,574,815 | <p>Use <code>replace()</code> method.</p>
<pre><code>file = open('out.txt', 'r')
data = file.read()
file.close()
data.replace('\n', '')
</code></pre>
| 0 | 2016-09-19T13:47:32Z | [
"python",
"regex",
"newline",
"python-2.x"
] |
Replace newline in python when reading line for line | 39,574,730 | <p>I am trying to do a simple parsing on a text in python which I have no issues with in bash using tr '\n' ' '. Basically to get all of the lines on a single line. In python print line is a bit different from what I understand. re.sub cannot find my new line because it doesn't exist even though when I print to an ou... | 0 | 2016-09-19T13:43:36Z | 39,575,029 | <p>You can write directly to stdout to avoid the automatic newline of <code>print</code>:</p>
<pre><code>from sys import stdout
stdout.write("foo")
stdout.write("bar\n")
</code></pre>
<p>This will print <code>foobar</code> on a single line.</p>
| 1 | 2016-09-19T13:57:46Z | [
"python",
"regex",
"newline",
"python-2.x"
] |
Replace newline in python when reading line for line | 39,574,730 | <p>I am trying to do a simple parsing on a text in python which I have no issues with in bash using tr '\n' ' '. Basically to get all of the lines on a single line. In python print line is a bit different from what I understand. re.sub cannot find my new line because it doesn't exist even though when I print to an ou... | 0 | 2016-09-19T13:43:36Z | 39,575,150 | <p>When you call the <code>print</code> statement, you automatically add a new line. Just add a comma:</p>
<pre><code>print line_2,
</code></pre>
<p>And it will all print on the same line.</p>
<p>Mind you, if you're trying to get all lines of a file, and print them on a single line, there are more efficient ways to ... | 1 | 2016-09-19T14:04:12Z | [
"python",
"regex",
"newline",
"python-2.x"
] |
Replace newline in python when reading line for line | 39,574,730 | <p>I am trying to do a simple parsing on a text in python which I have no issues with in bash using tr '\n' ' '. Basically to get all of the lines on a single line. In python print line is a bit different from what I understand. re.sub cannot find my new line because it doesn't exist even though when I print to an ou... | 0 | 2016-09-19T13:43:36Z | 39,575,557 | <p>Using <code>with</code> ensures you close the file after iteration.</p>
<p>Iterating saves memory and doesn't load the entire file.</p>
<p><code>rstrip()</code> removes the newline in the end.</p>
<p>Combined:</p>
<pre><code>with open('out.txt', 'r') as f:
for line in f:
print line.rstrip(),
</code><... | 1 | 2016-09-19T14:24:10Z | [
"python",
"regex",
"newline",
"python-2.x"
] |
Using python 2 or 3, matplotlib and tkinter causes an extra empty window to open on calling plt.show() | 39,574,732 | <p>I am making an interactive data analysis tool that I am having trouble with (in <code>python 2.7</code>, <code>3.4</code> and <code>3.5</code>). The full program makes graphs that the user has to interact with and then close. It also requires the user to input files via a filechooser. </p>
<p>The issue is whenever ... | 1 | 2016-09-19T13:43:41Z | 39,575,994 | <p>You could try naming the figure as maybe it's getting confused as to what you are referring to when you ask it to show a figure</p>
<pre><code>x = np.arange(0,5,0.1)
y = np.sin(x)
fig1 = plt.figure()
plt.plot(x,y)
plt.show(fig1)
</code></pre>
| 0 | 2016-09-19T14:45:33Z | [
"python",
"python-3.x",
"matplotlib",
"tkinter"
] |
Using python 2 or 3, matplotlib and tkinter causes an extra empty window to open on calling plt.show() | 39,574,732 | <p>I am making an interactive data analysis tool that I am having trouble with (in <code>python 2.7</code>, <code>3.4</code> and <code>3.5</code>). The full program makes graphs that the user has to interact with and then close. It also requires the user to input files via a filechooser. </p>
<p>The issue is whenever ... | 1 | 2016-09-19T13:43:41Z | 39,599,850 | <p>After some more research, it looks like the extra window is a root window. This link explains it:</p>
<p><a href="https://bytes.com/topic/python/answers/768419-askopenfilename-tkfiledialog-problem" rel="nofollow">https://bytes.com/topic/python/answers/768419-askopenfilename-tkfiledialog-problem</a></p>
<pre><code>... | 0 | 2016-09-20T16:59:02Z | [
"python",
"python-3.x",
"matplotlib",
"tkinter"
] |
Using python 2 or 3, matplotlib and tkinter causes an extra empty window to open on calling plt.show() | 39,574,732 | <p>I am making an interactive data analysis tool that I am having trouble with (in <code>python 2.7</code>, <code>3.4</code> and <code>3.5</code>). The full program makes graphs that the user has to interact with and then close. It also requires the user to input files via a filechooser. </p>
<p>The issue is whenever ... | 1 | 2016-09-19T13:43:41Z | 39,601,718 | <p>Ok I think I solved it myself after a bit of poking around in the matplotlib source. I tried changing the matplotlib backend to gtk3cairo. I guess the <code>Tk().withdraw()</code> was also affecting the matplotlib backend. Works on my linux distro but still need to test it on windows. If I find a solution that works... | 0 | 2016-09-20T18:52:20Z | [
"python",
"python-3.x",
"matplotlib",
"tkinter"
] |
Django filter-save QuerySet | 39,574,742 | <p>I've a django model:-</p>
<pre><code>class ModelA(models.Model):
flag = models.BooleanField(default=True)
</code></pre>
<p>Next, I query it:- </p>
<p><code>obj = ModelA.objects.filter(flag=True)</code></p>
<p>Now, I change the <code>flag</code> of first object.</p>
<pre><code>obj1 = obj[0]
obj1.flag = False... | 0 | 2016-09-19T13:44:21Z | 39,575,287 | <p>Because the first object does not match anymore the filtered queryset, you can't find it in the <code>obj</code> pointer. If you want to clone the queryset to another variable you can use <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#values-list" rel="nofollow">values_list</a>.</p>
| -1 | 2016-09-19T14:11:05Z | [
"python",
"django",
"django-queryset"
] |
Django filter-save QuerySet | 39,574,742 | <p>I've a django model:-</p>
<pre><code>class ModelA(models.Model):
flag = models.BooleanField(default=True)
</code></pre>
<p>Next, I query it:- </p>
<p><code>obj = ModelA.objects.filter(flag=True)</code></p>
<p>Now, I change the <code>flag</code> of first object.</p>
<pre><code>obj1 = obj[0]
obj1.flag = False... | 0 | 2016-09-19T13:44:21Z | 39,575,470 | <p>I believe that every time you run <code>obj[0]</code>, Django goes back to the database and runs the query. You can see the queries that are executed by using <code>django.db.connection</code>:</p>
<pre><code>>>> from django.db import connection
>>> obj = ModelA.objects.filter(flag=True)
>>... | 0 | 2016-09-19T14:19:35Z | [
"python",
"django",
"django-queryset"
] |
Django filter-save QuerySet | 39,574,742 | <p>I've a django model:-</p>
<pre><code>class ModelA(models.Model):
flag = models.BooleanField(default=True)
</code></pre>
<p>Next, I query it:- </p>
<p><code>obj = ModelA.objects.filter(flag=True)</code></p>
<p>Now, I change the <code>flag</code> of first object.</p>
<pre><code>obj1 = obj[0]
obj1.flag = False... | 0 | 2016-09-19T13:44:21Z | 39,575,617 | <p>If you look at <code>Queryset.__getitem__()</code> (django/db/models/query.py), you'll find this (django 1.10):</p>
<pre><code>295 qs = self._clone()
296 qs.query.set_limits(k, k + 1)
297 return list(qs)[0]
</code></pre>
<p>Note that you only get there if the queryset has not been iterated yet - else it would f... | 0 | 2016-09-19T14:27:08Z | [
"python",
"django",
"django-queryset"
] |
Error loading MySQLdb module: No module named 'MySQLdb' | 39,574,813 | <p>I have tried a lot to solve this issue but I did not solve it. I have searched a lot on google and stackoverflow, no option is working for me. Please help me. Thanks in advance. I am using django 1.10, python 3.4.
I have tried :</p>
<ol>
<li>pip install mysqldb.</li>
<li>pip install mysql.</li>
<li>pip install mysq... | 2 | 2016-09-19T13:47:27Z | 39,574,842 | <p>MySQLdb is not compatible with Python 3. Use mysql-client or mysql-connect.</p>
| 1 | 2016-09-19T13:48:47Z | [
"python",
"mysql",
"django"
] |
Error loading MySQLdb module: No module named 'MySQLdb' | 39,574,813 | <p>I have tried a lot to solve this issue but I did not solve it. I have searched a lot on google and stackoverflow, no option is working for me. Please help me. Thanks in advance. I am using django 1.10, python 3.4.
I have tried :</p>
<ol>
<li>pip install mysqldb.</li>
<li>pip install mysql.</li>
<li>pip install mysq... | 2 | 2016-09-19T13:47:27Z | 39,575,525 | <p>You can use <strong>mysqlclient</strong> instead of MySQLdb which is not compatible with Python 3:</p>
<pre><code>pip install mysqlclient
</code></pre>
| 1 | 2016-09-19T14:22:46Z | [
"python",
"mysql",
"django"
] |
Error loading MySQLdb module: No module named 'MySQLdb' | 39,574,813 | <p>I have tried a lot to solve this issue but I did not solve it. I have searched a lot on google and stackoverflow, no option is working for me. Please help me. Thanks in advance. I am using django 1.10, python 3.4.
I have tried :</p>
<ol>
<li>pip install mysqldb.</li>
<li>pip install mysql.</li>
<li>pip install mysq... | 2 | 2016-09-19T13:47:27Z | 39,575,675 | <p>MySQLdb is only for Python 2.x. You can't install in Python 3.x versions. Now from your question i can see that you are working with Django. In this case you have three alternatives, from <a href="https://docs.djangoproject.com/en/1.10/ref/databases/#mysql-notes" rel="nofollow">Django mysql notes</a>:</p>
<ul>
<li>... | 1 | 2016-09-19T14:29:55Z | [
"python",
"mysql",
"django"
] |
How to convert suds object to xml string | 39,574,831 | <p>This is a duplicate to this question:
<a href="http://stackoverflow.com/questions/33303813/how-to-convert-suds-object-to-xml">How to convert suds object to xml</a>
<br>But the question has not been answered: "totxt" is not an attribute on the Client class.
Unfortunately I lack of reputation to add comments. <br>So ... | 0 | 2016-09-19T13:48:21Z | 39,589,789 | <p>You have some issues in <code>write_customer_obj_xml_file</code> function:</p>
<p>Fix bad path:</p>
<pre><code>output_filename = r'C:\temp\test.xml'
</code></pre>
<blockquote>
<p>The following line is the problem. "to_xml" does not exist and I can't find a way to do it.</p>
</blockquote>
<p>What's the type of ... | 0 | 2016-09-20T08:59:04Z | [
"python",
"xml",
"soap",
"suds"
] |
How to convert suds object to xml string | 39,574,831 | <p>This is a duplicate to this question:
<a href="http://stackoverflow.com/questions/33303813/how-to-convert-suds-object-to-xml">How to convert suds object to xml</a>
<br>But the question has not been answered: "totxt" is not an attribute on the Client class.
Unfortunately I lack of reputation to add comments. <br>So ... | 0 | 2016-09-19T13:48:21Z | 39,614,744 | <p>I found a way that works for me. The trick is to create the Client with the option "nosend=True".
<br>
In the <a href="https://jortel.fedorapeople.org/suds/doc/suds.options.Options-class.html" rel="nofollow">documentation</a> it says:<br></p>
<blockquote>
<p><strong>nosend</strong> - Create the soap envelope but ... | 0 | 2016-09-21T11:02:32Z | [
"python",
"xml",
"soap",
"suds"
] |
filter tags of django-taggit in Django's Queryset | 39,574,909 | <p>Having the following models:</p>
<pre><code>class Post(models.Model):
title = models.CharField(max_length=250)
tags = TaggableManager()
</code></pre>
<p>and the data areï¼</p>
<pre><code>**post.title** **post.tags**
Django By Example python,django,web
Who wa... | 0 | 2016-09-19T13:52:34Z | 39,692,261 | <p>Django is counting only the <code>python</code> and <code>data</code> tags which you included in your filter clause - other tags are not counted. (Note that the only example with <code>sam_tags</code> of 2 is the one tagged both <code>data</code> and <code>python</code>.) This is probably unexpected behavior, but ... | 1 | 2016-09-25T22:01:54Z | [
"python",
"django",
"django-1.9",
"django-taggit"
] |
Python-Django Response the text of error | 39,574,918 | <p>How can I response the text of validation error to my template with Ajax?</p>
<pre><code>def create_user(request):
if request.method == 'POST':
is_super = True
if request.POST.get('is_super') in 'false':
is_super = False
if request.POST.get('password') == request.POST.get('co... | -1 | 2016-09-19T13:52:54Z | 39,748,062 | <pre><code>def create_user(request):
if request.method == 'POST':
is_super = True
if request.POST.get('is_super') in 'false':
is_super = False
if request.POST.get('password') == request.POST.get('confirm'):
user = User.objects.create(first_name=request.POST.get('first... | 0 | 2016-09-28T12:49:30Z | [
"python",
"ajax",
"django"
] |
TensorFlow "tf.image" functions on an image batch | 39,574,999 | <p>I would like to use this function in TensorFlow, however it operates on 3D tensors rather than 4D tensors: I have an outer dimension of batch_size. </p>
<pre><code>tf.image.random_flip_left_right(input_image_data)
</code></pre>
<p>That said, this function expects a tensor (image) of shape:</p>
<pre><code>(width, ... | 1 | 2016-09-19T13:56:24Z | 39,578,657 | <p>You would have to use something like tf.pack and tf.unpack or tf.gather and tf.concatenate to convert from your 4D array to your 3D array.</p>
<p>Depending upon how your loading your data you can do the processing in numpy. Another alternative is to process each image before you put it into a batch. </p>
<p>Let m... | 0 | 2016-09-19T17:16:57Z | [
"python",
"image-processing",
"machine-learning",
"computer-vision",
"tensorflow"
] |
TensorFlow "tf.image" functions on an image batch | 39,574,999 | <p>I would like to use this function in TensorFlow, however it operates on 3D tensors rather than 4D tensors: I have an outer dimension of batch_size. </p>
<pre><code>tf.image.random_flip_left_right(input_image_data)
</code></pre>
<p>That said, this function expects a tensor (image) of shape:</p>
<pre><code>(width, ... | 1 | 2016-09-19T13:56:24Z | 39,852,683 | <p>You can use map_fcn as described in this post <a href="http://stackoverflow.com/questions/38920240/tensorflow-image-operations-for-batches">TensorFlow image operations for batches</a></p>
<p>result = tf.map_fn(lambda img: tf.image.random_flip_left_right(img), images)</p>
| 1 | 2016-10-04T12:43:57Z | [
"python",
"image-processing",
"machine-learning",
"computer-vision",
"tensorflow"
] |
Button instance has no _call_ method | 39,575,022 | <pre><code> #AssessmentGUI
from Tkinter import *
window=Tk()
window.title('Troubleshooting')
def start():
wet()
def wet():
global wetlabel
wetlabel=Label(window, text="Has the phone got wet? Y/N")
wetsubmit()
def wetsubmit():
wetlabel.pack()
wetanswer=(entry.get())
if wetanswer=="Y":
... | 0 | 2016-09-19T13:57:25Z | 39,575,120 | <p>You have a class, named <code>Button</code>,and then you create a variable named <code>Button</code>. You have now destroyed the class, so the next time you try to create a button, you are calling your variable instead.</p>
<p>Lesson: don't use variable names that are the same as classes. </p>
| 1 | 2016-09-19T14:02:49Z | [
"python",
"user-interface",
"tkinter",
"label",
"call"
] |
create multidimensional dictionary to count word occurence | 39,575,236 | <p>I have a source.txt file consisting of words. Each word is in a new line.</p>
<pre><code>apple
tree
bee
go
apple
see
</code></pre>
<p>I also have a taget_words.txt file, where the words are also in one line each.</p>
<pre><code>apple
bee
house
garden
eat
</code></pre>
<p>Now I have to search for each of the targ... | -5 | 2016-09-19T14:08:09Z | 39,689,816 | <p>The first issue you will face is your lack of understanding of dicts. Each key can occur only once, so if you ask the interpreter to give you the value of the one you gave you might get a surprise:</p>
<pre><code>>>> {'apple':'tree', 'apple':'bee', 'apple':'go'}
{'apple': 'go'}
</code></pre>
<p>The proble... | 0 | 2016-09-25T17:37:02Z | [
"python",
"dictionary",
"multidimensional-array",
"counter"
] |
Function to check a variable and change it | 39,575,281 | <p>I am making a calculator to turn RGB values into Hexidecimal numbers. as I was coding I realised I had written the same code three times to check user input for red, green, and blue. So I thought, why not use a function to check my variables for me!! Here is my code:</p>
<pre><code>invalid_msg = 'Whoops looks like ... | 1 | 2016-09-19T14:10:40Z | 39,575,577 | <p>You need to do something like something like</p>
<pre><code>red = check_rgb(red)
</code></pre>
<p>When you just do</p>
<pre><code>check_rgb(red)
</code></pre>
<p>The return value is not used.</p>
| 2 | 2016-09-19T14:25:25Z | [
"python",
"python-2.7"
] |
Function to check a variable and change it | 39,575,281 | <p>I am making a calculator to turn RGB values into Hexidecimal numbers. as I was coding I realised I had written the same code three times to check user input for red, green, and blue. So I thought, why not use a function to check my variables for me!! Here is my code:</p>
<pre><code>invalid_msg = 'Whoops looks like ... | 1 | 2016-09-19T14:10:40Z | 39,575,680 | <p>You can check the condition on the three colors calling separately the function and then compare all them in the same statement:</p>
<pre><code>red_ok = check_rgb(red)
green_ok = check_rgb(green)
blue_ok = check_rgb(blue)
if (red_ok and green_ok and blue_ok) :
val = (red << 16) + (green << 8) + blue... | 0 | 2016-09-19T14:30:12Z | [
"python",
"python-2.7"
] |
Function to check a variable and change it | 39,575,281 | <p>I am making a calculator to turn RGB values into Hexidecimal numbers. as I was coding I realised I had written the same code three times to check user input for red, green, and blue. So I thought, why not use a function to check my variables for me!! Here is my code:</p>
<pre><code>invalid_msg = 'Whoops looks like ... | 1 | 2016-09-19T14:10:40Z | 39,576,137 | <p>As Davis Yoshida mentions, merely doing <code>check_rgb(red)</code> doesn't change the original value of <code>red</code>, since you forgot to save the value that <code>check_rgb</code> returns.</p>
<p>I recommend expanding your helper function so that it gets the user input and validates it too. Here's an example ... | 0 | 2016-09-19T14:52:05Z | [
"python",
"python-2.7"
] |
Code works in Windows, but not on Mac | 39,575,564 | <p>So I'm new to programming, and recently I got an assignment to create a program that could convert binary to decimal and vice versa, and also decimal to hexadecimal and vice versa. The problem is, I'm not allowed to use available functions such as <code>int()</code> or <code>hex()</code> or <code>bin()</code>.</p>
... | 0 | 2016-09-19T14:24:42Z | 39,575,819 | <p>The value of <code>temporary_result</code> never changes, but remains <code>""</code>. Therefore the value of <code>result</code> will always be the <code>str(x % 2)</code> for the most-recently-processed value of <code>x</code>. Given that the loop terminates when <code>x</code> goes to zero, it's likely that the f... | 1 | 2016-09-19T14:37:21Z | [
"python",
"windows",
"osx",
"python-3.x"
] |
Code works in Windows, but not on Mac | 39,575,564 | <p>So I'm new to programming, and recently I got an assignment to create a program that could convert binary to decimal and vice versa, and also decimal to hexadecimal and vice versa. The problem is, I'm not allowed to use available functions such as <code>int()</code> or <code>hex()</code> or <code>bin()</code>.</p>
... | 0 | 2016-09-19T14:24:42Z | 39,575,860 | <p>Why do you need temporary_result when the value never changes within your loop? </p>
<pre><code>def dectobin(x):
result = ""
while x > 0:
result = str(x % 2) + result
x = x // 2
return result
</code></pre>
| 0 | 2016-09-19T14:39:20Z | [
"python",
"windows",
"osx",
"python-3.x"
] |
KMeans clustering of textual data | 39,575,591 | <p>I have a pandas dataframe with the following 2 columns:</p>
<pre><code> Database Name Name
db1_user Login
db1_client Login
db_care Login
db_control LoginEdit
db_technology View
db_advan... | -2 | 2016-09-19T14:26:10Z | 39,581,534 | <p>What is the <strong>mean</strong> of</p>
<pre><code>Login
LoginEdit
View
</code></pre>
<p>supposed to be?</p>
<p>There is a reason why k-means only works on continuous numerical data. Because the <em>mean</em> requires such data to be well defined.</p>
<p>I don't think clustering is applicable on your problem <e... | 0 | 2016-09-19T20:26:04Z | [
"python",
"dataframe",
"cluster-analysis",
"k-means"
] |
KMeans clustering of textual data | 39,575,591 | <p>I have a pandas dataframe with the following 2 columns:</p>
<pre><code> Database Name Name
db1_user Login
db1_client Login
db_care Login
db_control LoginEdit
db_technology View
db_advan... | -2 | 2016-09-19T14:26:10Z | 39,698,930 | <p>I don't understand whether you want to develop clusters for each GROUP of "Name" Attributes, or alternatively create n clusters regardless of the value of "Name"; and I don't understand what clustering could achieve here.</p>
<p>In any case, just a few days ago there was a similar question on the datascience SE sit... | 1 | 2016-09-26T09:16:38Z | [
"python",
"dataframe",
"cluster-analysis",
"k-means"
] |
OpenCV and Anaconda Python | 39,575,666 | <p>How can you import <code>OpenCV</code> to run in <code>Python</code>?</p>
<p>I ran it on a windows platform. My main problem i ran into was using Python 3.5 (presuming it was the latest) and the latest version of OpenCV but i didn't know that OpenCV sis not compatible with Python 3.5 so online video tutorials on yo... | -3 | 2016-09-19T14:29:15Z | 39,577,324 | <pre><code>conda install -c menpo opencv3=3.1.0
</code></pre>
<p>or </p>
<pre><code>conda install -c anaconda opencv=2.4.10
</code></pre>
<p>It's a bit annoying that you need to know which collection a package is in if it isn't the standard one, but a certain search engine will find it.</p>
| 0 | 2016-09-19T15:57:58Z | [
"python",
"opencv",
"anaconda"
] |
Create a structured array in python | 39,575,721 | <p>I would like to create a dictionary in Python using numpy commands. </p>
<p>First I tried to define the structure and then to populate the array according to a number/case selected by the user. When I try to request one of the cases I get the following error (for case 1):</p>
<pre><code>cannot copy sequence with... | 0 | 2016-09-19T14:32:08Z | 39,578,177 | <p>print the initial <code>usgStruct</code> array:</p>
<pre><code>In [329]: usgStruct
Out[329]:
array([(0, 0, 0, '', 0, 0, 0)],
dtype=[('satNr', '<i4'), ('satAzimuth', '<i4'), ('satElevation', '<i4'), ('scenarioEnv', '<U'), ('scenarioHead', '<i4'), ('scenarioLen', '<i4'), ('speed', '<i4')]... | 0 | 2016-09-19T16:47:57Z | [
"python",
"arrays",
"numpy",
"structure"
] |
OpenCV Select Ink On Scanned Page | 39,575,744 | <p>Say we have a picture of a page with text on it. However, a threshold is not sufficient. On an example image, the page has a large shadow that covers half the image, such that at some points, there is paper that is darker than the lightest ink.</p>
<p>What's the best way to get a mask of the ink on the page? I'm th... | 0 | 2016-09-19T14:33:25Z | 39,577,889 | <p>There are two things you can try:</p>
<ul>
<li>Convert the image to HSV and check the hue component</li>
<li>Use algorithms to remove shadow from the image and then process it.
An example of such methods can be found in <a href="http://www.serc.iisc.ernet.in/~venky/SE263/papers/Salvador_CVIU2004.pdf" rel="nofollow... | 0 | 2016-09-19T16:30:57Z | [
"python",
"opencv",
"mask",
"threshold"
] |
How do I get opencv for python3 with anaconda3? | 39,575,800 | <p>So, initially, I just had python 3.5 from the anaconda installation and all was fine. Then I was following a tutorial that suggested the use of enthought canopy, which used python 2.7.
After this I did a 'pip install opencv-python' and that installed the 2.7 version of the library. I should note, I am on Ubunutu ... | 0 | 2016-09-19T14:35:56Z | 39,601,323 | <p>Once you have anaconda installed, try the following (as seen in <a href="https://rivercitylabs.org/up-and-running-with-opencv3-and-python-3-anaconda-edition/" rel="nofollow">this tutorial</a>):</p>
<pre><code>conda create -n opencv numpy scipy scikit-learn matplotlib python=3
source activate opencv
conda install -c... | 1 | 2016-09-20T18:30:15Z | [
"python",
"python-3.x",
"opencv"
] |
Does the entire scope path need to match for variable reuse in TensorFlow? | 39,575,892 | <p>Is the variable <code>Test</code> shared in these two scenarios?</p>
<pre class="lang-py prettyprint-override"><code>with tf.name_scope("ns1"):
with tf.variable_scope("vs1"):
var = tf.get_variable("Test", [1,2,3])
with tf.name_scope("ns2"):
with tf.variable_scope("vs1", reuse=True):
var = tf.get_variab... | 0 | 2016-09-19T14:40:19Z | 39,578,326 | <p>Yes, the variable is shared. In general, name_scope does <em>not</em> influence variable names, only variable_scope does (but yes, the whole prefix of variable_scopes must match). I think that it is reasonable to try and not use name_scope at all, it can be confusing when mixed with variable_scope. Also note that yo... | 2 | 2016-09-19T16:56:21Z | [
"python",
"tensorflow"
] |
password field is showing password in plain text | 39,575,910 | <p>I have used django allauth for user registration and login system. I could show the form by simplifying the lines of code using for loop. I got the right field type(TextInput and PasswordInput) for each field too. However the password field which has PasswordInput shows password in plain text. How can i resolve this... | 1 | 2016-09-19T14:41:10Z | 39,576,523 | <p>You can add class by overriding <code>__init__</code> method in form class</p>
<pre><code>def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['password'].widget.attrs['class'] = 'form-control'
</code></pre>
| 2 | 2016-09-19T15:10:51Z | [
"python",
"django",
"python-3.x",
"django-allauth"
] |
password field is showing password in plain text | 39,575,910 | <p>I have used django allauth for user registration and login system. I could show the form by simplifying the lines of code using for loop. I got the right field type(TextInput and PasswordInput) for each field too. However the password field which has PasswordInput shows password in plain text. How can i resolve this... | 1 | 2016-09-19T14:41:10Z | 39,576,622 | <p>The password is showing in plain text because you're assigning <code><input></code> types incorrectly, therefore not hiding passwords as <code><input type="password"></code> does.</p>
<p>From reading the comments, it looks like you're trying to add custom bootstrap classes to the form fields. As <a href... | 1 | 2016-09-19T15:15:46Z | [
"python",
"django",
"python-3.x",
"django-allauth"
] |
password field is showing password in plain text | 39,575,910 | <p>I have used django allauth for user registration and login system. I could show the form by simplifying the lines of code using for loop. I got the right field type(TextInput and PasswordInput) for each field too. However the password field which has PasswordInput shows password in plain text. How can i resolve this... | 1 | 2016-09-19T14:41:10Z | 39,576,808 | <p>You can also try this:</p>
<pre><code><input class="form-control" type="{{ field.field.widget.input_type }}"
name="{{ field.name }}"
id="id_{{ field.name }}" >
</code></pre>
| 0 | 2016-09-19T15:28:07Z | [
"python",
"django",
"python-3.x",
"django-allauth"
] |
Calling mapPartitions on a class method in python | 39,575,917 | <p>I'm fairly new to Python and to Spark but let me see if I can explain what I am trying to do.</p>
<p>I have a bunch of different types of pages that I want to process. I created a base class for all the common attributes of those pages and then have a page specific class inherit from the base class. The idea being ... | 1 | 2016-09-19T14:41:28Z | 39,577,121 | <p>A few suggestions:</p>
<ul>
<li>Don't create connections directly. Use connection pool (since each executor uses separate process setting pool size to one is just fine) and make sure that connections are automatically closed on timeout) instead.</li>
<li>Use <a href="http://stackoverflow.com/q/1318406/1560062">Borg... | 0 | 2016-09-19T15:46:15Z | [
"python",
"apache-spark"
] |
Get next value from a row that satisfies a condition in pandas | 39,575,947 | <p>I have a DataFrame that looks something like this:</p>
<pre><code> | event_type | object_id
------ | ------ | ------
0 | A | 1
1 | D | 1
2 | A | 1
3 | D | 1
4 | A | 2
5 | A | 2
6 | D | 2
7 | A |... | 0 | 2016-09-19T14:43:22Z | 39,576,338 | <p>You can do it with groupby like:</p>
<pre><code>def populate_next_a(object_df):
object_df['a_index'] = pd.Series(object_df.index, index=object_df.index)[object_df.event_type == 'A']
object_df['a_index'].fillna(method='bfill', inplace=True)
object_df['next_A'] = object_df['a_index'].where(object_df.event... | 2 | 2016-09-19T15:01:26Z | [
"python",
"python-3.x",
"pandas"
] |
Saving as csv output of applyin a "main" function in python | 39,575,972 | <p>I've been applying a main function in Python, by saying:</p>
<pre><code>def main():
"some code here"
if __name__ == '__main__':
main()
</code></pre>
<p>Then I get a result like this:</p>
<pre><code>[['This is my car not yours'], ['He answered me sorry'], ['no problem'], ['\nYou are crazy'], ['All cars ar... | 0 | 2016-09-19T14:44:34Z | 39,576,228 | <p>Hope this is what you wanted:</p>
<pre><code>def main():
return [['This is my car not yours'], ['He answered me sorry'], ['no problem'], ['\nYou are crazy'], ['All cars are the same']]
if __name__ == '__main__':
with open('output.txt', 'w') as f:
a = ('').join(str(main()))
f.write(a)
</code... | 0 | 2016-09-19T14:56:44Z | [
"python",
"csv"
] |
docker-py: how can I check if the build was successful? | 39,575,982 | <p>I'm trying to build myself a neat pipeline in Python 3. My problem, everything seems to be working nice, Jenkins always gives me a green bubble, but sometimes docker build fails to executed.</p>
<p>So <code>client.build</code> doesn't raise an error if the build breaks for some reason:</p>
<pre><code>try:
self... | 0 | 2016-09-19T14:45:09Z | 39,577,514 | <p><code>client.build</code> returns the messages outputted by <code>docker</code> when issuing the <code>docker build</code> command. Your initial mistake is in not capturing the response:</p>
<pre><code>response = cl.build(fileobj=f, rm = True, tag='myv/v')
</code></pre>
<p>and if successful the contents look as th... | 2 | 2016-09-19T16:07:56Z | [
"python",
"python-3.x",
"docker",
"dockerpy"
] |
Django 1.9 using django sessions in two page forms | 39,576,016 | <p>How can I use Django sessions to have a user be able to start a form on one page, and move to the next page and have them complete the form? </p>
<p>I have looked into pagination and wizard forms, but I don't get them at all. </p>
<p>When I have one page with a small portion of a model I'm using - in forms - and a... | 2 | 2016-09-19T14:46:28Z | 39,578,988 | <p>I think it's a good idea to use sessions to store the forms because you don't want on each page to store the user input into the database because what if s/he change mind in the 3rd page and s/he wants to discard the registration or whatever it is?</p>
<p>I think is better to store the forms in session until you ge... | 1 | 2016-09-19T17:36:12Z | [
"python",
"django",
"django-forms",
"django-sessions",
"django-1.9"
] |
Excluding a set of indices from an array whilst keeping its original order | 39,576,019 | <p>I have an HDF5 dataset which I read as a numpy array: </p>
<pre><code>my_file = h5py.File(h5filename, 'r')
file_image = my_file['/image']
</code></pre>
<p>and a list of indices called <code>in</code>. </p>
<p>I want to split the <code>image</code> dataset into two separate <code>np.array</code>s: one containing i... | 0 | 2016-09-19T14:46:32Z | 39,578,735 | <p>I'm not following why or how you are choosing the indexes, but as the error indicates, when you index an array on the h5 file, then indexes have to be sorted. Remember files are serial storage, so it is easier and faster to read straight through rather than go back and forth. Regardless of where the constraint lie... | 1 | 2016-09-19T17:20:44Z | [
"python",
"numpy",
"indexing",
"h5py"
] |
Excluding a set of indices from an array whilst keeping its original order | 39,576,019 | <p>I have an HDF5 dataset which I read as a numpy array: </p>
<pre><code>my_file = h5py.File(h5filename, 'r')
file_image = my_file['/image']
</code></pre>
<p>and a list of indices called <code>in</code>. </p>
<p>I want to split the <code>image</code> dataset into two separate <code>np.array</code>s: one containing i... | 0 | 2016-09-19T14:46:32Z | 39,579,003 | <p>Using <code>in</code> as a variable name is not a good idea, since <code>in</code> is a Python keyword (e.g. see the list comprehensions below). For clarity I've renamed it as <code>idx</code></p>
<p>One straightforward solution would be to simply iterate over your set of indices in a standard Python <code>for</cod... | 1 | 2016-09-19T17:37:16Z | [
"python",
"numpy",
"indexing",
"h5py"
] |
Install multiple .service files with dh_systemd packaging | 39,576,120 | <p>I'm currently packaging a python app with dh_virtualenv, to deploy it on Ubuntu 16.04, daemonized with systemd.</p>
<p>I use the dh_systemd plugin to automatically install the file my_app.service will install the .deb package, but I'd like to run another process in a different service that schedules tasks for my ap... | 0 | 2016-09-19T14:51:16Z | 39,795,036 | <p>Found the solution <a href="http://%20http://unix.stackexchange.com/questions/306234/is-it-possible-to-install-two-services-for-one-package-using-dh-installinit-how" rel="nofollow">here</a> : </p>
<pre><code>override_dh_installinit:
dh_installinit --name=service1
dh_installinit --name=service2
</cod... | 0 | 2016-09-30T15:27:59Z | [
"python",
"virtualenv",
"packaging",
"systemd",
"debhelper"
] |
What is the relationship between a python virtual environment and specific system libraries? | 39,576,125 | <p>We have an application which does some of its work in Python in a python virtual environment setup using virtualenv.</p>
<p>We've hit a problem where the version of a system library does not match the version installed in the virtual environment. That is we have <code>NetCDF4</code> installed into the virtual envi... | 0 | 2016-09-19T14:51:24Z | 39,576,379 | <p>When you use <code>virtualenv</code> to create a virtual environment you have the option of whether or not to include the standard site packages as part of the environment. Since this is now default behaviour (though it can be asserted by using <code>--no-site-packages</code> in the command line) it's possible that ... | 0 | 2016-09-19T15:03:45Z | [
"python",
"linux",
"virtualenv"
] |
Selecting values from a series in pandas | 39,576,156 | <p>I have a dataset D with Columns from [A - Z] in total 26 columns. I have done some test and got to know which are the useful columns to me in a series S.</p>
<pre><code>D #Dataset with columns from A - Z
S
B 0.78
C 1.04
H 2.38
</code></pre>
<p>S has the columns and a value associated with it, So I now know the... | 1 | 2016-09-19T14:52:53Z | 39,576,217 | <p>IIUC you can use:</p>
<pre><code>cols = ['B','C','D']
df = df[cols]
</code></pre>
<p>Or if column names are in <code>Series</code> as values:</p>
<pre><code>S = pd.Series(['B','C','D'])
df = df[S]
</code></pre>
<p>Sample:</p>
<pre><code>df = pd.DataFrame({'A':[1,2,3],
'B':[4,5,6],
... | 2 | 2016-09-19T14:56:06Z | [
"python",
"pandas",
"select",
"dataframe",
"multiple-columns"
] |
Save base64 image in django file field | 39,576,174 | <p>I have following input</p>
<pre><code>"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA7YAAAISCAIAAAB3YsSDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAA5JxJREFUeNrsnQl4FEX6xqcJJEAS7ivhBkMAQTSJ4h0QEQ+I90rAc1cOL3QBXXV1AV1dVwmrsCqQ9VwJ6HoC7oon0T8iEkABwRC5IeE+kkAIkPT/nfmSmprunskk5CDw/p55hu7qOr76api8........"
</cod... | 3 | 2016-09-19T14:53:31Z | 39,577,190 | <p>This question looks like it should help: <a href="http://stackoverflow.com/questions/7514964/django-how-to-create-a-file-and-save-it-to-a-models-filefield">Django - how to create a file and save it to a model's FileField?</a> </p>
<p>You should be able to decode the base64 string and supply that as the <code>co... | 1 | 2016-09-19T15:50:31Z | [
"python",
"django",
"image",
"filefield"
] |
Save base64 image in django file field | 39,576,174 | <p>I have following input</p>
<pre><code>"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA7YAAAISCAIAAAB3YsSDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAA5JxJREFUeNrsnQl4FEX6xqcJJEAS7ivhBkMAQTSJ4h0QEQ+I90rAc1cOL3QBXXV1AV1dVwmrsCqQ9VwJ6HoC7oon0T8iEkABwRC5IeE+kkAIkPT/nfmSmprunskk5CDw/p55hu7qOr76api8........"
</cod... | 3 | 2016-09-19T14:53:31Z | 39,587,386 | <pre><code>import base64
from django.core.files.base import ContentFile
format, imgstr = data.split(';base64,')
ext = format.split('/')[-1]
data = ContentFile(base64.b64decode(imgstr), name='temp.' + ext) # You can save this as file istance.
</code></pre>
<p>Use this code snippet to decode the base64 string.</p>
| 1 | 2016-09-20T06:45:14Z | [
"python",
"django",
"image",
"filefield"
] |
printing UTF-8 in Python 3 using Sublime Text 3 | 39,576,308 | <p>I have this Python3 code to attempt to read and print from a utf-8 encoded file:</p>
<pre><code>f = open('mybook.txt', encoding='utf-8')
for line in f:
print(line)
</code></pre>
<p>When I build using Sublime Text 3 I get the following error:</p>
<pre><code>UnicodeEncodeError: 'ascii' codec can't encode charac... | 2 | 2016-09-19T15:00:26Z | 39,583,630 | <p>The answer was actually in the question linked in your question - <code>PYTHONIOENCODING</code> needs to be set to <code>"utf-8"</code>. However, since OS X is silly and doesn't pick up on environment variables set in Terminal or via <code>.bashrc</code> or similar files, this won't work in the way indicated in the ... | 3 | 2016-09-19T23:39:17Z | [
"python",
"python-3.x",
"utf-8",
"sublimetext3",
"sublimetext"
] |
Validating a users input | 39,576,320 | <p>I'm fairly new to Python and I'm using a while True loop. Inside that loop I have </p>
<pre><code>Sentence= input("please enter a sentence").lower().split()
</code></pre>
<p>However I want to create validation so an error message appears when the user inputs a number instead of a letter. I was researching and saw ... | 0 | 2016-09-19T15:00:51Z | 39,576,406 | <pre><code>sentence = input("please enter a sentence").lower().split()
for word in sentence:
if not word.isalpha():
print("The word %s is not alphabetic." % word)
</code></pre>
| 1 | 2016-09-19T15:04:54Z | [
"python"
] |
Validating a users input | 39,576,320 | <p>I'm fairly new to Python and I'm using a while True loop. Inside that loop I have </p>
<pre><code>Sentence= input("please enter a sentence").lower().split()
</code></pre>
<p>However I want to create validation so an error message appears when the user inputs a number instead of a letter. I was researching and saw ... | 0 | 2016-09-19T15:00:51Z | 39,576,840 | <p>Something like this?</p>
<pre><code>sentence = input("please enter a sentence: ").lower().split()
while False in [word.isalpha() for word in sentence]:
sentence = input("Do not use digits. Enter again: ").lower().split()
</code></pre>
| 0 | 2016-09-19T15:29:21Z | [
"python"
] |
rename the pandas Series | 39,576,340 | <p>I have some wire thing when renaming the pandas Series by the datetime.date</p>
<pre><code>import pandas as pd
a = pd.Series([1, 2, 3, 4], name='t')
</code></pre>
<p>I got <code>a</code> is:</p>
<pre><code>0 1
1 2
2 3
3 4
Name: t, dtype: int64
</code></pre>
<p>Then, I have:</p>
<pre><code>ts = pd.Se... | 0 | 2016-09-19T15:01:28Z | 39,576,580 | <p>Because <code>rename</code> does not change the object unless you set the <code>inplace</code> argument as <code>True</code>, as seen in the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.rename.html" rel="nofollow">docs</a>.</p>
<p>Notice that the <code>copy</code> argument can be use... | 2 | 2016-09-19T15:13:54Z | [
"python",
"python-2.7",
"pandas"
] |
IMDb dataset find number of 10 ratings for a movie | 39,576,473 | <p>I'm trying to sort IMDb movies based on the number of (rated 10) votes they got.<br> Unfortunately, I can't seem to find that piece of information in their public dataset on their FTP servers (It's not in the ratings file).<br>
Example of the information I'm trying to extract:
<a href="http://www.imdb.com/title/tt01... | -1 | 2016-09-19T15:08:15Z | 39,577,684 | <p>You should be able to get the rating information by using the IMDbPY package.</p>
<p>Follow the steps as shown in the link <a href="http://imdbpy.sourceforge.net/support.html#documentation" rel="nofollow">IMDbPY</a>.</p>
<p>You can actually do it in two ways,</p>
<ol>
<li>Use the <strong>api</strong> provided whi... | 0 | 2016-09-19T16:18:49Z | [
"python",
"database",
"web-scraping"
] |
Why Python and java does not need any header file whereas C and C++ needs them | 39,576,478 | <p>I am a complete newbie to python transiting from C++. </p>
<p>While learning C++, I was explained that header files tells about the working of the function or define them to the compiler so that it understands what means what i.e., iostream contains the definition of cin (nd much more) so that the compiler knows th... | -1 | 2016-09-19T15:08:32Z | 39,576,524 | <p>Java and Python have <code>import</code> which is similar to include.</p>
<p>Some inbuilt functions are built in and hence does not require any imports.</p>
| -1 | 2016-09-19T15:10:54Z | [
"python"
] |
Why Python and java does not need any header file whereas C and C++ needs them | 39,576,478 | <p>I am a complete newbie to python transiting from C++. </p>
<p>While learning C++, I was explained that header files tells about the working of the function or define them to the compiler so that it understands what means what i.e., iostream contains the definition of cin (nd much more) so that the compiler knows th... | -1 | 2016-09-19T15:08:32Z | 39,576,570 | <p>Header files in C/C++ are a "copy paste" mechanism. The included header file is literally written into the file while preprocessing (copy pasting the source code together).
After that is done, the compiler transaltes the source code. The linker then connects the function calls.
That is somewhat outdated and error p... | 2 | 2016-09-19T15:13:32Z | [
"python"
] |
Why Python and java does not need any header file whereas C and C++ needs them | 39,576,478 | <p>I am a complete newbie to python transiting from C++. </p>
<p>While learning C++, I was explained that header files tells about the working of the function or define them to the compiler so that it understands what means what i.e., iostream contains the definition of cin (nd much more) so that the compiler knows th... | -1 | 2016-09-19T15:08:32Z | 39,576,943 | <p>In Java and Python we use a similar keyword called <strong>import</strong> to add a package and use the methods in it. But in advanced languages like Java and Python few packages are imported by default.
<strong>e.g.</strong> in Java <strong>java.lang.*</strong> is imported by default.</p>
| 0 | 2016-09-19T15:35:00Z | [
"python"
] |
Python Parsing XML - if element == "value" do x | 39,576,517 | <p>sorry if title isn't that clear, I'm currently parsing a xml file that has lots of nested tags, for example it goes:</p>
<pre><code><Artifacts>
<Artifact name="1">
<Fragments>
<hits>
<hit sequence="1">
<Fragment name="1">Data</Fragment>
<Fragment nam... | -1 | 2016-09-19T15:10:35Z | 39,578,089 | <p>With minidom:</p>
<pre><code>from xml.dom import minidom
xmlstr = '''
<Artifacts>
<Artifact name="1">
<Fragments>
<Fragment name="1">Data</Fragment>
</Fragments>
</Artifact>
<Artifact name="2">
</Artifact>
</Artifacts>
'''
def with_children(tag):
if... | 1 | 2016-09-19T16:42:23Z | [
"python",
"xml"
] |
Python Parsing XML - if element == "value" do x | 39,576,517 | <p>sorry if title isn't that clear, I'm currently parsing a xml file that has lots of nested tags, for example it goes:</p>
<pre><code><Artifacts>
<Artifact name="1">
<Fragments>
<hits>
<hit sequence="1">
<Fragment name="1">Data</Fragment>
<Fragment nam... | -1 | 2016-09-19T15:10:35Z | 39,580,500 | <p>Here is a simple example using <code>lxml</code>:</p>
<pre><code>from lxml import etree
content = '''\
<Artifacts>
<Artifact name="1">
<Fragments>
<Fragment name="1">Data</Fragment>
</Fragments>
</Artifact>
<Artifact name="2">
<Fragments>... | 1 | 2016-09-19T19:16:26Z | [
"python",
"xml"
] |
using SSL with nginx in a django app | 39,576,535 | <p>This is my yo_nginx.conf file:</p>
<pre><code>upstream django {
server unix:///home/ubuntu/test/yo/yo.sock; # for a file socket, check if the path is correct
}
# Redirect all non-encrypted to encrypted
server {
server_name 52.89.220.11;
listen 80;
return 301 https://52.89.220.11$request_uri;
}
#... | 2 | 2016-09-19T15:11:24Z | 39,576,627 | <p>Below is most of the config we use. It ensures the appropriate headers are set. One word of caution, our <code>ssl_ciphers</code> list is probably not ideal as we need to support some clients on older devices.</p>
<pre><code>server {
listen 443;
server_name uidev01;
ssl on;
... | 2 | 2016-09-19T15:16:03Z | [
"python",
"django",
"ssl",
"nginx"
] |
using SSL with nginx in a django app | 39,576,535 | <p>This is my yo_nginx.conf file:</p>
<pre><code>upstream django {
server unix:///home/ubuntu/test/yo/yo.sock; # for a file socket, check if the path is correct
}
# Redirect all non-encrypted to encrypted
server {
server_name 52.89.220.11;
listen 80;
return 301 https://52.89.220.11$request_uri;
}
#... | 2 | 2016-09-19T15:11:24Z | 39,578,138 | <p>For redirection from HTTP to HTTPS use:</p>
<pre><code>server {
listen 80;
server_name yourdomain.com;
return 301 https://$server_name$request_uri;
}
</code></pre>
<p>But if your website is not working with HTTPS, it means you have invalid certificate. The reasons should be not-signed certificate ... | 0 | 2016-09-19T16:45:19Z | [
"python",
"django",
"ssl",
"nginx"
] |
using SSL with nginx in a django app | 39,576,535 | <p>This is my yo_nginx.conf file:</p>
<pre><code>upstream django {
server unix:///home/ubuntu/test/yo/yo.sock; # for a file socket, check if the path is correct
}
# Redirect all non-encrypted to encrypted
server {
server_name 52.89.220.11;
listen 80;
return 301 https://52.89.220.11$request_uri;
}
#... | 2 | 2016-09-19T15:11:24Z | 39,579,594 | <p>All I had to do was add default_server and also change the permission of my socket in the uwsgi/sites/sample.ini file from 664 to 666.</p>
<pre><code>server {
listen 443 default_server ssl;
...
}
</code></pre>
| 1 | 2016-09-19T18:12:57Z | [
"python",
"django",
"ssl",
"nginx"
] |
Python Selenium Webdriver.Firefox() hangs at 'about:blank&utm_content=firstrun' | 39,576,552 | <p>Am using Selenium version 2.53.6 and have tried it with Firefox 44,45,46 and 47...</p>
<p>Whenever I run the line </p>
<blockquote>
<p>driver = webdriver.Firefox()</p>
</blockquote>
<p>Firefox initializes but hangs at 'about:blank&utm_content=firstrun' and I cannot type additional code on the command line.<... | 0 | 2016-09-19T15:12:18Z | 39,577,507 | <p>I would recommend using chrome. <a href="http://chromedriver.storage.googleapis.com/2.9/chromedriver_win32.zip" rel="nofollow">http://chromedriver.storage.googleapis.com/2.9/chromedriver_win32.zip</a> Download that and extract it to your <code>python27/scripts</code> folder located in the root directory in the <code... | 0 | 2016-09-19T16:07:25Z | [
"python",
"selenium",
"firefox"
] |
Implementing CNN with tensorflow | 39,576,631 | <p>I'm new in convolutional neural networks and in Tensorflow and I need to implement a conv layer with further parameters:</p>
<p>Conv. layer1: filter=11, channel=64, stride=4, Relu.</p>
<p>The API is following:</p>
<pre><code>tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, na... | 1 | 2016-09-19T15:16:20Z | 39,577,003 | <p>At first, you need to create a filter variable:</p>
<pre><code>W = tf.truncated_normal(shape = [11, 11, 3, 64], stddev = 0.1)
</code></pre>
<p>First two fields of shape parameter stand for filter size, third for the number of input channels (I guess your images have 3 channels) and fourth for the number of output ... | 1 | 2016-09-19T15:38:16Z | [
"python",
"neural-network",
"tensorflow",
"convolution",
"conv-neural-network"
] |
python lxml - simply get/check class of HTML element | 39,576,673 | <p>I use <code>tree.xpath</code> to iterate over all interesting HTML elements but I need to be able to tell whether the current element is part of a certain CSS class or not.</p>
<pre><code>from lxml import html
mypage = """
<div class="otherclass exampleclass">some</div>
<div class="otherclass">th... | 1 | 2016-09-19T15:18:32Z | 39,576,674 | <p>You can elegantly use the <a href="https://docs.python.org/3/reference/expressions.html#in" rel="nofollow">membership test operator <code>in</code></a>:</p>
<pre><code>for item in tree.xpath( "//div" ):
if "exampleclass" in iter(item.classes):
print("foo")
</code></pre>
<blockquote>
<p>For user-defined cla... | 0 | 2016-09-19T15:18:32Z | [
"python",
"class",
"python-3.x",
"lxml"
] |
python lxml - simply get/check class of HTML element | 39,576,673 | <p>I use <code>tree.xpath</code> to iterate over all interesting HTML elements but I need to be able to tell whether the current element is part of a certain CSS class or not.</p>
<pre><code>from lxml import html
mypage = """
<div class="otherclass exampleclass">some</div>
<div class="otherclass">th... | 1 | 2016-09-19T15:18:32Z | 39,580,476 | <p>There is no need for <em>iter</em>, <code>if "exampleclass" in item.classes:</code> does the exact same thing, only more efficiently. </p>
<pre><code>from lxml import html
mypage = """
<div class="otherclass exampleclass">some</div>
<div class="otherclass">things</div>
<div class="exam... | 1 | 2016-09-19T19:13:51Z | [
"python",
"class",
"python-3.x",
"lxml"
] |
Python recv multicast returns one byte | 39,576,696 | <p>recv is not working as expected.
I am sending 10 bytes (verified with wireshark) and recv is only getting the first byte and discarding the rest (until the next sendto).
Is this a multicast thing? I'm pretty sure I've done this same thing with unicast UDP and had no issues.</p>
<p>Here is my example code:</p>
<pr... | 1 | 2016-09-19T15:19:38Z | 39,579,879 | <p>You are only getting one byte because you set your buffer size to one.</p>
<p>From the <a href="https://docs.python.org/2/library/socket.html#socket.socket.recv" rel="nofollow">documentation for <code>socket.recv</code></a>:</p>
<blockquote>
<p>The maximum amount of data to be received at once is specified by bu... | 1 | 2016-09-19T18:33:00Z | [
"python",
"blocking",
"multicast",
"recv"
] |
Getting data from Google Maps python object | 39,576,737 | <p>I've gathered some data from Google Maps API but I'm stuck on getting out the LAT/LNG.</p>
<p>Creating object:</p>
<pre><code>loc = self.google_maps.geocode(location)
</code></pre>
<p>I cannot traverse down this object:</p>
<pre><code>pprint(loc)
</code></pre>
<p><a href="http://i.stack.imgur.com/J7CVI.png" rel... | 0 | 2016-09-19T15:22:45Z | 39,576,765 | <p>You should try:</p>
<pre><code>loc[0]['address_components']
# ^ index the list
</code></pre>
<p>That's because your dict is contained in a list.</p>
<p>The same applies to other dictionaries that deeply nested:</p>
<pre><code>loc[0]['address_components'][0]['long_name']
# or loc[0]['address_components'][1]['l... | 3 | 2016-09-19T15:24:25Z | [
"python"
] |
Assign value to a slice of a numpy array | 39,576,757 | <p>I want to get slices from a numpy array and assign them to a larger array.
The slices should be 64 long and should be taken out evenly from the source array.
I tried the following:</p>
<pre><code>r = np.arange(0,magnitude.shape[0],step)
magnitudes[counter:counter+len(r),ch] = magnitude[r:r+64]
</code></pre>
<p>I ... | -1 | 2016-09-19T15:24:01Z | 39,578,337 | <p><code>magnitude[r:r+64]</code> where <code>r</code> is an array is wrong. The variables in the slice must be scalars, <code>magnitude[3:67]</code>, not <code>magnitude[[1,2,3]:[5,6,7]]</code>.</p>
<p>If you want to collect multiple slices you have to do something like</p>
<pre><code>In [345]: x=np.arange(10)
In [... | 2 | 2016-09-19T16:57:28Z | [
"python",
"arrays",
"numpy",
"indexing"
] |
Transform to normal Data Frame which has row as list. Split rows to column | 39,576,800 | <p>My Data Frame output from reading a complex json looks like below.</p>
<p>Where individual row is a list within a single column.</p>
<p>Below is the sample Data Frame(<code>df</code>)</p>
<pre><code>col
[A,1,3,4,Null]
[B,4,5,6,Null]
[C,7,8,9,Null]
</code></pre>
<p>I tried to split to individual column using pand... | 1 | 2016-09-19T15:27:35Z | 39,576,878 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_records.html" rel="nofollow"><code>DataFrame.from_records</code></a>, but first need create nested <code>list</code> from values of column <code>col</code>:</p>
<pre><code>df = pd.DataFrame({'col':[['A',1,3,4,'Null'],['... | 1 | 2016-09-19T15:31:13Z | [
"python",
"list",
"pandas",
"dataframe",
"multiple-columns"
] |
Transform to normal Data Frame which has row as list. Split rows to column | 39,576,800 | <p>My Data Frame output from reading a complex json looks like below.</p>
<p>Where individual row is a list within a single column.</p>
<p>Below is the sample Data Frame(<code>df</code>)</p>
<pre><code>col
[A,1,3,4,Null]
[B,4,5,6,Null]
[C,7,8,9,Null]
</code></pre>
<p>I tried to split to individual column using pand... | 1 | 2016-09-19T15:27:35Z | 39,576,919 | <p>You can construct a df from the result of using <code>apply</code> and <code>pd.Series</code> ctor on each row:</p>
<pre><code>In [99]:
pd.DataFrame(df['col'].apply(pd.Series).values, columns=['colA','colB','colC','colD','colE'])
Out[99]:
colA colB colC colD colE
0 A 1 3 4 Null
1 B 4 5 ... | 0 | 2016-09-19T15:33:40Z | [
"python",
"list",
"pandas",
"dataframe",
"multiple-columns"
] |
Using django-photologue to assign single image to a model | 39,576,870 | <p>I'm working on my first project in django, and the first part of it is a blog app. I've installed django-photologue which seems very useful for the intended purposes for later apps. Although this app will be used extensively later for posting galleries in other apps, assigning single photo to a model still eludes me... | 0 | 2016-09-19T15:30:39Z | 39,602,813 | <p>As per Andreas' comment: it looks like your database does not reflect your Post model; it looks like either you have migrations that have not been applied to the database (run <code>python manage.py migrate --list</code> to see them), or else you have not yet created migrations for your Post model - <a href="https:/... | 1 | 2016-09-20T19:59:32Z | [
"python",
"django",
"postgresql",
"photo",
"photologue"
] |
Updating postgres column using python dataframe | 39,576,900 | <p>I am generating dataframe (<code>df</code>) for different dates and it will have the following variables</p>
<pre><code>date value rowId
2016-05-14 2.5 1
2016-05-14 3.0 2
2016-05-14 3.4 5
</code></pre>
<p>I have to update a column (<code>value</code>) in postgres t... | 0 | 2016-09-19T15:32:26Z | 39,577,021 | <p>Well, closing transaction with commit should help. I'm not sure if you are using <code>psycopg2</code>, or any other library which has a <code>commit()</code> function. If not, then a simple <code>cur.execute('COMMIT')</code> should be enough. This should be run right after the <code>for</code> loop.</p>
| 0 | 2016-09-19T15:39:26Z | [
"python",
"sql",
"postgresql",
"dataframe"
] |
Is the below function O(n) time and O(1) space, where n = |A|? | 39,576,942 | <pre><code>def firstMissingPositive(self, A):
least = 1024*1024*1024
# worst case n ops
for i in A:
if i < least and i > 0:
least = i
if least > 1:
return 1
else:
# should be O(n)
A_set = set(A)
# worst case n ops again
while True:... | 0 | 2016-09-19T15:34:58Z | 39,577,059 | <p>It's not <code>O(1)</code> space, it's <code>O(n)</code> space, since you need to build the set. </p>
<p>As for the time, according to <a href="https://wiki.python.org/moin/TimeComplexity" rel="nofollow">the Python wiki</a>, set containment takes <code>O(n)</code> worst case. So your algorithm is thus <code>O(n^2)<... | 2 | 2016-09-19T15:42:12Z | [
"python",
"algorithm",
"time-complexity"
] |
TypeError: __deepcopy__() takes 1 positional argument but 2 were given error? | 39,577,016 | <p>I'm doing a deepcopy for a list of objects, but I keep getting following error:</p>
<pre><code>deepcopy __deepcopy__() takes 1 positional argument but 2 were given
</code></pre>
<p>and following traceback:</p>
<pre class="lang-none prettyprint-override"><code>TypeError Traceback (m... | -1 | 2016-09-19T15:39:02Z | 39,657,547 | <p>I found the problem was in fact in the definition of the variable <code>regions</code>. It is a list of classes <code>AreaRegion</code>, which contained assignment into class <code>__dict__</code>:</p>
<pre><code>from matplotlib.path import Path
...
class AreaRegion:
def __init__(self):
...
s... | 0 | 2016-09-23T09:40:24Z | [
"python"
] |
list indices must be integers, not str | 39,577,110 | <pre><code>class targil4(object):
def plus():
x=list(raw_input('enter 4 digit Num '))
print x
for i in x:
int(x[i])
x[i]+=1
print x
plus()
</code></pre>
<p>this is my code, I try to get input of 4 digits from user, then to add 1 to each digit, and print ... | 2 | 2016-09-19T15:45:25Z | 39,577,181 | <p>You can also use <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk" rel="nofollow">list comprehension</a> and do</p>
<pre><code>y = [int(i) + 1 for i in x]
print y
</code></pre>
| 0 | 2016-09-19T15:49:53Z | [
"python",
"string",
"list",
"integer",
"indices"
] |
list indices must be integers, not str | 39,577,110 | <pre><code>class targil4(object):
def plus():
x=list(raw_input('enter 4 digit Num '))
print x
for i in x:
int(x[i])
x[i]+=1
print x
plus()
</code></pre>
<p>this is my code, I try to get input of 4 digits from user, then to add 1 to each digit, and print ... | 2 | 2016-09-19T15:45:25Z | 39,577,309 | <p>I believe you may get more out of an answer here by actually looking at each statement and seeing what is going on. </p>
<pre><code># Because the user enters '1234', x is a list ['1', '2', '3', '4'],
# each time the loop runs, i gets '1', '2', etc.
for i in x:
# here, x[i] fails because your i value is a string... | 1 | 2016-09-19T15:57:19Z | [
"python",
"string",
"list",
"integer",
"indices"
] |
How to make argparse work in executable program | 39,577,267 | <p>I have a program command line which uses the argparse module.</p>
<pre><code>import argparse
def run():
print 'Running'
def export():
print 'Exporting'
def argument_parser():
parser = argparse.ArgumentParser()
parser.add_argument('run', action='store_true')
parser.add_argument('export', acti... | 1 | 2016-09-19T15:55:10Z | 39,577,523 | <p>Use the <a href="https://docs.python.org/3/library/cmd.html" rel="nofollow"><code>cmd</code> module</a> to create a shell.</p>
<p>You can then use <code>cmd.Cmd()</code> class you create to run single commands through the <a href="https://docs.python.org/3/library/cmd.html#cmd.Cmd.onecmd" rel="nofollow"><code>cmd.C... | 1 | 2016-09-19T16:08:16Z | [
"python",
"argparse",
"pyinstaller"
] |
Asynchronous receiving TCP packets in python | 39,577,302 | <p>I have an instant messaging app, with client written in python.</p>
<p>Code that connects to a server:</p>
<pre><code>def connect(self, host, port, name):
host = str(host)
port = int(port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send('CONNECT:' + name)
... | 0 | 2016-09-19T15:56:56Z | 39,577,818 | <p>There is a way with <code>select</code> function to monitor multiple streams, make a list of all the streams you need to handle and use the <code>select</code> function for it, for the user input use <code>sys.stdin</code> and all the sockets that you expect to chat with.<br>
check this: <a href="https://docs.python... | 0 | 2016-09-19T16:27:14Z | [
"python",
"sockets",
"tcp"
] |
Python Selenium Explicit WebDriverWait function only works with presence_of_element_located | 39,577,365 | <p>I am trying to use Selenium WebDriverWait in Python to wait for items to load on a webpage , however, using any expected condition apart from <strong>presence_of_element_located</strong> seems to result in the error </p>
<blockquote>
<p>selenium.common.exceptions.WebDriverException: Message: SyntaxError: missing ... | 0 | 2016-09-19T15:59:55Z | 39,577,900 | <p>Copy pasted the same code and it works.
Dint have enough repo to post comments so had to put it in answer section.</p>
| 0 | 2016-09-19T16:31:39Z | [
"python",
"selenium"
] |
Python Selenium Explicit WebDriverWait function only works with presence_of_element_located | 39,577,365 | <p>I am trying to use Selenium WebDriverWait in Python to wait for items to load on a webpage , however, using any expected condition apart from <strong>presence_of_element_located</strong> seems to result in the error </p>
<blockquote>
<p>selenium.common.exceptions.WebDriverException: Message: SyntaxError: missing ... | 0 | 2016-09-19T15:59:55Z | 39,578,019 | <p>These minor changes work for me.</p>
<ol>
<li>visibility_of_element_located ===> presence_of_element_located</li>
<li>driver.quit() ===> driver.close()</li>
</ol>
<p>See the following:</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui impo... | 0 | 2016-09-19T16:38:21Z | [
"python",
"selenium"
] |
which averaging should be used when computing the ROC AUC on imbalanced data set? | 39,577,408 | <p>I am doing a binary classification task on imbalanced data set .. and right now computing the ROC AUC using :
<code>sklearn.metrics.roc_auc_score(y_true, y_score, average='macro')</code> <a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html" rel="nofollow">source</a>
and I hav... | 0 | 2016-09-19T16:02:15Z | 39,580,846 | <p>The average='weighted' is your choice for the problem of imbalanced classes
as it follows from 3.3.2.1 in</p>
<blockquote>
<p><a href="http://scikit-learn.org/stable/modules/model_evaluation.html" rel="nofollow">http://scikit-learn.org/stable/modules/model_evaluation.html</a></p>
</blockquote>
| 1 | 2016-09-19T19:40:22Z | [
"python",
"machine-learning",
"scikit-learn"
] |
Why is my Python Tuple only storing first value? | 39,577,443 | <p>I am storing a mysql query w/in a tuple in my python script. I have a raw_input variable w/in the script which I would like to check if their is a match w/in the tuple.</p>
<pre><code>curs.execute("""SELECT username, id FROM employees WHERE gid!=4""")
rows=curs.fetchall()
db.close()
uname = raw_input('Type the use... | 1 | 2016-09-19T16:04:01Z | 39,577,751 | <p>This may be a better approach based on what I assume you are trying to do.</p>
<p>There is no reason for the loop in Python to search for the user when you can simply add that to your <code>WHERE</code> clause.</p>
<pre><code># Get the username from input
uname = raw_input('Type the username for the new device: ')... | 0 | 2016-09-19T16:23:10Z | [
"python",
"mysql",
"tuples"
] |
What is the pythonic way of specifying a minimal module version? | 39,577,484 | <p>I'm writing a Python script where one of its imported modules needs to be at least version <code>x.y.z</code>.</p>
<pre><code>import pandas as pd
# Check the pandas version
_pdversion = map(lambda x: int(x), pd.__version__.split('.'))
if _pdversion[1] < 18:
# Not sure the most sensible exception class..
... | 1 | 2016-09-19T16:06:25Z | 39,577,845 | <p>I think the most pythonic way would be to specify it in a requirements.txt file, and keep everything in a virtual environment.</p>
<p>Or: </p>
<pre><code>import pkg_resources
pkg_resources.require("requests==2.11.1")
import requests
</code></pre>
| 0 | 2016-09-19T16:28:47Z | [
"python",
"dependencies",
"packaging"
] |
Use DBus daemon to exchange message from C application to python application | 39,577,527 | <p>Hi I am pretty new to DBus daemon and would like to accomplish simple message exchange between C application and python application, which are running on custom linux-like environment. My understanding is</p>
<ol>
<li>First, start dbus-daemon from init file </li>
<li>Register the C application and the python applic... | 0 | 2016-09-19T16:08:31Z | 39,578,717 | <p><em>[You asked for simple message passing]</em> Do you really need DBus?</p>
<p>If you're asking for simple message passing between a C app and Python, why not use a message-passing library like Rabbit/ZeroMQ? Those already solve all the issues related to passing/receiving messages.</p>
<p>And, if you want to keep... | 0 | 2016-09-19T17:20:01Z | [
"python",
"linux",
"dbus"
] |
Use DBus daemon to exchange message from C application to python application | 39,577,527 | <p>Hi I am pretty new to DBus daemon and would like to accomplish simple message exchange between C application and python application, which are running on custom linux-like environment. My understanding is</p>
<ol>
<li>First, start dbus-daemon from init file </li>
<li>Register the C application and the python applic... | 0 | 2016-09-19T16:08:31Z | 39,591,363 | <p>There are two default buses on each Linux system - the system bus (shared for all users, made for system services) and the session bus. All DBus libraries let you trivially connect to one of those buses.</p>
<p>Then, in the receiver process, you need to take ownership of a bus name (a string that will let other pro... | 0 | 2016-09-20T10:10:40Z | [
"python",
"linux",
"dbus"
] |
How to handle concurrent modifications in django? | 39,577,548 | <p>I am trying to build a project(like e-commerce) using Django and integrate it with android. (I am not building website, I am trying mobile only, so I am using <em>django-rest-framework</em> to create api)</p>
<p>So my question is how to handle a case where two or more users can book an item at the same time when th... | 0 | 2016-09-19T16:09:43Z | 39,584,832 | <p><code>django-locking</code> is the way to go.</p>
| 0 | 2016-09-20T02:31:09Z | [
"python",
"django",
"django-models",
"django-rest-framework"
] |
If item in list does not contain "string", add a "string2" to the item? | 39,577,562 | <p>In Python I have a list of this sort:</p>
<pre><code>list = ["item.1", "sdfhkjdsffs/THIS-STRING", "fsdhfjsdhfsdf/THIS-STRING",
item4/THIS-STRING, item5]
</code></pre>
<p>How do I go about adding <code>"some string"</code> for each item in list that does <em>not</em> contain <code>"THIS-STRING"</code>?</p>
| -2 | 2016-09-19T16:10:33Z | 39,577,620 | <pre><code>result = [x if x.find("SOME-STRING")>=0 else x+"some string" for x in list]
</code></pre>
| 0 | 2016-09-19T16:14:47Z | [
"python",
"list"
] |
Storing user permissions on rows of data | 39,577,568 | <p>I have a table with rows of data for different experiments.</p>
<pre><code>experiment_id data_1 data_2
------------- ------ -------
1
2
3
4
..
</code></pre>
<p>I have a user database on django, and I would like to store permissions indicating which users can access which ro... | 0 | 2016-09-19T16:11:11Z | 39,577,734 | <p>I'm not 100% sure what all will work best for you but in the past I find using a solution as follows to be the easiest to query against and maintain in the future.</p>
<pre><code>Table: Experiment
Experiment_Id | data_1 | data_2
-----------------------------------
1 | ... | ...
2 ... | 0 | 2016-09-19T16:22:07Z | [
"python",
"mysql",
"django",
"database",
"sqlite3"
] |
Storing user permissions on rows of data | 39,577,568 | <p>I have a table with rows of data for different experiments.</p>
<pre><code>experiment_id data_1 data_2
------------- ------ -------
1
2
3
4
..
</code></pre>
<p>I have a user database on django, and I would like to store permissions indicating which users can access which ro... | 0 | 2016-09-19T16:11:11Z | 39,578,092 | <p>It depends on the way you will use the permissions for.<br>
<br>
- In case you will use this values inside a query
you have two options for example to get the users with specific permiss </p>
<ul>
<li>Create a <a href="https://en.wikipedia.org/wiki/Mask_(computing)" rel="nofollow">bit masking</a> number fields and... | 0 | 2016-09-19T16:42:33Z | [
"python",
"mysql",
"django",
"database",
"sqlite3"
] |
Getting the last value for each week, with the matching date | 39,577,617 | <p>So I start out with a <code>pd.Series</code> called <code>jpm</code>, and I would like to group it into weeks and take the last value from each week. This works with the code below, it does get the last value. But it changes corresponding index to the Sunday of the week, and I would like it to <strong>leave it uncha... | 2 | 2016-09-19T16:14:38Z | 39,578,315 | <p>You could provide a <code>DateOffset</code> by specifying the class name <code>Week</code> and indicating the weekly frequency <code>W-FRI</code>, by setting the <code>dayofweek</code> property as 4 [Monday : 0 â Sunday : 6]</p>
<pre><code>jpm.groupby(pd.TimeGrouper(freq=pd.offsets.Week(weekday=4))).last().tail(5... | 1 | 2016-09-19T16:55:33Z | [
"python",
"pandas"
] |
Getting the last value for each week, with the matching date | 39,577,617 | <p>So I start out with a <code>pd.Series</code> called <code>jpm</code>, and I would like to group it into weeks and take the last value from each week. This works with the code below, it does get the last value. But it changes corresponding index to the Sunday of the week, and I would like it to <strong>leave it uncha... | 2 | 2016-09-19T16:14:38Z | 39,586,375 | <p>you can do it this way:</p>
<pre><code>In [15]: jpm
Out[15]:
Date
2015-11-02 64.125610
2015-11-04 64.428918
2015-11-06 66.982593
2015-11-10 66.219427
2015-11-12 64.575682
2015-11-16 65.074678
Name: Adj Close, dtype: float64
In [16]: jpm.groupby(jpm.index.week).transform('last').drop_duplicates(ke... | 1 | 2016-09-20T05:32:52Z | [
"python",
"pandas"
] |
Getting the last value for each week, with the matching date | 39,577,617 | <p>So I start out with a <code>pd.Series</code> called <code>jpm</code>, and I would like to group it into weeks and take the last value from each week. This works with the code below, it does get the last value. But it changes corresponding index to the Sunday of the week, and I would like it to <strong>leave it uncha... | 2 | 2016-09-19T16:14:38Z | 39,598,938 | <p>It seems a little tricky to do this in pure pandas, so I used numpy</p>
<pre><code>import numpy as np
weekly = jpm.groupby(pd.TimeGrouper('W-SUN')).last()
weekly.index = jpm.index[np.searchsorted(jpm.index, weekly.index, side="right")-1]
</code></pre>
| 1 | 2016-09-20T16:06:45Z | [
"python",
"pandas"
] |
Dynamically setting scrapy request call back | 39,577,650 | <p>I'm working with scrapy. I want to rotate proxies on a per request basis and get a proxy from an api I have that returns a single proxy. My plan is to make a request to the api, get a proxy, then use it to set the proxy based on :</p>
<pre><code>http://stackoverflow.com/questions/39430454/making-request-to-api-fr... | 1 | 2016-09-19T16:17:01Z | 39,583,110 | <p>The stacktrace info suggests Scrapy has encountered a request object whose <code>url</code> is <code>None</code>, which is expected to be of string type.</p>
<p>These two lines in your code:</p>
<pre><code>newrequest.replace(url = 'http://ipinfo.io/ip') #TESTING
newrequest.replace(callback= self.form_output) #TEST... | 1 | 2016-09-19T22:37:48Z | [
"python",
"scrapy"
] |
How to maintain different country versions of same language in Django? | 39,577,656 | <p>I would like to have a few different versions of the same language in Django, customized for different countries (e.g. <code>locale/en</code>, <code>locale/en_CA</code>, <code>locale/en_US</code>, etc.). If there is no language for specific country I would expect to use the default language version (<code>locale/en<... | 12 | 2016-09-19T16:17:30Z | 39,646,423 | <p>may I suggest you to put a breakpoint into the LocaleMiddleware Class? </p>
<p>In this way, you might found out a clue which thing was actually getting your way from getting the right Language.</p>
<p>Becaue according the <a href="https://docs.djangoproject.com/en/1.10/_modules/django/middleware/locale/#LocaleMid... | 0 | 2016-09-22T18:31:18Z | [
"python",
"django",
"internationalization",
"django-i18n"
] |
How to maintain different country versions of same language in Django? | 39,577,656 | <p>I would like to have a few different versions of the same language in Django, customized for different countries (e.g. <code>locale/en</code>, <code>locale/en_CA</code>, <code>locale/en_US</code>, etc.). If there is no language for specific country I would expect to use the default language version (<code>locale/en<... | 12 | 2016-09-19T16:17:30Z | 39,733,169 | <p>This is a quirk of Python (not specifically Django) and the gettext module.</p>
<p>Ticket <a href="https://code.djangoproject.com/ticket/8626" rel="nofollow">8626</a> was raised on the Django issue tracker around the time of the 1.0 release and after some suggestions and debate, the Django devs deemed it a "won't f... | 3 | 2016-09-27T19:50:17Z | [
"python",
"django",
"internationalization",
"django-i18n"
] |
How to select a name of a new list from existing string? | 39,577,863 | <p>I'm quite new to python and I'm not able to solve this. In a loop, I have a list with some numbers and a string with the desired name of the list. I want to create a new list identical to the existing list a named it according to the name from the string. </p>
<p><code>values = [1,2,3]
name='Ehu'</code></p>
<p>Wha... | 1 | 2016-09-19T16:29:51Z | 39,578,137 | <p>While you <em>can</em> do what you ask:</p>
<pre><code>>>> globals()['Ehu'] = [1,2,3]
>>> Ehu
[1, 2, 3]
</code></pre>
<p>or for local variables:</p>
<pre><code>>>> def f():
... f.__dict__['Ehu'] = [1,2,3]
... print(Ehu)
...
>>> f()
[1, 2, 3]
</code></pre>
<p>That is a bad ... | 0 | 2016-09-19T16:45:18Z | [
"python"
] |
How to select a name of a new list from existing string? | 39,577,863 | <p>I'm quite new to python and I'm not able to solve this. In a loop, I have a list with some numbers and a string with the desired name of the list. I want to create a new list identical to the existing list a named it according to the name from the string. </p>
<p><code>values = [1,2,3]
name='Ehu'</code></p>
<p>Wha... | 1 | 2016-09-19T16:29:51Z | 39,578,484 | <p>Can be done using <code>globals</code>:</p>
<pre><code>>>> g = globals()
>>> name = 'Ehu'
>>> g['{}'.format(name)] = [1, 2, 3]
>>> Ehu
[1, 2, 3]
</code></pre>
<hr>
| 1 | 2016-09-19T17:06:42Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.