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 |
|---|---|---|---|---|---|---|---|---|---|
How to display @ instead of being encoded as %40 (urlencode) in browser address bar? | 38,319,627 | <p>I've tried to use this line in Python3 (Flask) project, which is UTF-8 encoding:</p>
<pre><code>@app.route('/@<username>', methods=['GET', 'POST'])
</code></pre>
<p>But in browser address bar, it always displays like:</p>
<pre><code>http://example.com/%40username
</code></pre>
<p>How to display the origina... | 2 | 2016-07-12T03:37:13Z | 38,320,062 | <p>Are you are using url_for from python code? One approach in such case is to call urllib.unquote on return value of url_for</p>
<p>Sample code:</p>
<pre><code>from flask import Flask, url_for, redirect
import urllib
app = Flask(__name__)
@app.route("/")
def hello():
return redirect(urllib.unquote(url_for('user... | 1 | 2016-07-12T04:31:46Z | [
"python",
"html",
"url",
"flask"
] |
ValueError: Inconsistent number of samples when using sklearn on defaultdict | 38,319,722 | <p>I am reading columns in .csv files as inputs to a sklearn Naive Bayes fit. However, I am running into these errors and warnings:</p>
<p><em>DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single... | 0 | 2016-07-12T03:48:26Z | 38,336,673 | <p>I found the solution to my problem. Seems like the issue wasn't about shaping the data structure, but with setting it to be a number type rather than a string type.</p>
<pre><code>x = np.array(columns[9]).reshape(len(columns[10]), 1).astype(np.float)
y = np.array(columns[10])
clf.fit(x, y)
</code></pre>
| 0 | 2016-07-12T18:45:45Z | [
"python",
"csv",
"scikit-learn",
"defaultdict"
] |
Creating and Deleting Buckets Programmatically in Google Cloud Storage | 38,319,785 | <p>I am using Google App Engine and Google Cloud Storage. I would like to create a bucket daily using a cron job. Also, delete a bucket programmatically. I was able to manually create a bucket using the Google Cloud Console.</p>
<p>How do I create/delete buckets from GAE using python? </p>
<p>Also, is it a good desig... | 1 | 2016-07-12T03:55:46Z | 38,321,492 | <p>It's probably not the best idea to create a new bucket every day. There's not a lot of harm in it, but there's also no advantage, as a single bucket can grow to be pretty much as big as you might ever need. It's generally a better idea to use different buckets for logically different kinds of data.</p>
<p>As far as... | 2 | 2016-07-12T06:30:25Z | [
"python",
"google-app-engine",
"google-cloud-storage",
"bucket"
] |
How to resolve this error? "RestartFreqExceeded: 5 in 1s" in django+celery+rabbitmq+mysql+redis | 38,319,920 | <p>So I am using django with celery. rabbitmq is the broker. redis is the cache. mysql is the db. (everything in localhost)</p>
<ol>
<li>I am using python2.7 and using virtualenv based virtual environment</li>
<li>I start the redis server (local) at default port</li>
<li><p>In a new terminal, I run </p>
<pre><code>py... | 2 | 2016-07-12T04:14:28Z | 38,320,023 | <p>To answer your question, <code>Your RabbitMQ is down</code> due to that consumer started to reconncet and it went to contineous loop and it created an exception <code>RestartFreqExceeded</code>. Please try starting your <code>RabbitMQ</code> server and run your celery. </p>
| 1 | 2016-07-12T04:27:44Z | [
"python",
"celery",
"django-celery",
"celerybeat",
"djcelery"
] |
Rotating map plot using basemap in python | 38,319,980 | <p>I am trying to plot data from a netcdf using <code>Basemap</code> but I guess since the latitude indices are inverted I get a map that is upside down. How should I fix this? Thanks!</p>
<pre><code>fnc = Dataset(ncfile, 'r')
lat = fnc.variables['latitude'][:]
lon = fnc.variables['longitude'][:]
level = fnc.variables... | 0 | 2016-07-12T04:22:13Z | 38,335,852 | <p>First, note that you're currently reading in one dimension of <code>Data</code>:</p>
<pre><code>mydata = fnc.variables['Data'][:]
</code></pre>
<p>but later you're trying to extract slices of it as if it were 4D:</p>
<pre><code>imgplot = plt.imshow(mydata[0, 0, :, :])
</code></pre>
<p>So, you'll want to read-in ... | 1 | 2016-07-12T17:52:17Z | [
"python",
"gis",
"netcdf",
"matplotlib-basemap",
"netcdf4"
] |
Rotating map plot using basemap in python | 38,319,980 | <p>I am trying to plot data from a netcdf using <code>Basemap</code> but I guess since the latitude indices are inverted I get a map that is upside down. How should I fix this? Thanks!</p>
<pre><code>fnc = Dataset(ncfile, 'r')
lat = fnc.variables['latitude'][:]
lon = fnc.variables['longitude'][:]
level = fnc.variables... | 0 | 2016-07-12T04:22:13Z | 38,335,883 | <p>I believe that plotting command needs to be aware of the map coordinates x,y. Try to replace the </p>
<pre><code>im = m.imshow(mydata[0, 0, :, :])
</code></pre>
<p>with</p>
<pre><code>m.pcolormesh(x,y,mydata[0,0,:,:])
</code></pre>
<p>and it should work.</p>
| 0 | 2016-07-12T17:54:15Z | [
"python",
"gis",
"netcdf",
"matplotlib-basemap",
"netcdf4"
] |
How to cache Django Rest Framework API calls? | 38,320,008 | <p>I'm using Memcached as backend to my django app. This code works fine in normal django query:</p>
<pre><code>def get_myobj():
cache_key = 'mykey'
result = cache.get(cache_key, None)
if not result:
result = Product.objects.all().filter(draft=False)
cache.set(cache_key,... | 0 | 2016-07-12T04:25:35Z | 38,346,728 | <p>Ok, so, in order to use caching for your queryset:</p>
<pre><code>class ProductListAPIView(generics.ListAPIView):
def get_queryset(self):
return get_myobj()
serializer_class = ProductSerializer
</code></pre>
<p>You'd probably want to set a timeout on the cache set though (like 60 seconds):</p>
<pre><c... | 2 | 2016-07-13T08:43:09Z | [
"python",
"django",
"caching",
"django-rest-framework",
"memcached"
] |
Indexing very large csv files in Python | 38,320,009 | <p>I feel like this is a very stupid question, but I'm unable to think about the problem anymore. </p>
<p>I have a very large amount of data (60+GB) in csv format ordered by id:</p>
<pre><code>id, "{data}"
id2, "{data}"
...
</code></pre>
<p>I have another set of data that needs to be combined with this data in a dic... | 0 | 2016-07-12T04:25:44Z | 38,320,126 | <pre><code>def get_row(id):
with open("fname.csv") as f:
row = next(itertools.islice(f,id-1,id),None)
return row
</code></pre>
<p>its still going to be painfully slow ... you should think about using a database ... or at the very least storing the data as fixed width entries (ie always 37 bytes per... | 0 | 2016-07-12T04:37:22Z | [
"python",
"csv",
"indexing"
] |
Get class's method return outside of class itself | 38,320,012 | <p>I'm new in Python, so please give possibly detailed explanation.
So, I have code where I post form via ajax on /query an then obtain data on server to return for displaying on template /search:</p>
<p>views.py</p>
<pre><code>class SomeClass(View):
def post(self, request, *args, **kwargs):
if request.m... | 1 | 2016-07-12T04:26:04Z | 38,321,003 | <p>I think your example code is not really clear. So I'll attempt to answer, generally, the actual question.</p>
<p>Basically, a class method is just a function that operates on the class instance, passed in as implicit argument usually named "self". </p>
<pre><code>class SomeClass:
def some_method(self, request... | 0 | 2016-07-12T05:56:47Z | [
"python",
"django"
] |
Get class's method return outside of class itself | 38,320,012 | <p>I'm new in Python, so please give possibly detailed explanation.
So, I have code where I post form via ajax on /query an then obtain data on server to return for displaying on template /search:</p>
<p>views.py</p>
<pre><code>class SomeClass(View):
def post(self, request, *args, **kwargs):
if request.m... | 1 | 2016-07-12T04:26:04Z | 38,321,281 | <p>You need to add the results to the context that you are returning; to do that use <code>get_context_data</code>, available from the <a href="https://docs.djangoproject.com/en/1.9/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin" rel="nofollow"><code>ContextMixin</code></a>.</p>
<p>To disp... | 0 | 2016-07-12T06:17:14Z | [
"python",
"django"
] |
How to change working directory in Python 2.7(Anaconda 4.0.1) | 38,320,109 | <p>everyone. I'm new to this community and currently learning some Python language. I am having problem setting new working directory.</p>
<p>I read many posts posted here in this website and I tried(Sorry, I couldn't figure it out how to write code in here but...)</p>
<p>import os</p>
<p>os.chdir('(Working director... | -1 | 2016-07-12T04:36:22Z | 38,320,526 | <p>Sounds like you are typing commands directly into the interpreter. If so when you close the interpreter it dose not remember what you did in the last session. Try saving your code in a .py file. Gedit works well for editing .py files. After saving your file open the terminal and change directories to the location of... | 0 | 2016-07-12T05:16:41Z | [
"python",
"python-2.7"
] |
why tkinter now working properly for python when file run with terminal in mac | 38,320,248 | <p>I'm using <code>tkinter</code> to build <code>gui</code> with my mac.normally I'm using python <code>IDLE</code> to run and test the code.I created a new file with <code>.py</code> extension and run it.it works properly.this is the code.</p>
<pre><code>from tkinter import *
mywin = Tk();
mywin.title("window for m... | 0 | 2016-07-12T04:51:14Z | 38,322,209 | <p>Idle and Terminal python version are different !
Need using same version of Python.</p>
<p>No module named tkinter is python2.X error ! No module named Tkinter is python3.X error.</p>
| 2 | 2016-07-12T07:11:46Z | [
"python",
"osx",
"python-2.7",
"tkinter"
] |
Do I have to create a whole new array to store results from convolution? | 38,320,316 | <p>I was playing with my convolution algorithm in Python and I noticed that while sliding the filter along the <em>original</em> array and updating entries therein, the result came out quite murky:</p>
<p><a href="http://i.stack.imgur.com/A7qsp.gif" rel="nofollow"><img src="http://i.stack.imgur.com/A7qsp.gif" alt="ent... | 0 | 2016-07-12T04:57:43Z | 38,320,467 | <p>You should use a second array to store the result. Otherwise you are basing most of your calculations on <em>pixels you have already changed</em> instead of on the original pixels that were in the image. That's why your first example changes more than you expect.</p>
<p>Technically you <em>can</em> do it without a ... | 4 | 2016-07-12T05:11:29Z | [
"python",
"convolution"
] |
How do I get Django multi-argument url tags working? | 38,320,336 | <p>I can't figure out which part I'm mucking up!</p>
<p>The error I'm getting is:</p>
<blockquote>
<p>Reverse for 'update_rating' with arguments '()' and keyword arguments
'{u'pk': 9, u'on_title': True}' not found. 1 pattern(s) tried:
['y/update_rating/(?P[\w-]+)/(?P[True|False])$']</p>
</blockquote>
<p><stron... | 0 | 2016-07-12T04:59:36Z | 38,320,464 | <p>Problem with this pattern: </p>
<pre><code>url('^update_rating/(?P<pk>[\w-]+)/(?P<on_title>[True|False])$', views.update_rating, name='update_rating')
</code></pre>
<p>You passed wrong regexp to variables, <code>pk</code> must match integers so <code>\d+</code> and booleans must match words <code>\w... | 2 | 2016-07-12T05:11:10Z | [
"python",
"django",
"django-templates",
"django-views"
] |
Python: Matplotlib legend with custom labelspacing | 38,320,353 | <p>I know that in Python's matlplotlib legend function we can adjust the spacing between the labels using "labelspacing", for example:</p>
<pre><code>lgd = ax.legend(..., labelspacing=2)
</code></pre>
<p>but can I have a more custom spacing between labels where for example the space between the first two labels is <e... | 0 | 2016-07-12T05:01:54Z | 38,340,037 | <p>Looks like there's no easy way to do this, as <code>plt.legend</code> uses a <code>VPacker</code> to manage the entries in the legend: <a href="https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/legend.py#L713" rel="nofollow">https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/legend... | 1 | 2016-07-12T22:46:33Z | [
"python",
"matplotlib"
] |
String fails to paste in the new iPython 5.0 | 38,320,372 | <p>In the python 2.7 console, as well as iPython 4, I was able to paste this string into a variable like so:</p>
<pre><code>In [2]: c = 'ÃjÃÃñõµÃâJÃq´ž#»&â¢Â¼Â²nÃòQZ<_'
</code></pre>
<p>Subsequently I could type:</p>
<p><code>In [3]: print(c)</code> and it would return <code>ÃjÃÃñõµÃ... | 4 | 2016-07-12T05:02:50Z | 38,321,863 | <p><a href="http://blog.jupyter.org/2016/07/08/ipython-5-0-released/" rel="nofollow">http://blog.jupyter.org/2016/07/08/ipython-5-0-released/</a></p>
<p>Ipython5 replaced the default <code>readline</code> with a new prompt_toolkit. </p>
<p>It looks like your string has several characters that the old readline ignor... | 1 | 2016-07-12T06:51:32Z | [
"python",
"string",
"ipython",
"non-ascii-characters"
] |
Send value when python script ask choice with php | 38,320,401 | <p>I want to sending data from php frontend to python. I have the following php code.</p>
<pre><code>shell_exec ("sudo python /python/ba10e.py >/dev/null 2>&1 &");
</code></pre>
<p>With the above code, sending data to python works, However when python program asks for a choice mentioned below:</p>
<pre... | 0 | 2016-07-12T05:06:03Z | 38,320,779 | <p>Since you are looking for communication rather than just script invocation, I think you should look at inter-process communication methods, such as sockets. You can find plenty of resources online on how to do this, <a href="https://docs.python.org/3/howto/sockets.html" rel="nofollow">here's</a> one from the python ... | 0 | 2016-07-12T05:38:53Z | [
"php",
"python"
] |
TypeError while entering information into database | 38,320,438 | <p>I have written the following piece of code to enter information into a database.</p>
<pre><code>import sqlite3
with sqlite3.connect('highscores.db') as conn:
#Python 3 users, change raw_input to input.
user = raw_input('Name: ')
score = int(raw_input('Score: '))
result = conn.execute("SELECT * FRO... | 0 | 2016-07-12T05:08:50Z | 38,320,489 | <p>From <a href="https://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor.fetchone" rel="nofollow">https://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor.fetchone</a>:</p>
<pre><code>fetchone()
Fetches the next row of a query result set, returning a single sequence, or None when no more data is available.
... | 1 | 2016-07-12T05:13:01Z | [
"python",
"sqlite3"
] |
Check key, value of nested dictionary in python? | 38,320,480 | <p>I'm generating a nested dictionary in my program. After generating, I want to iterate through that dictionary, and check for the dictionary key and value.</p>
<p><strong>Program-Code</strong></p>
<p>This is the dictionary I want to iterate whose value contains another dictionary. </p>
<pre><code> main_dict = {10... | 0 | 2016-07-12T05:12:15Z | 38,321,098 | <p>As the comments pointed out, you are not checking if <code>line</code> is of length 3:</p>
<pre><code>for line in reader:
if not len(line) == 3:
continue
</code></pre>
<p>Concerning your algorithm, I would use nested <code>defaultdict</code> to avoid the if/else lines.</p>
<p>EDIT: I added a new defau... | 0 | 2016-07-12T06:04:09Z | [
"python",
"dictionary"
] |
Modify Class Object Argument Based On When Calling A Method | 38,320,491 | <p>This is a heavily simplified version of what I am working on, I just don't want to put 5,000 lines in here. So I know this works and all, but I want to be able to have the method"eat" be able to be applied non-specifically to any object that this class parents (such as "John Smith", and adding lets say "Mike Doe".) ... | 0 | 2016-07-12T05:13:23Z | 38,320,588 | <p>Just use <code>self</code>:</p>
<pre><code>def eat(self):
self.hunger = False
print("%s Ate Food" % self.name)
</code></pre>
| 0 | 2016-07-12T05:21:50Z | [
"python",
"object",
"methods"
] |
Python IOError: [Errno 2] No such file or directory: | 38,320,722 | <p>I am just trying to open an image, I know there are several IOError questions on here, but I have not been able to understand the explanations.</p>
<p>The code i typed is here</p>
<pre><code>from PIL import Image
image = Image.open("Lenna.png")
image.load()
</code></pre>
<p>The error obtained is as follows:</p>
... | -4 | 2016-07-12T05:33:32Z | 38,320,790 | <blockquote>
<p>IOError: [Errno 2] No such file or directory: 'Lenna.png'</p>
</blockquote>
<p>check path of the file</p>
| 0 | 2016-07-12T05:39:47Z | [
"python",
"pillow"
] |
Python IOError: [Errno 2] No such file or directory: | 38,320,722 | <p>I am just trying to open an image, I know there are several IOError questions on here, but I have not been able to understand the explanations.</p>
<p>The code i typed is here</p>
<pre><code>from PIL import Image
image = Image.open("Lenna.png")
image.load()
</code></pre>
<p>The error obtained is as follows:</p>
... | -4 | 2016-07-12T05:33:32Z | 38,320,806 | <p>You are trying to use relative filename. Python can't find such file in current work dir. Try to use full absolute path such as 'C:\Lenna.png'.</p>
| 0 | 2016-07-12T05:41:06Z | [
"python",
"pillow"
] |
Create dictionary with count of each unique item from an excel column | 38,320,776 | <p>I have a column in excel with a header. The column contains 25-30 unique values in them and is totally 28000 rows long. I want my output to be a dictionary with keys being each unique item from the column and values being its count</p>
<pre><code>df1 = pandas.read_excel(file,sheet)
Counter(df1)
</code></pre>
<p>a... | 0 | 2016-07-12T05:38:33Z | 38,320,852 | <p><code>Counter</code> counts the items in an iterable. When you iterate over a dataframe, it iterates over the column names. That is why <code>Counter</code> is simply returning the name of the column with a count of 1. You need to count the items in a column of the dataframe, so you need to do something like this:</... | 1 | 2016-07-12T05:45:14Z | [
"python",
"pandas",
"counter"
] |
Create dictionary with count of each unique item from an excel column | 38,320,776 | <p>I have a column in excel with a header. The column contains 25-30 unique values in them and is totally 28000 rows long. I want my output to be a dictionary with keys being each unique item from the column and values being its count</p>
<pre><code>df1 = pandas.read_excel(file,sheet)
Counter(df1)
</code></pre>
<p>a... | 0 | 2016-07-12T05:38:33Z | 38,320,967 | <p>Another way to return the dictionary without using collections is</p>
<pre><code>dict(df1["column_header"].value_counts())
</code></pre>
| 0 | 2016-07-12T05:54:04Z | [
"python",
"pandas",
"counter"
] |
OpenCV-Python: How to detect a hotspot in thermal image? | 38,320,796 | <p>I am using openCV and Python to make a computer vision application that detects hotspots in an image from thermal cameras. </p>
<p>The image is basically of a big machinery and I want to get the hottest (in terms of temperature) part of the image.<br>
What I thought of till now:</p>
<ol>
<li>Use color quantizatio... | 2 | 2016-07-12T05:40:11Z | 38,326,066 | <p>In order to estimate a threshold dynamically, you need to look at the distribution of the data. For this purpose, you need to calculate the histogram of the red.
Then, find a threshold such that a certain percentage of the pixels are below it. For example 90%.</p>
| 2 | 2016-07-12T10:20:00Z | [
"python",
"opencv",
"computer-vision",
"cluster-analysis"
] |
Python ignoring if statement in while loop | 38,320,805 | <p>I recently finished learning Python on Codecademy, so I decided to make a rock, paper, scissors game for my first real program since it seemed fairly simple.</p>
<p>When testing the program, Python seems to ignore the big if/elif statement that's nested within the while loop. The game generates a random integer (0 ... | 0 | 2016-07-12T05:41:04Z | 38,320,863 | <p>you are missing to return from method choose, and catching it with </p>
<pre><code>humanchoice = choose()
</code></pre>
| 0 | 2016-07-12T05:46:11Z | [
"python",
"python-2.7"
] |
Python ignoring if statement in while loop | 38,320,805 | <p>I recently finished learning Python on Codecademy, so I decided to make a rock, paper, scissors game for my first real program since it seemed fairly simple.</p>
<p>When testing the program, Python seems to ignore the big if/elif statement that's nested within the while loop. The game generates a random integer (0 ... | 0 | 2016-07-12T05:41:04Z | 38,321,120 | <p><code>choose()</code> does not return a value. Therefore it always returns <code>None</code>. <code>None</code> will never be equal to <code>0</code>. Therefore your <code>if</code> statement is never triggered.</p>
<p>In Python 3 comparing <code>None</code> and <code>0</code> would actually be an error, which woul... | 0 | 2016-07-12T06:05:12Z | [
"python",
"python-2.7"
] |
How do the server distinguish whether it is a robot or a human when using selenium webdriver to crawl web pages? | 38,320,811 | <p>Our lab has cooperation with a web company, it has developed technology that can protect web pages from being crawled by web-crawler.The testing website is <a href="http://119.254.209.77/" rel="nofollow">http://119.254.209.77/</a> .I can't get urls on the page of left part such as "Checking". It will create a url ju... | 0 | 2016-07-12T05:41:32Z | 38,321,251 | <p>Seems like the site is checking to see where you're mouse is before passing you to the next page. Moving to the element before clicking it works for me:</p>
<pre><code>driver = webdriver.Chrome()
driver.get('http://119.254.209.77/')
time.sleep(5)
pageSource = driver.page_source
print(driver.page_source)
# the targe... | 1 | 2016-07-12T06:15:33Z | [
"python",
"selenium",
"firefox",
"web-crawler"
] |
How can I execute the code line by line in jupyter-notebook? | 38,320,837 | <p>I'm reading the book, <code>Python Machine Learning</code>, and tried to analyze the code. But it offers only <code>*.ipynb</code> file and it makes me very bothersome.</p>
<p>For example, </p>
<p><a href="http://i.stack.imgur.com/VVzTb.png" rel="nofollow"><img src="http://i.stack.imgur.com/VVzTb.png" alt="enter i... | 2 | 2016-07-12T05:43:41Z | 38,330,690 | <p>You can just add new cells, then cut-and-paste the parts you want to the new cells. So, for example, you can put the imports and <code>%matplotlib inline</code> in the first cell (since those only ever need to be run when the notebook is first opened), the <code>y</code> generation in the second, the <code>X</code>... | 0 | 2016-07-12T13:44:39Z | [
"python",
"ipython",
"ipython-notebook",
"jupyter",
"jupyter-notebook"
] |
How to replace a contour (rectangle) in an image with a new image using Python? | 38,320,865 | <p>I'm currently using the opencv (CV2) and Python Pillow image library to try and take an image of arbitrary phones and replace the screen with a new image. I've gotten to the point where I can take an image and identify the screen of the phone and get all the coordinates for the corner, but I'm having a really hard t... | 1 | 2016-07-12T05:46:18Z | 38,321,072 | <p>You can overlay the new image (rotated to screen orientation of the phone) on to the original image by</p>
<pre><code>import cv2
A_img = cv2.imread("new_image.png")
B_img = cv2.imread("larger_image.jpg")
x_offset=y_offset=50
B_img[y_offset:y_offset+A_img.shape[0], x_offset:x_offset+A_img.shape[1]] = A_img
</code></... | 0 | 2016-07-12T06:01:44Z | [
"python",
"opencv",
"image-processing",
"computer-vision",
"pillow"
] |
How to replace a contour (rectangle) in an image with a new image using Python? | 38,320,865 | <p>I'm currently using the opencv (CV2) and Python Pillow image library to try and take an image of arbitrary phones and replace the screen with a new image. I've gotten to the point where I can take an image and identify the screen of the phone and get all the coordinates for the corner, but I'm having a really hard t... | 1 | 2016-07-12T05:46:18Z | 38,323,528 | <p>I downloaded your image data and reproduced the problem in my local machine to find out the solution. Also downloaded <code>lenna.png</code> to fit inside the phone screen.</p>
<pre><code>import cv2
import numpy as np
# Template image of iPhone
img1 = cv2.imread("/Users/anmoluppal/Downloads/46F1U.jpg")
# Sample im... | 0 | 2016-07-12T08:23:40Z | [
"python",
"opencv",
"image-processing",
"computer-vision",
"pillow"
] |
Why this simple Tensorflow code is not successful? (ConvnetJS using Tensorflow) | 38,321,024 | <p>There is an simple and educational toy classifier (2 fully connected layers) as JAVA applet: <a href="http://cs.stanford.edu/people/karpathy/convnetjs/demo/classify2d.html" rel="nofollow">http://cs.stanford.edu/people/karpathy/convnetjs/demo/classify2d.html</a></p>
<p>Here, input is a list of 2D pts with {0,1} labe... | 1 | 2016-07-12T05:58:09Z | 38,368,469 | <p>After having a closer look, it seems to me there is no problem with the loss definition.</p>
<hr>
<p>I have found some parameter definitions differ from the original <a href="http://cs.stanford.edu/people/karpathy/convnetjs/demo/classify2d.html" rel="nofollow">ConvNetJS demo</a>. Choosing the same parameters did n... | 2 | 2016-07-14T07:51:12Z | [
"python",
"tensorflow"
] |
ImportError: No module named readability | 38,321,055 | <p>i install python readability from : <a href="https://github.com/buriy/python-readability" rel="nofollow">https://github.com/buriy/python-readability</a></p>
<p>i can use: </p>
<pre><code>python -m readability.readability -u http://pypi.python.org/pypi/readability-lxml
</code></pre>
<p>but when i use in readabilit... | 0 | 2016-07-12T06:00:00Z | 38,321,122 | <p>It's trying to import your file. Simply rename it. </p>
<blockquote>
<p>File "<strong>readability.py</strong>", line 1, in from<br>
readability.readability import Document<br>
ImportError: No module named readability</p>
</blockquote>
| 1 | 2016-07-12T06:05:30Z | [
"python",
"readability"
] |
Groupby a data set in Python | 38,321,102 | <p>I have 30 years of daily data. I want to calculate average daily over 30 years. For example, I have data like this</p>
<pre><code>1/1/2036 0
1/2/2036 73.61180115
1/3/2036 73.77733612
1/4/2036 73.61183929
1/5/2036 73.75443268
1/6/2036 73.58483887
.........
12/22/2065 73.90600586
12/23/2065 74.3... | 2 | 2016-07-12T06:04:14Z | 38,321,548 | <p>You can pass a function to <code>df.groupby</code> which will act on the indices to make the groups. So, for you, use:</p>
<pre><code>df.groupby(lambda x: (x.day,x.month)).mean()
</code></pre>
| 1 | 2016-07-12T06:33:34Z | [
"python",
"pandas"
] |
Groupby a data set in Python | 38,321,102 | <p>I have 30 years of daily data. I want to calculate average daily over 30 years. For example, I have data like this</p>
<pre><code>1/1/2036 0
1/2/2036 73.61180115
1/3/2036 73.77733612
1/4/2036 73.61183929
1/5/2036 73.75443268
1/6/2036 73.58483887
.........
12/22/2065 73.90600586
12/23/2065 74.3... | 2 | 2016-07-12T06:04:14Z | 38,323,388 | <p>Consider the following series <code>s</code></p>
<pre><code>days = pd.date_range('1986-01-01', '2015-12-31')
s = pd.Series(np.random.rand(len(days)), days)
</code></pre>
<p>then what you're looking for is:</p>
<pre><code>s.groupby([s.index.month, s.index.day]).mean()
</code></pre>
<hr>
<h3>Timing</h3>
<p>@juan... | 1 | 2016-07-12T08:16:07Z | [
"python",
"pandas"
] |
How to use pointer to typedef struct in Cython Extension Type | 38,321,205 | <p>Say I have the following <code>typedef struct</code> in my header file <code>example.h</code>:</p>
<pre><code>typedef struct A A;
</code></pre>
<p>I am tring to make a Cython Extension Type with a pointer to <code>A</code> as a class variable in <code>test.pyx</code>, and then I call an initialization function <co... | 0 | 2016-07-12T06:12:53Z | 38,326,675 | <p>This is because you have to declare it before you use it. For example you have this in your c code <code>example.h</code> :</p>
<pre><code>typedef struct struct_name{
int a;
float b;
}struct_alias;
</code></pre>
<p>Then your <code>.pyx</code> file should look like:</p>
<pre><code>cdef extern from "example... | 1 | 2016-07-12T10:47:16Z | [
"python",
"cython"
] |
How to get details of a facebook post from post url using facebook api? | 38,321,207 | <p>I want to fetch the details of a facebook post from the post's url. The post will be a public post.</p>
<p>Is it possible to do this via facebook api? If its possible,how?(a link or explanation)</p>
<p>I tried reading through graph api. But I couldn't find the relevant information.</p>
| -2 | 2016-07-12T06:12:57Z | 38,328,369 | <p>You can get any object by fetching it by id and passing encoded url as id. It was working for me as far as now anyway.</p>
<p>simply call:</p>
<pre><code>https://graph.facebook.com/v2.6/?id=[ENCODED_URL]&access_token=[TOKEN]
</code></pre>
<p>Also. Post url contains id anyway, so you can just extract the id fr... | 0 | 2016-07-12T12:02:15Z | [
"python",
"facebook",
"facebook-graph-api"
] |
how to use dot production on batch data? | 38,321,248 | <p>I am trying to apply <strong>tanh(dot(x,y))</strong>;
x and y are batch data of my RNN. </p>
<p>x,y have shape (n_batch, n_length, n_dim) like (2,3,4) ; 2 samples with 3 sequences, each is 4 dimensions.</p>
<p>I want to do inner or dot production to last dimension. Then tanh(dot(x,y)) should have shape of (n_bat... | 0 | 2016-07-12T06:15:11Z | 38,353,930 | <p>This expression should do the trick:</p>
<blockquote>
<p>theano.tensor.tanh((x * y).sum(2))</p>
</blockquote>
<p>The dot product is computed 'manually' by doing element-wise multiplication, then summing over the last dimension.</p>
| 0 | 2016-07-13T14:03:48Z | [
"python",
"numpy",
"theano",
"deep-learning",
"keras"
] |
Error was retrieving data from S3 using boto for python | 38,321,360 | <p>I'm trying to get data from Amazon S3 using boto for python.</p>
<pre><code>from boto.s3.connection import S3Connection
AWS_KEY = 'MY_KEY'
AWS_SECRET = 'MY_SECRET'
aws_connection = S3Connection(AWS_KEY, AWS_SECRET)
bucket = aws_connection.get_bucket('s3://mybucket.buckets.com/')
for file_key in bucket.list():
... | 0 | 2016-07-12T06:22:35Z | 38,322,646 | <p>You just need to pass the name of you bucket, not a seamless URL (note that s3 endpoint would be <a href="http://s3-aws-region.amazonaws.com/bucket" rel="nofollow">http://s3-aws-region.amazonaws.com/bucket</a>)</p>
<p>If you're using boto2</p>
<pre><code>from boto.s3.connection import S3Connection
AWS_KEY = 'MY_K... | 1 | 2016-07-12T07:35:21Z | [
"python",
"amazon-web-services",
"amazon-s3",
"boto"
] |
Subtract consecutive columns in a Pandas or Pyspark Dataframe | 38,321,427 | <p>I would like to perform the following operation in a pandas or pyspark dataframe but i still havent found a solution.</p>
<p>I want to subtract the values from consecutive columns in a dataframe.</p>
<p>The operation I am describing can be seen in the image below.</p>
<p><a href="http://i.stack.imgur.com/ZQgOH.jp... | 3 | 2016-07-12T06:26:43Z | 38,321,574 | <pre><code>df = pd.DataFrame(np.random.rand(3, 4), ['row1', 'row2', 'row3'], ['A', 'B', 'C', 'D'])
df.T.diff().T
</code></pre>
<p><a href="http://i.stack.imgur.com/IkRpR.png" rel="nofollow"><img src="http://i.stack.imgur.com/IkRpR.png" alt="enter image description here"></a></p>
| 2 | 2016-07-12T06:35:14Z | [
"python",
"pandas",
"pyspark",
"multiple-columns",
"subtract"
] |
Subtract consecutive columns in a Pandas or Pyspark Dataframe | 38,321,427 | <p>I would like to perform the following operation in a pandas or pyspark dataframe but i still havent found a solution.</p>
<p>I want to subtract the values from consecutive columns in a dataframe.</p>
<p>The operation I am describing can be seen in the image below.</p>
<p><a href="http://i.stack.imgur.com/ZQgOH.jp... | 3 | 2016-07-12T06:26:43Z | 38,323,285 | <p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.diff.html" rel="nofollow"><code>diff</code></a> has an <code>axis</code> param so you can just do this in one step:</p>
<pre><code>In [63]:
df = pd.DataFrame(np.random.rand(3, 4), ['row1', 'row2', 'row3'], ['A', 'B', 'C', 'D'])
df
Out[... | 3 | 2016-07-12T08:10:26Z | [
"python",
"pandas",
"pyspark",
"multiple-columns",
"subtract"
] |
how to get a full list from a function python | 38,321,500 | <p>I'm totally new about python. So here is my issue.</p>
<pre><code>def visitdir(path):
result = []
for root,dirs,files in os.walk(path):
for filepath in files:
result = ''.join(os.path.join(root,filepath))
print result
if __name__ == '__main__':
path = raw_inpu... | 0 | 2016-07-12T06:30:44Z | 38,321,586 | <p>When you call <code>return</code> you finish the function flow and return the value.
Also why do you create the list 'result' and then override it with the string?</p>
<p>I think what you meant to do is something like this:</p>
<pre><code>def visitdir(path):
result = []
for root,dirs,files in os.walk(path... | 0 | 2016-07-12T06:36:01Z | [
"python"
] |
how to get a full list from a function python | 38,321,500 | <p>I'm totally new about python. So here is my issue.</p>
<pre><code>def visitdir(path):
result = []
for root,dirs,files in os.walk(path):
for filepath in files:
result = ''.join(os.path.join(root,filepath))
print result
if __name__ == '__main__':
path = raw_inpu... | 0 | 2016-07-12T06:30:44Z | 38,321,606 | <p><code>return</code> terminates execution of given function.</p>
<p>One of easiest ways of doing it would be to <code>yield</code> values and make generator from your function.</p>
<pre><code>def visitdir(path):
for root,dirs,files in os.walk(path):
for filepath in files:
result = ''.join(os... | 0 | 2016-07-12T06:37:01Z | [
"python"
] |
how to get a full list from a function python | 38,321,500 | <p>I'm totally new about python. So here is my issue.</p>
<pre><code>def visitdir(path):
result = []
for root,dirs,files in os.walk(path):
for filepath in files:
result = ''.join(os.path.join(root,filepath))
print result
if __name__ == '__main__':
path = raw_inpu... | 0 | 2016-07-12T06:30:44Z | 38,321,625 | <p>You should append the results to the results list that you created.</p>
<pre><code>def visitdir(path):
result = []
for root,dirs,files in os.walk(path):
for filepath in files:
result.append(''.join(os.path.join(root,filepath)))
return result
if __name__ == '__main__':
path = raw_... | 0 | 2016-07-12T06:37:46Z | [
"python"
] |
Is it possible in python to store a time counter inside a database that counts down, when the counter is stop, it will be able to call some API? | 38,321,556 | <p><strong>Is it possible in python programming to store a time counter inside a database that counts down, and when the counter is about to run down, it will be able to call some API and change a particular person record update on my API...</strong></p>
<p>i am reach some website but it's not a my solution</p>
<p>li... | -1 | 2016-07-12T06:34:10Z | 38,325,084 | <p>you and write a handler and monitor that particular table in DB and return the status result if it satisfies that condition </p>
| 0 | 2016-07-12T09:36:07Z | [
"python",
"mysql",
"flask-sqlalchemy"
] |
Why is the order of multiple `for` list comprehension the way it is? | 38,321,559 | <p>I know the right way to have multiple <code>for</code> in a nested list comprehension is as follows (Python 3):</p>
<pre><code>lista = [[[1,2],[3],[4,5,6]],[[7],[8,9]]]
flatlista = [i for k in lista for j in k for i in j]
# results with [1, 2, 3, 4, 5, 6, 7, 8, 9]
</code></pre>
<p>But my natural language instinct... | -2 | 2016-07-12T06:34:30Z | 38,321,692 | <p>Because that's what <a href="https://www.python.org/dev/peps/pep-0202/" rel="nofollow">PEP 202 -- <em>List Comprehensions</em></a> set it to. The PEP doesn't quite motivate why however, as it was created as an afterthought; the discussion had taken place on the development lists years before the PEP was created, or ... | 5 | 2016-07-12T06:41:37Z | [
"python",
"python-3.x",
"syntax"
] |
OpenCV 3.1 - Cannot find library of opencv_contrib | 38,321,666 | <p>I've installed OpenCV3.1 with Python 2.7 on Ubuntu following this <a href="http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/" rel="nofollow">link</a>. For short, when building the library, I've passed this flag</p>
<p><code>cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_... | 0 | 2016-07-12T06:40:00Z | 38,322,762 | <p>Did you Download the OpenCV contrib package and place it in the specified location ? If not then download it from <a href="https://github.com/opencv/opencv_contrib" rel="nofollow">here</a></p>
<p>Then Put it inside a specific folder and while compiling it with Cmake give the path(absolute path) till <em>modules</e... | 0 | 2016-07-12T07:41:32Z | [
"python",
"c++",
"opencv"
] |
eval vs json conversion and parsing of a dictionary like string | 38,321,676 | <p>It's been a while since my last python project so I'm a bit rusty -- feel free to offer any advise or criticism where due -- so I have a few questions regarding eval and JSON.</p>
<p>For this project I'm limited to Python 2.6 default library -- I'm attempting to parse the database contents of a proprietary Linux ba... | 2 | 2016-07-12T06:40:37Z | 38,322,681 | <p>Generally, when running a single command with <code>subprocess</code> you don't need <code>shell=True</code> if you make the command name and each option a separate string, i.e </p>
<pre><code>['cmd', 'arg1', 'arg2']
</code></pre>
<p>You <em>do</em> need <code>shell=True</code> to execute commands that are interna... | 2 | 2016-07-12T07:37:09Z | [
"python",
"json",
"dictionary",
"eval",
"abstract-syntax-tree"
] |
Pytables check if column exists | 38,321,684 | <p>Is it possible to use Pytables (or Pandas) to detect whether a hdf file's table contains a certain column? To load the hdf file I use:</p>
<pre><code>from pandas.io.pytables import HDFStore
# this doesn't read the full file which is good
hdf_store = HDFStore('data.h5', mode='r')
# returns a "Group" object, not sure... | 2 | 2016-07-12T06:41:06Z | 38,323,230 | <p>I may have found a solution, but am unsure of (1) why it works and (2) whether this is a robust solution.</p>
<pre><code>import tables
h5 = tables.openFile('data.h5', mode='r')
df_node = h5.root.__getattr__('tablename')
# Not sure why `axis0` contains the column data, but it seems consistent
# with the tested h5 fi... | 2 | 2016-07-12T08:07:08Z | [
"python",
"pandas",
"pytables"
] |
fast way to substitute string pairs in file | 38,321,747 | <p>I have a file with ~10,000 lines containing 2 columns: </p>
<blockquote>
<p><code>org_string1 \t replacement_string1</code></p>
<p><code>org_string2 \t replacement_string2</code></p>
</blockquote>
<p>What is the best way (speed/convenience) to substitute all these org_string with their corresponding replace... | 0 | 2016-07-12T06:45:18Z | 38,326,239 | <p>Here's a technique using Perl which may help:</p>
<pre><code>my %map = (
'the' => 'a',
'fox' => 'frog',
'jumps' => 'somersaults'
);
my $line = "the quick bown fox jumps over the lazy dog";
$line =~ s{\b(\w+)\b}{$map{$1} // $1}eg;
say $line;
</code></pre>
<p>This example uses a hard-code... | 3 | 2016-07-12T10:27:49Z | [
"python",
"perl",
"sed",
"substitution"
] |
Extend queryset in django python | 38,321,791 | <p>I am looking for way how to add new objects to existing queryset, or how to implement what I want by other way. </p>
<p><code>contact = watson.filter(contacts, searchline)
</code> This line returns queryset, which I later use to iterate.</p>
<p>Then I want to do this to add more objects, which watson couldn't find... | 0 | 2016-07-12T06:48:03Z | 38,321,900 | <p>You can use | and Q lookups. See <a href="https://docs.djangoproject.com/en/1.9/topics/db/queries/#complex-lookups-with-q-objects" rel="nofollow">the docs</a>.</p>
<p>I'm not sure I've fully understood your initial query, but I think that in your case you would want to do:</p>
<pre><code>query = Q(contacts='Foo', ... | 0 | 2016-07-12T06:53:44Z | [
"python",
"django"
] |
Extend queryset in django python | 38,321,791 | <p>I am looking for way how to add new objects to existing queryset, or how to implement what I want by other way. </p>
<p><code>contact = watson.filter(contacts, searchline)
</code> This line returns queryset, which I later use to iterate.</p>
<p>Then I want to do this to add more objects, which watson couldn't find... | 0 | 2016-07-12T06:48:03Z | 38,324,384 | <p>You should look at a queryset as a sql query that will be executed later. When constructing a queryset and save the result in a variable, you can later filter it even more, but you can not expand it. If you need a query that has more particular rules (like, you need an OR operation) you should state that when you ar... | 0 | 2016-07-12T09:04:04Z | [
"python",
"django"
] |
Python SSH Server(twisted.conch) change the password prompt | 38,321,820 | <p>I wrote a SSH server with Twisted Conch. When I execute "ssh username@xx.xx.xx.xx" command on the client side. My twisted SSH server will return a prompt requesting password that like "username@xx.xx.xx.xx's password: ".
But now I want to change this password prompt that like "your codes is:". Dose anyone know ho... | 0 | 2016-07-12T06:49:24Z | 38,324,034 | <p>The password prompt is part of keyboard-authentication which is part of the ssh protocol and thus cannot be changed. Technically, the prompt is actually client side. However, you can bypass security (very bad idea) and then output "your codes is"[sic] via the channel</p>
| 0 | 2016-07-12T08:48:34Z | [
"python",
"ssh",
"twisted.conch",
"password-prompt"
] |
How to parallel a Theano function using multiprocessing? | 38,321,879 | <p>I have a function returned by theano.function(), and I want to use it within multiprocessing for speedup. The following is a simplified demo script to show where I run into problem:</p>
<pre><code>import numpy as np
from multiprocessing import Pool
from functools import partial
import theano
from theano import tens... | 1 | 2016-07-12T06:52:38Z | 38,343,602 | <p>Turns out it's related with the partial() function. The full explanation is here <a href="https://github.com/Theano/Theano/issues/4720#issuecomment-232029702" rel="nofollow">https://github.com/Theano/Theano/issues/4720#issuecomment-232029702</a></p>
| 0 | 2016-07-13T05:53:02Z | [
"python",
"multiprocessing",
"theano"
] |
'charmap' codec can't encode character error in Python while parsing HTML | 38,321,913 | <p>Here is my code:</p>
<pre><code>dataFile = open('dataFile.html', 'w')
res = requests.get('site/pm=' + str(i))
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
linkElems = soup.select('#content')
dataFile.write(str(linkElems[0]))
</code></pre>
<p>I have some other code to but this is the cod... | -1 | 2016-07-12T06:54:41Z | 38,322,246 | <p>You opened your text file without specifying an encoding:</p>
<pre><code>dataFile = open('dataFile.html', 'w')
</code></pre>
<p>This tells Python to use the <em>default codec for your system</em>. Every Unicode string you try to write to it will be encoded to that codec, and your Windows system is not set up with ... | 0 | 2016-07-12T07:13:19Z | [
"python",
"beautifulsoup",
"python-3.5"
] |
Reading outlook email with a specific from address in python with POP3 | 38,321,958 | <pre><code>import getpass, poplib
user = 'my_user_name'
Mailbox = poplib.POP3_SSL('pop-mail.outlook.com.com', '995')
Mailbox.user(user)
Mailbox.pass_('my_password')
numMessages = len(Mailbox.list()[1])
for i in range(numMessages):
for msg in Mailbox.retr(i+1)[1]:
print msg
Mailbox.quit()
</code></pre>
... | 0 | 2016-07-12T06:57:34Z | 38,322,338 | <p>The POP3 protocol only allows to:</p>
<ul>
<li>get the number of messages</li>
<li>retrieve a full message</li>
<li>delete a message</li>
</ul>
<p>An optional command (TOP msg n) allows to read only the n first lines of a message. In theory, you could use it to only fully download messages coming from a specific a... | 0 | 2016-07-12T07:17:53Z | [
"python",
"pop3",
"outlook.com"
] |
dataframe error reading csv | 38,321,987 | <p>I'm trying to open a dataframe, inserting into pandas for some analysis.</p>
<pre><code>raw = pd.read_csv('/home/chris/Desktop/Cambridge/SOURCE_DATA/Node_56_Nairobi_OutputFile.xls', encoding='utf16', error_bad_lines=False)
</code></pre>
<p>I tried suggestions on other threads. Then this is happening:</p>
<pre><co... | 0 | 2016-07-12T06:59:16Z | 38,322,308 | <p>Wait, this solved it. In a moment of sheer monumental stupidity and coding frustration, I got .csv files and .xls files mixed up...</p>
<pre><code>raw = pd.read_excel('/home/chris/Desktop/Cambridge/SOURCE_DATA/Node_56_Nairobi_OutputFile.xls')
</code></pre>
<p><em>facepalm</em></p>
| 0 | 2016-07-12T07:16:20Z | [
"python",
"pandas",
"dataframe"
] |
How to get "17"<"9" to create an error? | 38,322,113 | <p>Is there any good way to get rid of the possibility of application to strings of the greater smaller comparison operators and the min max functions? Like aliasing? The problem is that the behaviour is just not useful. </p>
<p>So that '17'<'9' gives an error and not the (for me) beautifully useless and confusing... | -5 | 2016-07-12T07:05:40Z | 38,323,156 | <p>I'll risk flames... :-) What you can do is create a new string class, almost identical to the native one, but with providing a new set of equality functions.</p>
<p>For example, just overriding the <code>></code> operation:</p>
<pre><code>class newstr(str): # Inheriting str class
def __gt__(self, s):
... | 1 | 2016-07-12T08:02:32Z | [
"python",
"string",
"python-2.7",
"comparison"
] |
Django channels websocket.receive is not handled | 38,322,197 | <p>I'm trying to implement Django channels going through the docs.<br>
So like the docs i'm making <code>consumers.py</code></p>
<pre><code>def ws_message(message):
message.reply_channel.send({
"text": message.content['text'],
})
</code></pre>
<p>and <code>routing.py</code> as </p>
<pre><code>from channe... | 1 | 2016-07-12T07:11:10Z | 38,331,101 | <p>The problem was with the version of Twisted. By now the latest version of it is 16.3.0 but the Channels require 16.2.0 version. So with 16.2.0 version of Twisted it works as should.</p>
| 1 | 2016-07-12T14:01:17Z | [
"python",
"django",
"websocket",
"django-channels"
] |
sqlalchemy failed to update my model | 38,322,245 | <p>I'm trying to update a db model. So I tried the below code,</p>
<pre><code>if not sell_requests:
request.r_quantity = request.quantity
request.status = StatusEnum.opened
print request
print request.quantity
print request.r_quantity
con = session.commit()
print con
</code></pre>
<p>See, I made... | -2 | 2016-07-12T07:13:14Z | 38,326,338 | <p>It would seem that there's an error in the program logic: in the function <code>calc_r_quantity_and_status</code> the current request is first processed, but then all "previous" requests are processed and the current request is included. For example given a session of a single buy request of some company and quantit... | 1 | 2016-07-12T10:31:50Z | [
"python",
"sqlalchemy"
] |
Summing values from pandas dataframe columns depending on row index value | 38,322,333 | <p>I have a NxN dataframe. Each row corresponds to a certain url given as its index (without "http://"). Each also column represents url with boolean values indicating if this page (row index) links to that page (column name). The urls are the same in index and columns. </p>
<pre><code>In [1]: import pandas as pd
In ... | 2 | 2016-07-12T07:17:26Z | 38,322,877 | <p>Create a series of index/column pairs. Filter out the ones that are same domains and fill back in with <code>False</code>. Then add the axis1 sum to the axis0 sum.</p>
<pre><code>def domain(x):
return x.str.extract(r'([^/]+)', expand=False)
dfi = df.stack().index.to_series().apply(lambda x: pd.Series(x, ['u1... | 2 | 2016-07-12T07:47:23Z | [
"python",
"pandas",
"filtering"
] |
Summing values from pandas dataframe columns depending on row index value | 38,322,333 | <p>I have a NxN dataframe. Each row corresponds to a certain url given as its index (without "http://"). Each also column represents url with boolean values indicating if this page (row index) links to that page (column name). The urls are the same in index and columns. </p>
<pre><code>In [1]: import pandas as pd
In ... | 2 | 2016-07-12T07:17:26Z | 38,361,745 | <p>not very pandas but still... one can iterate over elements</p>
<pre><code>In [40]: def same_domain(url1, url2):
return url1.split('/')[0] == url2.split('/')[0]
In [41]: def clear_inner_links(df):
for r in df.index:
for c in df.columns:
if(same_domain(r,c)):
df.loc[r,c] = False
return d... | 1 | 2016-07-13T21:08:27Z | [
"python",
"pandas",
"filtering"
] |
PyQt having a status bar & menu bar QWidget | 38,322,349 | <p><br>
I am trying to create a PyQt application that has both status bar and a menu bar with other Widgets in the window. Below is the code which I managed to get it run with class <code>QtGui.QMainWindow</code> method. But as I intend to add further features, I realise I must use <code>QtGui.QWidget</code> instead.<b... | 2 | 2016-07-12T07:18:33Z | 38,323,171 | <p>Here is a working solution using your code. I added a <code>centralWidget</code> and a <code>centralLayout</code> to the <code>QMainWindow</code> which now holds your <code>qbtn</code>:</p>
<pre><code>import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QMainWindow):
... | 1 | 2016-07-12T08:03:13Z | [
"python",
"qt",
"pyqt",
"qwidget",
"qmainwindow"
] |
PyQt having a status bar & menu bar QWidget | 38,322,349 | <p><br>
I am trying to create a PyQt application that has both status bar and a menu bar with other Widgets in the window. Below is the code which I managed to get it run with class <code>QtGui.QMainWindow</code> method. But as I intend to add further features, I realise I must use <code>QtGui.QWidget</code> instead.<b... | 2 | 2016-07-12T07:18:33Z | 38,323,346 | <p>You could just move your buttons/labels/etc. to a <code>QWidget</code>, and add this widget to the main window. Here is how it could look like (I changed the imports so that it is a bit more readable).</p>
<p><em>Your content widget class :</em></p>
<pre><code>class ExampleContent(QWidget):
def __init__(self, ... | 1 | 2016-07-12T08:14:00Z | [
"python",
"qt",
"pyqt",
"qwidget",
"qmainwindow"
] |
PyQt having a status bar & menu bar QWidget | 38,322,349 | <p><br>
I am trying to create a PyQt application that has both status bar and a menu bar with other Widgets in the window. Below is the code which I managed to get it run with class <code>QtGui.QMainWindow</code> method. But as I intend to add further features, I realise I must use <code>QtGui.QWidget</code> instead.<b... | 2 | 2016-07-12T07:18:33Z | 38,405,594 | <p>You can also use a combination of QMainWindow and QWidget. </p>
<p>I have found this useful in some cases. You can add statusbar and menubar to the MainWindow section and the widgets to the QWidget area. </p>
<pre><code>import sys
from PyQt4 import QtCore, QtGui
class MainWindow(QtGui.QMainWindow):
def __init__... | 0 | 2016-07-15T22:02:50Z | [
"python",
"qt",
"pyqt",
"qwidget",
"qmainwindow"
] |
How to query various models with many-to-many through relation in shopping cart (Django) | 38,322,362 | <p>I built a shopping cart that uses a CartItem model as a many-to-many through relation and which queries currently the Product model.</p>
<p>However, I want to not only query the Product model but around 5 other models as well where other types of Products are stored (I needed to do so because of a bulk csv upload).... | 0 | 2016-07-12T07:19:39Z | 38,324,775 | <p>What you can do is a raw query, with a raw query you can do joins or apply direct SQL code to database. The result will be a cursor which you can transform to a dictionary or another structure. </p>
<p>This topis : <a href="https://docs.djangoproject.com/es/1.9/topics/db/sql/" rel="nofollow">Performing raw SQL quer... | 0 | 2016-07-12T09:20:53Z | [
"python",
"django",
"postgresql",
"cart",
"shopping"
] |
celery periodic task as asnyc on django | 38,322,509 | <p>I'm not good at english, so if you cannot understand my sentence, give me any comment.</p>
<p>I use celery for periodic task on django.</p>
<pre><code>CELERYBEAT_SCHEDULE = {
'send_sms_one_pm': {
'task': 'tasks.send_one_pm',
'schedule': crontab(minute=0, hour=13),
},
'send_sms_ten_am': ... | 0 | 2016-07-12T07:27:39Z | 38,322,953 | <p>Did you assign <code>CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'</code> in your settings as well?
If you want one task starts to run after another one, you should use <code>apply_asnyc()</code> with link <code>kwargs</code>, it looks like this: </p>
<pre><code>res=[signature(your_task.name, args... | 0 | 2016-07-12T07:51:01Z | [
"python",
"django",
"celery",
"djcelery"
] |
Python Multiprocessing sharing of global values | 38,322,574 | <p>What i am trying to do is to make use of global variable by each process.
But my process is not taking the global values</p>
<pre><code>import multiprocessing
count = 0
def smile_detection(thread_name):
global count
for x in range(10):
count +=1
print thread_name,count
return count ... | 4 | 2016-07-12T07:31:01Z | 38,322,893 | <p>Unlike threading, multiprocessing is a bit trickier to handle shared state due to forking (or spawning) of a new process. Especially in windows. To have a shared object, use a multiprocessing.Array or multiprocessing.Value. In the case of the array, you can, in each process, dereference its memory address in another... | 1 | 2016-07-12T07:48:11Z | [
"python",
"shared-memory",
"python-multiprocessing"
] |
Python Multiprocessing sharing of global values | 38,322,574 | <p>What i am trying to do is to make use of global variable by each process.
But my process is not taking the global values</p>
<pre><code>import multiprocessing
count = 0
def smile_detection(thread_name):
global count
for x in range(10):
count +=1
print thread_name,count
return count ... | 4 | 2016-07-12T07:31:01Z | 38,322,919 | <p>To share data between processes you to need to let <code>mutiprocessing.Manager</code> manage the shared data:</p>
<pre><code>count = multiprocessing.Manager().Value('i', 0) # creating shared variable
lock = multiprocessing.Manager().Lock() # we'll use lock to acquire lock on `count` before count += 1
def smile_de... | 0 | 2016-07-12T07:49:20Z | [
"python",
"shared-memory",
"python-multiprocessing"
] |
Python Multiprocessing sharing of global values | 38,322,574 | <p>What i am trying to do is to make use of global variable by each process.
But my process is not taking the global values</p>
<pre><code>import multiprocessing
count = 0
def smile_detection(thread_name):
global count
for x in range(10):
count +=1
print thread_name,count
return count ... | 4 | 2016-07-12T07:31:01Z | 38,322,970 | <p>Try doing it like this:</p>
<pre><code>import multiprocessing
def smile_detection(thread_name, counter, lock):
for x in range(10):
with lock:
counter.value +=1
print thread_name, counter.value
count = multiprocessing.Value('i', 0)
lock = multiprocessing.Lock()
x = multiproc... | 0 | 2016-07-12T07:51:46Z | [
"python",
"shared-memory",
"python-multiprocessing"
] |
Python Multiprocessing sharing of global values | 38,322,574 | <p>What i am trying to do is to make use of global variable by each process.
But my process is not taking the global values</p>
<pre><code>import multiprocessing
count = 0
def smile_detection(thread_name):
global count
for x in range(10):
count +=1
print thread_name,count
return count ... | 4 | 2016-07-12T07:31:01Z | 38,322,986 | <p>You can use a <a href="https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Value" rel="nofollow"><code>multiprocessing.Value</code></a> :</p>
<blockquote>
<p>Return a ctypes object allocated from shared memory. By default the return value is actually a synchronized wrapper for the object.</p>
<... | 1 | 2016-07-12T07:52:50Z | [
"python",
"shared-memory",
"python-multiprocessing"
] |
Start Django with different setting values | 38,322,618 | <p>I am writing test for my Django app. I want to start Django with different settings value and run tests for each case. (eg one test for settings.ALLOW_ROBOTS=True and another test for settings.ALLOW_ROBOTS=False). I am not interested in overriding the value at run time. I want to start the server with different sett... | 0 | 2016-07-12T07:33:33Z | 38,322,671 | <p>If I understand your question correctly, you would like to be able to use multiple settings modules. If so, setting the <a href="https://docs.djangoproject.com/en/1.9/topics/settings/#envvar-DJANGO_SETTINGS_MODULE" rel="nofollow"><code>DJANGO_SETTINGS_MODULE</code></a> environment variable before starting the server... | 0 | 2016-07-12T07:36:40Z | [
"python",
"django"
] |
Start Django with different setting values | 38,322,618 | <p>I am writing test for my Django app. I want to start Django with different settings value and run tests for each case. (eg one test for settings.ALLOW_ROBOTS=True and another test for settings.ALLOW_ROBOTS=False). I am not interested in overriding the value at run time. I want to start the server with different sett... | 0 | 2016-07-12T07:33:33Z | 38,322,798 | <p>You can choose which settings.py file to use with <code>DJANGO_SETTINGS_MODULE</code>; you can have many that import * from a main one, and then change what needs to be changed.</p>
<p>Alternatively, settings.py is just a Python file. You can get values of settings from environment variables, if you want:</p>
<pre... | 1 | 2016-07-12T07:43:24Z | [
"python",
"django"
] |
Python regex for mixture of English and Chinese characters unable to return matches | 38,322,763 | <p>I am stuck and need some help in pointing the mistake.
I am trying to extract a portion of the html code from a webpage which is done using tables, and with same class and id in many places. Hence I am unable to use only BeautifulSoup4 to extract it. I will need a little regex to extract. Only then to use html parse... | 0 | 2016-07-12T07:41:34Z | 39,313,947 | <p>This is my suggestion.</p>
<pre><code>import urllib.request
from bs4 import BeautifulSoup
url = urllib.request.urlopen('http://www.check4d.com')
html = str(url.read()).encode('cp437', 'ignore') #ignores chinese characters in page
soup = BeautifulSoup(html, 'html.parser')
content = soup.findAll("div", { "class" : "... | 1 | 2016-09-04T05:53:09Z | [
"python",
"raspberry-pi"
] |
xlsxwriter image does not show in header when opened with LibreOffice | 38,323,022 | <p>I've needed to create a custom invoice using python xlsxwriter, where I need to create a custom header with a company logo. The resulting workbook must be opened using LibreOffice, not Excel.</p>
<p>Using the example from <a href="http://xlsxwriter.readthedocs.io/example_headers_footers.html" rel="nofollow">http://... | 3 | 2016-07-12T07:55:02Z | 38,323,293 | <p>Your example does work. Here is the output I get when I run it with the latest version of the module and Excel 2013:</p>
<p><a href="http://i.stack.imgur.com/aifRm.png" rel="nofollow"><img src="http://i.stack.imgur.com/aifRm.png" alt="enter image description here"></a></p>
<p>Perhaps you have an old version of Xls... | 0 | 2016-07-12T08:10:56Z | [
"python",
"xlsx",
"openoffice-calc",
"xlsxwriter",
"libreoffice-calc"
] |
xlsxwriter image does not show in header when opened with LibreOffice | 38,323,022 | <p>I've needed to create a custom invoice using python xlsxwriter, where I need to create a custom header with a company logo. The resulting workbook must be opened using LibreOffice, not Excel.</p>
<p>Using the example from <a href="http://xlsxwriter.readthedocs.io/example_headers_footers.html" rel="nofollow">http://... | 3 | 2016-07-12T07:55:02Z | 38,324,673 | <p><strong><em>Edited</em></strong></p>
<p>The xlsx with logo header works perfectly in Excel. </p>
<p>It is not displaying in LibreOffice(5.1.4.2 10m0(Build:2)),which is could potentially be a bug in LibreOffice/OpenOffice.</p>
| 0 | 2016-07-12T09:16:54Z | [
"python",
"xlsx",
"openoffice-calc",
"xlsxwriter",
"libreoffice-calc"
] |
matplotlib 3d - beginners level | 38,323,045 | <p>Hi i can't seem to create a 3d representation with simple coordinates - i don't want the lines - (each coords different from 0 represent a finger applied on a touchscreen)</p>
<pre><code>from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subpl... | -1 | 2016-07-12T07:56:22Z | 38,323,446 | <p>To perform <code>plot_surface</code>, your input arrays (<code>X,Y,Z</code>) should be 2D arrays.
In your case you are trying to feed in 1D arrays, and that is why when you
run your code you get an empty plot with just the grids. </p>
<p>Here is an example of your code that will work:</p>
<pre><code>from mpl_too... | 1 | 2016-07-12T08:18:29Z | [
"python",
"matplotlib"
] |
Pandas groupby-median function fills empty bins with random numbers | 38,323,362 | <p>I am learning the different aspects of Python Pandas and I stumbled over some odd behaviour of the median function for groupby-objects when it's used on binned data.</p>
<p>Example Code:</p>
<pre><code>import pandas as pd
d = pd.DataFrame([1,2,5,6,9,3,6,5,9,7,11,36,4,7,8,25,8,24,23])
b = [0,5,10,15,20,25,30,35,4... | 4 | 2016-07-12T08:14:35Z | 38,323,725 | <p>I'm pretty sure it's a bug:</p>
<p>Consider:</p>
<pre><code>gb = d.groupby(pd.cut(d[0],b))
gb.median()
</code></pre>
<p><a href="http://i.stack.imgur.com/CzfBm.png" rel="nofollow"><img src="http://i.stack.imgur.com/CzfBm.png" alt="enter image description here"></a></p>
<p>but:</p>
<pre><code>gb.get_group('(0, ... | 2 | 2016-07-12T08:33:20Z | [
"python",
"pandas",
"median"
] |
Pandas groupby-median function fills empty bins with random numbers | 38,323,362 | <p>I am learning the different aspects of Python Pandas and I stumbled over some odd behaviour of the median function for groupby-objects when it's used on binned data.</p>
<p>Example Code:</p>
<pre><code>import pandas as pd
d = pd.DataFrame([1,2,5,6,9,3,6,5,9,7,11,36,4,7,8,25,8,24,23])
b = [0,5,10,15,20,25,30,35,4... | 4 | 2016-07-12T08:14:35Z | 38,344,272 | <p>I reported this problem as a bug and it was added to the 0.19.0 milestone:</p>
<p><a href="https://github.com/pydata/pandas/issues/13629" rel="nofollow">https://github.com/pydata/pandas/issues/13629</a></p>
| 0 | 2016-07-13T06:38:29Z | [
"python",
"pandas",
"median"
] |
Page doesn't redirect correctly | 38,323,390 | <p>I'm learning django with myself and when I was following the tutorial <a href="https://docs.djangoproject.com/en/1.9/intro/tutorial04/" rel="nofollow">Writing your first Django app, part 4</a> today, I met this problem.(I'm using django 1.9.7 and Python 3.5.2 64-bit and PyCharm) </p>
<p>When I select a choice and c... | 1 | 2016-07-12T08:16:14Z | 38,331,548 | <p>Sorry for wasting all your time. It was a typo which caused the problem.
<p>polls\template\polls\detail.html
<code><form action="{% url 'polls:vote' question.id %}" methon="post"></code>
<p><code>methon</code> should be <code>method</code>, and the problem has been solved.</p>
| 0 | 2016-07-12T14:21:24Z | [
"python",
"django"
] |
PyCluster unable to install package | 38,323,412 | <p>Downloading/unpacking PyCluster</p>
<p>Getting page <a href="http://pypi.python.org/simple/PyCluster" rel="nofollow">http://pypi.python.org/simple/PyCluster</a>
URLs to search for versions for PyCluster:
* httpss://pypi.python.org/simple/PyCluster/
Getting page httpss://pypi.python.org/simple/PyCluster/
Ana... | 0 | 2016-07-12T08:16:51Z | 38,323,470 | <p><a href="https://pypi.python.org/pypi/Pycluster" rel="nofollow">here is</a> the package there is no source or binary available to download.</p>
<p>a module (<a href="https://pypi.python.org/pypi/pyclustering" rel="nofollow">pyclustering</a>) with similar name.</p>
<p>The Python Package Index (<strong>PYPI</strong>... | 0 | 2016-07-12T08:20:06Z | [
"python",
"python-2.7",
"packages",
"installation-package"
] |
How make tkinter frame go behind other | 38,323,489 | <p>I'm trying to make (self.center = Separator) go behind that only line would be in center, because I need to separate 2 frames, but when I try on small screen those 2 frames are covered by separator or at least make center frame background transparent, if you need full code <a href="https://github.com/aurimasjank/Pin... | 1 | 2016-07-12T08:21:29Z | 38,328,419 | <p>I think your problem is due to the width of column 1 which is determined by the largest widget (I don't think it's the separator here, but the progress bar). I suggest you to put all row 0 widget in one frame so that they won't be impacted by the other wigets width:</p>
<pre><code>from tkinter import Tk, Frame
from... | 0 | 2016-07-12T12:04:35Z | [
"python",
"tkinter"
] |
pyplot.imshow for rectangles | 38,323,669 | <p>I am currently using <code>matplotlib.pyplot</code> to visualize some 2D data:</p>
<pre><code>from matplotlib import pyplot as plt
import numpy as np
A=np.matrix("1 2 1;3 0 3;1 2 0") # 3x3 matrix with 2D data
plt.imshow(A, interpolation="nearest") # draws one square per matrix entry
plt.show()
</code></pre>
<p>Now... | 0 | 2016-07-12T08:30:31Z | 38,349,402 | <pre><code>import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import matplotlib.cm as cm
from matplotlib.collections import PatchCollection
import numpy as np
A = np.matrix("1 2 1;3 0 3;1 2 0;4 1 2") # 4x3 matrix with 2D data
grid_x0 = np.array([0.0, 1.0, 4.0, 6.7])
grid_y0 = np.array([0.0, 2.5,... | 1 | 2016-07-13T10:42:46Z | [
"python",
"matplotlib",
"rectangles",
"imshow"
] |
pyplot.imshow for rectangles | 38,323,669 | <p>I am currently using <code>matplotlib.pyplot</code> to visualize some 2D data:</p>
<pre><code>from matplotlib import pyplot as plt
import numpy as np
A=np.matrix("1 2 1;3 0 3;1 2 0") # 3x3 matrix with 2D data
plt.imshow(A, interpolation="nearest") # draws one square per matrix entry
plt.show()
</code></pre>
<p>Now... | 0 | 2016-07-12T08:30:31Z | 38,369,603 | <p>Here is a reusable function based on the code from @ophir-carmi:</p>
<pre><code>import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.collections import PatchCollection
import itertools
import numpy as np
def gridshow(grid_x, grid_y, data, **kwargs):
vmin = kwargs.pop("vmin",... | 1 | 2016-07-14T08:49:34Z | [
"python",
"matplotlib",
"rectangles",
"imshow"
] |
Trying all possible combinations in a dynamic order | 38,323,738 | <p>I'll try to explain my situation. I have a set of problems to solve:</p>
<pre><code># pseudocode to illustrate the problem
problems= ['A','M','X']
</code></pre>
<p>There are a few variables that I can modify in order to solve these problems. Each variable can assume different values.</p>
<pre><code>variables= ['B... | 0 | 2016-07-12T08:34:05Z | 38,360,350 | <p>Alright, I've managed to write an iterator that does what I want. It's the ugliest piece of code I've ever written, but whatever.</p>
<p>I'm still hoping for a better solution though.</p>
<pre><code>class DynamicOrderProduct:
"""
Given a dict of {variable:(value1,value2,value3,...)}, allows iterating over ... | 0 | 2016-07-13T19:41:33Z | [
"python",
"combinations"
] |
Does Python's logging.config.dictConfig() apply the logger's configuration settings? | 38,323,810 | <p>I've been trying to implement a basic logger that writes to a file in Python 3.5, loading the settings from a JSON config file.
I'll show my code first;</p>
<p><code>log_config.json</code></p>
<pre><code>{
"version": 1,
"disable_existing_loggers": "false",
"logging": {
"formatters": {
... | 0 | 2016-07-12T08:37:59Z | 38,340,609 | <p>Ah, I figured out what was wrong. Turns out it was the JSON.
From <a href="https://gist.github.com/glenfant/4358668" rel="nofollow">this example</a> which I was basing my work off of, it has an extra <code>logging</code> property in the JSON, which encapsulates all the loggers, handlers etc.</p>
<p>Removing that pr... | 0 | 2016-07-12T23:57:25Z | [
"python",
"json",
"python-3.x",
"logging"
] |
Can I create a class that will be created by non trivial syntax? | 38,323,894 | <p>Consider for example Quaternion math (<a href="https://en.wikipedia.org/wiki/Quaternion" rel="nofollow">https://en.wikipedia.org/wiki/Quaternion</a>).</p>
<p>Obviously I can build a class that will define a new quaternion by</p>
<pre><code>a = quaternion(1, 2, 3, 4)
print(a)
# 1 + 2i + 3j + 4k
</code></pre>
<p>Ho... | 4 | 2016-07-12T08:41:54Z | 38,324,364 | <p>Short answer: No, you cannot.</p>
<p>Long answer: Well, you can, but then it is not python anymore.</p>
<p>The complex literals are handled when parsing python. They are a well-integrated part of the python language with custom syntax. You cannot simply define your own custom syntax in python. It requires to modif... | 2 | 2016-07-12T09:03:18Z | [
"python"
] |
Can I create a class that will be created by non trivial syntax? | 38,323,894 | <p>Consider for example Quaternion math (<a href="https://en.wikipedia.org/wiki/Quaternion" rel="nofollow">https://en.wikipedia.org/wiki/Quaternion</a>).</p>
<p>Obviously I can build a class that will define a new quaternion by</p>
<pre><code>a = quaternion(1, 2, 3, 4)
print(a)
# 1 + 2i + 3j + 4k
</code></pre>
<p>Ho... | 4 | 2016-07-12T08:41:54Z | 38,324,560 | <p>You could define unit quaternions, define addition and subtraction to work with simple numbers too, and then just write expressions.</p>
<pre><code># quaternion.py
...
i = quaternion(0, 1, 0, 0)
j = quaternion(0, 0, 1, 0)
k = quaternion(0, 0, 0, 1)
# main.py
from quaternion import i,j,k
a = 1 + 2*i + 3*j + 4*k
</c... | 4 | 2016-07-12T09:11:54Z | [
"python"
] |
Python cycle through list of dicts to find attributes | 38,323,921 | <p>I've got a complex JSON stucture which has been loaded into a dict:</p>
<pre><code>{
"assets": [
{
"account": "Prod",
"distributiongroups": [],
"name": "Admin",
"networks": [
{
...
},
{
"account": "Dev",
"distributiongroups": []
...
</co... | 3 | 2016-07-12T08:43:28Z | 38,323,953 | <p>Yes, use a <a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions">list comprehension</a> to build a new list from a loop:</p>
<pre><code>accounts = [account['name'] for account in data['assets']]
</code></pre>
<p>This takes the <code>'name'</code> value for each dictionary in the list... | 5 | 2016-07-12T08:44:47Z | [
"python",
"list",
"dictionary"
] |
What status code should a PATCH request with no changes return? | 38,323,976 | <p>If a PATCH request is made with a VALID payload, but the values in the payload are exactly the same as those in db, should it return 200 or 400 or other status code?</p>
| 0 | 2016-07-12T08:46:11Z | 38,324,115 | <p>You have to return 4xx HTTP status code if there is an error.</p>
<p>In your case, there is not so I think that 200 is the best response.</p>
<p>The RFC says when you have to return an error status code.</p>
<p><a href="https://tools.ietf.org/html/rfc5789#section-2.2" rel="nofollow">https://tools.ietf.org/html/rf... | 2 | 2016-07-12T08:52:33Z | [
"python",
"django",
"request",
"django-rest-framework",
"http-status-codes"
] |
Kivy App crashes: "Not Responding" | 38,324,209 | <p>I want to <strong>make apps using kivy</strong>. I installed <strong>python 2.7</strong> and <strong>kivy 1.9.1</strong>.</p>
<p>I used <a href="https://kivy.org/docs/installation/installation-windows.html" rel="nofollow">this link</a> to install kivy.</p>
<p>And I am following <a href="https://www.youtube.com/wat... | 3 | 2016-07-12T08:57:02Z | 38,332,305 | <p>The problem is solved finally. I was supposed to install Python 2.7.12 64-bit but my version was 2.7.0 64-bit. After changing python version, it worked! :)</p>
| 1 | 2016-07-12T14:52:31Z | [
"python",
"visual-studio",
"python-2.7",
"kivy"
] |
How to store a frame to a file using OpenCV | 38,324,264 | <p>I am reading frames from a camera using:</p>
<p><code>capture=cv.CaptureFromCAM(0)
frame1 = cv.QueryFrame(capture)</code></p>
<p>How can I save this frame into a jpg file?</p>
| 0 | 2016-07-12T08:59:14Z | 38,324,442 | <p>you can try this</p>
<pre><code>cv.SaveImage("frame.jpg". ,frame1);
</code></pre>
| 1 | 2016-07-12T09:07:17Z | [
"python",
"opencv",
"video",
"frame"
] |
Python - changing Pandas DataFrame with float64's to list with integers | 38,324,381 | <p>I have a Pandas DataFrame on which I would like to do some manipulations. First I sort my dataframe on the entropy using this code:</p>
<pre><code>entropy_dataframe.sort_values(by='entropy',inplace=True,ascending=False)
</code></pre>
<p>This gives me the following dataframe (<code><class 'pandas.core.frame.Data... | 0 | 2016-07-12T09:04:02Z | 38,328,156 | <p>Since users may not skim through all of the comments on your original question, I'll condense our results into a single answer.</p>
<ul>
<li><p>According to <code>sys.maxint</code>, a 32bit version of python is running. Since some list elements are larger than <code>maxint</code> (<code>2**31 - 1</code>), the eleme... | 1 | 2016-07-12T11:52:34Z | [
"python",
"numpy",
"pandas",
"data-type-conversion"
] |
Python Wheels on linux (how? and why?) | 38,324,391 | <p>I know that wheels are binary version of a module uploaded on PyPI.</p>
<p>with <code>pip install</code></p>
<ul>
<li>On Windows: I get wheels downloaded and installed.</li>
<li>On Ubuntu: I should get the source distribution of the package <strong>BUT</strong> in <a href="https://pypi.python.org/pypi/PyQt5/5.6" r... | 5 | 2016-07-12T09:04:24Z | 38,491,184 | <blockquote>
<p>Why do some packages provide wheels for Linux platform?</p>
</blockquote>
<p>Why shouldn't they, as long as source distributions are available as well? :)</p>
<p>Your question is not clear. If you meant</p>
<blockquote>
<p>Why do some packages provide platform-specific wheels for Linux platform i... | 2 | 2016-07-20T21:30:43Z | [
"python",
"pypi",
"python-wheel"
] |
Python and importing floating-point numbers from the excel file | 38,324,421 | <p>So I have an excel file that looks like this</p>
<pre><code> Name R s l2 max_amplitude ref_amplitude
R_0.3_s_0.5_l2_0.1 0.3 0.5 0.1 1.45131445 1.45131445
R_0.3_s_0.5_l2_0.6 0.3 0.5 0.6 3.52145743 3.52145743
...
R_1.1_s_2.0_l2_1.6 1.1 2.0 1.6 5.07415199 5.07415199
R_1.1_s_2.0_l2... | 4 | 2016-07-12T09:06:17Z | 38,324,761 | <p>Don't check floats for equality. There are some issues with floating point arithmetic (check <a href="http://floating-point-gui.de/" rel="nofollow">here</a> for example).</p>
<p>Instead, check for <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.isclose.html" rel="nofollow">closeness</a> (really r... | 4 | 2016-07-12T09:20:17Z | [
"python",
"excel",
"pandas",
"import",
"floating"
] |
What is the reason for _secret_backdoor_key variable in Python HMAC library source code? | 38,324,441 | <p>When I was browsing Python HMAC module source code today I found out that it contains global variable <code>_secret_backdoor_key</code>. This variable is then checked to interrupt object initialization. </p>
<p>The code looks like this</p>
<pre><code># A unique object passed by HMAC.copy() to the HMAC constructor,... | 9 | 2016-07-12T09:07:13Z | 38,324,561 | <p>To create a copy of the HMAC instance, you need to create an <em>empty</em> instance first.</p>
<p>The <code>_secret_backdoor_key</code> object is used as a sentinel to exit <code>__init__</code> early and not run through the rest of the <code>__init__</code> functionality. The <code>copy</code> method then sets th... | 8 | 2016-07-12T09:11:57Z | [
"python",
"hash",
"python-internals"
] |
WSGIPath Error while Deploying Django App using AWS Elasticbeanstalk | 38,324,468 | <p>I am trying to deploy my Django Project on AWS using Elastic Beanstalks. I have tried multiple value changes for WSGIPath.
But Everytime, I am getting the same Error:</p>
<p>while running 'eb create' from ubuntu terminal:</p>
<p>Error Logs (from Eb logs):</p>
<pre><code>-------------------------------------
/var... | 1 | 2016-07-12T09:08:35Z | 38,680,996 | <p>Updated myapp.config File Which worked:</p>
<pre><code>option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: "myapp/wsgi.py"
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
</code></pre>
| 0 | 2016-07-31T05:16:11Z | [
"python",
"amazon-web-services",
"amazon-ec2",
"elastic-beanstalk"
] |
Running Django app in a server | 38,324,548 | <p>I have created a simple hello world app in a server and would like to test it live. I'm using ssh to access the server, I have used the following commands to set it up: <code>django-admin startproject mysite</code>, and <code>python manage.py startapp site</code>. </p>
<p>Changed urls.py in "wrong" folder to:</p>
... | -3 | 2016-07-12T09:11:21Z | 38,325,145 | <p>Django does not include a server for production purposes. You need to setup a webserver like Apache or Nginx. The documentation on the django website explains you how: <a href="https://docs.djangoproject.com/en/1.9/howto/deployment/" rel="nofollow">https://docs.djangoproject.com/en/1.9/howto/deployment/</a></p>
<p>... | 2 | 2016-07-12T09:39:03Z | [
"python",
"django"
] |
Show loading icon during server side functions on page refresh | 38,324,581 | <p>I have a flask app with some fairly heavy server side functions that cause a page to take a while to load. I'd like a loading icon for the few seconds that the user is waiting. Now the issue I am facing is that most of the solutions listed for this kind of thing are all related to waiting for the page <em>content</e... | 0 | 2016-07-12T09:12:47Z | 38,324,814 | <p>Try the following implementation.</p>
<p>Have a loader <code>div</code> in all your pages.</p>
<p><code><div class='loader'></div></code></p>
<p>Apply default CSS as:</p>
<pre><code>.loader {
position: absolute;
top:0;
left:0;
right:0;
bottom: 0;
text-align: center;
margin: auto;
display: none
}
</co... | 0 | 2016-07-12T09:22:48Z | [
"javascript",
"python",
"html",
"css",
"flask"
] |
How to keep a slice of a numpy array and clear the rest from memory? | 38,324,603 | <p>I have a list which contains several large <code>numpy arrays</code></p>
<p>I want to only keep a slice of each of those arrays, and clear my system memory. I have tried using the keywords <code>del</code> and <code>None</code> but those do not seem to have any effect (I use the fedora system monitor to monitor RAM... | 0 | 2016-07-12T09:13:53Z | 38,324,974 | <p>You can achieve this by transposing the list twice: <code>my_list.transpose()[10:100].transpose()</code></p>
<pre><code>arr1=[0,1,2,3,4]
arr2=[0,1,2,3,4]
arr3=[0,1,2,3,4]
my_list=np.array([arr1,arr2,arr3])
my_list.transpose()[1:4].transpose()
</code></pre>
<p>returns:</p>
<pre><code>array([[1, 2, 3],
[1, 2... | 0 | 2016-07-12T09:30:49Z | [
"python",
"python-3.x",
"numpy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.