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
listlengths
1
5
append system path in Go language
38,387,813
<p>I have python code as</p> <pre><code>import sys sys.path.append("/usr/local/py") </code></pre> <p>How can I convert this code in go language? how to append the path to system path?</p>
-1
2016-07-15T04:20:47Z
38,387,998
<p>Go creates statically linked binaries when you compile. The closest equivalent would be setting your GOPATH environment variable to search that directory as well. Typically, when you set up your environment you export that variable so go knows where to look for packages. You can append as many directories to that...
1
2016-07-15T04:45:13Z
[ "python", "go" ]
NetworkX tutorial gives key error over value selection
38,387,906
<p>I'm working through a networkX tutorial, and page nine is this:</p> <pre><code>&gt;&gt;&gt; g = nx . Graph () &gt;&gt;&gt; g . add_node (1 , name = ‘ Obrian ’) &gt;&gt;&gt; g . add_nodes_from ([2] , name = ‘ Quintana ’ ]) &gt;&gt;&gt; g [1][ ‘ name ’] ‘ Obrian ’ </code></pre> <p>Which I reconstruct...
1
2016-07-15T04:33:12Z
38,387,953
<p>You need to access the node property of the graph explicitly. That is, replace <code>g[1]['name']</code> with <code>g.node[1]['name']</code></p> <p>You may be working from an out-of-date tutorial.</p>
4
2016-07-15T04:39:23Z
[ "python", "python-2.7", "graph", "nodes", "networkx" ]
What do I modify in the code in order for it to work in Python 2.7?
38,387,928
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>credit_num = input("Enter the credit card number: ").replace(" ", "") tot1 = 0 tot2 = 0 for i in credit_num[-1::-2]: ...
0
2016-07-15T04:36:07Z
38,387,945
<p>Replace <code>input()</code> with <code>raw_input()</code> and change the print function calls to print statements or you can import <code>print_function</code> from <code>__future__</code> as @BrenBarn suggests, e.g.:</p> <pre><code>from __future__ import division, print_function credit_num = raw_input("Enter the...
2
2016-07-15T04:38:17Z
[ "python", "python-2.7", "python-3.5" ]
What do I modify in the code in order for it to work in Python 2.7?
38,387,928
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>credit_num = input("Enter the credit card number: ").replace(" ", "") tot1 = 0 tot2 = 0 for i in credit_num[-1::-2]: ...
0
2016-07-15T04:36:07Z
38,388,004
<p>If you want the same script to work in both Python 2.x and Python 3.x, I suggest using the "six" module and the following code. (Note that the first two added lines are the only change I've made.)</p> <pre><code>from __future__ import print_function from six.moves import input credit_num = input("Enter the credit ...
1
2016-07-15T04:45:37Z
[ "python", "python-2.7", "python-3.5" ]
Input/Output items of the 'work' function in GNU Radio
38,388,041
<p>Is there a way to print (in the terminal or to a file) the input items passed to the work function and the output items produced there? I have written a GNU radio block (in Python) and I need to access the above information.</p> <p>Any help is appreciated! :) </p>
-1
2016-07-15T04:49:38Z
38,678,023
<p>Assuming you're using a <code>sync_block</code> as block type, your work function will look like this:</p> <pre><code>def work(self, input_items, output_items): </code></pre> <p>where <code>input_items</code> is a 2D-array. First axis is the input ports (you might have only one) and second axis is the input items....
0
2016-07-30T20:05:35Z
[ "python", "gnuradio" ]
what does on_delete does on Django models?
38,388,423
<p>I'm quite familiar with Django, but recently noticed there exists a <code>on_delete=models.CASCADE</code> option with the models, I have searched for the documentation for the same but couldn't find anything more than,</p> <blockquote> <p><strong>Changed in Django 1.9:</strong></p> <p><code>on_delete</code> ...
3
2016-07-15T05:26:57Z
38,389,376
<p>The <code>on_delete</code> method is used to tell Django what to do with model instances that depend on the model instance you delete. (e.g. a <code>ForeignKey</code> relationship). The <code>on_delete=models.CASCADE</code> tells Django to cascade the deleting effect i.e. continue deleting the dependent models as we...
2
2016-07-15T06:37:58Z
[ "python", "django", "django-models" ]
what does on_delete does on Django models?
38,388,423
<p>I'm quite familiar with Django, but recently noticed there exists a <code>on_delete=models.CASCADE</code> option with the models, I have searched for the documentation for the same but couldn't find anything more than,</p> <blockquote> <p><strong>Changed in Django 1.9:</strong></p> <p><code>on_delete</code> ...
3
2016-07-15T05:26:57Z
38,389,488
<p>This is the behaviour to adopt when the referenced object is deleted. It is not specific to django, this is an SQL standard.</p> <p>There are 6 possible actions to take when such event occurs:</p> <ul> <li><code>CASCADE</code>: When the referenced object is deleted, also delete the objects that have references to ...
8
2016-07-15T06:44:00Z
[ "python", "django", "django-models" ]
Print or return the request arguments/form data
38,388,556
<p>I am using wsgi-request-logger <a href="https://github.com/pklaus/wsgi-request-logger" rel="nofollow">https://github.com/pklaus/wsgi-request-logger</a> in a flask application and need it to also log the request parameters (ie. the arguments that would be sent with the request).</p> <p>Using request.form or request....
0
2016-07-15T05:40:03Z
38,389,023
<p>You should post more code of your application, otherwise it's very difficult to help.</p> <p>You can't use Flask's <code>request</code> object in the WSGI layer. The <code>wsgi-request-logger</code> runs before Flask, that's why there is no request context yet.</p> <p>You other code was probably run in a module an...
0
2016-07-15T06:14:52Z
[ "python", "python-2.7", "logging", "flask", "werkzeug" ]
If else statement using URL
38,388,649
<p>HI I would like to ask for help on how to use URL in if statement</p> <p>where</p> <pre><code>IF URL = detailsUrl disable a div ELSE show div </code></pre> <p>for example this is my urls.py</p> <pre><code> url(r'^(?P&lt;question_id&gt;[0-9]+)/$', views.detail, name='detail') </code></pre> <p>I would like to kn...
-2
2016-07-15T05:46:43Z
38,388,794
<p>You can use <code>request.path</code> in templates to control which divs are rendered:</p> <pre><code>{% url 'detail' 1 as details %} {% if request.path == details %} &lt;div&gt;Details&lt;/div&gt; {% else %} &lt;div&gt;Else&lt;/div&gt; {% endif %} </code></pre> <p>Mind that you need to have <code>django.c...
2
2016-07-15T05:57:02Z
[ "python", "django" ]
how to import pandas in ipython notebook on ubuntu
38,388,677
<p>I am trying to import pandas in ipython notebook but that time getting below error:</p> <p>In [2]: import pandas as pd</p> <hr> <p>ImportError Traceback (most recent call last) in () ----> 1 import pandas as pd</p> <p>ImportError: No module named 'pandas'</p>
-1
2016-07-15T05:48:40Z
38,388,896
<p>Okay this is most definitely an error which appears when you don't have a particular module installed in your Ipython Environment. In your case, it is the 'pandas' module you are trying to import:</p> <pre><code>import pandas as pd </code></pre> <p>This won't work before you have your pandas module installed in yo...
1
2016-07-15T06:04:50Z
[ "python", "pandas", "ipython" ]
I want to send an Integer array from Raspberry Pi to Arduino and display the recived integers in the Arduino Serial monitor
38,388,740
<p>I have two integer arrays created using Python language in the Raspberry Pi. I want to send those two integer arrays to a arduino board. I want to display the received integers in the Serial monitor of the Arduino.</p> <p>Please some one give me the source codes that needed to run in Raspberry Pi (Python program c...
0
2016-07-15T05:53:27Z
38,389,207
<p>I think it's going to depend on what the technology you have available to you.</p> <p>We need to consider how you want to move the bytes between the two. How do you package (serialize) the data before you move it over the network? </p> <p>What kind of communication link do you have? You could use <a href="https://...
-1
2016-07-15T06:26:28Z
[ "python", "arduino", "raspberry-pi" ]
How to change a space when a button is pressed with kivy?
38,388,782
<p>I am trying create a GUI by implementing the template of the <a href="https://www.packtpub.com/packtlib/book/Application-Development/9781785286926/1/ch01lvl1sec13/Our%20project%20%20Comic%20Creator" rel="nofollow">ComicCreator GUI</a> sample as a template for my own project. The <a href="https://www.packtpub.com/pac...
1
2016-07-15T05:55:43Z
38,391,384
<p>The layout frame should be <a href="https://kivy.org/docs/api-kivy.uix.screenmanager.html" rel="nofollow">a screen manager</a>, and each layout <a href="https://kivy.org/docs/api-kivy.uix.screenmanager.html#kivy.uix.screenmanager.Screen" rel="nofollow">a screen</a>. Screen transitions would be then triggered by pres...
0
2016-07-15T08:27:43Z
[ "python", "raspberry-pi", "kivy", "kivy-language" ]
How to change a space when a button is pressed with kivy?
38,388,782
<p>I am trying create a GUI by implementing the template of the <a href="https://www.packtpub.com/packtlib/book/Application-Development/9781785286926/1/ch01lvl1sec13/Our%20project%20%20Comic%20Creator" rel="nofollow">ComicCreator GUI</a> sample as a template for my own project. The <a href="https://www.packtpub.com/pac...
1
2016-07-15T05:55:43Z
38,460,480
<p>A neat way to do this is to use screen.</p> <p>Since I allready have an example of this app from you earlier question, it was easy to implement the screens, and rewrite the classes a bit.</p> <p>When a button is pressed, you set the screenmanager's current to whatever the name you named the screen you want.</p> <...
2
2016-07-19T13:47:52Z
[ "python", "raspberry-pi", "kivy", "kivy-language" ]
Sort A list of Strings Based on certain field
38,388,799
<p>Overview: I have data something like this (each row is a string): </p> <blockquote> <p>81:0A:D7:19:25:7B, <strong>2016-07-14 14:29:13</strong>, 2016-07-14 14:29:15, -69, 22:22:22:22:22:23,null,^M 3B:3F:B9:0A:83:E6, <strong>2016-07-14 01:28:59</strong>, 2016-07-14 01:29:01, -36, 33:33:33:33:33:31,null,^M B3:C0...
4
2016-07-15T05:57:44Z
38,389,035
<p>You can use the list method <code>list.sort</code> which sorts in-place or use the <code>sorted()</code> built-in function which returns a new list. the <code>key</code> argument takes a function which it applies to each element of the sequence before sorting. You can use a combination of <code>string.split(',')</co...
8
2016-07-15T06:15:18Z
[ "python", "list", "python-2.7", "sorting" ]
Sort A list of Strings Based on certain field
38,388,799
<p>Overview: I have data something like this (each row is a string): </p> <blockquote> <p>81:0A:D7:19:25:7B, <strong>2016-07-14 14:29:13</strong>, 2016-07-14 14:29:15, -69, 22:22:22:22:22:23,null,^M 3B:3F:B9:0A:83:E6, <strong>2016-07-14 01:28:59</strong>, 2016-07-14 01:29:01, -36, 33:33:33:33:33:31,null,^M B3:C0...
4
2016-07-15T05:57:44Z
38,389,049
<p>If the format of the line in itself shall not be changed, maybe (I do not know the wider context of the solution) a simple shell transformation is fitting well (I know it is not a python solution).</p> <p>So:</p> <pre><code>$ sort -t, -k2,2 sort_me_on_first_timestamp_field.txt 3B:3F:B9:0A:83:E6, 2016-07-14 01:28:...
2
2016-07-15T06:16:23Z
[ "python", "list", "python-2.7", "sorting" ]
Sort A list of Strings Based on certain field
38,388,799
<p>Overview: I have data something like this (each row is a string): </p> <blockquote> <p>81:0A:D7:19:25:7B, <strong>2016-07-14 14:29:13</strong>, 2016-07-14 14:29:15, -69, 22:22:22:22:22:23,null,^M 3B:3F:B9:0A:83:E6, <strong>2016-07-14 01:28:59</strong>, 2016-07-14 01:29:01, -36, 33:33:33:33:33:31,null,^M B3:C0...
4
2016-07-15T05:57:44Z
38,389,853
<p>you can use <code>string.split()</code>,string.split(',')[1]</p>
1
2016-07-15T07:05:48Z
[ "python", "list", "python-2.7", "sorting" ]
Using cython to cross compile project from intel ubuntu to arm
38,388,812
<p>I have simple python + cython project (hello world example from <a href="http://docs.cython.org/src/tutorial/cython_tutorial.html" rel="nofollow">http://docs.cython.org/src/tutorial/cython_tutorial.html</a>) on my ubuntu 16 x86_64. I can build this project with cython for x86_64.</p> <p>How can I build the project ...
0
2016-07-15T05:58:27Z
38,405,683
<p>Architecture dependent libraries and headers files are needed for cross compiling. </p> <p>When testing if python3.5-dev package and others could be installed after <code>dpkg --add-architecture armhf</code> and <code>apt-get update</code> (after some modification to sources.list), the result was basically.</p> <p...
1
2016-07-15T22:11:52Z
[ "python", "gcc", "cross-compiling", "cython" ]
How can I list out all current clusters when using a single linkage algorithm?
38,388,874
<p>I'm now doing clustering on python using <code>from scipy.cluster.hierarchy import linkage</code> From the manual I know that it gives result in this form --> [A, B, length, #] which A and B is the indices of elements that are going to merge in this...stage(?), but can I get any information about clusters which is a...
0
2016-07-15T06:03:02Z
38,389,531
<p>As described in <a href="http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.cluster.hierarchy.linkage.html#scipy.cluster.hierarchy.linkage" rel="nofollow">the documentation</a>, <code>linkage</code> gives you the distance between clusters, which is the same as the cophenetic distance between elements i...
1
2016-07-15T06:46:33Z
[ "python", "algorithm", "hierarchical-clustering", "linkage" ]
Ask about an error in matplotlib streamplot "The rows of 'x' must be equal"
38,389,001
<p>I'm trying to plot (B_x,B_z) field line an the code is written below. The function I used is 'streamplot(x,z,Bx,Bz)'. After the running, 'x','z','Bx',and 'Bz' have a type as a float64 and the size were (30L,30L), equal.</p> <p>However, orange canvas plot of the range (0,1) and "ValueError: The rows of 'x' must be e...
0
2016-07-15T06:13:08Z
38,389,199
<p><code>streamplot</code> needs <code>x</code> and <code>z</code> to be vectors. Try:</p> <pre><code>x = np.linspace(-90000000,9000000, 30) z = np.linspace(-90000000,9000000, 30) ax.streamplot(x,z,Bx,Bz) </code></pre>
0
2016-07-15T06:26:14Z
[ "python", "matplotlib" ]
Working with load more request with scrapy python
38,389,038
<p>I am trying to scrape a site using scrapy, My spider is as follows:</p> <pre><code>class AngelSpider(Spider): name = "angel" allowed_domains = ["angel.co"] start_urls = ( "https://angel.co/companies?locations[]=India", ) def start_requests(self): page_size = 25 head...
1
2016-07-15T06:15:28Z
38,393,736
<p>The website you're trying to scrap uses javascript, you either have to use <a href="http://selenium-python.readthedocs.io/" rel="nofollow">Selenium</a> or <a href="https://github.com/scrapy-plugins/scrapy-splash" rel="nofollow">Scrapy-splash</a> to emulate the browser.</p>
-1
2016-07-15T10:24:01Z
[ "python", "web-scraping", "scrapy", "scrapy-spider" ]
Working with load more request with scrapy python
38,389,038
<p>I am trying to scrape a site using scrapy, My spider is as follows:</p> <pre><code>class AngelSpider(Spider): name = "angel" allowed_domains = ["angel.co"] start_urls = ( "https://angel.co/companies?locations[]=India", ) def start_requests(self): page_size = 25 head...
1
2016-07-15T06:15:28Z
38,404,416
<p>From what I've seen, the website first does a POST request to <a href="https://angel.co/company_filters/search_data" rel="nofollow">https://angel.co/company_filters/search_data</a>, which returns JSON data containing the startup ids, like this:</p> <pre><code>{ "ids": [ 146538,277273,562440,67592,124939...
0
2016-07-15T20:15:08Z
[ "python", "web-scraping", "scrapy", "scrapy-spider" ]
Python - Randomly flipping 2 characters in a word other than the first and last one
38,389,172
<p>This code flips all characters in the word besides the first and last character. How do I make it so that it only randomly flips two characters besides the first and last character?</p> <p>For example:</p> <pre><code>computers cmoputers comupters compuetrs </code></pre> <p>Code:</p> <pre><code>def scramble(word)...
-1
2016-07-15T06:24:38Z
38,389,434
<p>Try to see if this code works for you:</p> <pre><code>import numpy as np def switchtwo(word): ind1 = np.random.randint(1, len(word)-1) ind2 = np.random.randint(1, len(word)-1) l = list(word) l[ind1], l[ind2] = l[ind2], l[ind1] return "".join(l) </code></pre> <p>Note that here is is possible th...
1
2016-07-15T06:40:53Z
[ "python", "python-2.7" ]
Python - Randomly flipping 2 characters in a word other than the first and last one
38,389,172
<p>This code flips all characters in the word besides the first and last character. How do I make it so that it only randomly flips two characters besides the first and last character?</p> <p>For example:</p> <pre><code>computers cmoputers comupters compuetrs </code></pre> <p>Code:</p> <pre><code>def scramble(word)...
-1
2016-07-15T06:24:38Z
38,389,685
<p>The following works using only the standard library. Also, it always chooses 2 distinct characters from inside the string. </p> <pre><code>import random def scramble2(word): indx = random.sample(range(1,len(word)-1), 2) string_list = list(word) for i in indx: string_list[i], string_list[-i+len(w...
0
2016-07-15T06:55:07Z
[ "python", "python-2.7" ]
Python - Randomly flipping 2 characters in a word other than the first and last one
38,389,172
<p>This code flips all characters in the word besides the first and last character. How do I make it so that it only randomly flips two characters besides the first and last character?</p> <p>For example:</p> <pre><code>computers cmoputers comupters compuetrs </code></pre> <p>Code:</p> <pre><code>def scramble(word)...
-1
2016-07-15T06:24:38Z
38,389,784
<p>This should work at flipping two letters. If the length of the word is less than or equal to 3, then it cannot be flipped. In that case it just returns the word back.</p> <pre><code>from random import randint def scramble(word): if len(word) &lt;= 3: return word word = list(word) i = randint(1,...
1
2016-07-15T07:01:38Z
[ "python", "python-2.7" ]
In TACTIC,while using server.execute_cmd() method, how do we return data to the frontend?
38,389,378
<p>I am actually working on a TACTIC project which uses AngularJS on the frontend and Python scripts on the backend. Here when the python script is executed using <code>server.execute_cmd(cls_name,args)</code> from the Javascript code, the python script is run, BUT isn't able to return a value back to the front-end!</...
0
2016-07-15T06:37:59Z
38,441,606
<p>To return any o/p back to the calling function, you need to populate and return <strong>self.info</strong></p> <pre><code>self.info["your_key_here"] = [your_answer] </code></pre> <p>In this way, the front-end or the calling command will receive the desired return value. I hope this answers helps others who have ha...
0
2016-07-18T16:19:33Z
[ "python", "tactic" ]
What is the operator precedence of "=" in Python?
38,389,391
<p><a href="https://docs.python.org/3/reference/expressions.html" rel="nofollow">Python's documentation</a> doesn't mention the operator precedence of <code>=</code>. So what is it?</p>
-1
2016-07-15T06:38:45Z
38,389,405
<p><code>=</code> is not an operator. <code>=</code> is an <a href="https://docs.python.org/3/reference/simple_stmts.html#assignment-statements" rel="nofollow">assignment <strong>statement</strong></a>.</p> <p>Because it is a statement, it can't be part of an expression (expressions are instead part of certain stateme...
9
2016-07-15T06:39:35Z
[ "python", "operators", "variable-assignment", "assignment-operator", "operator-precedence" ]
How to force a flask-restful app to interpret the post body as json regardsless of the request's mime-type
38,389,498
<p>I have a python <code>flask-restful</code> app which receives json in the post body. Here the two minimal files <code>app.py</code> and <code>info.py</code>:</p> <p><strong>The application module <code>app.py</code>:</strong></p> <pre><code>from flask import Flask from flask_restful import Resource, Api, reqparse...
0
2016-07-15T06:44:39Z
38,389,999
<p>According to <a href="http://flask-restful-cn.readthedocs.io/en/0.3.4/api.html#reqparse.Argument" rel="nofollow">the flask-restful docs</a>, the <code>location</code> keyword argument of <code>add_argument</code> indicates a property of <code>flask.Request</code> from which to pull the argument.</p> <p>According to...
1
2016-07-15T07:13:41Z
[ "python", "json", "rest", "flask" ]
How to split pandas series into key value?
38,389,522
<p>I want to split pandas series into the key and value pair. My program is converting it into the key and value pairs but I want this key and value in well format.</p> <p>Input text file contains following data :</p> <p><strong>Input.txt-</strong></p> <pre><code>3=123|4=88|5=M|8=75|9=29 3=38|4=13|5=I|8=17.3|9=10|10...
0
2016-07-15T06:46:09Z
38,395,419
<p>I can answer half of your question. To get rid of the brackets and the index, you need to slightly adjust your code such as: </p> <pre><code>i = 0 while i &lt; len(dfs): #index of each column print ('\nindex[%d]'%i) for (_,k),v in dfs[i].iteritems(): print (k,' : ',v) i = i + 1 </code></...
0
2016-07-15T11:50:34Z
[ "python", "dataframe", "key", "value" ]
setting default value as combination of two different fields in django
38,390,026
<p>I am learning Django and took one project for myself to learn, an Expense Manager .... Here's my code below:</p> <pre><code>from __future__ import unicode_literals from django.core.validators import RegexValidator from django.db import models # Create your models here. class Person(models.Model): first_name=...
1
2016-07-15T07:15:18Z
38,390,056
<p>Make <code>info</code> a property or method</p> <pre><code>@property def info(self): return "{} from {}".format(self.borrower_name, self.lender_name) </code></pre> <p>You won't be able to use it in any query's but from the way you've shown it, I don't think you'll ever need to anyway.</p>
1
2016-07-15T07:16:45Z
[ "python", "django" ]
Python Netflix Query
38,390,095
<p>I am trying to get the name of TV Show (Episode/Season)/Movie from the Netflix URL. Is there a way of doing it using <code>requests</code> and <code>urllib</code>? I guess I'll need the API key and secret for that. </p> <p>This is what I'm trying to do. </p> <p>e.g. I have this URL for Z Nation. </p> <pre><cod...
-1
2016-07-15T07:18:51Z
38,390,641
<p>Sadly, Netflix has discontinued the use of its public API and is not accepting any new developers. </p> <p>You can look into <a href="http://netflixroulette.net/api/" rel="nofollow">Netflix Roulette API</a>, which is an unofficial API and lets you run queries on Netflix. You can use that API in conjunction with <co...
1
2016-07-15T07:47:35Z
[ "python", "python-2.7", "urllib", "netflix" ]
Sampling one record per unique value (pandas, python)
38,390,242
<p>I work with python-pandas dataframes, and I have a large dataframe containing users and their data. Each user can have multiple rows. I want to sample 1-row per user. My current solution seems not efficient:</p> <pre><code>df1 = pd.DataFrame({'User': ['user1', 'user1', 'user2', 'user3', 'user2', 'user3'], ...
2
2016-07-15T07:26:10Z
38,390,332
<p>This is what you want:</p> <pre><code>df1.groupby('User').apply(lambda df: df.sample(1)) </code></pre> <p><a href="http://i.stack.imgur.com/C1B60.png" rel="nofollow"><img src="http://i.stack.imgur.com/C1B60.png" alt="enter image description here"></a></p> <p>Without the extra index:</p> <pre><code>df1.groupby('U...
4
2016-07-15T07:30:29Z
[ "python", "pandas", "dataframe", "unique", "sampling" ]
Sampling one record per unique value (pandas, python)
38,390,242
<p>I work with python-pandas dataframes, and I have a large dataframe containing users and their data. Each user can have multiple rows. I want to sample 1-row per user. My current solution seems not efficient:</p> <pre><code>df1 = pd.DataFrame({'User': ['user1', 'user1', 'user2', 'user3', 'user2', 'user3'], ...
2
2016-07-15T07:26:10Z
38,390,371
<pre><code>df1_user_sample_one = df1.groupby('User').apply(lambda x:x.sample(1)) </code></pre> <p>Using DataFrame.groupby.apply and lambda function to sample 1 </p>
0
2016-07-15T07:32:49Z
[ "python", "pandas", "dataframe", "unique", "sampling" ]
Sampling one record per unique value (pandas, python)
38,390,242
<p>I work with python-pandas dataframes, and I have a large dataframe containing users and their data. Each user can have multiple rows. I want to sample 1-row per user. My current solution seems not efficient:</p> <pre><code>df1 = pd.DataFrame({'User': ['user1', 'user1', 'user2', 'user3', 'user2', 'user3'], ...
2
2016-07-15T07:26:10Z
38,390,675
<p>Based on number of rows per user this might be faster:</p> <pre><code>df.sample(frac=1).drop_duplicates(['User']) </code></pre>
3
2016-07-15T07:50:01Z
[ "python", "pandas", "dataframe", "unique", "sampling" ]
Python - LibreOffice Calc - Find & Replace with Regular Expression
38,390,502
<p>I try to code a Find &amp; Replace method with Python in LibreOffice's Calc to replace all the ".+" with "&amp;" (in a single column - not so important) - unfortunately, even a standard Find &amp; Replace method seems to be impossible (to me). That's what I have up to now:</p> <pre><code>import uno def search() ...
1
2016-07-15T07:40:18Z
38,401,787
<p>This code changes all non-empty cells in column A to <code>&amp;</code>:</p> <pre><code>def calc_search_and_replace(): desktop = XSCRIPTCONTEXT.getDesktop() model = desktop.getCurrentComponent() sheet = model.Sheets.getByIndex(0) COLUMN_A = 0 cellRange = sheet.getCellRangeByPosition(COLUMN_A, 0,...
0
2016-07-15T17:15:40Z
[ "python", "libreoffice", "calc", "uno" ]
Find intersection of dictionary values which are lists
38,390,596
<p>I have dictionaries in a list with same keys, while the values are variant:</p> <pre><code>[{1:[1,2,3,4,5], 2:[6,7,8], 3:[1,3,5,7,9]}, {1:[2,3,4], 2:[6,7], 3:[1,3,5]}, ...] </code></pre> <p>I would like to get intersection as dictionary under same keys like this:</p> <pre><code>{1:[2,3,4], 2:[6,7], 3:[1,3,5]} <...
-1
2016-07-15T07:45:20Z
38,390,785
<p>Give this a try?</p> <pre><code>dicts = [{1:[1,2,3,4,5], 2:[6,7,8], 3:[1,3,5,7,9]},{1:[2,3,4], 2:[6,7], 3:[1,3,5]}] result = { k: set(dicts[0][k]).intersection(*(d[k] for d in dicts[1:])) for k in dicts[0].keys() } print(result) # Output: # {1: {2, 3, 4}, 2: {6, 7}, 3: {1, 3, 5}} </code></pre> <p>If you want li...
0
2016-07-15T07:55:18Z
[ "python" ]
Find intersection of dictionary values which are lists
38,390,596
<p>I have dictionaries in a list with same keys, while the values are variant:</p> <pre><code>[{1:[1,2,3,4,5], 2:[6,7,8], 3:[1,3,5,7,9]}, {1:[2,3,4], 2:[6,7], 3:[1,3,5]}, ...] </code></pre> <p>I would like to get intersection as dictionary under same keys like this:</p> <pre><code>{1:[2,3,4], 2:[6,7], 3:[1,3,5]} <...
-1
2016-07-15T07:45:20Z
38,390,798
<p>For a list of dictionaries, reduce the whole list as this:</p> <pre><code>&gt;&gt;&gt; from functools import reduce &gt;&gt;&gt; d = [{1:[1,2,3,4,5], 2:[6,7,8], 3:[1,3,5,7,9]},{1:[2,3,4], 2:[6,7], 3:[1,3,5]}] &gt;&gt;&gt; reduce(lambda x, y: {k: sorted(list(set(x[k])&amp;set(y[k]))) for k in x.keys()}, d) {1: [2, 3...
0
2016-07-15T07:55:53Z
[ "python" ]
Find intersection of dictionary values which are lists
38,390,596
<p>I have dictionaries in a list with same keys, while the values are variant:</p> <pre><code>[{1:[1,2,3,4,5], 2:[6,7,8], 3:[1,3,5,7,9]}, {1:[2,3,4], 2:[6,7], 3:[1,3,5]}, ...] </code></pre> <p>I would like to get intersection as dictionary under same keys like this:</p> <pre><code>{1:[2,3,4], 2:[6,7], 3:[1,3,5]} <...
-1
2016-07-15T07:45:20Z
38,390,980
<p>I would probably do something along these lines:</p> <pre><code># Take the first dict and convert the values to `set`. output = {k: set(v) for k, v in dictionaries[0].items()} # For the rest of the dicts, update the set at a given key by intersecting it with each of the other lists that have the same key. for d in...
0
2016-07-15T08:05:20Z
[ "python" ]
Find intersection of dictionary values which are lists
38,390,596
<p>I have dictionaries in a list with same keys, while the values are variant:</p> <pre><code>[{1:[1,2,3,4,5], 2:[6,7,8], 3:[1,3,5,7,9]}, {1:[2,3,4], 2:[6,7], 3:[1,3,5]}, ...] </code></pre> <p>I would like to get intersection as dictionary under same keys like this:</p> <pre><code>{1:[2,3,4], 2:[6,7], 3:[1,3,5]} <...
-1
2016-07-15T07:45:20Z
38,391,140
<p>use <a href="http://stackoverflow.com/questions/18554012/intersecting-two-dictionaries-in-python"><code>dict.viewkeys</code></a> and <code>dict.viewitems</code></p> <pre><code>In [103]: dict.viewkeys? Docstring: D.viewkeys() -&gt; a set-like object providing a view on D's keys dict.viewitems? Docstring: D.viewitem...
0
2016-07-15T08:13:43Z
[ "python" ]
InvalidTemplateLibraryError on initial runserver using wagtail
38,390,600
<p>Everytime i do <code>python manage.py runserver</code> an error said </p> <blockquote> <p>Invalid template library specified. </p> <p>ImportError raised when trying to load 'wagtail.wagtailcore.templatetags.wagtailcore_tags': cannot import name _htmlparser </p> </blockquote>
0
2016-07-15T07:45:33Z
38,392,288
<p>There is some bug with new version of html5lib. I found two solutions for this problem:</p> <ol> <li>Downgrade html5lib (I tried with version 0.9999999)</li> </ol> <blockquote> <p>pip uninstall html5lib<br> pip install html5lib==0.9999999</p> </blockquote> <p>After downgrade everything seems to work perfectly...
3
2016-07-15T09:14:12Z
[ "python", "django" ]
InvalidTemplateLibraryError on initial runserver using wagtail
38,390,600
<p>Everytime i do <code>python manage.py runserver</code> an error said </p> <blockquote> <p>Invalid template library specified. </p> <p>ImportError raised when trying to load 'wagtail.wagtailcore.templatetags.wagtailcore_tags': cannot import name _htmlparser </p> </blockquote>
0
2016-07-15T07:45:33Z
38,394,490
<p>You can too add it to your requirements project file, i.e.:</p> <pre><code>wagtail==1.3.1 html5lib==0.9999999 </code></pre>
0
2016-07-15T11:00:15Z
[ "python", "django" ]
How to pick numbers from a string until the first non-number character appears?
38,390,640
<p>I have a collection of strings like: </p> <pre><code>"0" "90/100" None "1-5%/34B-1" "-13/7" </code></pre> <p>I would like to convert these into integers (or <code>None</code>) so that I start picking numbers from the beginning and stop at the first non-number character. The above data would thus become:</p> <pre>...
0
2016-07-15T07:47:16Z
38,390,824
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; s = ["0", "90/100", None, "1-5%/34B-1", "-13/7"] &gt;&gt;&gt; [int(c) if c else None for c in (re.sub('([0-9]*).*', r'\1', str(x)) for x in s)] [0, 90, None, 1, None] </code></pre> <h3>How it works</h3> <p>We have two list comprehensions. The inner removes everything f...
0
2016-07-15T07:57:18Z
[ "python", "python-3.x" ]
How to pick numbers from a string until the first non-number character appears?
38,390,640
<p>I have a collection of strings like: </p> <pre><code>"0" "90/100" None "1-5%/34B-1" "-13/7" </code></pre> <p>I would like to convert these into integers (or <code>None</code>) so that I start picking numbers from the beginning and stop at the first non-number character. The above data would thus become:</p> <pre>...
0
2016-07-15T07:47:16Z
38,390,963
<p>a basic way to do this, would be:</p> <pre><code>input_list = ["0", "90/100", None, "1-5%/34B-1", "-13/7"] char_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] output_list = [] for input_str in input_list: if isinstance(input_str, str): i = 0 for input_char in input_str: ...
0
2016-07-15T08:04:15Z
[ "python", "python-3.x" ]
How to pick numbers from a string until the first non-number character appears?
38,390,640
<p>I have a collection of strings like: </p> <pre><code>"0" "90/100" None "1-5%/34B-1" "-13/7" </code></pre> <p>I would like to convert these into integers (or <code>None</code>) so that I start picking numbers from the beginning and stop at the first non-number character. The above data would thus become:</p> <pre>...
0
2016-07-15T07:47:16Z
38,391,352
<p>Is this the sort of thing you're looking for ?</p> <pre><code>import re data = ['0', '90/100', None, '1-5%/34B-1', '-13/7'] def pick_right_numbers(old_n): if old_n is None: return None else: digits = re.match("([0-9]*)",old_n).groups()[0] if digits.isdigit(): return int(...
0
2016-07-15T08:26:15Z
[ "python", "python-3.x" ]
How to pick numbers from a string until the first non-number character appears?
38,390,640
<p>I have a collection of strings like: </p> <pre><code>"0" "90/100" None "1-5%/34B-1" "-13/7" </code></pre> <p>I would like to convert these into integers (or <code>None</code>) so that I start picking numbers from the beginning and stop at the first non-number character. The above data would thus become:</p> <pre>...
0
2016-07-15T07:47:16Z
38,391,696
<p>There are various methods to check if an object is a number. See for instance <a href="http://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-number-float-in-python">this answer</a>. </p> <p>However you only need to check one char at a time, so your method is actually fine. The array will be perm...
0
2016-07-15T08:44:03Z
[ "python", "python-3.x" ]
Scrapy is not able to find my spiders in the current project
38,390,715
<p>I currently have a scrapy project with the following structure:</p> <pre><code>. ├── articlescraper │   ├── __init__.py │   ├── __init__.pyc │   ├── items.py │   ├── items.pyc │   ├── pipelines.py │   ├── pipelines.pyc │   ├── scheduler.py ...
1
2016-07-15T07:51:39Z
38,390,865
<p>You need to supply a <code>scrapy.spider</code> class not a name of a spider there.</p> <pre><code>from articlescraper.nujijspider import NujijSpider process.crawl(NujijSpider) </code></pre> <p>Check out <a href="http://doc.scrapy.org/en/latest/topics/practices.html?#run-scrapy-from-a-script" rel="nofollow">offici...
0
2016-07-15T07:59:42Z
[ "python", "scrapy" ]
I always get this error when creating a Kivy app
38,390,789
<p>I am trying to make a simple app made from Kivy on Windows:</p> <pre><code>import kivy from kivy.app import App from kivy.uix.label import Label class MyApp(App): def build(self): return Label(text='Hello world') if __name__ == '__main__': MyApp().run() </code></pre> <p>(EDIT) But each time I ...
1
2016-07-15T07:55:28Z
38,485,851
<p>Though the installation instructions say <code>gstreamer</code> is optional I had to install it to get kivy to work (windows). As on the installation page:<br> <code>python -m pip install kivy.deps.gstreamer --extra-index-url https://kivy.org/downloads/packages/simple/</code> </p> <p>(uninstalling reproduced the e...
1
2016-07-20T16:22:04Z
[ "python", "kivy" ]
How to round a number to n decimal places in Python
38,390,950
<p>I want, what I enter in the entry field should be automatic rounded to n decimal points.</p> <pre><code>import Tkinter as Tk root = Tk.Tk() class InterfaceApp(): def __init__(self,parent): self.parent = parent root.title("P") self.initialize() def initialize(self): frPic ...
-1
2016-07-15T08:03:44Z
38,391,583
<p>I suppose what you want is not to round the float value itself, you want to show a float value with a precision of n decimal points. Try this:</p> <pre><code>&gt;&gt;&gt; n = 2 &gt;&gt;&gt; '{:.{}f}'.format( 3.1415926535, n ) '3.14' &gt;&gt;&gt; n = 3 &gt;&gt;&gt; '{:.{}f}'.format( 3.1415926535, n ) '3.142' </code>...
0
2016-07-15T08:37:40Z
[ "python", "tkinter", "decimalformat", "decimal-point" ]
How to round a number to n decimal places in Python
38,390,950
<p>I want, what I enter in the entry field should be automatic rounded to n decimal points.</p> <pre><code>import Tkinter as Tk root = Tk.Tk() class InterfaceApp(): def __init__(self,parent): self.parent = parent root.title("P") self.initialize() def initialize(self): frPic ...
-1
2016-07-15T08:03:44Z
38,392,844
<p>You do not get the expected result because when you run <code>a.set(round(self.entry, 2))</code> inside <code>initialize()</code> , the value of <code>self.entry.get()</code> is always <code>0</code> (the default value after creation)</p> <p>You rather need to attach a <a href="http://effbot.org/zone/tkinter-callba...
1
2016-07-15T09:40:50Z
[ "python", "tkinter", "decimalformat", "decimal-point" ]
Stream Analytics deserialising JSON from Python via Event Hub
38,391,125
<p>I have set up an Azure Event Hub and I am sending AMQP messages in JSON format from a Python script, and am attempting to stream those messages to Power BI using Stream Analytics. The messages a very simple device activity from and IoT device</p> <p>The Python snippet is</p> <pre><code>msg = json.dumps({ "Hub": MA...
0
2016-07-15T08:12:36Z
38,424,273
<p>This is caused by client API incompatibility. Python uses Proton to send the JSON string in the body of an AMQP Value message. The body is encoded as an AMQP string (AMQP type encoding bytes + utf8 encoded bytes of string). Stream Analytics uses Service Bus .Net SDK which exposes AMQP message as EventData and its bo...
2
2016-07-17T17:56:42Z
[ "python", "json", "azure", "amqp", "asa" ]
Stream Analytics deserialising JSON from Python via Event Hub
38,391,125
<p>I have set up an Azure Event Hub and I am sending AMQP messages in JSON format from a Python script, and am attempting to stream those messages to Power BI using Stream Analytics. The messages a very simple device activity from and IoT device</p> <p>The Python snippet is</p> <pre><code>msg = json.dumps({ "Hub": MA...
0
2016-07-15T08:12:36Z
38,561,413
<p>As @XinChen said, the issue was caused by the AMQP protocol.</p> <p>Per my experience, the two workaround ways below are effective for this case.</p> <ol> <li>Using <a href="https://msdn.microsoft.com/en-us/library/azure/dn790664.aspx" rel="nofollow"><code>Send Event</code></a> REST API instead of Azure Python SDK...
0
2016-07-25T06:55:56Z
[ "python", "json", "azure", "amqp", "asa" ]
Stream Analytics deserialising JSON from Python via Event Hub
38,391,125
<p>I have set up an Azure Event Hub and I am sending AMQP messages in JSON format from a Python script, and am attempting to stream those messages to Power BI using Stream Analytics. The messages a very simple device activity from and IoT device</p> <p>The Python snippet is</p> <pre><code>msg = json.dumps({ "Hub": MA...
0
2016-07-15T08:12:36Z
38,647,299
<p>These two things worked for me:</p> <ul> <li>add <code>message.inferred = True</code></li> <li>check to make sure your specifying dumps encoding <code>encoding='utf-8'</code> not <code>encoding='utf8'</code> as in your example.</li> </ul> <p>Updated OP:</p> <pre><code>msg = json.dumps({ "Hub": MAC, "DeviceID": id...
0
2016-07-28T21:48:15Z
[ "python", "json", "azure", "amqp", "asa" ]
Nginx + gunicorn Django 1.9 CSRF verification failed
38,391,376
<p><strong>Background :</strong><br> I am trying to configure cloudflare <strong>flexible</strong> SSL with django.<br> Browser &lt;-HTTPS-> Cloudflare &lt;-HTTP-> Nginx &lt;--> Gunicorn</p> <p><strong>Issue :</strong><br> I am getting <strong>CSRF verification failed. Request aborted for admin panel login</strong> - ...
1
2016-07-15T08:27:24Z
38,391,778
<p>It seems you have made a mistake while naming http-header. You have to ensure that the name of the <strong>X-Forwarded-Proto</strong> header is correct in both: <em>nginx</em> configuration and <em>Django</em>'s settings.py.</p> <p>So you should modify your <strong>settings.py</strong> file by replacing the line:</...
0
2016-07-15T08:47:42Z
[ "python", "django", "nginx", "django-csrf" ]
Tkinter : Make canvas draggable
38,391,513
<p>i am creating a project that involves making a <code>RawTurtle</code> on a canvas. And I was wondering what would I do if the drawing is out of the screen. Can anyone tell me how to make the Tkinter Canvas widget draggable ?</p> <pre><code>from tkinter import * root = Tk() c = Canvas(root) t = RawTurtle(c) ....# W...
0
2016-07-15T08:34:22Z
38,396,634
<p>this is an answer for python 3, but change the imports and it should work fine with python 2</p> <pre><code>#!python3 import tkinter as tk import turtle def run_turtles(*args): for t, d in args: t.circle(200, d) root.after_idle(run_turtles, *args) def scroll_start(event): screen.scan_mark(eve...
1
2016-07-15T12:51:30Z
[ "python", "canvas", "tkinter", "drag" ]
Regular Expression (find matching characters in order)
38,391,633
<p>Let us say that I have the following string variables:</p> <pre><code>welcome = "StackExchange 2016" string_to_find = "Sx2016" </code></pre> <p>Here, I want to find the string <code>string_to_find</code> inside <code>welcome</code> using regular expressions. I want to see if each character in <code>string_to_find<...
1
2016-07-15T08:40:40Z
38,391,660
<p>Use wildcard matches with <code>.</code>, repeating with <code>*</code>:</p> <pre><code>expression = 'S.*x.*2.*0.*1.*6' </code></pre> <p>You can also assemble this expression with <code>join()</code>:</p> <pre><code>expression = '.*'.join('Sx2016') </code></pre> <p>Or just find it without a regular expression, c...
1
2016-07-15T08:42:02Z
[ "python", "regex" ]
Regular Expression (find matching characters in order)
38,391,633
<p>Let us say that I have the following string variables:</p> <pre><code>welcome = "StackExchange 2016" string_to_find = "Sx2016" </code></pre> <p>Here, I want to find the string <code>string_to_find</code> inside <code>welcome</code> using regular expressions. I want to see if each character in <code>string_to_find<...
1
2016-07-15T08:40:40Z
38,391,687
<p>Your answer is rather trivial. The <code>.*</code> character combination matches 0 or more characters. For your purpose, you would put it between all characters in there. As in <code>S.*x.*2.*0.*1.*6</code>. If this pattern is matched, then the string obeys your condition.</p> <p>For a general string you would inse...
3
2016-07-15T08:43:27Z
[ "python", "regex" ]
Regular Expression (find matching characters in order)
38,391,633
<p>Let us say that I have the following string variables:</p> <pre><code>welcome = "StackExchange 2016" string_to_find = "Sx2016" </code></pre> <p>Here, I want to find the string <code>string_to_find</code> inside <code>welcome</code> using regular expressions. I want to see if each character in <code>string_to_find<...
1
2016-07-15T08:40:40Z
38,391,797
<p>This function might fit your need</p> <pre><code>import re def check_string(text, pattern): return re.match('.*'.join(pattern), text) </code></pre> <p><code>'.*'.join(pattern)</code> create a pattern with all you characters separated by <code>'.*'</code>. For instance</p> <pre><code>&gt;&gt; ".*".join("Sx2016...
0
2016-07-15T08:48:37Z
[ "python", "regex" ]
Regular Expression (find matching characters in order)
38,391,633
<p>Let us say that I have the following string variables:</p> <pre><code>welcome = "StackExchange 2016" string_to_find = "Sx2016" </code></pre> <p>Here, I want to find the string <code>string_to_find</code> inside <code>welcome</code> using regular expressions. I want to see if each character in <code>string_to_find<...
1
2016-07-15T08:40:40Z
38,393,387
<p>Actually having a sequence of <em>chars</em> like <code>Sx2016</code> the pattern that best serve your purpose is a more specific:</p> <pre><code>S[^x]*x[^2]*2[^0]*0[^1]*1[^6]*6 </code></pre> <p>You can obtain this kind of check defining a function like this:</p> <pre><code>import re def contains_sequence(text, s...
0
2016-07-15T10:06:53Z
[ "python", "regex" ]
How to retrieve all permissions of a specific model in django?
38,391,729
<p>By default each django model has 3 permissions (add, change, delete). In a model I can define my custom permission to adds more. </p> <pre><code>class Company(models.Model): owner = models.ForeignKey(User) name = models.CharField(max_length=64, unique=True) description = models.TextField(max_length=512)...
1
2016-07-15T08:45:25Z
38,391,832
<p>you can check on <code>codename</code> field which will be something like: <code>'change_company'</code> etc ...</p> <pre><code>model_name = 'company' all_perms_on_this_modal = Permission.objects.filter(codename__contains=model_name) </code></pre>
1
2016-07-15T08:50:23Z
[ "python", "django", "django-models", "permissions", "group" ]
How to retrieve all permissions of a specific model in django?
38,391,729
<p>By default each django model has 3 permissions (add, change, delete). In a model I can define my custom permission to adds more. </p> <pre><code>class Company(models.Model): owner = models.ForeignKey(User) name = models.CharField(max_length=64, unique=True) description = models.TextField(max_length=512)...
1
2016-07-15T08:45:25Z
38,391,991
<p>I would suggest you something like this:</p> <pre><code>all_permissions = Permission.objects.filter(content_type__app_label='app label', content_type__model='lower case model name') </code></pre> <p>Retrieving model's <code>app_label</code>:</p> <pre><code>Company._meta.app_label </code></pre> <p>Retrieving mode...
1
2016-07-15T08:57:38Z
[ "python", "django", "django-models", "permissions", "group" ]
In Django, how can use build properties?
38,392,095
<p>In python django framework,</p> <p>I want to use different database connection property on local, alpha, release environment.</p> <p>For example..</p> <pre><code>DATABASES = { 'default': { 'ENGINE': 'django.db.backends.oracle', 'NAME': 'mydb', 'USER': 'scott', 'PASSWORD': 'tiger', 'HOST': '${h...
0
2016-07-15T09:03:08Z
38,392,319
<p>You can have multiple <code>settings</code> modules.</p> <pre><code>myproject/ settings/ __init__.py base.py dev.py alpha.py prod.py </code></pre> <p>Use <code>myproject.settings.base</code> as an "abstract" base you can import in all "concrete" module. For instance:</p>...
3
2016-07-15T09:15:57Z
[ "python", "django" ]
Combine values from 2 dicts into a np.array python
38,392,116
<p>I have two dicts </p> <pre><code>a = {0:[1,2,3,4], 1:[5,6,7,8],...} b = {0:[4,3,2,1], 1:[8,7,6,5],...} </code></pre> <p>I would like to create an <code>np.array c</code> for each key-value pair such as follows</p> <pre><code>c1 = array([[1,4],[2,3],[3,2],[4,1]]) c2 = array([[5,8],[6,7],[7,6],[8,5]]) </code></pre>...
2
2016-07-15T09:04:14Z
38,392,248
<p>Yes, you can put <code>np.array</code> into a Python dictionary. Just use a <a href="https://www.python.org/dev/peps/pep-0274/" rel="nofollow">dict comprehension</a> and <a href="https://docs.python.org/3.5/library/functions.html#zip" rel="nofollow"><code>zip</code></a> the lists from <code>a</code> and <code>b</cod...
3
2016-07-15T09:12:14Z
[ "python", "arrays", "numpy", "dictionary" ]
Combine values from 2 dicts into a np.array python
38,392,116
<p>I have two dicts </p> <pre><code>a = {0:[1,2,3,4], 1:[5,6,7,8],...} b = {0:[4,3,2,1], 1:[8,7,6,5],...} </code></pre> <p>I would like to create an <code>np.array c</code> for each key-value pair such as follows</p> <pre><code>c1 = array([[1,4],[2,3],[3,2],[4,1]]) c2 = array([[5,8],[6,7],[7,6],[8,5]]) </code></pre>...
2
2016-07-15T09:04:14Z
38,393,419
<p>You can also use <code>column_stack</code> with a list comprehension:</p> <pre><code>import numpy as np [np.column_stack((a[k], b[k])) for k in b.keys()] Out[30]: [array([[1, 4], [2, 3], [3, 2], [4, 1]]), array([[5, 8], [6, 7], [7, 6], [8, 5]])] </code></pre>
2
2016-07-15T10:08:28Z
[ "python", "arrays", "numpy", "dictionary" ]
How can i import vtk in PyCharm
38,392,124
<p>I'm trying to use VTK directly in PyCharm (vtkpython-7.0.0-Windows-64bit.exe)</p> <p>After changing the interpreter references I still can not import vtk. When I want to load the vtkpython.exe directly i have an error.</p> <p><a href="http://i.stack.imgur.com/Y0cg8.jpg" rel="nofollow"><img src="http://i.stack.imgu...
1
2016-07-15T09:04:39Z
38,392,165
<p>If you want to use <code>vtk</code> in python, you don't need to set it as the interpreter. Your interpreter is still the python installation. <code>vtk</code> is connected to your python installation. If you want to use it, you have to import it with <code>import vtk</code>.</p>
0
2016-07-15T09:06:47Z
[ "python", "pycharm", "vtk" ]
How can i import vtk in PyCharm
38,392,124
<p>I'm trying to use VTK directly in PyCharm (vtkpython-7.0.0-Windows-64bit.exe)</p> <p>After changing the interpreter references I still can not import vtk. When I want to load the vtkpython.exe directly i have an error.</p> <p><a href="http://i.stack.imgur.com/Y0cg8.jpg" rel="nofollow"><img src="http://i.stack.imgu...
1
2016-07-15T09:04:39Z
39,561,104
<p>May be it is late but you can try this:</p> <ol> <li>Install <a href="https://www.continuum.io/downloads" rel="nofollow">Anaconda</a> as the interpreter for python.</li> <li><p>Launch command-prompt or terminal and type for python 2.7</p> <p><code>conda create -n py27 python=2.7 anaconda</code></p></li> <li>Upon ...
2
2016-09-18T18:21:07Z
[ "python", "pycharm", "vtk" ]
Getting Audience->User explorer details from google analytics using API,what will be the metrics and dimension
38,392,173
<p>In google analytics i want to get details of Audience->User explorer through google analytics API (python API). I am following the below link <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/common-queries" rel="nofollow">https://developers.google.com/analytics/devguides/reporting/core/v...
1
2016-07-15T09:07:31Z
38,392,655
<p>Google Analytics does not expose user id and client id through the API. So by default you cannot recreate the user explorer report through the API. </p> <p>You'd have to store the client or user id in a custom dimension, and even then I'm not sure it would be possible to get the same kind of report, let alone in a ...
1
2016-07-15T09:31:48Z
[ "python", "google-analytics", "google-analytics-api" ]
Is there a way to make this sequence creator faster?
38,392,176
<p>I hope someone can give me some tips on how to speed up the following process. Its not really slow, but any time won could be very helpful.</p> <pre><code>from datetime import datetime START_CLOCK = datetime.now() TotalNumbcol = 266 NeighborsperColumn = [[3, 2, 5, 6, 7], [3, 6, 1, 7, 5, 4, 10, 11, 12, 13], [7, 2, 1...
0
2016-07-15T09:07:49Z
38,399,610
<p>Thank you for the working example. This allowed my to help you. Here is some code. The basic idea is to replace:</p> <pre><code>shuffle(Column_Numbers2) </code></pre> <p>with</p> <pre><code>Column_Numbers2 = np.random.permutation(Column_Numbers2).tolist() </code></pre> <p>This makes your code about 3 times faste...
0
2016-07-15T15:14:09Z
[ "python", "optimization", "time", "sequence" ]
How to generate a gpx file by using Python?
38,392,212
<p>I have a <strong>.trace</strong> file and I have generated it to <strong>.kml</strong> file. But, now I think that I need an <strong>gpx</strong> file to plot the data on to a map with speeds. </p> <p>How to generate a <strong>gpx</strong> file from <strong>.trace</strong> file by using Python?</p> <p>I am new to ...
0
2016-07-15T09:10:05Z
38,421,121
<p>A fast search in a major search engine would have given you the answer to that question. Here is the recipe proposed by <a href="http://timwise.blogspot.fr/2014/02/converting-kml-to-gpx-with-python.html" rel="nofollow">Tim Abell</a> to transform kml into gpx. He provides the script for it <a href="https://gist.githu...
1
2016-07-17T12:21:56Z
[ "python", "trace", "gpx" ]
TypeError: must be unicode, not str in NLTK
38,392,407
<p>I am using python2.7, nltk 3.2.1 and python-crfsuite 0.8.4. I am following this page : <a href="http://www.nltk.org/api/nltk.tag.html?highlight=stanford#nltk.tag.stanford.NERTagger" rel="nofollow">http://www.nltk.org/api/nltk.tag.html?highlight=stanford#nltk.tag.stanford.NERTagger</a> for nltk.tag.crf module. </p> ...
1
2016-07-15T09:20:14Z
38,393,549
<p>In Python 2, regular quotes <code>'...'</code> or <code>"..."</code> create byte strings. To get Unicode strings, use a <code>u</code> prefix before the string, like <code>u'dfd'</code>.</p> <p>To read from a file, you'll want to specify an encoding. See <a href="http://stackoverflow.com/questions/10971033/backport...
2
2016-07-15T10:14:32Z
[ "python", "nltk", "crf" ]
Pandas: compare list values and write new column
38,392,440
<p>I have a new question regarding with my <a href="http://stackoverflow.com/questions/38376533/add-new-column-with-existing-column-names">my old post</a>. In that post the problem were simplified, having only two w's to compare. Now, suppose I have more than 2, e.g., 3, with frequencies (1,1,0). I would like to check ...
1
2016-07-15T09:22:03Z
38,392,729
<p>EDITED:</p> <pre><code># You should drop all extra fields # don't worry they are still present in original dataframe (df) words = df.drop(['FID'], axis=1) # Get maximums for each row maxes = words.max(axis=1) # Create new column with the features names with maximum values df['max'] = words.idxmax(axis=1) # Creat...
3
2016-07-15T09:35:06Z
[ "python", "pandas" ]
Django - Update View, creating new Objects instead of updating,
38,392,514
<p>I am trying to use Update view in django, in the simplest manner, but it is not being updated, rather a new object of the model is being created in the database. I have done the same thing for another model Track, and its working fine. I feel it might be something trivial that might be causing the problem.</p> <p>I...
1
2016-07-15T09:25:33Z
38,393,982
<p>Well, as other folks said in comments, your view creates new object instead of update because you have editable primary key. </p> <p>You see, undercover <code>UpdateView</code> creates form for your model and calls <code>save</code> on that form. </p> <p>It's the <code>save</code> method of <code>BaseModelForm</co...
1
2016-07-15T10:36:25Z
[ "python", "django" ]
Raspberry Arduino communication via pyserial stops after a day
38,392,689
<p>I connected a Raspberry Pi and an Arduino via USB. Arduino is getting data from the world via sensors (EC and temperature sensor) and writing this data to serial. The Raspberry is writing this data into a database.</p> <p>The Arduino sketch:</p> <pre><code>#include &lt;OneWire.h&gt; #include &lt;DallasTemperature....
0
2016-07-15T09:33:25Z
38,550,565
<p>My problem is solved.</p> <p>When I added massive serial printing on the Arduino side I found out that there is not really nothing received on the Raspberry side but much less, so that my python program could just not parse what the Arduino sketch was sending. Another observation was this:</p> <p>When I watched th...
0
2016-07-24T09:31:53Z
[ "python", "arduino", "serial-port", "raspberry-pi", "pyserial" ]
scrapy Request callback not working when dont_filter=False
38,392,696
<p>I am using Scrapy 1.1.0 with Python 3.5 to scrape data from a website. The following code is working...</p> <pre><code>class ImdbSpider(scrapy.Spider): name = "imdbFav" allowed_domains = ["http://www.imdb.com"] start_urls = [ "http://www.imdb.com/title/tt0203166/" ] recommendRegex = re.c...
0
2016-07-15T09:33:36Z
38,393,551
<p>This is the common friend problem:</p> <ul> <li>Greg and Melissa are friends </li> <li>Melissa and John are friends </li> <li>John and Jake are friends</li> <li>Jake and Greg are friends</li> </ul> <p>In your case it's about movies:</p> <ul> <li>Together suggests We are the best</li> <li>We are the best suggests ...
0
2016-07-15T10:14:40Z
[ "python", "python-3.x", "web-scraping", "scrapy" ]
All 'SearchIndex' classes must use the same 'text' fieldname for the 'document=True' field. Offending index is '<personal.search_indexes.PostIndex
38,392,873
<p>I am trying to create multiple query using haystack-whoosh my last problem is sloved by putting double backslashes but now a new error came. I am getting error below in command prompt:</p> <pre><code> C:\Users\varun\Desktop\Project\mysite&gt;python manage.py rebuild_index C:\Python34\lib\importlib\_bootstrap.py:...
0
2016-07-15T09:42:07Z
38,500,911
<p>Every search index must have field with <code>document=True</code> with the same name in all search indexes, e.g:</p> <pre><code>class FirstIndex(ndexes.SearchIndex,indexes.Indexable): text = indexes.EdgeNgramField(document=True) class SecondIndex(ndexes.SearchIndex,indexes.Indexable): text = indexes.EdgeN...
1
2016-07-21T09:55:33Z
[ "python", "django", "django-haystack", "whoosh" ]
In Pyspark how to add all values in a list?
38,392,918
<p>I am running the below pyspark transformation in jupyter notebook. My requirement is to add all values in the element like 469+84451+903... and should return only the total count.</p> <p>Below are the transformation and action:</p> <pre><code>In [46]: newdispokey1.collect() [(u'Hello', 469), (u'is', 84451), (u'...
1
2016-07-15T09:44:08Z
38,393,601
<p>The simplest solution is </p> <pre><code>&gt;&gt;&gt; newdispokey1.values().sum() 750558 </code></pre> <p>The problem is with the types of the parameter to the <code>reduce</code> method - the type of the reducer. It receives two elements: one is the previous result, or the first element, and the second is the new...
3
2016-07-15T10:17:13Z
[ "python", "apache-spark", "pyspark" ]
I am getting these error in " AttributeError: 'NoneType' object has no attribute 'get_all_permissions'
38,392,939
<pre><code>class TenantViewSet(viewsets.ModelViewSet): """ API endpoint that allows Tenant users to be viewed. """ model = TenantUser serializer_class = TenantUserSerializer def list(self, request, domain): tenants = TenantUser.objects.all() serializer = TenantUserSerializer(ten...
1
2016-07-15T09:45:13Z
38,394,143
<p>My guess <strong><code>get_current_tenant_user</code></strong> function doesn't return user. Ensure that user returned from that function with <strong><code>return</code></strong> or <strong><code>yield</code></strong> statement.</p>
0
2016-07-15T10:44:07Z
[ "python", "django-rest-framework" ]
Service error when creating amazon lambda function
38,393,024
<p>Hi I am trying to create a lambda function in amazon lambda. Just trying to follow the python tutorial.</p> <p>After following all the steps I get a "Service Error" when creating the function. </p> <p>I found this forum discussing about this <a href="https://forums.aws.amazon.com/thread.jspa?threadID=233266" rel="...
3
2016-07-15T09:48:54Z
39,031,349
<p>I was having this problem, but it disappeared when I selected "Choose an existing role" instead of letting the wizard create a role, under "Lambda function handler and role". If I create a role manually I can then assign it to the Lambda afterwards. Maybe that'll help you, too?</p>
1
2016-08-19T04:52:03Z
[ "python", "amazon-web-services", "lambda", "amazon", "aws-lambda" ]
Difference between two products nearest to zero: non brute-force solution?
38,393,078
<p>In a <a href="https://nordnorsk.vitensenter.no/">science museum in Norway</a> I came across the following mathematical game:</p> <p><a href="http://i.stack.imgur.com/aBECB.jpg"><img src="http://i.stack.imgur.com/aBECB.jpg" alt="enter image description here"></a></p> <p>The goal is to place the 10 digits from 0 to ...
16
2016-07-15T09:51:25Z
38,393,328
<p>As a heuristic you could compute the square root of 12345 (about 111) and go on from there, searching for the nearest values to 123 and 45 which you can create with the remaining numbers. I did not implement this but it could be a more intelligent approach.</p> <p>Another example:</p> <p>sqrt(36189) -> About 190</...
0
2016-07-15T10:04:04Z
[ "python", "algorithm", "brute-force" ]
Difference between two products nearest to zero: non brute-force solution?
38,393,078
<p>In a <a href="https://nordnorsk.vitensenter.no/">science museum in Norway</a> I came across the following mathematical game:</p> <p><a href="http://i.stack.imgur.com/aBECB.jpg"><img src="http://i.stack.imgur.com/aBECB.jpg" alt="enter image description here"></a></p> <p>The goal is to place the 10 digits from 0 to ...
16
2016-07-15T09:51:25Z
38,394,212
<p>If you assume there is a solution with difference 0, you can do via prime factors.</p> <p>If a<em>b - c</em>d = 0, then the prime factors of a<em>b and c</em>d must be the same. You can start the search by going through all 3-digit primes (there are only 143) and see whether they have a multiple that only contains ...
2
2016-07-15T10:46:51Z
[ "python", "algorithm", "brute-force" ]
Difference between two products nearest to zero: non brute-force solution?
38,393,078
<p>In a <a href="https://nordnorsk.vitensenter.no/">science museum in Norway</a> I came across the following mathematical game:</p> <p><a href="http://i.stack.imgur.com/aBECB.jpg"><img src="http://i.stack.imgur.com/aBECB.jpg" alt="enter image description here"></a></p> <p>The goal is to place the 10 digits from 0 to ...
16
2016-07-15T09:51:25Z
38,395,431
<p>12 seconds is too much for my taste. My C++ brute force attack took ~430ms without any heuristics or deep optimizations. Anyway you need to add some heuristics for example:</p> <p><strong>Bitwidth of multiplication result is around the sum of bitwidth of the operands.</strong></p> <p>So you need to test only the s...
1
2016-07-15T11:51:06Z
[ "python", "algorithm", "brute-force" ]
Difference between two products nearest to zero: non brute-force solution?
38,393,078
<p>In a <a href="https://nordnorsk.vitensenter.no/">science museum in Norway</a> I came across the following mathematical game:</p> <p><a href="http://i.stack.imgur.com/aBECB.jpg"><img src="http://i.stack.imgur.com/aBECB.jpg" alt="enter image description here"></a></p> <p>The goal is to place the 10 digits from 0 to ...
16
2016-07-15T09:51:25Z
38,407,302
<p>There are 126 ways to split 10 digits into 2 sets of 5 without duplicates. For each set of 5 digits, there are 120 ways (permutations) to arrange them into the form <code>ab*cde</code>, or 72 ways if the group contains zero and a leading zero is not allowed. That means a brute-force algorithm would need to check 126...
1
2016-07-16T03:05:00Z
[ "python", "algorithm", "brute-force" ]
Difference between two products nearest to zero: non brute-force solution?
38,393,078
<p>In a <a href="https://nordnorsk.vitensenter.no/">science museum in Norway</a> I came across the following mathematical game:</p> <p><a href="http://i.stack.imgur.com/aBECB.jpg"><img src="http://i.stack.imgur.com/aBECB.jpg" alt="enter image description here"></a></p> <p>The goal is to place the 10 digits from 0 to ...
16
2016-07-15T09:51:25Z
38,427,233
<p>This one assumes a difference of zero is possible (although it could be adapted to finding the minimum/s by sorting — thank you, m69, for that idea — each group of 120 permutations and using binary search, adding a factor of <code>(log2 120)</code> to the time complexity): hash the multiples for all <code>10 cho...
2
2016-07-18T00:40:19Z
[ "python", "algorithm", "brute-force" ]
Write to file and print to screen out of step with each other
38,393,151
<p>I have a problem with writing to file. What seems to happen is that a program prints numbers to screen in the order 0,1,2,3 (zeroth, first, second, third) but writes to file in the order -1, 0, 1, 2. Even when the print to screen command follows the write to file command. Sample code follows. Any ideas how to make i...
0
2016-07-15T09:54:37Z
38,393,273
<p>The problem is most likely that you're opening the output file dozens of times, but never closing it.</p> <p>You should do <code>f = open(data_file,'a')</code> <em>before</em> the loop and only <em>once</em>. Then when everything's done, <em>call</em> <code>f.close()</code> (<code>f.close</code> is not the same as ...
4
2016-07-15T10:01:36Z
[ "python" ]
Write to file and print to screen out of step with each other
38,393,151
<p>I have a problem with writing to file. What seems to happen is that a program prints numbers to screen in the order 0,1,2,3 (zeroth, first, second, third) but writes to file in the order -1, 0, 1, 2. Even when the print to screen command follows the write to file command. Sample code follows. Any ideas how to make i...
0
2016-07-15T09:54:37Z
38,394,579
<p>To make sure the file is always closed, you should use the <code>with</code> statement. For example:</p> <pre><code>with open(data_file, 'a') as f: f.write("\n" + str(j)) </code></pre> <p>This will close the file, even if an exception happens during the <code>write</code>.</p> <p>Alternatively, you need to us...
1
2016-07-15T11:04:54Z
[ "python" ]
Fill up a dictionary in parallel with multiprocessing
38,393,269
<p>Yesterday i asked a question: <a href="http://stackoverflow.com/questions/38378310/reading-data-in-parallel-with-multiprocess">Reading data in parallel with multiprocess</a></p> <p>I got very good answers, and i implemented the solution mentioned in the answer i marked as correct. </p> <pre><code>def read_energies...
2
2016-07-15T10:01:20Z
38,560,235
<p>You are incurring a good amount of overhead in (1) starting up each process, and (2) having to copy the <code>pandas.DataFrame</code> (and etc) across several processes. If you just need to have a <code>dict</code> filled in parallel, I'd suggest using a shared memory <code>dict</code>. If no key will be overwritt...
3
2016-07-25T05:24:35Z
[ "python", "multiprocess" ]
Django -- Models don't exist, but Django still loads them
38,393,274
<p>Im getting a <code>ProgrammingError</code> when I try to delete a User object, this is wherever User.delete occurs, it even happens in the admin.</p> <p><strong>The Error</strong> </p> <p>Django apparently 'thinks' that there's a relationship between <code>auth_user</code> and <code>apiHandlers_cardholders</code> ...
1
2016-07-15T10:01:40Z
38,411,177
<p>This is very likely to be because you have a stray models.pyc file somewhere. Clear out all the *.pyc files. You can try something like this if you are on linux:</p> <pre><code>find . -name '*pyc' -exec 'rm' '{}' ';' </code></pre> <p>Follow that by <code>./manage.py makemigrations apihandlers</code> and then <code...
0
2016-07-16T12:25:57Z
[ "python", "django", "postgresql", "django-models" ]
include common headers and footers
38,393,292
<p>instead of writing a common header and footer like CSS, scripts etc in every template, how can I attach templates with common header and footer files.</p>
-2
2016-07-15T10:02:39Z
38,393,506
<p>In order to extend both a header and a footer from a html template, you should have both header/footer in the same file, and add a jinja block for each place where you would like to add content. (You should really read some documentation first though)</p> <p>Then, in the specific page, you start with <code>{% exte...
0
2016-07-15T10:12:33Z
[ "python", "django" ]
Python click button with requests
38,393,314
<p>I have been trying to 'click' a button on a site with the requests module on a website, but I can't get it working.</p> <p>This is the button on the site:</p> <pre><code>&lt;div data-expected-currency="1" data-asset-type="T-Shirt" class="btn-primary btn-medium PurchaseButton " data-se="item-buyforrobux" data-item-...
0
2016-07-15T10:03:30Z
38,393,463
<p><code>Clicking</code> a button is not directly possible with the requests library. If you really need to <code>click</code> on something from your python code, you need a scriptable, possibly headless browser. </p> <p>What you <em>can</em> do, is to figure out what request goes to the server when the button is clic...
0
2016-07-15T10:10:38Z
[ "python", "python-3.x" ]
Unable to render ChoiceField on template in Django
38,393,316
<p>I'm trying to show a ChoiceField in a template on Django but I'm unable to make it work.</p> <p>I have found some solutions here, but seems not work to me (<a href="http://stackoverflow.com/questions/11639238/how-to-display-choicefield-select-widget-on-template">Possible solution</a>), but I get the error: <code>to...
0
2016-07-15T10:03:38Z
38,393,900
<p>Thanks to @raphv, the solution was put <code>{{form.networkPartitions}}</code> and <code>{{form.applicationPolicies}}</code> on the template. So simple....</p>
0
2016-07-15T10:32:31Z
[ "python", "django", "django-forms", "choicefield" ]
How to use ansible 'expect' module for multiple different responses?
38,393,343
<p>Here I am trying to test my bash scripy where it is prompting four times.</p> <pre><code>#!/bin/bash date &gt;/opt/prompt.txt read -p "enter one: " one echo $one echo $one &gt;&gt;/opt/prompt.txt read -p "enter two: " two echo $two echo $two &gt;&gt;/opt/prompt.txt read -p "enter three: " three echo $three echo $th...
1
2016-07-15T10:04:40Z
39,458,575
<p>The reason is that the questions are interpreted as regexps. Hence you must escape characters with a special meaning in regular expressions, such as -()[]\?*. et cetara.</p> <p>Hence:</p> <pre><code>'Enter current password for root (enter for none):' </code></pre> <p>should instead be:</p> <pre><code>'Enter curr...
1
2016-09-12T20:48:41Z
[ "python", "python-2.7", "ansible", "ansible-playbook", "ansible-2.x" ]
Installing python 2.7.11 on shared hosting gives permission denied
38,393,386
<p>I am following <a href="https://my.bluehost.com/cgi/help/python-install" rel="nofollow">this guideline</a> to install python 2.7.11 on a CentOs shared hosting (bluehost). I get the following error during the <strong>make install</strong> phase: </p> <pre><code>(cd /home2/some_user/python/bin; ln -s python2 python)...
0
2016-07-15T10:06:50Z
38,409,720
<p>Doing this trick solved the issue: </p> <pre><code>cd /home2/some_user/python/bin; cp python2.7 python2 </code></pre> <p>So basically I got the error when running make install, ran above commands to trick the installation there is a python2 folder exists, and then reran the make install and python was installed s...
1
2016-07-16T09:32:43Z
[ "python", "bluehost", "python-install" ]
Python Flask endless redirect loop 302
38,393,440
<p>I have currently an issue where one of my pages in flask falls into an endless redirect loop:</p> <p><a href="http://i.stack.imgur.com/ZlAsd.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZlAsd.png" alt="enter image description here"></a></p> <p>I have already so many routes and methodes and had never a pr...
0
2016-07-15T10:09:35Z
38,396,833
<p><code>validate_on_submit</code> checks two things:</p> <ol> <li>Is the request a POST?</li> <li>Does the post body validate as the specified form?</li> </ol> <p>If either of these is false, the else block runs and generates the flash message. Since the first check will be false for all GETs, you'll receive the fla...
1
2016-07-15T13:02:32Z
[ "python", "python-2.7", "flask", "routing" ]
Looking for text in logs
38,393,450
<p>I have a new project to develop a log reader in Python 3.5 from txt files and I don't know how to start. The main goal is to extract pieces of logs (substrings) from a large and complex log txt file and display it in a structured way on a webpage. Would be possible please any help with libraries and commands in orde...
-2
2016-07-15T10:10:10Z
38,393,862
<p>I would say you convert the .txt files you mentioned into a list of strings, then use a for-loop:</p> <h1>for a in txt_files:</h1> <p>Then use some if statements to look out for keywords, and print certain messages depending on the input</p> <p>using this method you could also have it look out for certain words i...
1
2016-07-15T10:29:54Z
[ "python" ]
Display Models with Foreign Keys and Pagination
38,393,477
<p>I have a flask, sqlalchemy, jinja2 app with the follwing problem. I am trying to display a model in an html table and have pagination with it. The model has a bunch of foreign keys in it, so in the table I see the foreign key. I would like to display the <code>__repr__</code> of the model or one of the fields of t...
0
2016-07-15T10:11:19Z
38,398,570
<p>You just need to define the relationship between the two models— you've already defined the <code>FK</code> relationship, so something simple like:</p> <pre><code>buildings = db.relationship('Buildings') </code></pre> <p>would enable you to do <code>{{ log.buildings }}</code> to get the <code>__repr__</code> of ...
0
2016-07-15T14:24:21Z
[ "python", "flask", "sqlalchemy", "jinja2" ]
Proper JSON not received in Django Request
38,393,523
<p>I have a simple API where I get the JSON data from request and parse it. The above API works fine POSTMAN but does not work with jquery. </p> <p>In views.py :</p> <pre><code>def search_and_return(request): print(request.body.decode() , type(request)) request = request.body.decode() request = json.loads...
0
2016-07-15T10:13:07Z
38,393,603
<p>You need to use <code>JSON.stringify(arr)</code> while parsing data</p> <pre><code>$(document).ready(function() { $("#button").click(function() { $.ajax({ url:"http://10.124.92.208:8000/customer/retrieve_info", crossDomain:true, data: JSON.stringify({"order_c...
1
2016-07-15T10:17:21Z
[ "jquery", "python", "json", "ajax", "django" ]
How to calculate confidence score from dependency parse tree?
38,393,554
<p>Is there any way to get confidence score or any score from dependency parse tree of a sentence using ntlk or something else?</p> <p>Any advice and suggestions will be greatly appreciated!</p>
1
2016-07-15T10:14:47Z
38,422,483
<p>It's a hard task, I am not aware of any tool doing it, but if you probably post something on the corpora mailing list, or language technology section of reddit you will get better replies. But if was a research question, I would suggest training a PCFG on a penntreebank dataset and then using it to compute the proba...
1
2016-07-17T14:46:52Z
[ "python", "nlp", "nltk", "stanford-nlp" ]
Set working directory in Python / Spyder so that it's reproducible
38,393,628
<p>Coming from R, using <code>setwd</code> to change the directory is a big no-no against reproducibility because others do not have the same directory structure as mine. Hence, it's recommended to use relative path from the location of the script.</p> <p>IDEs slightly complicate this because they set their own workin...
5
2016-07-15T10:18:36Z
38,395,672
<p>It appears they did consider this as a feature in Spyder based on this GitHub ticket, but it is still waiting implementation as of mid-May:</p> <blockquote> <p>We could add an option to the Run dialog to automatically set the working directory to the one your script is being ran.</p> <p>However, someone el...
1
2016-07-15T12:04:03Z
[ "python", "spyder", "reproducible-research" ]
Tkinter : Create blur transparency
38,393,643
<p>I am wondering how to create a blur transparency effect in tkinter. I already know how to add the transparency effect to the window by using</p> <pre><code>root=Tk() root.attributes("-alpha",0.95) </code></pre> <p>But how can you add the blur part? </p>
0
2016-07-15T10:19:20Z
38,393,858
<p>This service is not provided by tkinter. However you can <a href="http://stackoverflow.com/a/19964474/">take a screenshot of your app</a> and blur it yourself (see for instance <a href="http://pillow.readthedocs.io/en/3.2.x/reference/ImageFilter.html" rel="nofollow">ImageFilter.GaussianBlur</a> or <a href="http://d...
1
2016-07-15T10:29:45Z
[ "python", "tkinter", "transparency", "blur" ]
Uploading a file via pyCurl
38,393,830
<p>I am trying to convert the following curl code into pycurl. I do not want to use requests. I need to use pycurl because requests is not fully working in my old python version.</p> <pre><code>curl -X POST -H "Accept-Language: en" -F "images_file=@fruitbowl.jpg" -F "parameters=@myparams.json" "https://gateway-a.watso...
1
2016-07-15T10:28:08Z
38,394,386
<pre><code>import pycurl c = pycurl.Curl() c.setopt(c.URL, 'https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key={api-key}&amp;version=2016-05-20') c.setopt(c.POST, 1) c.setopt(c.HTTPPOST, [("images_file", (c.FORM_FILE, "fruitbowl.jpg"))]) c.setopt(c.HTTPPOST, [("parameters", (c.FORM_FILE, "m...
1
2016-07-15T10:55:12Z
[ "python", "ibm-bluemix", "pycurl" ]
Trouble With PyQt4 Web Kit. Button dosent connect to function
38,393,836
<p>-PyQt4 -Python 3.4.2</p> <p>ive had a look through many different questions here and done research online.</p> <p>Basicly what has happened is that when i click on the Reload button nothing happens. Even when i tried to get it to print('Reload') nothing appears on the console. This also happens with the forward an...
-1
2016-07-15T10:28:28Z
38,399,989
<p>Firstly, you're using the same name for the button and the slot, so when <code>setupUi</code> is called, the former will shadow the latter.</p> <p>Secondly, the <code>lambda</code> does not actually <em>call</em> the slot, which explains why "nothing happens". Of course, you cannot really call it anyway, since it i...
0
2016-07-15T15:32:29Z
[ "python", "qt", "python-3.x", "pyqt", "qtwebkit" ]
Caching a static Database table in Django
38,393,932
<p>I have a Django web application that is currently live and receiving a lot of queries. I am looking for ways to optimize its performance and one area that can be improved is how it interacts with its database.</p> <p>In its current state, each request to a particular view loads an entire database table into a panda...
1
2016-07-15T10:34:19Z
38,413,952
<p>I had a similar problem and <a href="https://github.com/django-cache-machine/django-cache-machine" rel="nofollow">django-cache-machine</a> worked like a charm. It uses the Django caching features to cache the results of your queries. It is very easy to set up (assuming you have already configured Django's cache back...
1
2016-07-16T17:50:44Z
[ "python", "django", "caching" ]