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 |
|---|---|---|---|---|---|---|---|---|---|
Fastest way to iterate over two panda data frames | 37,833,210 | <p>I have two data frames:</p>
<p><code>dt1</code> where I store millions of registry key entries. Defined with columns: <code>Index([u'count', u'id', u'is_malicious', u'key', u'name', u'value'], dtype='object')</code></p>
<p>And <code>dt2</code> where I match those registry entries to machines across our network. De... | 0 | 2016-06-15T10:44:33Z | 37,840,050 | <p>Would something like this work for you?</p>
<pre><code>matches = dt2[dt2.registry_key_id.isin(dt1.id)]
count = len(matches)
</code></pre>
| 0 | 2016-06-15T15:44:10Z | [
"python",
"pandas",
"dataframe"
] |
Fastest way to iterate over two panda data frames | 37,833,210 | <p>I have two data frames:</p>
<p><code>dt1</code> where I store millions of registry key entries. Defined with columns: <code>Index([u'count', u'id', u'is_malicious', u'key', u'name', u'value'], dtype='object')</code></p>
<p>And <code>dt2</code> where I match those registry entries to machines across our network. De... | 0 | 2016-06-15T10:44:33Z | 37,853,969 | <p>Starting from Yarnspinner answer, I agree you can divide the problem in two steps:
counting all the ids in df2 and than mapping this information in df1.</p>
<pre><code>import pandas as pd
import string
df1=pd.DataFrame(data= {"id": ["a","b","c","d"]*5,"value":range(20)}, index = range(20))
df2=pd.DataFrame(data=... | 2 | 2016-06-16T08:35:32Z | [
"python",
"pandas",
"dataframe"
] |
boto3 Client Error: Server Side Encryption with Customer provided key is incompatible with the encryption method specified | 37,833,243 | <p>I'm using boto3 with my django application to upload some files to S3. But I receive the following error when I try to specify the client side encryption algorithm and and keys using <a href="https://boto3.readthedocs.io/en/latest/reference/services/s3.html#object" rel="nofollow">boto3's Object's API</a>.</p>
<bloc... | 0 | 2016-06-15T10:45:54Z | 37,982,616 | <p>After posting an issue on boto3 library I finally got a working example. Here is how it should be done.</p>
<pre><code>import boto3
import os
BUCKET = 'YOUR-BUCKET'
KEY = os.urandom(32)
s3 = boto3.client('s3')
print("Put object...")
s3.put_object(Bucket=BUCKET,
Key='encrypt-key', Body=b'foobar',
... | 1 | 2016-06-23T04:53:33Z | [
"python",
"django",
"encryption",
"amazon-s3",
"boto3"
] |
How do I remove punctuation from an item in a list and save it as a separate item in the list? | 37,833,260 | <p>I am trying to compress items from one list to another list and I need to be able to save punctuation as separate items in the list because if I don't, "you" and "you;" are saved as separate items in the list.</p>
<p>For example the original list is, </p>
<p><code>['Ask', 'not', 'what', 'your', 'country', 'can', '... | 4 | 2016-06-15T10:46:40Z | 37,833,745 | <p>You can implement with <code>regex</code>.</p>
<pre><code>import re
a = ['Ask', 'not', 'what', 'your', 'country', 'can', 'do', 'for', 'you;', 'ask', 'what', 'you', 'can', 'do', 'for', 'your', 'country!', 'This', 'is', 'a', 'quote', 'from', 'JFK', 'who', 'is', 'a', 'former', 'American', 'President.']
result = re.fin... | 2 | 2016-06-15T11:10:10Z | [
"python",
"arrays",
"list",
"arraylist",
"compression"
] |
How do I remove punctuation from an item in a list and save it as a separate item in the list? | 37,833,260 | <p>I am trying to compress items from one list to another list and I need to be able to save punctuation as separate items in the list because if I don't, "you" and "you;" are saved as separate items in the list.</p>
<p>For example the original list is, </p>
<p><code>['Ask', 'not', 'what', 'your', 'country', 'can', '... | 4 | 2016-06-15T10:46:40Z | 37,833,776 | <p>This is the code to separete the non alphabetic characters and also remove duplicates. hope it helps.</p>
<pre><code>def separate(mylist):
newlist = []
test = ''
a = ''
for e in mylist:
for c in e:
if not c.isalpha():
a = c
else:
te... | 0 | 2016-06-15T11:11:48Z | [
"python",
"arrays",
"list",
"arraylist",
"compression"
] |
Django Rest Framework POST Update if existing or create | 37,833,307 | <p>I am new to DRF.
I read the API docs, maybe it is oblivious but I couldn't find a handy way to do it.</p>
<p>I have an Answer object which has one-to-one relationship with a question.</p>
<p>On the front side I used to use POST method to create an answer sent to api/answers, and PUT method to update sent to e.g. a... | 2 | 2016-06-15T10:48:20Z | 37,844,922 | <p>I would use the serializers' create method. </p>
<p>In it you could check if the question (with the ID of it you provide in the 'question' primary key related field) already has an answer, and if it does, fetch the object and update it, otherwise create a new one.</p>
<p>So the first option would go something like... | 2 | 2016-06-15T20:14:26Z | [
"python",
"django",
"django-rest-framework"
] |
pandas groupby boxplot red diagonal line | 37,833,338 | <p>I'm plotting a box plot with </p>
<pre><code>>>> score.head()
Score Wafer_Slot
0 -10.710504 14
1 1.444185 23
2 -5.727797 14
3 8.029544 21
4 -1.569401 24
gscore = score.groupby('Wafer_Slot')
xticks = []
for i in range(25):
xticks.append(str(i+1... | 0 | 2016-06-15T10:49:48Z | 37,835,926 | <p>I solved. It was enough to use a different variable as grouping index:</p>
<pre><code>score['Score'] = svm_score
ws = desc.Wafer_Slot[test_index].tolist()
gscore = score.groupby(ws)
xticks = []
for i in range(25):
xticks.append(str(i+1))
#xticks.append(' ')
gscore.boxplot(subplots=False)
ax = plt.gca()
ax... | 0 | 2016-06-15T12:47:23Z | [
"python",
"pandas",
"matplotlib",
"boxplot"
] |
Saving to the Desktop folder on Windows | 37,833,416 | <p>I have a problem with saving a file to the "Desktop" folder on Windows. I have two <code>try</code> statements. The first tries to save the file for a Mac. The second tries to save it for Windows. The second <code>except</code> handler defaults to saving the file in the same folder as the application. </p>
<pre><co... | 0 | 2016-06-15T10:54:01Z | 37,841,195 | <p><code>os.getenv()</code> will return <code>None</code> if the variable is not found. In my opinion it would be more elegant to check if <code>getenv</code> does not return <code>None</code> and only then execute the the <code>try</code>/<code>except</code> block.</p>
<p>The more relevant issue seems to be how you t... | 1 | 2016-06-15T16:42:28Z | [
"python",
"windows",
"filepath"
] |
Why is setUpClass(cls): executed several times? | 37,833,441 | <p>I'm implementing component tests for a web service. I want to use the class method <code>setUpClass(cls):</code> to start my web service only once in the beginning, however <code>setUpClass(cls):</code> is executed before each of my test cases. Why? The documentation says it is executed only once before the test cas... | 0 | 2016-06-15T10:55:28Z | 37,833,824 | <p>Looking at the <a href="https://github.com/Microsoft/PTVS/blob/master/Python/Product/TestAdapter/TestExecutor.cs#L98-L284" rel="nofollow">Python tools for Visual Studio source code</a>, the VS test runner runs each test case <em>entirely in isolation</em>.</p>
<p>Each test case is run as a separate command-line inv... | 2 | 2016-06-15T11:13:21Z | [
"python",
"unit-testing",
"python-3.x",
"visual-studio-2013"
] |
How to solve Wagtail cyclic Block dependency when using a StreamBlock | 37,833,593 | <p>I would like to achieve something like this,</p>
<pre><code>from wagtail.wagtailcore.blocks import StreamBlock, StructBlock
class CarouselBlock(StructBlock):
content = StreamBlock([
('tab', TabBlock()),
('carousel', CarouselBlock())
])
class TabBlock(StructBlock):
content = StreamB... | 1 | 2016-06-15T11:03:12Z | 37,867,490 | <p>Unfortunately I don't think it'll be possible to make this work, even if you find a way to set up the circular reference in the definition. There are various places in Wagtail's code that will try to traverse the definition as a tree, and end up in an infinite recursion.</p>
<p>For example, this happens when freezi... | 2 | 2016-06-16T19:07:19Z | [
"python",
"django",
"wagtail",
"wagtail-streamfield"
] |
Python : What is the purpose of a colon in an if statement? | 37,833,625 | <p>I have this piece of python code below.</p>
<pre><code>def m(list):
v = list[0]
for e in list:
if v < e: v = e
return v
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
for row in values:
print(m(row), end = " ")
</code></pre>
<p>The result is 5, 33.</p>
<p>Can somebody explain me that following... | -14 | 2016-06-15T11:04:57Z | 37,833,736 | <pre><code>if v < e: v = e
</code></pre>
<p>can be read: "If v is less than e, make v the value of e."</p>
<p>As above you should put a new line to make it read easier:</p>
<pre><code>if v < e:
v = e
</code></pre>
| 4 | 2016-06-15T11:09:38Z | [
"python",
"if-statement"
] |
Python : What is the purpose of a colon in an if statement? | 37,833,625 | <p>I have this piece of python code below.</p>
<pre><code>def m(list):
v = list[0]
for e in list:
if v < e: v = e
return v
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
for row in values:
print(m(row), end = " ")
</code></pre>
<p>The result is 5, 33.</p>
<p>Can somebody explain me that following... | -14 | 2016-06-15T11:04:57Z | 37,833,744 | <p>It's called a colon in english, not a double colon or double comma.</p>
<p>I urge you to read a basic Python introduction.</p>
<pre><code>if v < e: v = e
</code></pre>
<p>Is the same as:</p>
<pre><code>if v < e:
v = e
</code></pre>
| 1 | 2016-06-15T11:10:09Z | [
"python",
"if-statement"
] |
Python : What is the purpose of a colon in an if statement? | 37,833,625 | <p>I have this piece of python code below.</p>
<pre><code>def m(list):
v = list[0]
for e in list:
if v < e: v = e
return v
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
for row in values:
print(m(row), end = " ")
</code></pre>
<p>The result is 5, 33.</p>
<p>Can somebody explain me that following... | -14 | 2016-06-15T11:04:57Z | 37,833,880 | <pre><code>In [8]: v = 1
In [9]: e = 2
In [10]: if v < e: v = e
In [11]: v
Out[11]: 2
In [12]: e
Out[12]: 2
</code></pre>
<p>is same as:</p>
<pre><code>In [13]: v = 1
In [14]: e = 2
In [15]: if v < e: # if True execute next statement
....: v = e
....:
In [16]: v
Out[16]: 2
In [17]: e
Out[17]: 2... | 1 | 2016-06-15T11:15:10Z | [
"python",
"if-statement"
] |
Python : What is the purpose of a colon in an if statement? | 37,833,625 | <p>I have this piece of python code below.</p>
<pre><code>def m(list):
v = list[0]
for e in list:
if v < e: v = e
return v
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
for row in values:
print(m(row), end = " ")
</code></pre>
<p>The result is 5, 33.</p>
<p>Can somebody explain me that following... | -14 | 2016-06-15T11:04:57Z | 37,834,011 | <p>Another way to write that code is like this, just for learning purposes:</p>
<pre><code> def max_nest_list(lst):
max_numbers = []
for sub_list in lst:
max_num = sub_list[0]
for num in sub_list[1:]:
if num > max_num:
max_num = num
... | 0 | 2016-06-15T11:21:29Z | [
"python",
"if-statement"
] |
OpenCV in Qpython | 37,833,638 | <p>I'm developing a project (in Python) that does video processing using OpenCV. Now I'm planning to implement that in my android phone. I read that Qpython supports python on android. <strong>So is there any way to import third party libs like OpenCV in Qpython.</strong></p>
<p>Thanks in advance. </p>
| 0 | 2016-06-15T11:05:39Z | 38,175,636 | <p>In Qpython3 there is a pip program (not sure if on qpython too) but running that program you can "pip install [your module]" Worked for me installing sqlalchemy and youtube_dl </p>
| 0 | 2016-07-04T00:53:33Z | [
"android",
"python",
"opencv",
"qpython"
] |
Django lte & gte failing When Checking For Dates Range | 37,833,819 | <p>I want to check the calendar for dates already booked so a user won't be able to book a room if it has been booked already. I used the lte and gte to check for dates and I'm not happy with the result so far.</p>
<p>Models:</p>
<pre><code>class HotelCalendar(models.Model):
user=models.ForeignKey(User)
hotel... | 0 | 2016-06-15T11:13:15Z | 37,834,012 | <p>Change this </p>
<pre><code>check_for_bookings=HotelCalendar.objects.filter(Q(checkin_booked_date__gte=start_date), Q(checkout_booked_date__lte=end_date), hotelrooms_id=1)
</code></pre>
<p>to </p>
<pre><code>check_for_bookings=HotelCalendar.objects.filter(Q(checkin_booked_date__gte=start_date) | Q(checkout_booked... | 0 | 2016-06-15T11:21:37Z | [
"python",
"django",
"django-models",
"django-forms",
"django-views"
] |
Django lte & gte failing When Checking For Dates Range | 37,833,819 | <p>I want to check the calendar for dates already booked so a user won't be able to book a room if it has been booked already. I used the lte and gte to check for dates and I'm not happy with the result so far.</p>
<p>Models:</p>
<pre><code>class HotelCalendar(models.Model):
user=models.ForeignKey(User)
hotel... | 0 | 2016-06-15T11:13:15Z | 37,838,745 | <p>You can use the date range</p>
<pre><code>start_date = "2011-01-01"
final_date = "2011-01-31"
check_for_bookings=HotelCalendar.objects.filter(checkin_booked_date__range=[start_date, final_date], hotelrooms_id=1)
</code></pre>
<p>date can also be a date object or string in above format</p>
| 0 | 2016-06-15T14:47:25Z | [
"python",
"django",
"django-models",
"django-forms",
"django-views"
] |
load .npy file in python3.4 error | 37,833,875 | <p>I recently test the code of <a href="https://github.com/machrisaa/tensorflow-vgg/blob/master/vgg16.py" rel="nofollow">Tensorflow VGG16</a>. When I load vgg16.npy in python3.4. it comes out the error.
The code is like this:</p>
<pre><code>self.data_dict = np.load(vgg16_npy_path, encoding='latin1').item()
</code></pr... | 1 | 2016-06-15T11:15:00Z | 37,838,261 | <p>It appears that you have an old version of NumPy installed for Python 3.4. From what I can tell, the <code>encoding</code> argument was added to <code>np.load()</code> between <a href="http://docs.scipy.org/doc/numpy-1.9.0/reference/generated/numpy.load.html" rel="nofollow">version 1.9.0</a> and <a href="http://docs... | 1 | 2016-06-15T14:26:26Z | [
"python",
"python-3.x",
"numpy",
"tensorflow",
"deep-learning"
] |
Max-valued-elements from list group by element's code | 37,833,892 | <p>I want to extract all elements of the maximum running date grouped by their codes from a list of dictionary.
Here is what I got so far: </p>
<pre><code>import datetime
from itertools import groupby
commission_list = [
{'code': 'COMMISSION_CODE1', 'runningdt': datetime.datetime.strptime('2016-04-12', '%Y-%m-%d'... | 1 | 2016-06-15T11:16:03Z | 37,834,442 | <p>You can use <a href="https://docs.python.org/3/library/operator.html#operator.itemgetter" rel="nofollow"><code>itemgetter</code></a> from the <code>operator</code> module to do this efficiently.</p>
<pre><code>In [16]: from operator import itemgetter
In [17]: sorted_data = sorted(commission_list, key=itemgetter('c... | 0 | 2016-06-15T11:41:29Z | [
"python",
"list",
"group-by",
"max"
] |
Function not working correctly in python script | 37,833,898 | <p>Question I want to compare a full name with the persons initials but, for some reason I keep getting this error. Any help will be greatly appreciated!</p>
<pre><code>#check.py", line 27, in check_fn a = self.my_name AttributeError: 'Check' object has no attribute 'my_name'
</code></pre>
<pre><code> import re
... | 0 | 2016-06-15T11:16:33Z | 37,833,996 | <p>you've never defined <code>self.my_name</code> (or <code>self.intials</code> for that matter).</p>
<p>your code:</p>
<pre><code> a = self.my_name
b = self.intials
</code></pre>
<p>did you want to have this code?</p>
<pre><code> a = my_name
b = intials
</code></pre>
| 1 | 2016-06-15T11:20:54Z | [
"python"
] |
Function not working correctly in python script | 37,833,898 | <p>Question I want to compare a full name with the persons initials but, for some reason I keep getting this error. Any help will be greatly appreciated!</p>
<pre><code>#check.py", line 27, in check_fn a = self.my_name AttributeError: 'Check' object has no attribute 'my_name'
</code></pre>
<pre><code> import re
... | 0 | 2016-06-15T11:16:33Z | 37,834,141 | <p>It's raising AttributeError because in the you haven't declared self.my_name or self.initials therefore your Check class hasn't got an attribute called my_name.</p>
| 0 | 2016-06-15T11:27:25Z | [
"python"
] |
Function not working correctly in python script | 37,833,898 | <p>Question I want to compare a full name with the persons initials but, for some reason I keep getting this error. Any help will be greatly appreciated!</p>
<pre><code>#check.py", line 27, in check_fn a = self.my_name AttributeError: 'Check' object has no attribute 'my_name'
</code></pre>
<pre><code> import re
... | 0 | 2016-06-15T11:16:33Z | 37,834,268 | <p>'self' points to the object of same class. Here my_name and initials are not defined in the class 'check'.</p>
<pre><code>a = my_name
b = intials
</code></pre>
<p>As these parameters are passed through the function, the above snippet will work for you.</p>
| 1 | 2016-06-15T11:33:07Z | [
"python"
] |
Frequency Response Scipy.signal | 37,833,940 | <p>I'm learning digital signal processing to implement filters and am using python to easily implement a test ideas. So I just started using the scipy.signal library to find the impulse response and frequency response of different filters.</p>
<p>Currently I am working through the book "Digital Signals, Processors and... | 5 | 2016-06-15T11:18:26Z | 37,841,802 | <p>The SciPy generated frequency response is correct. In any case, I wouldn't trust the book's figure which appears to have been drawn by hand.</p>
<p>If you want to find the frequency response "manually", this can be simply done by defining a function returning the original Z-transform and evaluating it on the unit c... | 2 | 2016-06-15T17:16:29Z | [
"python",
"scipy",
"signal-processing"
] |
How to get url that were timeouted or got error? | 37,833,962 | <p>I have python class on python+tornado, that works like crawler. I have lot of links on the same site and i need to got responses from all of them to my data base.
So difficult in this: I cant understand how can i catch urls, that got error(timeout, or runtime exeptions).
I know how to fix this with newbie-code(i've ... | 0 | 2016-06-15T11:19:19Z | 37,836,092 | <p>In a coroutine you can "yield" a future. The coroutine pauses until the future is resolved into a result or an exception:</p>
<pre><code>try:
result = yield self.http_client.fetch(request)
except Exception as exc:
print("Failure!: %s" % exc)
else:
self.queue.task_done()
body = result.body
trans... | 0 | 2016-06-15T12:54:52Z | [
"python",
"tornado"
] |
Verify how many pair of parentheses exist in a string in Python | 37,833,964 | <p>I'm wondering if there's any way to find how many pair of parentheses are in a string.</p>
<p>I have to do some string manipulation and I sometimes have something like:</p>
<p><code>some_string = '1.8.0*99(0000000*kWh)'</code></p>
<p>or something like</p>
<p><code>some_string = '1.6.1*01(007.717*kW)(1604041815)'... | 1 | 2016-06-15T11:19:24Z | 37,834,075 | <p>As parenthesis always present in pairs, So just count the left or right parenthesis in a string and you'll get your answer.</p>
<pre><code>num_of_parenthesis = string.count('(')
</code></pre>
| 4 | 2016-06-15T11:24:11Z | [
"python",
"regex",
"string",
"python-3.x"
] |
Verify how many pair of parentheses exist in a string in Python | 37,833,964 | <p>I'm wondering if there's any way to find how many pair of parentheses are in a string.</p>
<p>I have to do some string manipulation and I sometimes have something like:</p>
<p><code>some_string = '1.8.0*99(0000000*kWh)'</code></p>
<p>or something like</p>
<p><code>some_string = '1.6.1*01(007.717*kW)(1604041815)'... | 1 | 2016-06-15T11:19:24Z | 37,834,548 | <p>If you want all the digits in a single string, use <em>re.findall</em> after replacing any <code>.</code> and join into a single string:</p>
<pre><code>In [15]: s="'1.6.1*01(007.717*kW)(1604041815)'"
In [16]: ("".join(re.findall("\((\d+).*?\)", s.replace(".", ""))))
Out[16]: '0077171604041815'
In [17]: s = '1.8.... | 1 | 2016-06-15T11:45:41Z | [
"python",
"regex",
"string",
"python-3.x"
] |
Verify how many pair of parentheses exist in a string in Python | 37,833,964 | <p>I'm wondering if there's any way to find how many pair of parentheses are in a string.</p>
<p>I have to do some string manipulation and I sometimes have something like:</p>
<p><code>some_string = '1.8.0*99(0000000*kWh)'</code></p>
<p>or something like</p>
<p><code>some_string = '1.6.1*01(007.717*kW)(1604041815)'... | 1 | 2016-06-15T11:19:24Z | 37,834,606 | <p>You can do that: <em>(assuming you already know there's at least one parenthese)</em></p>
<pre><code>re.sub(r'[^0-9]+', '', some_string.split('(', 1)[1])
</code></pre>
<p>or only with <code>re.sub</code>:</p>
<pre><code>re.sub(r'^[^(]*\(|[^0-9]+', '', some_string)
</code></pre>
| 1 | 2016-06-15T11:48:35Z | [
"python",
"regex",
"string",
"python-3.x"
] |
Find threading.Lock's futex id | 37,834,039 | <p>I want to instrument a large Python project to be able to debug production issues that look like this:</p>
<pre><code>23321 07:49:57.925037 futex(0x23b2c20, FUTEX_WAIT_PRIVATE, 0, NULL <unfinished ...>
23321 07:50:12.435793 <... futex resumed> ) = 0
</code></pre>
<p>Here, a thread waited 14.4 seconds o... | 1 | 2016-06-15T11:22:48Z | 37,834,427 | <p>You can record program execution via <a href="http://rr-project.org/" rel="nofollow">rr</a>, and then you may set conditional breakpoint like this: </p>
<pre><code>b futex if $rdi==0x23b2c20
</code></pre>
| 1 | 2016-06-15T11:40:49Z | [
"python",
"multithreading",
"locking",
"strace",
"futex"
] |
Find threading.Lock's futex id | 37,834,039 | <p>I want to instrument a large Python project to be able to debug production issues that look like this:</p>
<pre><code>23321 07:49:57.925037 futex(0x23b2c20, FUTEX_WAIT_PRIVATE, 0, NULL <unfinished ...>
23321 07:50:12.435793 <... futex resumed> ) = 0
</code></pre>
<p>Here, a thread waited 14.4 seconds o... | 1 | 2016-06-15T11:22:48Z | 37,859,317 | <p>I managed to hack something for Python2, here's a demo:</p>
<pre><code>$ strace -T -e signal=none -e futex python2 test.py
futex(0x7f6da47be0a8, FUTEX_WAKE_PRIVATE, 2147483647) = 0 <0.000006>
('futex address', '0x55de8d1105b0')
futex(0x55de8d123a30, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, fff... | 0 | 2016-06-16T12:31:19Z | [
"python",
"multithreading",
"locking",
"strace",
"futex"
] |
Trying to do a natural join using python standard library | 37,834,183 | <p>I have 4 tables:</p>
<ol>
<li><code>shops</code> (attributes: <code>shop_id</code>, <code>name</code>, <code>lat</code>, <code>lng</code>)</li>
<li><code>products</code> (attributes: <code>product_id</code>, <code>shop_id</code>, <code>title</code>, <code>popularity</code></li>
<li><code>tags</code> (attributes: <c... | 0 | 2016-06-15T11:29:29Z | 37,857,186 | <p>So the answer was ...</p>
<pre><code>from collections import defaultdict
s_p_t_t=[]
hash_= defaultdict(list)
for idx, row in enumerate(shops_products):
hash_[row[0]].append(idx)
for row in tags_taggings:
if row[3] in hash_:
for x in hash_[row[3]]:
s_p_t_t.append(shops_products[x]+row)
<... | 0 | 2016-06-16T10:57:08Z | [
"python",
"sql",
"csv"
] |
Why isn't my frames background showing? | 37,834,256 | <p>I am making an app with Tkinter (2.7) that imports a frame from another file. Unfortunately though the background colour isn't showing even though I have defined it in the imported file. The text widget on the frame shows up though. I have tried taking the <code>mainframe = â¦</code> out of the class and putting it... | 0 | 2016-06-15T11:32:33Z | 37,834,700 | <p>You never put the frame in the root window. You need to call <code>pack</code>, <code>place</code> or <code>grid</code> on <code>mainframe</code>.</p>
| 1 | 2016-06-15T11:52:31Z | [
"python",
"tkinter"
] |
Python equivalent of bash sort lexicographical and numerical | 37,834,272 | <p>So I've been working on a Python script that combines some information into a "bed" format. Which means that I'm working with features on a genome, my first column is the scaffold name (string), the second the start position on that scaffold (integer) and the third column is the stop position (integer), the other co... | 5 | 2016-06-15T11:33:12Z | 37,834,336 | <p>Load data, sort them with <a href="https://docs.python.org/2/library/functions.html#sorted" rel="nofollow"><code>sorted</code></a>, write to a new file.</p>
<pre><code># Load data
lists = list()
with open(filename, 'r') as f:
for line in f:
lists.append(line.rstrip().split())
# Sort data
results = sor... | 2 | 2016-06-15T11:36:21Z | [
"python",
"bash",
"sorting",
"numeric",
"lexicographic"
] |
Python equivalent of bash sort lexicographical and numerical | 37,834,272 | <p>So I've been working on a Python script that combines some information into a "bed" format. Which means that I'm working with features on a genome, my first column is the scaffold name (string), the second the start position on that scaffold (integer) and the third column is the stop position (integer), the other co... | 5 | 2016-06-15T11:33:12Z | 37,836,423 | <p>The solution of @sparkandshine seems to be short and to the point for the specific sort pattern. Also the one offered by @j-f-sebastian to me looks excellent, terse and with important hints/links on internationalization and off-memory sorting strategies.</p>
<p><strong>Maybe</strong> the following more explicit sho... | 0 | 2016-06-15T13:09:42Z | [
"python",
"bash",
"sorting",
"numeric",
"lexicographic"
] |
Python equivalent of bash sort lexicographical and numerical | 37,834,272 | <p>So I've been working on a Python script that combines some information into a "bed" format. Which means that I'm working with features on a genome, my first column is the scaffold name (string), the second the start position on that scaffold (integer) and the third column is the stop position (integer), the other co... | 5 | 2016-06-15T11:33:12Z | 37,838,661 | <p>To sort by your own sort criteria, just pass the corresponding <code>key</code> function:</p>
<pre><code>with open('infile', 'rb') as file:
lines = file.readlines()
def sort_key(line):
fields = line.split()
try:
return fields[0], int(fields[1]), int(fields[2])
except (IndexError, ValueError... | 2 | 2016-06-15T14:43:58Z | [
"python",
"bash",
"sorting",
"numeric",
"lexicographic"
] |
Rand Dict value not working in python | 37,834,311 | <p>IS there any way for me to specify the VALUE of 'ben stiller' or 'bill murray that I want? </p>
<p>I know that I cant do random.choice(ben_stiller.values()):</p>
<p>I also changed the dict so the key is the name of the movie and works perfect now.</p>
<h2> ^</h2>... | -3 | 2016-06-15T11:34:42Z | 37,834,852 | <p>The full error syas</p>
<pre><code>File "movie.py", line 42
if guess == random.choice(bill_murray.keys())
^
SyntaxError: invalid syntax
</code></pre>
<p>So, the syntax is invalid. An <code>if</code> line needs to end with an <code>:</code></p>
<p>If we sort out line ... | 0 | 2016-06-15T11:59:44Z | [
"python",
"dictionary",
"random"
] |
Scrapy setup ubuntu 16.04 or any other | 37,834,330 | <p>My today installed fresh Ubuntu 16.04 was preinstalled with python:</p>
<pre><code>p@Scrapy:~$ python --version
Python 2.7.11+
p@Scrapy:~$ python3 --version
Python 3.5.1+
</code></pre>
<p>As mentioned on manual page <a href="http://doc.scrapy.org/en/latest/intro/install.html" rel="nofollow">http://doc.scrapy.org/e... | 0 | 2016-06-15T11:35:59Z | 37,835,006 | <p>The Scrapy install docs need updating. Really sorry about that.</p>
<p>Ubuntu packages from <a href="http://archive.scrapy.org/ubuntu" rel="nofollow">http://archive.scrapy.org/ubuntu</a> are not up to date (as I write these lines on 2016-06-15) so do not use them if you want latest (Py3 compatible) scrapy</p>
<p>T... | 1 | 2016-06-15T12:06:49Z | [
"python",
"ubuntu",
"scrapy"
] |
Enabling `xrange` in Python3 for portability | 37,834,380 | <p>I wrote a script which I wanted to enable for both Python 2 and Python 3.</p>
<p>After importing <code>division</code> and <code>print_function</code> from <code>__future__</code>, my only concern was that my <code>range</code> returns a whole array in Python 2, wasting time and memory.</p>
<p>I added the followin... | 1 | 2016-06-15T11:38:19Z | 37,834,619 | <p>You can simplify it a bit:</p>
<pre><code>if sys.version_info[0] == 3:
xrange = range
</code></pre>
<p>I would do it the other way around:</p>
<pre><code>if sys.version_info[0] == 2:
range = xrange
</code></pre>
<p>If you ever want to drop Python 2.x support, you can just remove those two lines without g... | 5 | 2016-06-15T11:49:00Z | [
"python",
"python-3.x",
"xrange"
] |
A For Loop to Multiply a Number Repeatedly Python | 37,834,393 | <p>I want to start with <code>x = 100</code>, then multiply it by 1.1 and get the result (110 in this case) then do the same again with the result. </p>
<p>I want the output to look something like </p>
<p>1.) 100<br>
2.) 110<br>
3.) 121<br>
.<br>
.<br>
.<br>
150.) Result.</p>
<p>I have no idea how to do this; I trie... | -6 | 2016-06-15T11:39:07Z | 37,834,697 | <p>You don't need a <code>y</code> variable, you can simply reasign the new value to x at every iteration of the loop.</p>
<pre><code>x = 100
for i in xrange(150):
print x
x = x * 1.1
</code></pre>
| 0 | 2016-06-15T11:52:27Z | [
"python",
"python-2.7"
] |
A For Loop to Multiply a Number Repeatedly Python | 37,834,393 | <p>I want to start with <code>x = 100</code>, then multiply it by 1.1 and get the result (110 in this case) then do the same again with the result. </p>
<p>I want the output to look something like </p>
<p>1.) 100<br>
2.) 110<br>
3.) 121<br>
.<br>
.<br>
.<br>
150.) Result.</p>
<p>I have no idea how to do this; I trie... | -6 | 2016-06-15T11:39:07Z | 37,834,800 | <p>You can do this by:</p>
<pre><code>x = 100
for i in range(150):
line = str(i+1) + '.) ' + str(x)
print(line)
x = 1.1*x
</code></pre>
| 1 | 2016-06-15T11:56:54Z | [
"python",
"python-2.7"
] |
Find specific values inside array | 37,834,397 | <p>I'm trying to insert conditioned values in an array into an empty array in exact position.</p>
<pre><code>empty_array = np.zeros([40,100])
for x in range (1,24):
array[x,:,:] #which is also sized 40x100
if the_values_in_the_array < 0.25:
the_values_in_the_array = 0
empty_array = empty_array ... | 3 | 2016-06-15T11:39:17Z | 37,834,894 | <pre><code>empty_array = np.zeros([40,100])
array = np.random.rand(24,40,100)
array[array<0.25]=0 # change all the values which is <0.25 to 0
for x in range(1,24):
empty_array += array[x,:,:]
</code></pre>
| 4 | 2016-06-15T12:01:53Z | [
"python",
"arrays",
"numpy"
] |
Find specific values inside array | 37,834,397 | <p>I'm trying to insert conditioned values in an array into an empty array in exact position.</p>
<pre><code>empty_array = np.zeros([40,100])
for x in range (1,24):
array[x,:,:] #which is also sized 40x100
if the_values_in_the_array < 0.25:
the_values_in_the_array = 0
empty_array = empty_array ... | 3 | 2016-06-15T11:39:17Z | 37,835,661 | <p>I think the is the operation you are trying to do. I suggest using the <code>np.where</code> routine for setting values less than 0.25 to zero. Then you can sum over just the first dimension of the array to get the output array you are looking for. I reduced the dimensions of the problem for the example. </p>
<... | 1 | 2016-06-15T12:36:44Z | [
"python",
"arrays",
"numpy"
] |
list of dicts access via class attributes | 37,834,417 | <p>I have a list of dicts and I need to access dicts values as attributes.</p>
<p>My code:</p>
<pre><code>class Comments:
def __init__(self):
self.comments = [{'id': 1, 'title': 'bla'},
{'id': 2, 'title': 'bla2'},
{'id': 3, 'title': 'bla3'}]
def __it... | 2 | 2016-06-15T11:40:19Z | 37,834,633 | <p>As @Tim Castelijns said, that's not how dicts work.</p>
<p>The behavior you seek can be achieved by having a <code>Comment</code> class which holds the <code>id</code> and <code>title</code> as members.</p>
<pre><code>class Comment
def __init__(self, id, title):
self.id = id
self.title = title
... | 4 | 2016-06-15T11:49:39Z | [
"python",
"list",
"class",
"dictionary"
] |
list of dicts access via class attributes | 37,834,417 | <p>I have a list of dicts and I need to access dicts values as attributes.</p>
<p>My code:</p>
<pre><code>class Comments:
def __init__(self):
self.comments = [{'id': 1, 'title': 'bla'},
{'id': 2, 'title': 'bla2'},
{'id': 3, 'title': 'bla3'}]
def __it... | 2 | 2016-06-15T11:40:19Z | 37,834,682 | <p>You can probably use <a href="https://pypi.python.org/pypi/bunch" rel="nofollow">Bunch</a> for this.</p>
<blockquote>
<p>Bunch is a dictionary that supports attribute-style access, a la JavaScript</p>
</blockquote>
| 0 | 2016-06-15T11:51:46Z | [
"python",
"list",
"class",
"dictionary"
] |
list of dicts access via class attributes | 37,834,417 | <p>I have a list of dicts and I need to access dicts values as attributes.</p>
<p>My code:</p>
<pre><code>class Comments:
def __init__(self):
self.comments = [{'id': 1, 'title': 'bla'},
{'id': 2, 'title': 'bla2'},
{'id': 3, 'title': 'bla3'}]
def __it... | 2 | 2016-06-15T11:40:19Z | 37,835,085 | <p>Another approach for completeness - use a <code>namedtuple</code>.</p>
<pre><code>from collections import namedtuple
Comment = namedtuple('Comment', ('id', 'title'))
comments = [Comment(42, 'What is the answer to life, the universe, and everything?'),
Comment(13, 'What is your favorite color?'),
... | 0 | 2016-06-15T12:10:26Z | [
"python",
"list",
"class",
"dictionary"
] |
list of dicts access via class attributes | 37,834,417 | <p>I have a list of dicts and I need to access dicts values as attributes.</p>
<p>My code:</p>
<pre><code>class Comments:
def __init__(self):
self.comments = [{'id': 1, 'title': 'bla'},
{'id': 2, 'title': 'bla2'},
{'id': 3, 'title': 'bla3'}]
def __it... | 2 | 2016-06-15T11:40:19Z | 37,835,418 | <p>You can make the comments instances of a dictionary subclass that allows normal access as well as dotted attribute-style access. There are several ways of implementing it, but the following is one of the simplest, which is to make the each instance its own <code>__dict__</code>:</p>
<pre><code>class Comment(dict):
... | 0 | 2016-06-15T12:26:19Z | [
"python",
"list",
"class",
"dictionary"
] |
list of dicts access via class attributes | 37,834,417 | <p>I have a list of dicts and I need to access dicts values as attributes.</p>
<p>My code:</p>
<pre><code>class Comments:
def __init__(self):
self.comments = [{'id': 1, 'title': 'bla'},
{'id': 2, 'title': 'bla2'},
{'id': 3, 'title': 'bla3'}]
def __it... | 2 | 2016-06-15T11:40:19Z | 37,835,479 | <pre><code>class AttrDict(dict):
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self
class Comments:
def __init__(self):
self.comments = [{'id': 1, 'title': 'bar'},
{'id': 2, 'title': 'foo'},
... | 0 | 2016-06-15T12:29:03Z | [
"python",
"list",
"class",
"dictionary"
] |
Pandas, mulitindexing | 37,834,474 | <p>I have data that I need to aggregate for per column and then per column again. What I need is total spend per product category for each unique customer. Multiindex should do this. Problem is that I am new to Pandas, and I don't understand multiindexing.</p>
<p>I have data structured like this:</p>
<pre><code> Cust... | 2 | 2016-06-15T11:42:44Z | 37,834,538 | <p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.sum.html" rel="nofollow"><code>sum</code></a>:</p>
<pre><code>df1 ... | 1 | 2016-06-15T11:45:17Z | [
"python",
"pandas",
"dataframe",
"pivot-table",
"multi-index"
] |
Change output file for running data stream? | 37,834,792 | <p>I created a simple python script that listens to a filtered twitter stream and that writes the data into a simple text file.</p>
<pre><code># -*- coding: utf-8 -*-
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
# security credentials ommited
searchstr = 'SEAR... | 0 | 2016-06-15T11:56:26Z | 37,835,319 | <p>Just replace </p>
<pre><code>'data.txt'
</code></pre>
<p>with</p>
<pre><code>time.strftime('%Y-%m-%d',time.localtime())+'-data.txt'
</code></pre>
<p>Do not forget to <code>import time</code> before using the above code. </p>
<p><code>time.localtime()</code> will get the current local time which will be form... | 1 | 2016-06-15T12:21:21Z | [
"python",
"twitter",
"file-io",
"output"
] |
Change output file for running data stream? | 37,834,792 | <p>I created a simple python script that listens to a filtered twitter stream and that writes the data into a simple text file.</p>
<pre><code># -*- coding: utf-8 -*-
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
# security credentials ommited
searchstr = 'SEAR... | 0 | 2016-06-15T11:56:26Z | 37,835,431 | <p>Alternatively, if you want the file timestamp in UTC instead of localtime:</p>
<pre><code>>>> import time
>>> time.strftime("%Y-%m-%d-data.txt", time.gmtime(time.time()))
'2016-06-15-data.txt'
</code></pre>
| 1 | 2016-06-15T12:27:02Z | [
"python",
"twitter",
"file-io",
"output"
] |
Hue gradient as colorbar on y axis with matplotlib | 37,834,881 | <p>I have the following Hue/Saturation 2D-Histogram. There are two things i like to change but don't know how.
<a href="http://i.stack.imgur.com/Dvbog.png" rel="nofollow"><img src="http://i.stack.imgur.com/Dvbog.png" alt="Hue/saturation 2D Histogram"></a></p>
<p><strong>1)</strong> Is it possible to replace the y-axis... | 1 | 2016-06-15T12:01:14Z | 37,838,155 | <p>Ok, I don't know how to do this exactly... the closest thing I can think of is to use <code>AxesGrid</code> from these matplotlib examples: <a href="http://matplotlib.org/examples/color/colormaps_reference.html" rel="nofollow">cmap</a> and <a href="http://matplotlib.org/examples/axes_grid/demo_edge_colorbar.html" re... | 1 | 2016-06-15T14:21:58Z | [
"python",
"numpy",
"matplotlib",
"colorbar"
] |
A Flask-SQLAlchemy update is creating a new record in MySQL | 37,834,896 | <p>I am trying to update a MySQL record from flask-sqlalchemy, but instead of updating the current record, it is adding a new one. But here's the really weird thing, when I run the same code from the Python prompt it updates properly without adding a new record.</p>
<p>Here is the relevant portion of the code:</p>
<p... | 0 | 2016-06-15T12:01:55Z | 37,837,962 | <p>Okay, so thanks to Daniel and Doobeh for pointing me in the right directions. Basically it came down to me not requesting the blog_id properly in the POST method of edit_entry. Here is the new (and working) code.</p>
<pre><code>def edit_entry():
form = BlogEntry()
if request.method == 'POST':
blog_i... | 0 | 2016-06-15T14:12:51Z | [
"python",
"mysql",
"flask",
"flask-sqlalchemy"
] |
script to export feature class to excel file and skip header row in excel | 37,834,931 | <p>I'm trying to whrite a python script to export table from Arcgis to excel or csv, the code work but i want to skip the first line of the excel/csv file (header) or move it to the 3rd row for exemple.</p>
<pre><code>"""
This script will convert a table to an excel spreadsheet. If the third-party
module xlwt is avail... | 0 | 2016-06-15T12:03:30Z | 37,836,513 | <p>What I understand is that you want to skip the first row when writing the output XLS file.
If you add a test on the rowidx and only write it in the output file only if >0 it should do what you want (the csv fallback case must be handled somewhere else)</p>
<pre><code># Write rows
for rowidx, row in enumerate(rows):... | 0 | 2016-06-15T13:13:23Z | [
"python",
"excel",
"csv",
"arcgis"
] |
Quickest way to grab lines from multiple Files | 37,835,059 | <p>I have files that vary in size, some are huge. I have many of these files, all are compressed with lzop. </p>
<p>The files look like this :</p>
<pre><code>nodedef>name VARCHAR,family VARCHAR,composite VARCHAR,color VARCHAR
1104283,C,1,'238,32,77' 0,1,4,'255,182,83' 1,1,4,'255,182,83'
7,1,4,'255,182,83' 11,1,4... | 2 | 2016-06-15T12:08:36Z | 37,835,482 | <p><code>grep</code> may not be effective when it comes to search for a text in a particular column, but <code>awk</code> thrives in achieving just that.</p>
<p>If you are looking to process multiple files and there can't be more that one line that contains a line with <code>2nd</code> column value as <code>C</code> t... | 4 | 2016-06-15T12:29:08Z | [
"python",
"unix",
"parallel-processing",
"grep"
] |
Quickest way to grab lines from multiple Files | 37,835,059 | <p>I have files that vary in size, some are huge. I have many of these files, all are compressed with lzop. </p>
<p>The files look like this :</p>
<pre><code>nodedef>name VARCHAR,family VARCHAR,composite VARCHAR,color VARCHAR
1104283,C,1,'238,32,77' 0,1,4,'255,182,83' 1,1,4,'255,182,83'
7,1,4,'255,182,83' 11,1,4... | 2 | 2016-06-15T12:08:36Z | 37,836,396 | <p>As an addition to the answer by @Inian for using awk for matching, a useful extention might be to use 'make' for easy (local) parallelism if you have many many files, or matching on some files can take a long-time:</p>
<pre><code>inputs = $(wildcard *.txt)
outputs = $(inputs:.txt=.matches)
%.matches : %.txt
./... | 1 | 2016-06-15T13:08:29Z | [
"python",
"unix",
"parallel-processing",
"grep"
] |
Xlsxwriter different formats to different cells in same column | 37,835,099 | <p>I have a problem when setting the format for different cells. I have two dataframes that contains numbers that should be shown in different formats. I have created a simple example to show my problem.</p>
<pre><code>import pandas as pd
import numpy as np
import xlsxwriter
frame1 = pd.DataFrame(np.random.randint(0,... | 2 | 2016-06-15T12:11:16Z | 37,835,354 | <p>The column format in Excel applies to the entire column and can only be overridden by a row format or a cell format.</p>
<p>So you would need to apply a cell format to the cells that you wanted to format differently and that isn't possible with the Pandas interface.</p>
<p>An alternative could be to use a conditio... | 1 | 2016-06-15T12:23:09Z | [
"python",
"excel",
"pandas",
"xlsxwriter"
] |
Xlsxwriter different formats to different cells in same column | 37,835,099 | <p>I have a problem when setting the format for different cells. I have two dataframes that contains numbers that should be shown in different formats. I have created a simple example to show my problem.</p>
<pre><code>import pandas as pd
import numpy as np
import xlsxwriter
frame1 = pd.DataFrame(np.random.randint(0,... | 2 | 2016-06-15T12:11:16Z | 37,835,904 | <p>The work-around would be using <code>conditional_format</code>, as mentioned by @jmcnamara, you just apply <code>{'type': 'top','value': str(f2rows),'format': format1}</code>, where <code>f2rows</code> is the number of rows of your dataframe and the <code>format1</code> is the format you would like to apply.</p>
<p... | 2 | 2016-06-15T12:46:23Z | [
"python",
"excel",
"pandas",
"xlsxwriter"
] |
How do I edit default index values for x positions in matplotlib bar chart | 37,835,161 | <p>With the following code I am displaying a bar chart using matplotlib. I am trying to show the x labels for each column to be the values for the OS key. Instead it print the index positoins for each category. The OS key is the category and the Conn is the values for each category. How do I go about this. Been struggl... | 2 | 2016-06-15T12:14:20Z | 37,835,202 | <p>pass <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.bar.html" rel="nofollow"><code>x='OS'</code></a> to use those values for the x-axis:</p>
<pre><code>myplot = df.plot.bar(x='OS')
</code></pre>
<p><a href="http://i.stack.imgur.com/ly2tG.png" rel="nofollow"><img src="http://i.... | 1 | 2016-06-15T12:15:56Z | [
"python",
"pandas",
"matplotlib",
"plot",
"dataframe"
] |
How do I edit default index values for x positions in matplotlib bar chart | 37,835,161 | <p>With the following code I am displaying a bar chart using matplotlib. I am trying to show the x labels for each column to be the values for the OS key. Instead it print the index positoins for each category. The OS key is the category and the Conn is the values for each category. How do I go about this. Been struggl... | 2 | 2016-06-15T12:14:20Z | 37,835,278 | <p>Another solution is <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> from column <code>OS</code>:</p>
<pre><code>df.set_index('OS').plot(kind='bar')
</code></pre>
<p><a href="http://i.stack.imgur.com/cleNt.png" rel="nofollow">... | 1 | 2016-06-15T12:18:55Z | [
"python",
"pandas",
"matplotlib",
"plot",
"dataframe"
] |
How can I specify the function type in my type hints? | 37,835,179 | <p>I want to use type hints in my current Python 3.5 project. My function should receive a function as parameter. </p>
<p><strong>How can I specify the type function in my type hints?</strong></p>
<pre><code>import typing
def my_function(name:typing.AnyStr, func: typing.Function) -> None:
# However, typing.Fu... | 2 | 2016-06-15T12:14:51Z | 39,624,147 | <p>As <a href="http://stackoverflow.com/questions/37835179/how-can-i-specify-the-function-type-in-my-type-hints/39624147#comment63131590_37835179">@Johnsharpe</a> noted, this can be done with <a href="https://docs.python.org/3.6/library/typing.html#typing.Callable" rel="nofollow"><code>typing.Callable</code></a>:</p>
... | 1 | 2016-09-21T18:36:57Z | [
"python",
"python-3.x",
"python-3.5",
"type-hinting",
"mypy"
] |
Writing your first Django app, error with from . import views | 37,835,453 | <p>I'm started learning python-django and I would like create my first django app.
I'm following the Django 1.8 tutorial. In my project "mysite", there is a source folder "polls". In the folder there is "views.py" module where a "index" function is defined. And there is a "urls.py" file:</p>
<pre><code>from django.con... | 0 | 2016-06-15T12:27:49Z | 37,836,101 | <p>Try to register polls in your applications in settings.py. Something like this:
<a href="http://i.stack.imgur.com/q6a0W.jpg" rel="nofollow">enter image description here</a></p>
| 0 | 2016-06-15T12:55:23Z | [
"python",
"django"
] |
Writing your first Django app, error with from . import views | 37,835,453 | <p>I'm started learning python-django and I would like create my first django app.
I'm following the Django 1.8 tutorial. In my project "mysite", there is a source folder "polls". In the folder there is "views.py" module where a "index" function is defined. And there is a "urls.py" file:</p>
<pre><code>from django.con... | 0 | 2016-06-15T12:27:49Z | 37,840,943 | <p>There are a couple of things that can cause this. I have two possible solutions that are not mentioned yet.</p>
<ol>
<li>Try to replace <code>url(r'^polls/', include('polls.urls')),</code> with <code>url(r'^polls/', include('mysite.polls.urls')),</code></li>
<li>Have you remembered to include an <code>__init__.py</... | 0 | 2016-06-15T16:30:23Z | [
"python",
"django"
] |
Matplotlib.pyplot - Deactivate axes in figure. /Axis of figure overlap with axes of subplot | 37,835,591 | <pre><code>%load_ext autoreload
%autoreload 2
%matplotlib inline
import numpy as np
import datetime as dt
import pickle
import pandas as pd
import datetime
from datetime import timedelta, date
from datetime import date as dt
import math
import os
import matplotlib.pyplot as plt
plt.style.use('ggplot')
from pylab impo... | -1 | 2016-06-15T12:33:40Z | 37,845,311 | <p>If you want to remove the axes completely, you should try:</p>
<pre><code>plt.axis('off')
</code></pre>
<p>If that doesn't work (or doesn't do what you want it to), try: </p>
<pre><code>cur_axes = plt.gca()
cur_axes.axes.get_xaxis().set_visible(False)
cur_axes.axes.get_yaxis().set_visible(False)
</code></pre>
| 0 | 2016-06-15T20:37:14Z | [
"python",
"matplotlib",
"axis",
"figure"
] |
Get elements from list using index from a list of arrays | 37,835,612 | <blockquote>
<p><strong>Question:</strong></p>
</blockquote>
<p>I have a list of arrays such as: </p>
<pre><code>a = [array([0, 4]), array([1, 3, 2])]
</code></pre>
<p>From another variable X, I want to take two subsets which are chosen by the index in each array in a. </p>
<pre><code>X = [0.1, 0.7, 0.9, 0.2, 0.3... | 0 | 2016-06-15T12:34:28Z | 37,835,708 | <p><code>return [X[i] for i in indices]</code> would work.</p>
| 1 | 2016-06-15T12:38:28Z | [
"python",
"arrays",
"list",
"indexing"
] |
Get elements from list using index from a list of arrays | 37,835,612 | <blockquote>
<p><strong>Question:</strong></p>
</blockquote>
<p>I have a list of arrays such as: </p>
<pre><code>a = [array([0, 4]), array([1, 3, 2])]
</code></pre>
<p>From another variable X, I want to take two subsets which are chosen by the index in each array in a. </p>
<pre><code>X = [0.1, 0.7, 0.9, 0.2, 0.3... | 0 | 2016-06-15T12:34:28Z | 37,835,718 | <p>My first attempt, which basically follows your way of doing things in a more compact way would be:</p>
<pre><code>result1, result2 = [ [X[ii] for ii in array] for array in a]
</code></pre>
<p>If you can be bothered to convert X to a numpy array, you can do:</p>
<pre><code>X = np.array([ 0.1, 0.7, 0.9, 0.2, 0.... | 0 | 2016-06-15T12:38:53Z | [
"python",
"arrays",
"list",
"indexing"
] |
Get elements from list using index from a list of arrays | 37,835,612 | <blockquote>
<p><strong>Question:</strong></p>
</blockquote>
<p>I have a list of arrays such as: </p>
<pre><code>a = [array([0, 4]), array([1, 3, 2])]
</code></pre>
<p>From another variable X, I want to take two subsets which are chosen by the index in each array in a. </p>
<pre><code>X = [0.1, 0.7, 0.9, 0.2, 0.3... | 0 | 2016-06-15T12:34:28Z | 37,835,820 | <p>Use a list comprehension, with a default for safety, in case an index from <code>a</code> is not in <code>X</code>:</p>
<pre><code>a = [array('i', [0, 4]), array('i', [1, 3, 2])]
X = [0.1, 0.7, 0.9, 0.2, 0.3]
result = [[(X[i:]+[0])[0] for i in o] for o in a]
# ^ default
# [[0.1, 0.3], [0.7, 0.2, ... | 0 | 2016-06-15T12:43:14Z | [
"python",
"arrays",
"list",
"indexing"
] |
Python webbrowser module isn't working correctly | 37,835,636 | <p>I'm creating this automation script in python that uses a dictionary to open a browser and when using webbrowser module to open a parsed dictionary, I keep getting a key error. Here is the code:</p>
<pre><code>import webbrowser, sys, requests
ptcl = 'https://'
tail = '.com/'
context_dict =
{
'fb': ptcl ... | 0 | 2016-06-15T12:35:39Z | 37,835,735 | <p>You lookup twice:</p>
<pre><code>page = context_dict[i.replace(',', '')]
</code></pre>
<p>then</p>
<pre><code>webbrowser.open(context_dict[page])
</code></pre>
<p>Remove one of the lookups.</p>
<p>I would suggest:</p>
<pre><code>def get_args():
if len(sys.argv) > 1:
for i in sys.argv[1:]:
... | 1 | 2016-06-15T12:39:38Z | [
"python"
] |
SyntaxError in virtual environment with Python 2.7 | 37,835,643 | <p>I have pip installed the virtualenvwrapper in my Ubuntu 14.04 and when I make a new virtual environment, regardless of the version of python I think I pick, I get Python 3 in the virtualenv. For example, if I:</p>
<pre><code>mkvirtualenv -p /usr/bin/python2.7 newvirenv
</code></pre>
<p>When I use ipython in the te... | -1 | 2016-06-15T12:35:58Z | 37,835,952 | <p>I was probably doing something wrong when installing ipython in the virtual environment. Doing:</p>
<pre><code>pip install ipython
</code></pre>
<p>Inside the virtual environment should work. Thanks jonrsharpe</p>
| 0 | 2016-06-15T12:48:39Z | [
"python",
"python-2.7",
"virtualenvwrapper"
] |
With the Sqlalchemy, trying to create a table in sql Database | 37,835,724 | <p>In my Python script I am using Sqlalchemy, after setting up a connection</p>
<pre><code>connection = engine.connect()
data_gov=connection.execute("select * into temp from mytest_1 where FollowersOf ='gov'")
data=data_gov.fetchall()
</code></pre>
<p>But I cant see any table in my sql database and cant able to fetc... | 1 | 2016-06-15T12:39:06Z | 37,838,080 | <p>After lot of attempts, somehow I myself got the answer. So its following, engine.connect() just creates a proxy connection. So after Few tweaks only</p>
<pre><code>connection = engine.raw_connection()
data_gov=connection.execute("select * into temp from mytest_1 where FollowersOf ='gov'").commit()
connection.close(... | 0 | 2016-06-15T14:18:25Z | [
"python",
"sql",
"sqlalchemy"
] |
What is the type of table_name in select_from(table_name)? | 37,835,783 | <p>I'm trying to get the number of rows from a SQL Server which consists of many tables by looping through it to see how much data they contain. However, I'm not sure what will go into select_from() function. As I currently supply Unicode for table names and it raised </p>
<pre><code>NoInspectionAvailable: No inspecti... | 0 | 2016-06-15T12:41:38Z | 37,837,234 | <p>Typically, it's a class name that refers to a class that describes the database table.</p>
<p>In the sqlalchemy docs, <a href="http://docs.sqlalchemy.org/en/latest/orm/tutorial.html" rel="nofollow">http://docs.sqlalchemy.org/en/latest/orm/tutorial.html</a>, they have you create a base class using declarative base a... | 1 | 2016-06-15T13:42:36Z | [
"python",
"sql",
"sql-server",
"sqlalchemy"
] |
Noestests: AttributeError using @patch when running Nosetests on multiple files | 37,835,846 | <p>I am running nosetests across multiple files and getting an error relating to the importing of a specific file, well I'm not actually sure what the error is related to, I think it is either something up with the import or something up with the patching of it. The error itself looks like:</p>
<p>(I'm getting one of ... | 0 | 2016-06-15T12:44:01Z | 37,856,974 | <p>I still have no idea what was wrong, but it seemed to be something to do with the importing.</p>
<p>Anyway, this workaround solved the problem, but not sure why exactly.</p>
<p>The <code>__init__.py</code> in <code>my_module</code> was empty initially. Then I edited it to expose the individual functions of <code>u... | 0 | 2016-06-16T10:46:42Z | [
"python",
"unit-testing",
"testing",
"nose"
] |
Using Selenium in Python to save a webpage on Firefox | 37,835,867 | <p>I am trying to use <code>Selenium</code> in <code>Python</code> to save webpages on <code>MacOS Firefox</code>. </p>
<p>So far, I have managed to click <code>COMMAND + S</code> to pop up the <code>SAVE AS window</code>. However,</p>
<p>I don't know how to: </p>
<ol>
<li>change the directory of the file, </li>
<l... | 0 | 2016-06-15T12:44:52Z | 37,835,976 | <p>You cannot interact with system dialogs like save file dialog.
If you want to save the page html you can do something like this:</p>
<pre><code>page = driver.page_source
file_ = open('page.html', 'w')
file_.write(page)
file_.close()
</code></pre>
| 2 | 2016-06-15T12:49:41Z | [
"python",
"selenium",
"firefox",
"save-as"
] |
Using Selenium in Python to save a webpage on Firefox | 37,835,867 | <p>I am trying to use <code>Selenium</code> in <code>Python</code> to save webpages on <code>MacOS Firefox</code>. </p>
<p>So far, I have managed to click <code>COMMAND + S</code> to pop up the <code>SAVE AS window</code>. However,</p>
<p>I don't know how to: </p>
<ol>
<li>change the directory of the file, </li>
<l... | 0 | 2016-06-15T12:44:52Z | 37,835,977 | <p>What you are trying to achieve is impossible to do with Selenium. The dialog that opens is not something Selenium can interact with.</p>
<p>The closes thing you could do is collect the <code>page_source</code> which gives you the entire HTML of a single page and save this to a file.</p>
<pre><code>import codecs
c... | 3 | 2016-06-15T12:49:42Z | [
"python",
"selenium",
"firefox",
"save-as"
] |
Getting a random number each time in a script | 37,835,879 | <p>I'm having trouble with the following bit of code:</p>
<pre><code>from random import randint
class character():
__init__(self):
#init stuff here
def luck(self, Luck = randint(0, 3)):
return Luck
</code></pre>
<p>I have to call this method multiple times in my script, for multiple instances,... | 0 | 2016-06-15T12:45:08Z | 37,835,998 | <p>In python, the default expressions that set the default values for function arguments are only executed once. This means that once you define the <code>luck</code> method, whatever value <code>randint()</code> spit out the first time will stay for all invocations.</p>
<p>To get a new random number every time the me... | 2 | 2016-06-15T12:50:30Z | [
"python",
"python-3.x",
"method-call"
] |
Getting a random number each time in a script | 37,835,879 | <p>I'm having trouble with the following bit of code:</p>
<pre><code>from random import randint
class character():
__init__(self):
#init stuff here
def luck(self, Luck = randint(0, 3)):
return Luck
</code></pre>
<p>I have to call this method multiple times in my script, for multiple instances,... | 0 | 2016-06-15T12:45:08Z | 37,836,030 | <p>This is a definition for the luck function. If the user specifies a number it will be returned. If instead no argument is given, Luck will be set from <code>randint</code> and that random value returned.</p>
<pre><code>def luck(self, Luck = None):
if Luck is None:
Luck = randint(0,3)
return Luck
</c... | 3 | 2016-06-15T12:51:56Z | [
"python",
"python-3.x",
"method-call"
] |
Getting a random number each time in a script | 37,835,879 | <p>I'm having trouble with the following bit of code:</p>
<pre><code>from random import randint
class character():
__init__(self):
#init stuff here
def luck(self, Luck = randint(0, 3)):
return Luck
</code></pre>
<p>I have to call this method multiple times in my script, for multiple instances,... | 0 | 2016-06-15T12:45:08Z | 37,836,057 | <p>You can use <code>None</code> or something for a default argument, check if you got <code>None</code> and if you did - call <code>randint()</code> (if not just return what you did get).<br>
If you use <code>randint()</code> in the function deceleration it will randomize it only once.</p>
| 0 | 2016-06-15T12:53:14Z | [
"python",
"python-3.x",
"method-call"
] |
How can I display on html (Django project), value of date filed but, the month 3 letters | 37,835,923 | <p>on my HTML file I have a value of a date filed like this : <code><div> {{ offer.expiry_time }} </div></code>
the output on the page is: <code>June ,15,2016</code></p>
<p>June for example has 4 letters but I need only the 3 first letters.</p>
<p>It should look like: <code>jun,15,2016</code></p>
| 0 | 2016-06-15T12:47:16Z | 37,836,058 | <p><a href="https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#date" rel="nofollow">You can pass arguments to the <code>date</code> filter</a>:</p>
<pre><code>{{ offer.expiry_time:"b,j,Y" }}
</code></pre>
<p>You can see the definitions of each of those letters in the documentation linked above.</p>
| 0 | 2016-06-15T12:53:14Z | [
"python",
"html",
"django",
"django-views"
] |
How to set default value by many2one field in odoo? | 37,836,054 | <p>I have following <strong>feeder_data</strong> class in <strong>'company_id1'</strong> I will select name of company.That company name has to set default value at <strong>data_value</strong> class 'company' field .It should have selected name as default value there </p>
<pre><code>class feeder_data(osv.Model):
... | 2 | 2016-06-15T12:53:08Z | 37,838,181 | <p>For setting the default value of <strong>company_id1</strong> in model <code>feeder.data</code>
try this way:</p>
<pre><code>def _default_company(self, cr, uid, context=None):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
if user.company_id:
return user.company_id.id
r... | 2 | 2016-06-15T14:22:46Z | [
"python",
"xml",
"openerp"
] |
Plotting OMI satelliate daily data using Basemap package | 37,836,063 | <p><strong>OMI</strong> (Ozone Monitoring Instrument) measures the key air quality components such as nitrogen dioxide(NO2), ozone(O3). The daily columnO3 file which I downloaded <a href="http://mirador.gsfc.nasa.gov/cgi-bin/mirador/granlist.pl?dataSet=OMNO2G&version=003&allversion=003&keyword=omno2&poi... | 0 | 2016-06-15T12:53:25Z | 37,846,444 | <p>The <code>Latitude</code> and <code>Longitude</code> variables have missing values too, which are -1.2676506e+30 and thus cause the large xrange and yrange in your plots. Also, note that the <code>_FillValue</code> and <code>MissingValue</code> attributes are lists, so your replacement with NaNs went wrong.</p>
<pr... | 1 | 2016-06-15T21:53:56Z | [
"python",
"matplotlib",
"matplotlib-basemap",
"hdf"
] |
Check if a string starts with any letter between 'A' and 'G' in django template | 37,836,068 | <p>How can I check if a string starts with 'A' or 'B' or 'C'.... or 'G' in django template.</p>
<p>I've this method presently. Can it be done in a better way?</p>
<pre><code>{% if val|slice:":1" == 'A' or val|slice:":1" == 'B' or val|slice:":1" == 'C'.... or val|slice:":1" == 'G' %}
</code></pre>
| 1 | 2016-06-15T12:53:27Z | 37,836,122 | <p>Strings are treated like sequences in Python so you can check membership like so:</p>
<pre><code>{% if val|first in 'ABCG' %}
# Do stuff
{% endif %}
</code></pre>
| 4 | 2016-06-15T12:56:23Z | [
"python",
"django"
] |
Odoo python fileopendialog | 37,836,077 | <p>does anybody knows how to open a filedialog on Odoo? I've add a button on a custom view, now I would like to browse for a file on THE CLIENT when this button is clicked.</p>
<p>Any ideas?</p>
<p>Thanks!</p>
| 1 | 2016-06-15T12:53:54Z | 37,836,215 | <p>you need to implement a custom widget for this. object buttons trigger actions in server side not client side</p>
<p>You can find more about widgets in the ofoocial documentation <a href="https://www.odoo.com/documentation/8.0/howtos/web.html" rel="nofollow">odoo.com/documentation/8.0/howtos/web.html</a> also you m... | 0 | 2016-06-15T13:00:35Z | [
"python",
"openerp",
"fileopendialog"
] |
Odoo python fileopendialog | 37,836,077 | <p>does anybody knows how to open a filedialog on Odoo? I've add a button on a custom view, now I would like to browse for a file on THE CLIENT when this button is clicked.</p>
<p>Any ideas?</p>
<p>Thanks!</p>
| 1 | 2016-06-15T12:53:54Z | 37,839,268 | <p>You can define binary fields in Odoo, like other fields. Look into ir.attachment model definition and its view definitions to get a good hint, how do it for such fields.</p>
| 1 | 2016-06-15T15:08:32Z | [
"python",
"openerp",
"fileopendialog"
] |
Search, Find, Print, Rename - PythonV2.7.5 String Extractor | 37,836,128 | <p>This is my first post on StackOverflow so I apologise if it is too vague.
Essentially, I have LOTS of files that are outputted from a program, and I am trying to automate the process of collecting all the Data. </p>
<p>All I want is the values of a string to be returned in a printed format. Which I have managed to... | 0 | 2016-06-15T12:56:44Z | 37,836,484 | <p>You could use the file object's <code>name</code> attribute.</p>
<pre><code>for line in lattE:
if re.match("text", line):
print lattE.name, line,
</code></pre>
| 0 | 2016-06-15T13:12:14Z | [
"python",
"string",
"search",
"printing"
] |
Search, Find, Print, Rename - PythonV2.7.5 String Extractor | 37,836,128 | <p>This is my first post on StackOverflow so I apologise if it is too vague.
Essentially, I have LOTS of files that are outputted from a program, and I am trying to automate the process of collecting all the Data. </p>
<p>All I want is the values of a string to be returned in a printed format. Which I have managed to... | 0 | 2016-06-15T12:56:44Z | 37,838,743 | <p>So I've been searching a bit further and found this really useful post [<a href="http://askubuntu.com/questions/352198/reading-all-files-from-a-directory][1]">http://askubuntu.com/questions/352198/reading-all-files-from-a-directory][1]</a></p>
<p>And Tried to combine that with my existing code... and it doesn't see... | 0 | 2016-06-15T14:47:19Z | [
"python",
"string",
"search",
"printing"
] |
Search, Find, Print, Rename - PythonV2.7.5 String Extractor | 37,836,128 | <p>This is my first post on StackOverflow so I apologise if it is too vague.
Essentially, I have LOTS of files that are outputted from a program, and I am trying to automate the process of collecting all the Data. </p>
<p>All I want is the values of a string to be returned in a printed format. Which I have managed to... | 0 | 2016-06-15T12:56:44Z | 37,840,128 | <p>Alternative method ... that actually worked. Thanks @Gabor Fekete. </p>
<pre><code>import fnmatch #Imports the synx for itteratively searching through Files
import os
import re #regex Expressions
for file in os.listdir('/.'): #Goes through Files in Directory
if fnmatch.fnmatch(file, '*.sum'): # Selects file... | 0 | 2016-06-15T15:47:16Z | [
"python",
"string",
"search",
"printing"
] |
Ansible not getting the value from list of dicts | 37,836,134 | <p>I need to:
- echo using debug the valueof the 'location'
- check if the 'location' contains specific word (whole word is fine)</p>
<p>based on this output generated by the <a href="https://github.com/cmprescott/ansible-xml" rel="nofollow">xml module</a>:</p>
<pre><code>ok: [127.0.0.1] => {
"apps": {
... | -1 | 2016-06-15T12:57:10Z | 37,837,656 | <p>Register the variable in the task, then create a new task with a when clause.</p>
<pre><code> - Existing XML task
xml: (skipping)
register: myvar
- Check for filename
debug: var=item.application.location
with_items: myvar.apps.matches
</code></pre>
<p><strong>EDIT:</strong> From comments, since... | 3 | 2016-06-15T13:59:48Z | [
"python",
"xml",
"ansible",
"ansible-playbook"
] |
Ansible not getting the value from list of dicts | 37,836,134 | <p>I need to:
- echo using debug the valueof the 'location'
- check if the 'location' contains specific word (whole word is fine)</p>
<p>based on this output generated by the <a href="https://github.com/cmprescott/ansible-xml" rel="nofollow">xml module</a>:</p>
<pre><code>ok: [127.0.0.1] => {
"apps": {
... | -1 | 2016-06-15T12:57:10Z | 37,838,355 | <pre><code>- debug:
var: item.application
when: item.application.location == "foobar"
with_items: "{{ apps.matches }}"
</code></pre>
| 2 | 2016-06-15T14:30:37Z | [
"python",
"xml",
"ansible",
"ansible-playbook"
] |
Function which returns the least-squares solution to a linear matrix equation | 37,836,311 | <p>I must rewrite code from Python to Swift but I'm stuck on function which should return the least-squares solution to a linear matrix equation. Does anyone of you know a library written in Swift which has an equivalent method to the <strong><a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.lin... | 4 | 2016-06-15T13:04:46Z | 38,029,684 | <p>The Accelerate framework included the <a href="http://www.netlib.org/lapack/index.html" rel="nofollow">LAPACK</a> linear algebra package,
which has a <a href="http://www.netlib.org/lapack/explore-html/d7/d3b/group__double_g_esolve_ga1df516c81d3e902cca1fc79a7220b9cb.html#ga1df516c81d3e902cca1fc79a7220b9cb" rel="nofol... | 1 | 2016-06-25T14:48:01Z | [
"python",
"swift",
"numpy",
"math",
"matrix"
] |
Hide ffmpeg's console window when running YoutubeDL in GUI application | 37,836,315 | <p>I'm developing a basic application which can download YouTube videos. Throughout the development, I had several quirks, including issues with formats.</p>
<p>I decided to use a hopefully foolproof format syntax that youtube-dl will happily download for me in almost any case.</p>
<p>Part of my YoutubeDL options loo... | 3 | 2016-06-15T13:04:56Z | 38,000,371 | <p>The problem is not really related to the code. In fact, it's more a "windows problem". If I run the code on my computer (which is a linux one), there's no problem. There's only one console (that one I used to launch the script). </p>
<p>I think that if you rename the file with <code>.pyw</code>, it will work. Accor... | 1 | 2016-06-23T19:37:22Z | [
"python",
"ffmpeg",
"youtube-dl"
] |
Make an Optional expression throw an error if it was present but didn't match | 37,836,398 | <p>I'm using the PyParsing library to define my own SQL-like DSL. Here is the relevant part from it:</p>
<pre><code>argument_separator = pp.Suppress(",")
brace_open = pp.Suppress("(")
brace_close = pp.Suppress(")")
argument_string = pp.quotedString.setParseAction(pp.removeQuotes)
keyword_author = pp.CaselessKeyword(... | 1 | 2016-06-15T13:08:42Z | 37,837,454 | <p>Try setting <code>parseAll</code> to <code>True</code> when parsing each line, e.g. <code>expression.parseString(line, parseAll=True)</code>. This will throw a <code>ParseException</code> exception if the entire line wasn't matched.</p>
<p>See <a href="http://www.cnd.mcgill.ca/~ivan/hw2/hw1/doc/pyparsing/HowToUsePy... | 2 | 2016-06-15T13:51:09Z | [
"python",
"dsl",
"pyparsing"
] |
How to access the response object using elasticsearch DSL for python | 37,836,490 | <p>I have the following code:</p>
<pre><code>s = Search(using=Elasticsearch('http://user:passwd@ipaddress'), index="myindex")
q = Q("multi_match", query='some query', fields=['_all'])
s = s.query(q)
response = s.execute()
print('Total %d hits found.' % response.hits.total)
for hit in response:
print(hit.title)
</... | 0 | 2016-06-15T13:12:32Z | 37,837,157 | <p>Apparently the ".title" references an actual column in their example.
When I used <code>hit.doc.FIRSTTAG</code>, FIRSTTAG being a column in MY NoSQL-db it worked.
Still does not explain the missing method, but I am happy with it for now.</p>
<p>So to anyone having the same problem:</p>
<p>Use your own columns name... | 0 | 2016-06-15T13:39:34Z | [
"python",
"elasticsearch",
"elasticsearch-dsl"
] |
How to treat response OneVsRestClassifier in Scikit-learn for multilabel | 37,836,506 | <p>I'm newbie in Scikit-learn and classification. My task is a multi-label classification problem. AS I understand <code>predict</code> returns array with <code>n</code> tuples which is the same as amount of features in sample. What does it mean? How I can get strict order and strict amount of predicted values?
Becaus... | 0 | 2016-06-15T13:12:55Z | 37,838,807 | <p>Your result is positive or negative for your five classes, so, 'a' 'c' for test[0] and 'a' for the second one.
The purpose of multilabel classification is to label each data by 0-5 of your five classes.</p>
<p>If you want strictly two labels you can run two single label classifications, it could be sufficient.</p>
| 0 | 2016-06-15T14:49:59Z | [
"python",
"scikit-learn",
"classification",
"multilabel-classification"
] |
What is the RegEx pattern for 24-06-2015 10:15:45: Aditya Krishnakant:? | 37,836,550 | <p>What is the RegEx pattern for <code>24-06-2015 10:15:45: Aditya Krishnakant:</code></p>
<p>If you look at the whatsapp chat transcript, it looks like a mess. The purpose of this code is to print messages sent by a person in a new line (for better readability). This is my code</p>
<pre><code>import re
f = open("wa... | -5 | 2016-06-15T13:14:56Z | 37,837,616 | <p>For some reason you're putting <code>\:</code> where <code>-</code> should be. Also, instead of <code>\s</code> you can be more specific and just use a space. You can be more specific with those kinds of things because you know exactly what the format is. Your other big problem is that you're only using <code>\w</co... | 1 | 2016-06-15T13:58:10Z | [
"python",
"regex",
"typeerror"
] |
group by region and date using pandas | 37,836,563 | <p><a href="http://i.stack.imgur.com/AuF99.png" rel="nofollow"><img src="http://i.stack.imgur.com/AuF99.png" alt="temp.csv"></a></p>
<p>Hello,</p>
<p>I have a csv file , please check the image for the sample input csv and I need to get a dataframe that has the sum of the "Amazon Elastic compute cloud" services runn... | 0 | 2016-06-15T13:15:30Z | 37,836,957 | <p>Here's the docs on the <a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html" rel="nofollow">general aggregation framework for pandas</a> and the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow">pandas.groupby</a> function specifically</p>
<p>I... | -2 | 2016-06-15T13:31:22Z | [
"python",
"csv",
"pandas",
"dataframe",
"grouping"
] |
group by region and date using pandas | 37,836,563 | <p><a href="http://i.stack.imgur.com/AuF99.png" rel="nofollow"><img src="http://i.stack.imgur.com/AuF99.png" alt="temp.csv"></a></p>
<p>Hello,</p>
<p>I have a csv file , please check the image for the sample input csv and I need to get a dataframe that has the sum of the "Amazon Elastic compute cloud" services runn... | 0 | 2016-06-15T13:15:30Z | 37,837,086 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.aggregate.html" rel="nofollow"><code>aggregate</code></a> - size by <c... | 2 | 2016-06-15T13:36:27Z | [
"python",
"csv",
"pandas",
"dataframe",
"grouping"
] |
What Promoted Object should I use when creating an AdSet with lead_generation optimization goal? | 37,836,579 | <p>I'm using facebookads python api, v2.6.</p>
<p>I'm trying to create an AdSet with optimization goal = lead_generation.</p>
<p>This is my code:</p>
<pre><code>ad_set = AdSet(parent_id = 'act_%s' % FB_ACCOUNT)
ad_set[AdSet.Field.name]= 'Teste AdSet'
ad_set[AdSet.Field.campaign_id]='6043402838999'
ad_set[AdSet.Field... | 0 | 2016-06-15T13:16:21Z | 37,841,345 | <p>In case anyone has the same issue, you have to use <code>page_id</code>.</p>
| 0 | 2016-06-15T16:50:39Z | [
"python",
"facebook",
"facebook-ads-api",
"facebook-marketing-api"
] |
What Promoted Object should I use when creating an AdSet with lead_generation optimization goal? | 37,836,579 | <p>I'm using facebookads python api, v2.6.</p>
<p>I'm trying to create an AdSet with optimization goal = lead_generation.</p>
<p>This is my code:</p>
<pre><code>ad_set = AdSet(parent_id = 'act_%s' % FB_ACCOUNT)
ad_set[AdSet.Field.name]= 'Teste AdSet'
ad_set[AdSet.Field.campaign_id]='6043402838999'
ad_set[AdSet.Field... | 0 | 2016-06-15T13:16:21Z | 37,851,355 | <blockquote>
<p>The ad set must have its promoted_object set to the corresponding <code><PAGE_ID></code>.</p>
</blockquote>
<p>reference:
<a href="https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create#create" rel="nofollow">https://developers.facebook.com/docs/marketing-api/guides/lead-ads/... | 0 | 2016-06-16T06:23:10Z | [
"python",
"facebook",
"facebook-ads-api",
"facebook-marketing-api"
] |
Standard Python Auth0 project does not seem to authenticate | 37,836,673 | <p>I am trying to run a standard Python Auth0 project <a href="https://auth0.com/docs/server-apis/python" rel="nofollow">available here</a>
If you are logged in it comes with valid pre-generated keys in .env file and I checked them anyway, so question is similar to <a href="http://stackoverflow.com/questions/34426066/d... | 0 | 2016-06-15T13:19:36Z | 37,837,287 | <p>In the document you linked under the section <a href="https://auth0.com/docs/server-apis/python#4-call-your-api" rel="nofollow">Call Your API</a> the request is done with the header <code>Authorization</code> for example if you need to connect with curl use the following option:</p>
<pre><code>--header 'Authorizati... | 1 | 2016-06-15T13:44:54Z | [
"python",
"oauth",
"flask",
"oauth-2.0",
"auth0"
] |
Issues with Running Flask and SQLAlchemy app through Docker | 37,836,803 | <p>I have a web application written in python, sqlalchemy and flask.</p>
<p>The app along with static files, style sheets etc are stored in a folder called flask-app and the program is to be run from:</p>
<pre><code>python server.py
</code></pre>
<p>When i run this from the terminal, it works perfectly well. But it ... | 0 | 2016-06-15T13:24:45Z | 37,838,991 | <p>flask is being installed for python 2.7x </p>
<p>as @polku suggested, try making use of pip3 if you wish to use the python3 interpreter</p>
<p>you may try installing python3-pip and using pip3 to install flask and SQLAlchemy </p>
<pre><code>FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python3-... | 0 | 2016-06-15T14:57:26Z | [
"python",
"docker",
"flask",
"sqlalchemy"
] |
Rename pivoted and aggregated column in PySpark Dataframe | 37,836,877 | <p>With a dataframe as follows:</p>
<pre><code>from pyspark.sql.functions import avg, first
rdd = sc.parallelize(
[
(0, "A", 223,"201603", "PORT"),
(0, "A", 22,"201602", "PORT"),
(0, "A", 422,"201601", "DOCK"),
(1,"B", 3213,"201602", "DOCK"),
(1,"B", 3213,"201601", "POR... | 3 | 2016-06-15T13:28:07Z | 37,842,998 | <p>A simple regular expression should do the trick:</p>
<pre><code>import re
def clean_names(df):
p = re.compile("^(\w+?)_([a-z]+)\((\w+)\)(?:\(\))?")
return df.toDF(*[p.sub(r"\1_\3", c) for c in df.columns])
pivoted = df_data.groupby(...).pivot(...).agg(...)
clean_names(pivoted).printSchema()
## root
## |... | 2 | 2016-06-15T18:21:38Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql"
] |
Django 1.9 Bulk Create New Users Not hashing Passswords Correctly | 37,836,882 | <p>I want to read in some data from a file to quickly create many test accounts. I'd prefer to use the bulk_create method since this is typically much faster for adding many records to a model. However, when using the bulk_create method with Django's User model the passwords aren't being hashed correctly meaning I'm th... | 1 | 2016-06-15T13:28:16Z | 37,837,187 | <p>Use <a href="https://docs.djangoproject.com/en/1.9/topics/auth/passwords/#django.contrib.auth.hashers.make_password" rel="nofollow"><code>make_password</code></a>. This ensures that hashed passwords are stored in your database. If <code>make_password</code> is too slow, <a href="http://stackoverflow.com/a/18273177/6... | 2 | 2016-06-15T13:40:48Z | [
"python",
"django"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.