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
Only part of unicode is replacing in python.Don't understand why
38,358,300
<pre><code>subject = page.select('div.container h1') subject = [x.text.replace('2015', '')for x in subject] print subject [u'\u20132016 Art Courses']# This is the code after. [u'2015\u20132016 Art Courses']#This is the code before. subject = [x.text.replace('20132016', '')for x in subject] </code></pre> <p>When I ...
1
2016-07-13T17:35:18Z
38,358,424
<p><code>\u2013</code> is a unicode symbol <code>en dash</code>. Check <a href="http://www.fileformat.info/info/unicode/char/2013/index.htm" rel="nofollow">here</a> for example.</p> <p>So to get rid of all but Art you need to replace it like this:</p> <pre><code>&gt;&gt;&gt; a = u'2015\u20132016 Art Courses' &gt;&gt;...
1
2016-07-13T17:42:16Z
[ "python", "string", "unicode", "replace" ]
Parsing XML to dataframe in python with same nodes
38,358,316
<p>I have this XML and i want to parse into panda's data frame:</p> <pre><code>&lt;DISTRITO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;NOME_DISTRITO&gt;BRAGANCA&lt;/NOME_DISTRITO&gt; &lt;CPE&gt;PT0002000022161425NP&lt;/CPE&gt; &lt;CPE&gt;PT0002000022161458JH&lt;/CPE&gt; &lt;CPE&gt;PT00020...
2
2016-07-13T17:36:18Z
38,360,591
<p>You have two problems, first you are overwriting values if you have repeated keys in the inner loop, you are also appending a <em>reference</em> to the same <em>dict/object</em> in the loop so any changes you make are reflected everywhere hence you only see the last value each time. </p> <p>You would need to creat...
1
2016-07-13T19:54:58Z
[ "python", "parsing", "pandas", "dataframe", "lxml" ]
Find wheel dependencies during an rpm build
38,358,342
<p>The rpm build for the project I'm working on isn't finding dependencies, and I can't seem to figure out why. I've installed all of them to my virtual environment and they are all being saved in my defined wheel directory. I'm using the <code>rpmvenv</code> library to generate the rpm, but every time I run it from my...
0
2016-07-13T17:37:56Z
38,377,240
<p>Pip and rpm use different dependecy resolver and db. If you install python module using pip, then rpm do not know about it. Rpm knows nothing about python paths and where it store modules. It just check rpmdb if python-numpy.rpm have been installed.</p> <p>If you need that package you can find it here <a href="http...
0
2016-07-14T14:43:11Z
[ "python", "ubuntu", "rpm" ]
'NoneType' object has no attribute, reference class variable declared before __init__
38,358,347
<p>I am using Flask with SQLAlchemy to create a 1-to-1 relationship between a Search request and parsed Data. Once a user has checked over the search results, they can click continue to parse the data (and create a Data class instance). However, I am unsure how to reference class variables before an <code>__init__</cod...
0
2016-07-13T17:38:18Z
38,358,562
<p>A few recommendations</p> <p>The <code>search</code> attributes actually <em>is</em> declared, it's just not set. If it wasn't declared, you would get an <code>AttributeError</code>. </p> <p>Call the superclass <code>__init__</code>. This is just good practice for all classes</p> <pre><code>def __init__(*args,...
0
2016-07-13T17:51:02Z
[ "python", "sqlalchemy", "python-requests" ]
How to save&restore DNNClassifier trained in TensorFlow python; iris example
38,358,419
<p>I'm new to TensorFlow, just started learning a few days ago. I've completed this tutorial(<a href="https://www.tensorflow.org/versions/r0.9/tutorials/tflearn/index.html#tf-contrib-learn-quickstart" rel="nofollow">https://www.tensorflow.org/versions/r0.9/tutorials/tflearn/index.html#tf-contrib-learn-quickstart</a>) a...
1
2016-07-13T17:42:09Z
38,489,883
<p>found the solution to this? In case you didn't you can do this specifying the model_dir parameter on the constructor when creating the DNNClassifier, this will create all the checkpoints and files in this directory(the saving step). When you want to do the restore step, you just create another DNNClassifier passing...
1
2016-07-20T20:06:17Z
[ "python", "tensorflow" ]
How to save&restore DNNClassifier trained in TensorFlow python; iris example
38,358,419
<p>I'm new to TensorFlow, just started learning a few days ago. I've completed this tutorial(<a href="https://www.tensorflow.org/versions/r0.9/tutorials/tflearn/index.html#tf-contrib-learn-quickstart" rel="nofollow">https://www.tensorflow.org/versions/r0.9/tutorials/tflearn/index.html#tf-contrib-learn-quickstart</a>) a...
1
2016-07-13T17:42:09Z
38,518,220
<p>Below is my Code...</p> <pre><code>import tensorflow as tf import numpy as np if __name__ == '__main__': # Data sets IRIS_TRAINING = "iris_training.csv" IRIS_TEST = "iris_test.csv" # Load datasets. training_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TRAINING, target_dtype=np.int) test_set = tf.co...
0
2016-07-22T04:33:09Z
[ "python", "tensorflow" ]
NLTK error using php
38,358,511
<p>I am developing a PHP website. I have an extra requirement to make a recommendation system. Python is best in that case. I already developed recommendation system in python and it works well. Now I want to combine python recommendation system with my PHP website. When I call python file from my PHP webpage I am gett...
0
2016-07-13T17:47:41Z
38,360,017
<p><code>nltk.download()</code> should be run from a Python shell which was started with root permissions. On Debian for example, <code>su</code>, <code>(yourrootpassword)</code> <code>python</code> and <code>nltk.download()</code>. You should be able to download everything there. </p> <p>The import for NLTK is NOT en...
0
2016-07-13T19:19:49Z
[ "php", "python", "nltk" ]
NLTK error using php
38,358,511
<p>I am developing a PHP website. I have an extra requirement to make a recommendation system. Python is best in that case. I already developed recommendation system in python and it works well. Now I want to combine python recommendation system with my PHP website. When I call python file from my PHP webpage I am gett...
0
2016-07-13T17:47:41Z
38,383,669
<p>I found solution to my problem. When I was running code from python shell, it was able to locate "nltk_data" folder but It was not able to reach this folder when I was trying to execute same code from PHP. I have added "nltk_data" path manually as shown below in my Python code once after importing nltk libraries and...
0
2016-07-14T20:25:29Z
[ "php", "python", "nltk" ]
Alternative of urllib.urlretrieve in Python 3.5
38,358,521
<p>I am currently doing a course on machine learning in UDACITY . In there they have written some code in python 2.7 but as i am currently using python 3.5 , i am getting some error . This is the code </p> <pre><code>import urllib url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz" urllib.urlretrieve(url, ...
0
2016-07-13T17:48:27Z
38,358,646
<p>You'd use <a href="https://docs.python.org/3/library/urllib.request.html#urllib.request.urlretrieve" rel="nofollow"><code>urllib.request.urlretrieve</code></a>. Note that this function "may become deprecated at some point in the future", so you might be better off using the less likely to be deprecated interface:</...
4
2016-07-13T17:54:47Z
[ "python", "python-3.x", "urllib2" ]
Python PriorityQueue order
38,358,523
<p>I'm trying to figure out in what order PriorityQueue.get() returns values in Python. First I thought that the smaller priority values get returned first but after few examples it's not like that. This is the example that I have run:</p> <pre><code>&gt;&gt;&gt; qe = PriorityQueue() &gt;&gt;&gt; qe.put("Br", 0) &gt;&...
1
2016-07-13T17:48:30Z
38,358,564
<p>According to <a href="https://docs.python.org/2/library/queue.html" rel="nofollow">doc</a>, the first parameter is priority, and second - is value. So that's why you get such result.</p> <blockquote> <p>A typical pattern for entries is a tuple in the form: (priority_number, data).</p> </blockquote> <p>So you sho...
1
2016-07-13T17:51:05Z
[ "python", "priority-queue" ]
wxPython styledtextctrl: How to get number of visible lines with word wrapping enabled?
38,358,541
<p>I am trying to determine the number of lines displayed on the screen in a wxPython styledtextctrl with word wrapping enabled. </p> <p>I have seen several answers to visible lines here:</p> <p><a href="http://stackoverflow.com/questions/19896965/wxpython-styledtextctrl-get-currently-visible-lines">wxPython - Styled...
1
2016-07-13T17:49:48Z
38,363,500
<p>I assume what you want is the number of <em>document</em> lines, rather than the number of <em>display</em> lines. So if wrapping is enabled, the former will be less than the latter if any lines are wrapped.</p> <p>As you've already discovered, <code>LinesOnScreen()</code> will give the number of visible <em>displa...
1
2016-07-13T23:54:53Z
[ "python", "wxpython", "scintilla" ]
Unable to retrieve known keys in python/boto
38,358,591
<p>I'm attempting to connect to a coworkers S3 bucket using python and boto. I was previously able to do this without any issues, but they recently added prefixes/directories to the bucket and I can no longer access the keys.</p> <p>Any attempts to get a key with bucket.get_key(keyname) return a NoneType. If I get all...
1
2016-07-13T17:52:44Z
38,396,618
<p>As mootmoot suggested, I installed boto3.</p> <p><a href="http://boto3.readthedocs.io/en/latest/guide/migration.html" rel="nofollow">http://boto3.readthedocs.io/en/latest/guide/migration.html</a></p> <p>boto3 works very differently from boto, so I had to make some changes to my code. The documentation can be found...
1
2016-07-15T12:51:03Z
[ "python", "amazon-s3", "boto", "boto3" ]
date type changed after strptime and then strftime?
38,358,689
<p>New to Python so I have question as following. Why a is not equal to b? Thank you.</p> <pre><code>fundData['SigDate'] 0 31DEC2008 1 31JAN2009 2 28FEB2009 3 31MAR2009 4 30APR2009 a=fundData['SigDate'] b=fundData['SigDate'].apply(lambda x : datetime.strptime...
1
2016-07-13T17:57:05Z
38,358,758
<p>The <code>'strptime/strftime'</code> transformation returns a string in <em>sentence case</em> for the month entry, so your comparison is rightly <code>False</code>:</p> <pre><code>&gt;&gt;&gt; from datetime import datetime as dt &gt;&gt;&gt; &gt;&gt;&gt; x = "31DEC2008" &gt;&gt;&gt; dt.strptime(x,'%d%b%Y').strftim...
1
2016-07-13T18:01:11Z
[ "python", "datetime" ]
How to programmatically update data in WFS geoserver layer
38,358,764
<p>I am building an application where the user retrieves all the features of a geoserver layer (store: postgres) and display them on a table. For doing this I use the OWSLib (get_feature).</p> <p>Now I need to add the functionality of editing the data (WFS-T). As far as I know OWSLib doesn't provide an add/update feat...
1
2016-07-13T18:01:23Z
38,371,270
<p>The error message (unusually) is actually helpful here - if the layer is read only you can run an update against it. So the question then becomes why is the layer read only? The most likely reason (especially if the transaction works in the demo page) is that your python script didn't authenticate with the server. F...
1
2016-07-14T10:04:54Z
[ "python", "geoserver" ]
Complex data transformation in Python
38,358,788
<p>My dataset looks like this : <a href="https://www.dropbox.com/s/u4brzjnhac0pwnj/TEST.xlsx?dl=0" rel="nofollow">https://www.dropbox.com/s/u4brzjnhac0pwnj/TEST.xlsx?dl=0</a></p> <p>I need to convert the data in the original table to the one in the desired table, in the attached file.</p> <p>I have a set of household...
0
2016-07-13T18:02:37Z
38,383,461
<p>Although i couldnt not do it faster in python, i was able to do it in sql pretty quickly using analytics function.</p> <pre><code> select month_id, household_id, tuned_duration,weekend_tuned_duration,channel_flips,most_common_daypart, programs_watched_per_hh,trend,midnight,morning,afternoon,evening, --rank() ove...
0
2016-07-14T20:11:51Z
[ "python", "pandas", "machine-learning" ]
Find a substring within a textfile in Python
38,358,833
<p>So I am trying to extract a link within a textfile in Python -- this link varies from textfile to textfile but has the same format. I tried using the re library but keep getting errors. </p> <p>The syntax of the link is:</p> <pre><code>docs.com/searchres.aspx?docformat=all&amp;docid=[SOME NUMBER] - </code></pre> ...
1
2016-07-13T18:04:56Z
38,359,244
<p>Here's a Python solution that uses memory maps. A few caveats:</p> <ol> <li>You said there was only one instance in the file, and if there is more than one, it will return the first.</li> <li>I put this together quickly from some old code. If <code>]</code> is not in the text file, it will continue reading. Take a ...
0
2016-07-13T18:29:19Z
[ "python", "string", "python-2.7", "find", "substring" ]
Find a substring within a textfile in Python
38,358,833
<p>So I am trying to extract a link within a textfile in Python -- this link varies from textfile to textfile but has the same format. I tried using the re library but keep getting errors. </p> <p>The syntax of the link is:</p> <pre><code>docs.com/searchres.aspx?docformat=all&amp;docid=[SOME NUMBER] - </code></pre> ...
1
2016-07-13T18:04:56Z
38,359,674
<p>So this response is simple, but works for small files. When you say "save this link" I assume having the url in a string variable is good enough.</p> <pre><code>import re f = open(filename_str, 'r') file_content = f.read() p = re.compile('docs.com(.)*\-') m = p.search(file_content) if m != None: link = m.group...
0
2016-07-13T18:58:22Z
[ "python", "string", "python-2.7", "find", "substring" ]
Python: Finding key with its value having the maximum absolute value in dictionary
38,358,928
<p>So say I have a dictionary like: </p> <pre><code>d = {'A': 2 , 'B': -4, 'C': 3} </code></pre> <p>I want to return 'B'. In the past my dictionary didn't have to store negative values and I had just been checking for the key with the maximum value with:</p> <pre><code>maxkey = max(d, key=lambda y: d[y]) </code></p...
1
2016-07-13T18:10:56Z
38,358,971
<p>When using a <code>lambda</code> expression in Python, you want to have the right side of the colon to be the function you're performing. If before, you wanted to sort by the values, ie. <code>d[y]</code> and now you want to take the absolute value of those, you just do it like so: </p> <pre><code>maxkey = max(d, k...
1
2016-07-13T18:13:09Z
[ "python", "dictionary" ]
Python: Finding key with its value having the maximum absolute value in dictionary
38,358,928
<p>So say I have a dictionary like: </p> <pre><code>d = {'A': 2 , 'B': -4, 'C': 3} </code></pre> <p>I want to return 'B'. In the past my dictionary didn't have to store negative values and I had just been checking for the key with the maximum value with:</p> <pre><code>maxkey = max(d, key=lambda y: d[y]) </code></p...
1
2016-07-13T18:10:56Z
38,358,979
<p>I think you want:</p> <pre><code>maxkey = max(d, key=lambda y: abs(d[y])) </code></pre>
5
2016-07-13T18:13:34Z
[ "python", "dictionary" ]
python pandas reading excel file
38,358,963
<p>I have a xlsx file which has headers in column A and values in columns B through Z. How do I use pandas to read the excel file so that it reads the column names from column A and fills those columns with values from columns B through Z. </p> <p>Right now when I try to read the excel file it uses the top row value i...
0
2016-07-13T18:12:43Z
38,359,031
<p>you can do it this way:</p> <pre><code>In [8]: df = pd.read_excel(fn, header=None, index_col=0).T In [9]: df Out[9]: 0 col1 col2 col3 col4 1 1 10 100 1000 2 11 101 1001 10001 </code></pre> <p>Source Excel file:</p> <p><a href="http://i.stack.imgur.com/xf8G9.jpg" rel="nofollow"><img src="ht...
2
2016-07-13T18:16:27Z
[ "python", "pandas" ]
Python converting time zone into hours?
38,358,977
<p>I'm running some Django unit tests, and one of them involves creating timezone-aware datetimes. </p> <p>My time stamp starts out as the string: <code>2011-12-05 00:00:00-07:00</code>, which gets passed to the model constructor. </p> <p>When I print the string stored in the model, I get: <code>2011-12-05 07:00:00+0...
0
2016-07-13T18:13:25Z
38,359,321
<p>From the <a href="https://docs.djangoproject.com/en/1.9/topics/i18n/timezones/" rel="nofollow">documentation</a>:</p> <blockquote> <p>When support for time zones is enabled, Django stores datetime information in UTC in the database, uses time-zone-aware datetime objects internally, and translates them to the end ...
2
2016-07-13T18:34:27Z
[ "python", "django", "timezone" ]
Matplotlib: is there an rcParams way to adjust legend border width?
38,359,008
<p><a href="http://matplotlib.org/users/customizing.html" rel="nofollow">This site</a> shows many (all?) rc parameters that can be adjusted in Matplotlib plots, either through the <code>matplotlibrc</code> file or using <code>matplotlib.rcParams[]</code> in a Python script. I can see no way to adjust the width of the ...
1
2016-07-13T18:15:02Z
38,379,176
<p>Depending on what you are trying to do, it may in fact be possible to set the width of the legend border via <code>rcParams</code>.</p> <p><strong>TL;DR</strong></p> <p>Set <code>patch.linewidth</code> in <code>matplotlibrc</code> or better yet, write a two-line wrapper function for <code>legend</code> and use tha...
2
2016-07-14T16:10:33Z
[ "python", "matplotlib", "legend-properties" ]
How to plot incomplete data with matplotlib
38,359,024
<p>I am doing some processing and I want to plot progress. I know my total number of runs, I calculate results on every 100th run and I want to generate a new plot every time. So, my code looks something like this</p> <pre> start = time.time() speeds = [] for step in range(steps): do_my_stuff() if step % 100 =...
0
2016-07-13T18:16:11Z
38,363,180
<p>I would plot every single pair of x and y interactively, and set the limits of the plot to the desired values. You can still append the data if you need it later on. Look at this example:</p> <pre><code>import time import matplotlib.pyplot as plt import matplotlib plt.ion() fig = plt.figure(1,figsize=(5,5)) ax =...
0
2016-07-13T23:12:28Z
[ "python", "numpy", "matplotlib" ]
python - minimax algorithm for tic tac toe updating the board by filling every empty space with the same symbol
38,359,039
<p>I have been trying to improve my understanding of python by programming small games, such as tic tac toe. I created a copy of the game from scratch, but then went off to find a way of creating a reasonable ai for the game. I decided to use minimax to achieve this goal. I found a tutorial for the algorithm and attemp...
0
2016-07-13T18:16:49Z
38,359,227
<p>Problem lies when you init your node you just copy the ref of <code>board</code>:</p> <pre><code>self.board = board </code></pre> <p>whereas you should copy the values</p> <pre><code>self.board = board[::] </code></pre> <p>Else all your Node objects refer to the same board: the global one.</p>
0
2016-07-13T18:28:30Z
[ "python", "algorithm", "tic-tac-toe", "minimax" ]
Reformat Pandas Data Frame with 1 Column's Values as Columns and other Columns as rows
38,359,124
<p>I have a <code>df</code> structured like:</p> <pre><code>name date A B C n1 07/01 a b c n1 06/01 aa bb cc n1 05/01 aaa bbb ccc ... </code></pre> <p>I need to structure the dataframe so it looks like:</p> <pre><code>name letters 05/01 06/01 07/01 n1 A aaa aa ...
2
2016-07-13T18:21:39Z
38,359,320
<p>Try this:</p> <pre><code>df1 = df.drop('name', 1).set_index('date').rename_axis('letters', 1).sort_index(1, ascending=1).T.reset_index() df1.set_index(pd.Index(['n1'] * len(df1), name='name')).reset_index().rename_axis(None, 1) </code></pre> <p><a href="http://i.stack.imgur.com/Cv8OI.png" rel="nofollow"><img src="...
1
2016-07-13T18:34:26Z
[ "python", "pandas" ]
Reformat Pandas Data Frame with 1 Column's Values as Columns and other Columns as rows
38,359,124
<p>I have a <code>df</code> structured like:</p> <pre><code>name date A B C n1 07/01 a b c n1 06/01 aa bb cc n1 05/01 aaa bbb ccc ... </code></pre> <p>I need to structure the dataframe so it looks like:</p> <pre><code>name letters 05/01 06/01 07/01 n1 A aaa aa ...
2
2016-07-13T18:21:39Z
38,360,326
<p>I wanted to preserve my other answer, but I think this is a better answer.</p> <pre><code>tpose = lambda df: df.drop('name', 1).set_index('date').T df.groupby('name', as_index=True).apply(tpose) </code></pre> <p><a href="http://i.stack.imgur.com/tYWtI.png" rel="nofollow"><img src="http://i.stack.imgur.com/tYWtI.pn...
0
2016-07-13T19:39:44Z
[ "python", "pandas" ]
Reformat Pandas Data Frame with 1 Column's Values as Columns and other Columns as rows
38,359,124
<p>I have a <code>df</code> structured like:</p> <pre><code>name date A B C n1 07/01 a b c n1 06/01 aa bb cc n1 05/01 aaa bbb ccc ... </code></pre> <p>I need to structure the dataframe so it looks like:</p> <pre><code>name letters 05/01 06/01 07/01 n1 A aaa aa ...
2
2016-07-13T18:21:39Z
38,364,159
<p>Try this: </p> <pre><code> pd.concat([df[["name"]],df.iloc[:,1:].set_index("date").T.reset_index()],axis= 1 ).rename(columns = {'index':'letter'}) name letter 07/01 06/01 05/01 0 n1 A a aa aaa 1 n1 B b bb bbb 2 n1 C c cc ccc </code></pre>
0
2016-07-14T01:31:13Z
[ "python", "pandas" ]
How can I export binary data from Python subprocess command through STDOUT?
38,359,148
<p>I am trying re-save a PDF with Ghostscript (to correct errors that PyPDF2 can't handle). I'm calling Ghostscript with <code>subprocess.check_output</code>, and I want to pass the original PDF in as STDIN and export the new one as STDOUT.</p> <p>When I save the PDF to a file and read it back in, it works fine. When ...
0
2016-07-13T18:23:05Z
38,363,006
<p>Turns out, this has nothing to do with Python. It's a Ghostscript error. As pointed out in this post: <a href="http://stackoverflow.com/questions/3351967/prevent-ghostscript-from-writing-errors-to-standard-output">Prevent Ghostscript from writing errors to standard output</a>, Ghostscript writes errors to stdout, wh...
0
2016-07-13T22:52:02Z
[ "python", "shell", "subprocess" ]
Read vertically all the values of all the possible combinations of an unknown number of lists with different sizes in Python
38,359,160
<p>I want implement a function that combines <strong>vertically</strong> all the elements of an <strong>unknown number of lists</strong> in Python. Each list has a <strong>different size</strong>. E.g., this is the list of list and each row is a list:</p> <pre><code>A0, A1 B0 C0, C1, C2 </code></pre> <p>Then I would...
0
2016-07-13T18:24:00Z
38,359,914
<p>I believe that what you want here is the cross-product of the various sets. You can do this with Python's <strong>itertools.product</strong> method. Documentation is <a href="https://docs.python.org/2/library/itertools.html#itertools.product" rel="nofollow">here</a>. Something like:</p> <pre><code>import itertoo...
2
2016-07-13T19:13:39Z
[ "python", "list", "function", "recursion" ]
Pythonic way to check if integer fits in 64 bits
38,359,202
<p>What is the Pythonic way (without using any external libraries) to check if an integer is small enough to fit in a 64 bit signed quantity?</p> <p>Sorry if this question has been asked before!</p>
3
2016-07-13T18:26:58Z
38,359,221
<p>Just check the size with the <a href="https://docs.python.org/2/library/stdtypes.html#int.bit_length" rel="nofollow"><code>int.bit_length()</code> method</a>:</p> <pre><code>if integer_value.bit_length() &lt;= 63: </code></pre> <p>The method takes the absolute value, so you want to leave a bit for the sign:</p> <...
8
2016-07-13T18:28:12Z
[ "python", "integer", "64bit" ]
Employing correlation coefficients (Pearson) for dimension reduction [Python]
38,359,240
<p>I'm utilizing <a href="http://stackoverflow.com/questions/3437513/finding-the-correlation-matrix?answertab=active#tab-top">this</a> answer in order to find the correlation coefficients greater than a given limit, f, in a matrix (ndarray) that is of shape (29421, 11001) [i.e. 29,421 rows and 11,001 columns].</p> <p>...
0
2016-07-13T18:29:02Z
38,577,345
<p>Figured it out...and this is the weirdest thing. I just needed to flip the axis.</p> <pre><code> # Create correlations. dataset_normalized_switched = np.swapaxes(dataset_normalized, 0, 1) columns = dataset_normalized_switched.shape[0] ### This is the major change... ms = dataset_normalized_switched.mean(axis...
0
2016-07-25T21:00:15Z
[ "python", "matrix", "dimension-reduction", "pearson-correlation" ]
Use GitHub Releases with Esky
38,359,302
<p>Is it possible to use the github releases as a sever to host updates that esky can use? And if yes, how do I implement this especially with regards to the url I provide to the </p> <pre><code>updater = esky.Esky(sys.executable, "http://localhost:8000") </code></pre> <p>command? Or do I have to host my releases som...
1
2016-07-13T18:32:49Z
38,436,908
<p>The default Esky finder needs a directory to look in. You could extend it to look in and download from github releases.</p> <p>I have had success with using <a href="https://pages.github.com/" rel="nofollow">Github pages</a> to serve my static files.</p> <p>For a github user of <code>linus</code> and project <code...
1
2016-07-18T12:37:26Z
[ "python", "git", "github", "esky" ]
Print individual elements of a list in python
38,359,359
<p>I have the following extract from an input file:</p> <pre><code>Query_7736 1624 SDLA**VY*EMQALRIKPSNVTFSILIKLYGRNKQVSKAIEVLEEMKR*GVQPGMIVYTC 1803 XP_002972017 833 MAEACELMRSLRSLRVSPDTVTFSTLIDGLCKCGQTDEACNVFDDMIAGGYVPNVVTYNV 894 XP_002972017 583 FEQASALFEEMVAKNLQPDVMTFGALIDGLCKAGQVEAARDILDLMGNLGVPPNVVTYN...
1
2016-07-13T18:36:41Z
38,359,479
<p>Just join each column of your last list with a comma</p> <pre><code>result = list(sequence[star_index] for star_index in star_indices) for i in range(len(result[0])): print(", ".join([l[i] for l in result])) </code></pre> <p>Here's what you get</p> <pre><code>In [2]: result = [['C', 'E', 'R', 'G'], ['S', 'A',...
0
2016-07-13T18:45:32Z
[ "python", "bioinformatics", "biopython" ]
Print individual elements of a list in python
38,359,359
<p>I have the following extract from an input file:</p> <pre><code>Query_7736 1624 SDLA**VY*EMQALRIKPSNVTFSILIKLYGRNKQVSKAIEVLEEMKR*GVQPGMIVYTC 1803 XP_002972017 833 MAEACELMRSLRSLRVSPDTVTFSTLIDGLCKCGQTDEACNVFDDMIAGGYVPNVVTYNV 894 XP_002972017 583 FEQASALFEEMVAKNLQPDVMTFGALIDGLCKAGQVEAARDILDLMGNLGVPPNVVTYN...
1
2016-07-13T18:36:41Z
38,359,736
<p>Given the following </p> <pre><code>In [7]: list(d2) Out[7]: [['C', 'E', 'R', 'G'], ['S', 'A', 'E', 'L'], ['C', 'Q', 'E', 'F'], ['H', 'A', 'E', 'R'], ['L', 'E', 'H', 'H'], ['S', 'S', 'K', 'R'], ['L', 'E', 'A', 'A'], ['R', 'K', 'E', 'S'], ['E', 'R', 'E', 'R'], ['Q', 'E', 'K', 'T'], ['C', 'K', 'E', 'R'], ...
0
2016-07-13T19:02:53Z
[ "python", "bioinformatics", "biopython" ]
Print individual elements of a list in python
38,359,359
<p>I have the following extract from an input file:</p> <pre><code>Query_7736 1624 SDLA**VY*EMQALRIKPSNVTFSILIKLYGRNKQVSKAIEVLEEMKR*GVQPGMIVYTC 1803 XP_002972017 833 MAEACELMRSLRSLRVSPDTVTFSTLIDGLCKCGQTDEACNVFDDMIAGGYVPNVVTYNV 894 XP_002972017 583 FEQASALFEEMVAKNLQPDVMTFGALIDGLCKAGQVEAARDILDLMGNLGVPPNVVTYN...
1
2016-07-13T18:36:41Z
38,361,216
<p>If you can have more than one "Query_" per file and in different order:</p> <pre><code>lines = [line.rstrip().split() for line in open('infile.txt')] # Load the indexes in one list, the sequences in another # As shown in http://stackoverflow.com/a/21023591/1688590 indexes, sequences = [], [] for line in lines: ...
1
2016-07-13T20:34:09Z
[ "python", "bioinformatics", "biopython" ]
How to initialize Tensor variable as identity matrix in TensorFlow
38,359,412
<p>How do I initialize a Tensor T as the identity matrix?</p> <p>The following initializes T as a 784 by 784 matrix of zeros.</p> <pre><code>T = tf.Variable(tf.zeros([784, 784])) </code></pre> <p>But I can't find a tf.fn that behaves as required. How can this be done?</p>
1
2016-07-13T18:40:08Z
38,359,737
<p>You can actually pass numpy arrays as an argument for initial_value, so <code>tf.Variable(initial_value = np.identity(784))</code> should do what you intend to do.</p>
2
2016-07-13T19:03:02Z
[ "python", "tensorflow" ]
python datetime remove minute and second information
38,359,475
<p>I have a datetime array which has hour, minute and second information. I want to remove the minute and second infromation from it and change the hour to the next hour.</p> <p>i.e. peak_interval</p> <pre><code>array([datetime.datetime(2010, 12, 13, 6, 0), datetime.datetime(2011, 1, 12, 7, 0), datetim...
0
2016-07-13T18:45:20Z
38,359,719
<p>One option is to use <code>timedelta</code> from <code>datetime</code>:</p> <pre><code>import datetime import numpy as np def reset(dt): return dt + datetime.timedelta(hours = 1, minutes = -dt.minute, seconds = -dt.second) np.vectorize(reset)(peak_interval) # array([datetime.datetime(2010, 12, 13, 7, 0), # ...
2
2016-07-13T19:00:59Z
[ "python", "datetime" ]
python datetime remove minute and second information
38,359,475
<p>I have a datetime array which has hour, minute and second information. I want to remove the minute and second infromation from it and change the hour to the next hour.</p> <p>i.e. peak_interval</p> <pre><code>array([datetime.datetime(2010, 12, 13, 6, 0), datetime.datetime(2011, 1, 12, 7, 0), datetim...
0
2016-07-13T18:45:20Z
38,359,964
<p>You can easily modify just a few fields using <a href="https://docs.python.org/3/library/datetime.html#datetime.datetime.replace" rel="nofollow"><code>datetime.datetime.replace</code></a></p> <pre><code>old_date = datetime.datetime(2011, 3, 23, 16, 45) new_date = old_date.replace(minute=0, second=0) + datetime.time...
2
2016-07-13T19:16:50Z
[ "python", "datetime" ]
What is the best way to remove accents with apache spark dataframes in PySpark?
38,359,534
<p>I need to delete accents from characters in spanish and others languages from different datasets. </p> <p>I already did a function based in the code provided in this <a href="http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string">post</a> that removes special th...
13
2016-07-13T18:49:18Z
38,361,250
<p>This solution is Python only, but is only useful if the number of possible accents is low (e.g. one single language like Spanish) and the character replacements are manually specified.</p> <p>There seems to be no built-in way to do what you asked for directly without UDFs, however you can chain many <code>regexp_re...
1
2016-07-13T20:36:08Z
[ "python", "apache-spark", "pyspark", "unicode-normalization" ]
What is the best way to remove accents with apache spark dataframes in PySpark?
38,359,534
<p>I need to delete accents from characters in spanish and others languages from different datasets. </p> <p>I already did a function based in the code provided in this <a href="http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string">post</a> that removes special th...
13
2016-07-13T18:49:18Z
38,438,628
<p>One possible improvement is to build a custom <a href="https://spark.apache.org/docs/latest/ml-guide.html#transformers" rel="nofollow"><code>Transformer</code></a>, which will handle Unicode normalization, and corresponding Python wrapper. It should reduce overall overhead of passing data between JVM and Python and ...
4
2016-07-18T13:57:09Z
[ "python", "apache-spark", "pyspark", "unicode-normalization" ]
What is the best way to remove accents with apache spark dataframes in PySpark?
38,359,534
<p>I need to delete accents from characters in spanish and others languages from different datasets. </p> <p>I already did a function based in the code provided in this <a href="http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string">post</a> that removes special th...
13
2016-07-13T18:49:18Z
38,521,579
<p>Another way for doing using python <a href="https://docs.python.org/2/library/unicodedata.html" rel="nofollow">Unicode Database</a> :</p> <pre><code>import unicodedata import sys from pyspark.sql.functions import translate, regexp_replace def make_trans(): matching_string = "" replace_string = "" for...
4
2016-07-22T08:21:59Z
[ "python", "apache-spark", "pyspark", "unicode-normalization" ]
Pyinstaller- python exe stopped working: "Cannot open self"
38,359,547
<p>I have been using Pyinstaller to convert pycharm scripts into executables. It has worked for me just fine in the past. However now when I try to run the executables (both old ones and new ones) I get the error "Cannot open self _____ or archive _____", where the first blank is the path of the executable and the seco...
1
2016-07-13T18:50:06Z
39,614,065
<p>The same happened to me when I:</p> <ol> <li>kept the executable opened on a Windows virtual machine;</li> <li>in the same time I began to rebuild the executable with Pyinstaller;</li> <li>then I rerun the executable and got the same message</li> </ol> <p>Once I closed the application and then ran Pyinstaller, the...
1
2016-09-21T10:31:03Z
[ "python", "python-3.x", "cmd", "exe", "pyinstaller" ]
How to count items in Postgresql-database with Django ORM by DateTimeField()
38,359,656
<p>We have a Django application with a Postgresql database. We have a model that contains a <code>DateTimeField()</code>.</p> <p>How do we count the items by hour per day? So that we get something like:</p> <pre><code>July 2, 2016, 4 p.m. | 10 July 2, 2016, 5 p.m. | 12 ... July 3, 2016, 4 p.m. | 7 July 3, 2016, 5 p.m...
2
2016-07-13T18:57:27Z
38,359,794
<p>Try with:</p> <pre><code>MyModel.objects.values('my_date__date', 'my_date__hour').annotate(Count('id')) </code></pre>
1
2016-07-13T19:06:17Z
[ "python", "django", "postgresql", "python-3.x", "django-queryset" ]
How to count items in Postgresql-database with Django ORM by DateTimeField()
38,359,656
<p>We have a Django application with a Postgresql database. We have a model that contains a <code>DateTimeField()</code>.</p> <p>How do we count the items by hour per day? So that we get something like:</p> <pre><code>July 2, 2016, 4 p.m. | 10 July 2, 2016, 5 p.m. | 12 ... July 3, 2016, 4 p.m. | 7 July 3, 2016, 5 p.m...
2
2016-07-13T18:57:27Z
38,359,913
<p>Django 1.10 introduces new database functions (<a href="https://docs.djangoproject.com/en/1.10/ref/models/database-functions/#extract" rel="nofollow">Extract</a> and <a href="https://docs.djangoproject.com/en/1.10/ref/models/database-functions/#trunc" rel="nofollow">Trunc</a>):</p> <pre><code>from django.db.models ...
2
2016-07-13T19:13:38Z
[ "python", "django", "postgresql", "python-3.x", "django-queryset" ]
How to count items in Postgresql-database with Django ORM by DateTimeField()
38,359,656
<p>We have a Django application with a Postgresql database. We have a model that contains a <code>DateTimeField()</code>.</p> <p>How do we count the items by hour per day? So that we get something like:</p> <pre><code>July 2, 2016, 4 p.m. | 10 July 2, 2016, 5 p.m. | 12 ... July 3, 2016, 4 p.m. | 7 July 3, 2016, 5 p.m...
2
2016-07-13T18:57:27Z
38,360,348
<p>So, until Django 1.10, this looks to be about the best way:</p> <pre><code>jobs = MyModel.objects.filter(my_date__lte=datetime.now()).extra({"hour": "date_trunc('hour', my_date)"}).values( "hour").order_by('my_date').annotate(count=Count("id")) </code></pre> <p>The above code is modified from that which is...
1
2016-07-13T19:41:22Z
[ "python", "django", "postgresql", "python-3.x", "django-queryset" ]
Creating continues nested for loop
38,359,723
<p>Is it possible to write a function that adds more <code>for</code> loops to a nested loop. So lets say I have a function <code>for_loops(3)</code>.</p> <pre><code> def for_loops(n): a = [] for add_v in range(n): a.append("AB") for i in range(len(a[0])): for j in r...
1
2016-07-13T19:01:43Z
38,359,888
<p>You can achieve a similar result using <code>itertools.product</code> which generates a Cartesian product </p> <pre><code>def for_loops(n): from itertools import product for row in product("AB", repeat = n): print " ".join(row) </code></pre> <p>The way it works is, given a set, it will generate the...
3
2016-07-13T19:11:46Z
[ "python", "loops" ]
Python 3.4 Convert bytes literal string to bytes object
38,359,861
<p>This is not about decoding using UTF-8. This is about reading a bytes object as a literal and needing it as a bytes object without reinventing the parsing process. If there is an answer to my question out there, it is hiding behind a lot of answers to questions about decoding.</p> <p>Here is what I need:</p> <pr...
1
2016-07-13T19:10:08Z
38,359,918
<p>One approach would be to remove all the clutter from x (<code>bytearray(b'</code> and <code>')</code>), then we just convert each character to its byte representation and wrap it into a <code>bytearray</code> object.</p> <pre><code>x = "bytearray(b'abc\xd8\xa2\xd8\xa8\xd8\xa7xyz')" y = bytes(ord(c) for c in x[12:-2...
1
2016-07-13T19:13:59Z
[ "python", "python-3.x" ]
numpy genfromtxt breaks on #
38,359,890
<p>I have a csv file that includes some <code>#</code>:</p> <pre><code>a,1,asdf a#,2,asdf </code></pre> <p>When I try to use numpy genfromtxt, it fails:</p> <pre><code>data = np.genfromtxt('TestCSV.csv', delimiter=',') ValueError: Some errors were detected ! Line #2 (got 1 columns instead of 3) </code></pre> <p>As...
0
2016-07-13T19:12:12Z
38,360,139
<p>The <code>#</code> is a special character for comments. To load your data with the <code>genfromtxt</code>, you have to replace it. </p> <pre><code>numpy.genfromtxt('txt', delimiter=',', dtype=str, comments='%') </code></pre> <p>And the output is:</p> <pre><code>array([['a', '1', 'asdf'], ['a#', '2', 'asdf...
2
2016-07-13T19:26:42Z
[ "python", "numpy" ]
Django Rest Framework: "Invalid literal for in()" with a CharField
38,359,900
<p>I am trying to create an API endpoint for user favorites. However, I have now hit an issue I cannot resolve.</p> <p>I am getting an invalid literal error for a CharField when POSTing to the endpoint.</p> <pre><code>ValueError at /api/users/2/favourites/ invalid literal for int() with base 10: 'track' </code></pre>...
0
2016-07-13T19:13:04Z
38,360,141
<p>Here you have a <code>CharField</code>:</p> <pre><code>type = serializers.CharField(source='content_type') </code></pre> <p>While <code>content_type</code> is a <code>ForeignKey</code> to <code>ContentType</code> which primary key is an integer:</p> <pre><code>content_type = models.ForeignKey(ContentType) </code>...
1
2016-07-13T19:26:47Z
[ "python", "django", "django-rest-framework" ]
pandas collapse Series values into one value
38,359,919
<p>How does one collapse a Series into one value? I tried <code>pd.concat()</code>.</p> <pre><code> dict = {"Cities": ["Chicago", "Hong Kong", "London"], "People": ["John", "Mike", "Sue"]} df = pd.Dataframe.from_dict(dict) Cities People 0 Chicago John 1 Hong Kong Mike 2 London Sue </co...
0
2016-07-13T19:13:59Z
38,359,978
<p>I believe ' '.join(series) should do it</p>
1
2016-07-13T19:17:56Z
[ "python", "pandas" ]
pandas collapse Series values into one value
38,359,919
<p>How does one collapse a Series into one value? I tried <code>pd.concat()</code>.</p> <pre><code> dict = {"Cities": ["Chicago", "Hong Kong", "London"], "People": ["John", "Mike", "Sue"]} df = pd.Dataframe.from_dict(dict) Cities People 0 Chicago John 1 Hong Kong Mike 2 London Sue </co...
0
2016-07-13T19:13:59Z
38,359,992
<p>You could use string method <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.cat.html" rel="nofollow"><code>Series.str.cat</code></a>, apart from <code>' '.join(df.People)</code></p> <pre><code>In [96]: df.People.str.cat(sep=' ') Out[96]: 'John Mike Sue' </code></pre>
1
2016-07-13T19:18:39Z
[ "python", "pandas" ]
pandas collapse Series values into one value
38,359,919
<p>How does one collapse a Series into one value? I tried <code>pd.concat()</code>.</p> <pre><code> dict = {"Cities": ["Chicago", "Hong Kong", "London"], "People": ["John", "Mike", "Sue"]} df = pd.Dataframe.from_dict(dict) Cities People 0 Chicago John 1 Hong Kong Mike 2 London Sue </co...
0
2016-07-13T19:13:59Z
38,360,087
<p>Try this:</p> <pre><code># Cannot be named dict, as dict is a type. dictionary = {"Cities": ["Chicago", "Hong Kong", "London"], "People": ["John", "Mike", "Sue"]} print(' '.join(dictionary['People']) </code></pre> <p>You don't have to type the first line, as it is a comment.</p>
0
2016-07-13T19:23:55Z
[ "python", "pandas" ]
Replicating "text to columns " using a script
38,359,935
<p>I have a csv file with the following format. Currently this is all in one string </p> <pre><code>Column 1 Frame 0 adm2_score:0.957 Frame 1 dm2_score:0.942 Frame 2 _adm2_score:0.935 Frame 3 _adm2_score:0.940 Frame 4 _adm2_score:0.927 Frame 5 _adm2_score:0.925 </code></pre> <p>However for my use case I want to separ...
0
2016-07-13T19:15:14Z
38,360,043
<p>You can use the <code>split()</code> function to divide it where you want</p> <pre><code>for line in file: list = line.split(":") ##turns into list at split at colon print list[0], ": ", list[1] </code></pre> <p>Or something similar to easily get what you want</p>
0
2016-07-13T19:21:09Z
[ "python", "csv", "delimiter" ]
Replicating "text to columns " using a script
38,359,935
<p>I have a csv file with the following format. Currently this is all in one string </p> <pre><code>Column 1 Frame 0 adm2_score:0.957 Frame 1 dm2_score:0.942 Frame 2 _adm2_score:0.935 Frame 3 _adm2_score:0.940 Frame 4 _adm2_score:0.927 Frame 5 _adm2_score:0.925 </code></pre> <p>However for my use case I want to separ...
0
2016-07-13T19:15:14Z
38,360,085
<p>just replace : by :\t using python. Simple standalone demo:</p> <pre><code>z="""Frame 0 VMAF_feature_adm2_score:0.957 Frame 1 VMAF_feature_adm2_score:0.942 Frame 2 VMAF_feature_adm2_score:0.935 Frame 3 VMAF_feature_adm2_score:0.940 Frame 4 VMAF_feature_adm2_score:0.927 Frame 5 VMAF_feature_adm2_score:0.925""".split...
1
2016-07-13T19:23:49Z
[ "python", "csv", "delimiter" ]
Replicating "text to columns " using a script
38,359,935
<p>I have a csv file with the following format. Currently this is all in one string </p> <pre><code>Column 1 Frame 0 adm2_score:0.957 Frame 1 dm2_score:0.942 Frame 2 _adm2_score:0.935 Frame 3 _adm2_score:0.940 Frame 4 _adm2_score:0.927 Frame 5 _adm2_score:0.925 </code></pre> <p>However for my use case I want to separ...
0
2016-07-13T19:15:14Z
38,361,326
<p>For any one who is confused as to how to this here is one method I found using a python script </p> <pre><code>import csv, sys z = open("output.csv","rb").read().splitlines() for l in z: print(l.replace(":",",")) </code></pre> <p>After that in commandline just run this </p> <pre><code>test.py &gt; new.csv </c...
0
2016-07-13T20:42:08Z
[ "python", "csv", "delimiter" ]
Python-how to calculate the highest tf-idf value of the first 100 words in different tweeets
38,360,010
<p>I have tens of thounds of tweets saved in one .txt file, I want to calculate calculate the highest tf-idf value of the first 100 words in these tweeets, in other words, I want to compare the word's tf-idf value between different tweets, presently,the only thing that I could complete is comparing word's tf-idf value ...
0
2016-07-13T19:19:29Z
38,360,140
<p>Now that I understand your question, I will try to answer your question a little better. </p> <p>To get the top 100 'tf-idf' scores in a way that is comparable across all tweets would either mean that you are letting go of the notion that there are distinct tweets, or you want to be able to compare the same words t...
1
2016-07-13T19:26:46Z
[ "python", "twitter", "scikit-learn", "tf-idf", "tweets" ]
Order of array items changing when being printed
38,360,037
<p>I was writing a Python program which includes printing a array created from user input in the order the user inputed each item of the array. Unfortunately, I have had few problems with that; Once it repeated the first item twice with one of the set, and then in another set it put the last 2 items at the beginning. I...
1
2016-07-13T19:20:49Z
38,360,066
<p>Don't you just want this?</p> <pre><code>for line in lines: print(line) </code></pre> <p><strong>EDIT</strong></p> <p>As an explanation of what's wrong with your code... you're looping one too many times (<code>leng+1</code> instead of <code>leng</code>). Then you're using <code>i - len(lines)</code>, which s...
2
2016-07-13T19:22:48Z
[ "python", "arrays" ]
Tensorflow cannot allocate memory even though it is available
38,360,181
<p>I am running a CNN on a rig with a GTX 970 with 4gb of VRAM. However, my code gets to the <code>tf.initialize_all_variables()</code>, it says that it cannot allocate all enough memory. Here is the exact line: </p> <pre><code>W tensorflow/core/common_runtime/bfc_allocator.cc:271] Ran out of memory trying to allocate...
0
2016-07-13T19:29:07Z
38,361,432
<p>From your logs:</p> <pre><code>Limit: 3460759552 InUse: 3460759552 MaxInUse: 3460759552 NumAllocs: 23 MaxAllocSize: 3410411008 </code></pre> <p>You are maxing out the memory of your GPU already, your model is too big to be processed on ...
0
2016-07-13T20:49:41Z
[ "python", "memory-management", "gpu", "tensorflow", "conv-neural-network" ]
Pandas and matplotlib doing linear graph
38,360,360
<p>Any idea whats missing in my code to avoid part of the graph/canvas and dates being out of the PNG image? Is it possible to have the dates written in 180 degrees or in vertical to not use so much space of the grapth? </p> <p>My data set is:</p> <pre><code>15/03/16 3000 300 200 12/04/16 3000 300 300 10/...
0
2016-07-13T19:42:02Z
38,361,071
<p>The data is there, it is just being plotted on the edge of the plot. You can change the y-limits globally with</p> <pre><code>df.plot(ylim=(0,3500)) df.plot(subplots=True, figsize=(6, 6), ylim=(0,3500)) </code></pre> <p>To change them for each plot, I think you'll need to plot the curves individually.</p> <p>To d...
0
2016-07-13T20:23:49Z
[ "python", "pandas", "matplotlib" ]
Removing accents with Python - Unicode doesn't work
38,360,450
<p>I'm trying to clean a spanish text with the following code:</p> <pre><code>import re import unicodedata file = open("dirty.txt").readlines() archivo = open("cleanText.txt", "w") textLowerCase = file[i].lower() unicodeText = textLowerCase.decode('unicode-escape') textWithoutAccents = unicodedata.normalize('NFKD', un...
-1
2016-07-13T19:47:19Z
38,360,757
<p>This is exactly what <strong>unidecode</strong> package does: <a href="https://pypi.python.org/pypi/Unidecode" rel="nofollow">https://pypi.python.org/pypi/Unidecode</a></p> <p>From the readme:</p> <blockquote> <p>The module exports a function that takes an Unicode object (Python 2.x) or string (Python 3.x) and r...
3
2016-07-13T20:04:42Z
[ "python", "unicode" ]
Pandas: Using asfreq
38,360,466
<p>I have a cyclical time series in mm:ss.0 format that looks like</p> <pre><code>59:58.5 59:58.7 59:59.1 00:00.0 00:00.1 00:00.2 </code></pre> <p>(This repeats for a while with no hour marker, i.e. it goes on for about five or six hours)</p> <p>What I want is to split the entire series into 30 second intervals, pre...
0
2016-07-13T19:48:10Z
38,363,246
<p>If you just want to split it, then use <code>groupby</code>. Each group will then hold the data for that group only.</p> <pre><code>grouped = df.groupby(&lt;time column or index&gt;) for name, group in grouped: print(name, group) </code></pre> <p>The reason you are getting the said error is because there are n...
0
2016-07-13T23:19:28Z
[ "python", "pandas", "time-series", "data-analysis" ]
Pandas read_csv without knowing whether header is present
38,360,496
<p>I have an input file with known columns, let's say two columns <code>Name</code> and <code>Sex</code>. Sometimes it has the header line <code>Name,Sex</code>, and sometimes it doesn't:</p> <p><strong>1.csv</strong>:</p> <pre><code>Name,Sex John,M Leslie,F </code></pre> <p><strong>2.csv</strong>:</p> <pre><code>J...
2
2016-07-13T19:49:47Z
38,360,744
<p>using new feature - <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#selection-by-callable" rel="nofollow">selection by callable</a>:</p> <pre><code>cols = ['Name','Sex'] df = (pd.read_csv(filename, header=None, names=cols) [lambda x: np.ones(len(x)).astype(bool) if (x.iloc...
2
2016-07-13T20:03:39Z
[ "python", "csv", "pandas" ]
Python: Compute all possible pairwise distances of a list (DTW)
38,360,515
<p>I have a list of items like so: <code>T=[T_0, T_1, ..., T_N]</code> where each of <code>T_i</code> is itself a time series. I want to find the pairwise distances (via DTW) for all potential pairs. </p> <p>E.g. If <code>T=[T_0, T_1, T_2]</code> and I had a DTW function <code>f</code>, I want to find <code>f(T_0, T_1...
1
2016-07-13T19:50:51Z
38,360,795
<p>I would recommend <strong>keeping a <code>set</code> of all of the pairs you've done so far</strong>, keeping in mind that <code>set</code> has a constant time lookup operation. Besides that, you should consider other approaches where you <strong>don't extend your lists so often</strong> (that nasty <code>+=</code> ...
1
2016-07-13T20:06:44Z
[ "python", "euclidean-distance" ]
Python: Compute all possible pairwise distances of a list (DTW)
38,360,515
<p>I have a list of items like so: <code>T=[T_0, T_1, ..., T_N]</code> where each of <code>T_i</code> is itself a time series. I want to find the pairwise distances (via DTW) for all potential pairs. </p> <p>E.g. If <code>T=[T_0, T_1, T_2]</code> and I had a DTW function <code>f</code>, I want to find <code>f(T_0, T_1...
1
2016-07-13T19:50:51Z
38,360,919
<p>I cannot answer your question about whether there is a more optimized dtw library, but you can use <code>itertools</code> to get the combinations you want without duplicates:</p> <pre><code>import itertools for combination in itertools.combinations(T, 2): f(combination[0], combination[1]) </code></pre> <p...
0
2016-07-13T20:13:48Z
[ "python", "euclidean-distance" ]
get number of fails and success from dataframe in time series
38,360,546
<p>I've given dataFrame:</p> <pre><code>Time Status ResponseTime PID 2016-07-13 17:33:49 OK 1623 42 2016-07-13 17:33:50 KO 1593 35 2016-07-13 17:33:50 OK 1604 19 2016-07-13 17:33:51 KO 1605 2...
1
2016-07-13T19:52:42Z
38,360,683
<pre><code>text = """Time Status ResponseTime PID 2016-07-13 17:33:49 OK 1623 42 2016-07-13 17:33:50 KO 1593 35 2016-07-13 17:33:50 OK 1604 19 2016-07-13 17:33:51 KO 1605 28 2016-07-13 17:33:5...
3
2016-07-13T20:00:08Z
[ "python", "pandas" ]
Pandas Dataframe if statement using apply errors
38,360,617
<p>I am Currently trying to create IF statements to apply a class element to certain cells so I can style them using CSS. I currently can't use the styling options that pandas gives because I am using the .to_html function. </p> <p>My table is as follows. {'Pwer':[-.3,-1.3,-2.4], 'Trend':[1.3,-1.3,-1.7]} </p> <p>I ...
0
2016-07-13T19:56:29Z
38,360,782
<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.mask.html" rel="nofollow"><code>mask</code></a>:</p> <pre><code>hist = pd.DataFrame({'Pwer':[-.3,-1.3,-2.4], 'Trend':[1.3,-1.3,-1.7]} ) print (hist) Pwer Trend 0 -0.3 1.3 1 -1.3 -1.3 2 -2.4 -1.7 hist['Pwer'...
0
2016-07-13T20:06:25Z
[ "python", "pandas" ]
Pandas Dataframe if statement using apply errors
38,360,617
<p>I am Currently trying to create IF statements to apply a class element to certain cells so I can style them using CSS. I currently can't use the styling options that pandas gives because I am using the .to_html function. </p> <p>My table is as follows. {'Pwer':[-.3,-1.3,-2.4], 'Trend':[1.3,-1.3,-1.7]} </p> <p>I ...
0
2016-07-13T19:56:29Z
38,360,831
<p>Something like this will work:</p> <pre><code>cond = ((hist['Pwer']&lt;0) &amp; (hist['Trend']&lt;0)) hist['Pwer'][cond] = hist['Pwer'][cond].apply(lambda x:'&lt;span class="Negative Trend_neg"&gt;{0}&lt;/span&gt;'.format(x)) </code></pre> <p>The output is</p> <pre><code> ...
2
2016-07-13T20:08:40Z
[ "python", "pandas" ]
Converting row of sparse matrix to dense leaks memory
38,360,674
<p>In my program I have two scipy.sparse.csr_matrix. One has only one row and the other is actually large. In each iteration of the program, I add and subtract rows of the matrices. Eventually I need to use .todense() on the single row matrix. I noticed that just calling this function makes the used memory grow without...
2
2016-07-13T19:59:48Z
38,361,530
<p>This is <a href="https://github.com/scipy/scipy/pull/5847" rel="nofollow">a bug</a>, will be fixed in scipy 0.18.0. There is no workaround.</p>
3
2016-07-13T20:55:18Z
[ "python", "scipy", "sparse-matrix" ]
HiveContext createDataFrame not working on pySpark (jupyter)
38,360,692
<p>I am doing an analysis on pySpark using the Jupyter notebooks. My code originally build dataframes using sqlContext = <strong>SQLContext</strong>(sc), but now I've switched to <strong>HiveContext</strong> since I will be using window functions.</p> <p>My problem is that now I'm getting a Java error when trying to c...
3
2016-07-13T20:00:46Z
38,362,611
<p><code>HiveContext</code> requires binaries build with Hive support. It means you have to enable Hive profile. Since you use <code>sbt assembly</code> you need at least:</p> <pre><code>sbt -Phive assembly </code></pre> <p>The same is required when building with Maven, for example:</p> <pre><code>mvn -Phive -DskipT...
1
2016-07-13T22:15:34Z
[ "java", "python", "apache-spark", "pyspark", "spark-hive" ]
Play 2048 using selenium
38,360,729
<p>I have written code that will play 2048 untill the game end but is there any way to have selenium click the try again button when it pops up?</p> <pre><code>from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from se...
1
2016-07-13T20:02:55Z
38,360,815
<p>After quickly playing the game, the retry button looks to be:</p> <pre><code>&lt;a class="retry-button"&gt;Try again&lt;/a&gt; </code></pre> <p>So</p> <pre><code>browser.find_element_by_class_name('retry-button').click() </code></pre> <p>Should work for you</p>
1
2016-07-13T20:07:54Z
[ "python", "python-3.x", "selenium" ]
Base64 encoded image in email
38,360,758
<p>I am trying to send html e-mails with base64 encoded images embeded in them, using gmail api and python.</p> <p>This is the html file that I want to send as email</p> <pre><code>&lt;h1&gt;This is a test message&lt;/h1&gt; &lt;p&gt; &lt;img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAMAAABOo35HAAAA...
2
2016-07-13T20:04:43Z
38,361,054
<p>The "=" character is an escape character when using Quoted-Printable HTML, so the =3D is just an escaped equals.</p> <p>There is probably something else wrong with the email. I don't think the =3D is it.</p> <p>Try feeding your message to a message lint utility and see if it complains about anything.</p> <p><a hr...
0
2016-07-13T20:22:45Z
[ "python", "html", "email", "mime", "gmail-api" ]
Base64 encoded image in email
38,360,758
<p>I am trying to send html e-mails with base64 encoded images embeded in them, using gmail api and python.</p> <p>This is the html file that I want to send as email</p> <pre><code>&lt;h1&gt;This is a test message&lt;/h1&gt; &lt;p&gt; &lt;img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAMAAABOo35HAAAA...
2
2016-07-13T20:04:43Z
38,362,229
<p>Instead of using embed base64 encoding, I decided to add images as attachments. Here is my new <code>test.html</code> file;</p> <pre><code>&lt;h1&gt;This is a test message&lt;/h1&gt; &lt;p&gt; &lt;img src="cid:asdfgh"&gt; &lt;/p&gt; </code></pre> <p>And here is my code</p> <pre><code>"""Send an email ...
2
2016-07-13T21:45:22Z
[ "python", "html", "email", "mime", "gmail-api" ]
How can I successfully cull a list of lists
38,360,784
<p>So I'm running a script that's appending to a list, lists of values, but in several instances I'll end up with virtually the same data, it'll just be re-ordered differently, I want to put in a check against this by checking my appended list to see if my re-ordered list is essentially there. For instance, I'll have ...
0
2016-07-13T20:06:27Z
38,361,768
<p>If the order inside the sampleList's lists doesn't matter you can sort ALL the lists before appending them with the .sort() method. This would uncover duplicates and provide a check possibility.</p> <pre><code> sampleList=[[1,2,3][4,5,6][7,8,9]] l=[2,3,1] if not(l.sort() in sampleList): sampleList.append...
0
2016-07-13T21:09:48Z
[ "python", "list", "set" ]
How can I successfully cull a list of lists
38,360,784
<p>So I'm running a script that's appending to a list, lists of values, but in several instances I'll end up with virtually the same data, it'll just be re-ordered differently, I want to put in a check against this by checking my appended list to see if my re-ordered list is essentially there. For instance, I'll have ...
0
2016-07-13T20:06:27Z
38,362,263
<p>If you're fine with discarding duplicates, you can actually create sets, cause they're easy:</p> <pre><code>sample_list = [ [0,5,1,4,8,9], [5, 4, 8, 9, 0, 1], [1, 0, 4, 5, 8, 9], [4, 8, 1, 0, 5, 9], [7,6,2], ] # This is a set comprehension. Unfortunately, # sets are not hashable, so we have to ...
1
2016-07-13T21:47:41Z
[ "python", "list", "set" ]
Filtering a list of tuples with lambda expressions in Python
38,360,912
<p>What would be the right filter so l will contain [(7,10),(9,20)]</p> <pre><code>&gt;&gt;&gt; l=[(0,5),(7,10),(9,20),(18,22)] &gt;&gt;&gt; l=filter(lambda x: x[0]&gt;6 and x[1]&lt;21, l) &gt;&gt;&gt; l &lt;filter object at 0x7fb2349829e8&gt; &gt;&gt;&gt; </code></pre> <p>I'm getting a "filter object", rather than ...
-1
2016-07-13T20:13:31Z
38,360,962
<pre><code>&gt;&gt;&gt; l=[(0,5),(7,10),(9,20),(18,22)] &gt;&gt;&gt; l=filter(lambda x: x[0]&gt;6 and x[1]&lt;21, l) &gt;&gt;&gt; list(l) &gt;&gt;&gt; [(7,10),(9,20)] </code></pre>
3
2016-07-13T20:16:18Z
[ "python", "lambda" ]
Python List of Two Columns from Excel
38,360,980
<p>So I have a list of dates in one column and a list of values in another. </p> <pre><code>2/8/13 474 2/7/13 463.25 2/6/13 456.47 2/5/13 444.05 2/4/13 453.91 2/1/13 459.11 1/31/13 456.98 1/30/13 457 1/29/13 458.5 1/28/13 437.83 1/25/13 451.69 1/24/13 460 1/23/13 508.81 1/22/13 504.56 1/18/13 498.52 1/17/13 510....
0
2016-07-13T20:17:58Z
38,361,223
<p>You can combine list methods like .split and the [:] delimiters to get less loops and lists and keep a better overview. An example for a given tuple called "tuple":</p> <pre><code> datelist=tuple.split(" ")[0].split("/") month=datelist[0] year=datelist[2] value=tuple.split(" ")[1] </code></pre> <p>I...
0
2016-07-13T20:34:20Z
[ "python", "list", "date", "merge", "average" ]
Python List of Two Columns from Excel
38,360,980
<p>So I have a list of dates in one column and a list of values in another. </p> <pre><code>2/8/13 474 2/7/13 463.25 2/6/13 456.47 2/5/13 444.05 2/4/13 453.91 2/1/13 459.11 1/31/13 456.98 1/30/13 457 1/29/13 458.5 1/28/13 437.83 1/25/13 451.69 1/24/13 460 1/23/13 508.81 1/22/13 504.56 1/18/13 498.52 1/17/13 510....
0
2016-07-13T20:17:58Z
38,361,752
<p>Here's my solution. Hope this helps:</p> <pre><code>from datetime import datetime def averageData(list_of_tuples): dic = {} for i in list_of_tuples: i = list(map(str,i.strip().split(' '))) dt = datetime.strptime(i[0] , '%Y-%m-%d') if (dt.month,dt.year) in dic: dic[(d...
0
2016-07-13T21:08:45Z
[ "python", "list", "date", "merge", "average" ]
How I can calculate standard deviation for rows of a dataframe?
38,361,022
<pre><code>df: name group S1 S2 S3 A mn 1 2 8 B mn 4 3 5 C kl 5 8 2 D kl 6 5 5 E fh 7 1 3 output: std (S1,S2,S3) 3.78 1 3 0.57 3.05 </code></pre> <p>This is working for getting std...
1
2016-07-13T20:20:21Z
38,361,061
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.std.html" rel="nofollow"><code>DataFrame.std</code></a>, which omit non numeric columns:</p> <pre><code>print (df.std()) S1 2.302173 S2 2.774887 S3 2.302173 dtype: float64 </code></pre> <p>If need <code>std</code> ...
2
2016-07-13T20:23:18Z
[ "python", "numpy", "pandas" ]
How I can calculate standard deviation for rows of a dataframe?
38,361,022
<pre><code>df: name group S1 S2 S3 A mn 1 2 8 B mn 4 3 5 C kl 5 8 2 D kl 6 5 5 E fh 7 1 3 output: std (S1,S2,S3) 3.78 1 3 0.57 3.05 </code></pre> <p>This is working for getting std...
1
2016-07-13T20:20:21Z
38,389,313
<p>When you can not do on rows whatever you can do on column you may use "transpose"</p> <pre><code>np.std( df.transpose()['S1'] ) </code></pre>
0
2016-07-15T06:33:44Z
[ "python", "numpy", "pandas" ]
Python 3.4, Pygame - I want to create a grid to be able to place sprites in differently
38,361,027
<p>Since I am new in python I do not know how to create certain things, I am using pygame and I want to create a grid to interact with a grid like in this <a href="http://imgur.com/FGcn7DP" rel="nofollow">picture</a>. I am using python 3.4.3 and pygame. I would like some help figuring out how to create a program to int...
0
2016-07-13T20:20:36Z
38,361,202
<p>You have to place the sprites manually.</p> <p>First, add them to a group:</p> <pre><code>group = pygame.sprite.Group() </code></pre> <p>This is very useful for drawing a collection of sprites.</p> <p>Second, use a nested for loop to create the sprites:</p> <pre><code>width, height = 10, 10 # 10 rows and 10 co...
0
2016-07-13T20:33:11Z
[ "python", "pygame", "python-3.4" ]
Celery beat not starting on Heroku
38,361,040
<p>I have an app that I've launched on Heroku, but the Celery beat process doesn't start when I start the server.</p> <p><strong>Procfile</strong></p> <pre><code>web: gunicorn -w 4 connect.wsgi celery: python manage.py celeryd -c 3 --beat </code></pre> <p>The worker can be seen to be started after the Heroku app is ...
5
2016-07-13T20:21:35Z
38,411,796
<p>Heroku only allow two free Dyno instances in one application if I'm not mistaken.</p>
4
2016-07-16T13:39:58Z
[ "python", "heroku", "celery", "django-celery", "celerybeat" ]
Celery beat not starting on Heroku
38,361,040
<p>I have an app that I've launched on Heroku, but the Celery beat process doesn't start when I start the server.</p> <p><strong>Procfile</strong></p> <pre><code>web: gunicorn -w 4 connect.wsgi celery: python manage.py celeryd -c 3 --beat </code></pre> <p>The worker can be seen to be started after the Heroku app is ...
5
2016-07-13T20:21:35Z
38,509,619
<p>@Jared Goguen: Hi pal,</p> <p>You probable need to scale up your workers in Heroku,</p> <blockquote> <p>Deploying on Heroku</p> <p>If you already created a Procfile above and attached the appropriate add-ons for the message broker and result store, all that’s left to do is push and scale your app:</p> </b...
1
2016-07-21T16:29:14Z
[ "python", "heroku", "celery", "django-celery", "celerybeat" ]
ValueError: math domain error - Black-Scholes Option Valuation
38,361,148
<p>I am writing a program to calculate the price of a Call Option explicitly using the Black-Scholes formula under the necessary conditions. I am getting an error when I run my code.</p> <p>I am not sure what is causing it. Please, any and all help is very greatly appreciated. Here is my code thus far:</p> <pre><code...
2
2016-07-13T20:29:58Z
38,361,449
<p><code>log(s/k)</code> is throwing the error. Even though 20/25 = 0.8, since they are both integers, 20/25 evaluates to 0, and <code>log(0)</code> throws the error. Convert s or k or both to a float, and that should solve your problem </p>
3
2016-07-13T20:50:42Z
[ "python", "numpy", "scipy" ]
Installing packages, not working (update)
38,361,217
<p>I need terminaltables, a package in python, for an assignment in school, the problem is, I can for some reason not make it work, I've installed pip, it's working and I can call pip help. I've used the commandoes: sudo pip install terminaltables and pip install terminaltables. After looking it up, my version of pip i...
1
2016-07-13T20:34:09Z
38,361,507
<p>You are running your file in Python 3, but you installed <code>terminaltables</code> for Python 2.</p> <p>Either use Python 2 (<code>python yatzy4.py</code>) or install <code>terminaltables</code> for Python 3 (Probably <code>pip3 install terminaltables</code>, depending on your setup.)</p>
1
2016-07-13T20:54:11Z
[ "python", "packages" ]
Python json.load returning string instead of dictionary
38,361,224
<p>I'm taking in a json file and only copying the necesary keys and their values to a new json file. I'm getting the error "TypeError: string indices must be integers" in reference to where I'm copying the values to myDict. From what I gather, json.load is returning a string rather than a dictionary. I validated the js...
1
2016-07-13T20:34:29Z
38,361,568
<p>In your json stub <code>"data"</code> key contains list. In your code you refer to it as a dictionary: <code>i.get('data').get('BaselineExposure')</code></p> <p>Instead you should iterate through your <code>"data"</code>. For example:</p> <pre><code>data = i.get('data') for d in data: print(d.get('BaselineExpo...
1
2016-07-13T20:57:33Z
[ "python", "json" ]
matplotlib plot matrix keeping the original coordinates
38,361,230
<p>I have two vectors <code>x</code> and <code>y</code> and a matrix such that <code>z[i,j] = f(x[i], y[j])</code></p> <p>I would like to plot <code>z</code> keeping on the axis the coordinates in <code>x</code> and <code>y</code>. In other words the point <code>z[i, j]</code> should stay in position <code>x[i], y[j]...
0
2016-07-13T20:34:45Z
38,361,500
<p>First of all, you may use <code>matshow</code>: <a href="http://matplotlib.org/examples/pylab_examples/matshow.html" rel="nofollow">http://matplotlib.org/examples/pylab_examples/matshow.html</a></p> <p>Or plot a 3d surface:</p> <pre><code>from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import mat...
0
2016-07-13T20:53:54Z
[ "python", "matplotlib", "geospatial" ]
matplotlib plot matrix keeping the original coordinates
38,361,230
<p>I have two vectors <code>x</code> and <code>y</code> and a matrix such that <code>z[i,j] = f(x[i], y[j])</code></p> <p>I would like to plot <code>z</code> keeping on the axis the coordinates in <code>x</code> and <code>y</code>. In other words the point <code>z[i, j]</code> should stay in position <code>x[i], y[j]...
0
2016-07-13T20:34:45Z
39,447,611
<p>you possibly could use a scatter plot. </p> <pre><code>import matplotlib.pyplot as plt import numpy as np N = 40 X = np.random.rand(N) Y = np.random.rand(N) def f(x,y): #function f return x+y Z = np.zeros([N,N]) for i in range(N): for j in range(N): Z[i,j] = f(X[i],Y[j]) plt.scatter(X[i],Y[j...
1
2016-09-12T09:49:34Z
[ "python", "matplotlib", "geospatial" ]
Hash Function not correct? Math.pow does not handle arbitrarily large numbers
38,361,235
<p>I am trying to solve this <a href="http://www.lintcode.com/en/problem/hash-function/" rel="nofollow">easy problem</a> on LintCode and I have my solution:</p> <pre><code>import math class Solution: """ @param key: A String you should hash @param HASH_SIZE: An integer @return an integer """ de...
1
2016-07-13T20:35:09Z
38,361,344
<blockquote> <blockquote> <p>Python handles arbitrarily large numbers by default</p> </blockquote> </blockquote> <p>Yes, it does, but only integers are arbitrarily large. <code>math.pow()</code> deals in floats, which do have a size limit.</p> <p>Try:</p> <pre><code>#UNTESTED multiplier=33**(len(key)-i-1) </...
3
2016-07-13T20:43:57Z
[ "python" ]
Hash Function not correct? Math.pow does not handle arbitrarily large numbers
38,361,235
<p>I am trying to solve this <a href="http://www.lintcode.com/en/problem/hash-function/" rel="nofollow">easy problem</a> on LintCode and I have my solution:</p> <pre><code>import math class Solution: """ @param key: A String you should hash @param HASH_SIZE: An integer @return an integer """ de...
1
2016-07-13T20:35:09Z
38,361,731
<p>A pair of facts that will lead you to a solution:</p> <ol> <li><p>The <code>pow(x, y, [z])</code> builtin function will accurately calculate <code>(x ** y) % z</code> without involving arbitrary-length integers.</p></li> <li><p><code>(a + b + …) % x</code> is the same as <code>(a%x + b%x + …) % x</code>. (That ...
3
2016-07-13T21:07:53Z
[ "python" ]
How to access a previous row in pymssql in python?
38,361,249
<p>For example, if I iterate over a query using:</p> <pre><code>for row in cursor: </code></pre> <p>And I want to make a comparison like:</p> <pre><code>if row[0] == previousrow[0]: #do something </code></pre> <p>How can I actually access the previous row?</p>
0
2016-07-13T20:36:03Z
38,361,538
<p>If you wanted to access the previous row from your <code>for</code> loop, you could use the following code.</p> <pre><code>previousrow = None for row in cursor: if (!(previousrow is None)): # do your comparison with previous row and row here previousrow = row </code></pre> <p>I don't write Python,...
1
2016-07-13T20:55:37Z
[ "python", "pymssql" ]
How do I parse this data in a Django template?
38,361,304
<pre><code>{u'4th-of-July': {'name': 4th of July', 'slug': u'4th-of-July'}} </code></pre> <p>I would like to have access to <code>'name'</code> and <code>'slug'</code> in a django HTML template. How do I go about doing this?</p>
0
2016-07-13T20:40:33Z
38,361,426
<p>You can access a dict in template with dot notation:</p> <p>Let's call your dictionary <code>data</code>:</p> <pre><code>{{ data.4th-of-July.name }} </code></pre> <p>And</p> <pre><code>{{ data.4th-of-July.slug }} </code></pre>
0
2016-07-13T20:49:13Z
[ "python", "django" ]
How do I parse this data in a Django template?
38,361,304
<pre><code>{u'4th-of-July': {'name': 4th of July', 'slug': u'4th-of-July'}} </code></pre> <p>I would like to have access to <code>'name'</code> and <code>'slug'</code> in a django HTML template. How do I go about doing this?</p>
0
2016-07-13T20:40:33Z
38,407,647
<p>Ideally in these cases you should iterate over the keys of the dict. Here is an example:</p> <pre><code>{% for key, value in dict_name.items %} &lt;!-- where dict_name denotes name of the dictionary containing {u'4th-of-July': {'name': 4th of July', 'slug': u'4th-of-July'}} --&gt; {{key}} &lt;!-- '4th-of-July...
0
2016-07-16T04:14:05Z
[ "python", "django" ]
Upload photos to Flickr With API Flickr Python
38,361,312
<p>I tried upload photo to flickr with the API Python but I get this error:</p> <blockquote> <p>err code="100" msg="Invalid API Key (Key has invalid format)"</p> </blockquote> <p>I'm supposed Flickr authenticated because simpler ones I call functions that also require authentication as flickr.photos.getInfo, flick...
0
2016-07-13T20:41:25Z
38,361,595
<p>I'm guessing you are using the API from <a href="https://stuvel.eu/flickrapi" rel="nofollow">https://stuvel.eu/flickrapi</a>?</p> <p>If so, the docs say the API key and secret need to be a unicode string (<a href="https://stuvel.eu/flickrapi-doc/2-calling.html" rel="nofollow">https://stuvel.eu/flickrapi-doc/2-calli...
1
2016-07-13T20:59:07Z
[ "python", "python-3.x" ]
Import JSON to NEO4J using py2neo
38,361,325
<p>I am trying to import a JSON file obtained thru an API request to StackOverflow to NEO4J. I have been following this <a href="https://neo4j.com/blog/cypher-load-json-from-url/" rel="nofollow">tutorial</a>. However, I get errors like the following while trying to execute the query:</p> <pre><code> File "/Users/ahme...
0
2016-07-13T20:42:05Z
38,363,017
<p>A couple of things to make your script work :</p> <p><code>from py2neo import neo4j</code> is not a valid dependency anymore</p> <p>In your query, you pass a json map as parameter but you don't use the parameters syntax in the query, I added <code>WITH {json} as data</code> in the beginning of the query.</p> <p>A...
3
2016-07-13T22:54:12Z
[ "python", "neo4j", "cypher", "py2neo" ]
Write GeoDataFrame into SQL Database
38,361,336
<p>I hope that my question is not ridiculous since, surprisingly, this question has apparently not really been asked yet (to the best of my knowledge) on the popular websites.</p> <p>The situation is that I have several csv files containing more than 1 Mio observations in total. Each observation contains, among others...
1
2016-07-13T20:42:50Z
38,363,154
<p>So, I just implemented this for a PostGIS database, and I can paste my method here. For MySQL, you'll have to adapt the code.</p> <p>First step was to convert the geocoded columns into WKB hex string, because I use <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a>, with an engine based on <a href="...
0
2016-07-13T23:10:14Z
[ "python", "mysql", "pandas", "geopandas" ]
python vim linux - copy multiple lines from vim to ipython
38,361,387
<p>I am trying to copy a block of text (im in linux debian) from vim to ipython I select the block of text "yank", exit vim with ctrl-Z, enter ipython and shift-insert.</p> <p>However it always only paste the first line of my originaly copied block of text..</p> <p>Any idea how to paste multi lines?</p>
-1
2016-07-13T20:46:44Z
38,361,914
<p>When Typing <kbd>ctrl</kbd>+<kbd>z</kbd> while editing in vim keep in mind that you are back to the shell terminal so you cannot use any vim commands instead you need to use the shortcuts provided by your terminal of <code>Copy</code> and <code>Paste</code> by checking them in terminal <code>Edition &gt; Preferences...
1
2016-07-13T21:22:14Z
[ "python", "linux", "vim", "ipython" ]
python vim linux - copy multiple lines from vim to ipython
38,361,387
<p>I am trying to copy a block of text (im in linux debian) from vim to ipython I select the block of text "yank", exit vim with ctrl-Z, enter ipython and shift-insert.</p> <p>However it always only paste the first line of my originaly copied block of text..</p> <p>Any idea how to paste multi lines?</p>
-1
2016-07-13T20:46:44Z
38,362,116
<p>You have a couple of options:</p> <h1>Use your window manager</h1> <p>Highlight the text with your mouse and then middle click to paste. Some versions of Python have this behavior turned off, which is silly.</p> <h1>Use tmux</h1> <p>I have <a href="https://gist.github.com/waynew/bc84f66799a6529ffc9e0bfa128f51c4"...
1
2016-07-13T21:36:37Z
[ "python", "linux", "vim", "ipython" ]
using self.method_name inside a class method
38,361,411
<p>I'm new to <strong>OOP</strong> in <strong>Python</strong>. I'm using the <code>unittest</code> package for the first time. In the code below, which is from Python official documentation, when we use <code>self.assertEqual</code> are we calling the <code>assertEqual</code> method from the base class <code>unittest.T...
1
2016-07-13T20:48:12Z
38,366,671
<p>As specified in the <a href="https://docs.python.org/3.5/library/unittest.html#test-cases" rel="nofollow">documentation for <code>unittest</code></a>, <code>assertEqual</code> is a method provided by the <code>TestCase</code> class.</p> <p>In general, when a method is accessed (via <code>self.&lt;method_name&gt;</c...
0
2016-07-14T06:09:43Z
[ "python", "python-3.x", "django-unittest" ]
Blank lines in python bytecode
38,361,412
<p>When once disassembles a python function using the <code>dis</code> function, there are blank lines between some opcodes as shown below.</p> <pre><code> &gt;&gt;&gt; dis(fizzbuzz) 2 0 LOAD_FAST 0 (n) 3 LOAD_CONST 1 (3) 6 BINARY_MODULO ...
0
2016-07-13T20:48:14Z
38,361,667
<p>The blank lines are breaks between disassemblies of statements. The numbers at the front of the first lines of the block are the line numbers of the source, assuming you have them.</p> <p>For instance:</p> <pre><code>def test(): x = 1 y = 2 </code></pre> <p>will show up as</p> <pre><code>2 0 LO...
1
2016-07-13T21:03:23Z
[ "python", "virtual-machine", "bytecode" ]
Regular Expression with multiple matches - Python
38,361,413
<p>I have searched the web to find a similar problem but couldn't.</p> <p>Here is an address:</p> <blockquote> <p>the fashion potential hq 116 w 23rd st ste 5 5th floor new york ny 10011</p> </blockquote> <p>Using the following regex in python I tried to find the all possible main addresses in the above line: </...
1
2016-07-13T20:48:14Z
38,361,539
<p>You need to run 2 regex expressions, one with lazy dot and another with a greedy dot.</p> <p>First one is <a href="https://regex101.com/r/nT1iR4/7" rel="nofollow">this</a>:</p> <pre><code>^(.*?)(\b\d+\b)(.+)\b(ste|st|ave|blvd)\b\s*(.*)$ </code></pre> <p>The second one with the use lazy dot matching pattern inside...
0
2016-07-13T20:55:37Z
[ "python", "regex" ]