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
Count unique values with pandas
38,309,729
<p>I should to count quantity unique <code>ID</code> to every <code>domain</code> I have data</p> <pre><code>ID, domain 123, 'vk.com' 123, 'vk.com' 123, 'twitter.com' 456, 'vk.com' 456, 'facebook.com' 456, 'vk.com' 456, 'google.com' 789, 'twitter.com' 789, 'vk.com' </code></pre> <p>I try <code>df.groupby(['domain', '...
2
2016-07-11T14:38:25Z
38,309,830
<p>IIUC you want the number of different <code>ID</code> for every <code>domain</code>, then you can try this:</p> <pre><code>output = df.drop_duplicates() output.groupby('domain').size() </code></pre> <p>output:</p> <pre><code> domain facebook.com 1 google.com 1 twitter.com 2 vk.com 3 dtype:...
4
2016-07-11T14:44:10Z
[ "python", "pandas" ]
pyqt non-modal dialog always modal
38,309,803
<p>I have a dialog designed in Qt Designer and set as non-modal that when launched is always modal. I am using OS X El Capitan, Python 3.5.1, Qt 5.4.2, pyqt4.</p> <p>These code snippets show what I am doing:</p> <hr> <h2>Designer .ui code converted to python using pyuic.</h2> <pre><code>from PyQt4 import QtCore, Qt...
1
2016-07-11T14:42:30Z
38,360,936
<p>I rearranged some of your code because of personal preference (I'm sure you can put it back no problem), and now one is modal, and the other is nonmodal.</p> <p>When you create a nonmodal window, you must provide a parent QWidget in the instantiation of the QDialog class. Then, instead of using <code>QDialog.exec_(...
0
2016-07-13T20:14:40Z
[ "python", "qt", "pyqt4" ]
How to convert dictionary of list into data frame in Pandas
38,309,881
<p>I have the following dictionary of list:</p> <pre><code>my_dol = { "01_718": [232,211,222], "02_707": [404,284,295], "03_708": [221,209,220]} </code></pre> <p>How can I convert it to data frame like this::</p> <pre><code> 01_718 02_707 03_708 232 404 221 211 284 ...
2
2016-07-11T14:46:14Z
38,309,897
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_dict.html" rel="nofollow"><code>from_dict</code></a>:</p> <pre><code>In [54]: my_dol = { "01_718": [232,211,222], "02_707": [404,284,295], "03_708": [221,209,220]} pd.DataFrame.from_dict(my_dol) Out[54]...
2
2016-07-11T14:47:04Z
[ "python", "pandas" ]
Override a function in nltk - Error in ContextIndex class
38,309,909
<p>I am using <a href="http://www.nltk.org/api/nltk.html#nltk.text.Text.similar" rel="nofollow"><code>text.similar('example')</code></a> function from <a href="http://www.nltk.org/_modules/nltk/text.html" rel="nofollow"><code>nltk.Text</code></a> module. </p> <p>(Which <strong><em>prints</em></strong> the similar word...
1
2016-07-11T14:47:26Z
38,360,852
<p>You are getting the error because the <code>ContextIndex</code> constructor is trying to take the <code>len()</code> of your token list (the argument <code>tokens</code>). But you actually pass it as a generator, hence the error. To avoid the problem, just pass a true list, e.g.:</p> <pre><code>text = nltk.text.Con...
1
2016-07-13T20:09:55Z
[ "python", "nlp", "nltk", "similarity" ]
How to add a screen onto another screen in kivy?
38,309,911
<p>I'm trying to make a screen that has two rows, one of those rows are the actual game screen and the another one is a button to clear the table above. But the problem here is that the first row is blank when I run the app. That's the code that I am stuck till now:</p> <pre><code>import kivy from kivy.app import App ...
0
2016-07-11T14:47:26Z
38,315,578
<p>The answer to you question, is "You cannot do that". Screenmanager only shows one screen at a time.</p> <p>you can read about that in the docs <a href="https://kivy.org/docs/api-kivy.uix.screenmanager.html" rel="nofollow">https://kivy.org/docs/api-kivy.uix.screenmanager.html</a></p> <p>But to acheive something lik...
1
2016-07-11T20:21:52Z
[ "python", "kivy", "python-3.5" ]
python: get object arg and check NPE in one line
38,309,938
<p>I have a method <code>foo()</code> which eventually returns a <code>Student</code> named <em>john</em>.</p> <pre><code>#!/usr/bin/python3 from random import randint class Student(object): name = "" def foo(): if randint(0,1) == 0: student = Student() student.name = 'john' else: ...
1
2016-07-11T14:49:03Z
38,311,006
<p>You can use <code>getattr(obj, 'attr_to_get', default_value)</code>.</p> <p>In your example, the solution would be <code>getattr(foo(), 'name', None)</code>.</p>
1
2016-07-11T15:40:30Z
[ "python", "nullpointerexception" ]
Fabric fabfil execution model ArgumentParser
38,310,004
<p>I made some scripts that use Fabric, It does some work on multiple servers using ssh. But my scripts are like a classic python script </p> <p>Here is the shape (the way they look like) : <code>my_script.py</code> with some function and a main :</p> <pre><code>from fabric.api import * from a_custom_class import * ...
1
2016-07-11T14:51:36Z
38,331,545
<p>I found a way. But it's really ugly.</p> <pre><code>#fabfile.py import my_script as script def task(): execute(script.mainbis) </code></pre> <p>and in my_script.py, I creat a mainbis() that overide the sys.argv and call main function :</p> <pre><code>#my_script.py def mainbis(): # ask interactively the o...
0
2016-07-12T14:21:15Z
[ "python", "parameter-passing", "fabric" ]
From a text file to dict
38,310,016
<p>I am having some real trouble. I have a .txt file with contents like this: </p> <pre><code> {'x': '1', 'y': 's'} </code></pre> <p>And I would like to import this to a dict. I previously used this code, but it doesn't work:</p> <pre><code> import json database = {} f = open('ds.txt','r') def ...
-4
2016-07-11T14:52:02Z
38,310,203
<p>Your JSON string is invalid. Instead of single quotes (<code>'</code>), replace it with double quotes (<code>"</code>).</p> <pre><code>{"x": "1", "y": "s"} </code></pre>
1
2016-07-11T15:01:08Z
[ "python", "python-3.x" ]
From a text file to dict
38,310,016
<p>I am having some real trouble. I have a .txt file with contents like this: </p> <pre><code> {'x': '1', 'y': 's'} </code></pre> <p>And I would like to import this to a dict. I previously used this code, but it doesn't work:</p> <pre><code> import json database = {} f = open('ds.txt','r') def ...
-4
2016-07-11T14:52:02Z
38,310,709
<p>Try this:</p> <pre><code>import ast database = {} f=open("ds.txt", "r") def load(): return ast.literal_eval(str(f.read())) database = load() print(database['y']) </code></pre> <p><a href="http://stackoverflow.com/questions/3737900/how-do-you-convert-a-stringed-dictionary-to-a-python-dictionary">How do you co...
3
2016-07-11T15:25:30Z
[ "python", "python-3.x" ]
In python how can I find if the given time is between a range
38,310,032
<p>I need to execute a code between a set time every day. So I need to find if the current time is between a time range.</p> <pre><code>hralarm=False now = datetime.datetime.now().time() if datetime.time(hour=14,minute=40) &gt; now &gt; datetime.time(hour=14,minute=50): hralarm=True else : hralarm=False </cod...
0
2016-07-11T14:52:49Z
38,310,128
<p>You have your comparison operators mixed up. You are asking if the current time is <strong>before</strong> 14:40:</p> <pre><code>datetime.time(hour=14,minute=40) &gt; now # only times *smaller* will match </code></pre> <p>and <strong>after</strong> 14:50:</p> <pre><code>now &gt; datetime.time(hour=14,minute=50)...
3
2016-07-11T14:57:34Z
[ "python" ]
In python how can I find if the given time is between a range
38,310,032
<p>I need to execute a code between a set time every day. So I need to find if the current time is between a time range.</p> <pre><code>hralarm=False now = datetime.datetime.now().time() if datetime.time(hour=14,minute=40) &gt; now &gt; datetime.time(hour=14,minute=50): hralarm=True else : hralarm=False </cod...
0
2016-07-11T14:52:49Z
38,310,238
<pre><code>hralarm=False now = datetime.datetime.now().time() if datetime.time(hour=14,minute=40) &lt; now &lt; datetime.time(hour=14,minute=50): hralarm=True else : hralarm=False </code></pre>
0
2016-07-11T15:02:33Z
[ "python" ]
In python how can I find if the given time is between a range
38,310,032
<p>I need to execute a code between a set time every day. So I need to find if the current time is between a time range.</p> <pre><code>hralarm=False now = datetime.datetime.now().time() if datetime.time(hour=14,minute=40) &gt; now &gt; datetime.time(hour=14,minute=50): hralarm=True else : hralarm=False </cod...
0
2016-07-11T14:52:49Z
38,310,306
<pre><code>import time import datetime hralarm=False now = datetime.datetime.now().time() time1 = datetime.time(14, 40, 0) time2 = datetime.time(14, 50, 0) if (time1.hour &gt;= now.hour and time1.minute &lt; now.minute) and (now.hour &lt;= time2.hour and now.minute &lt; time2.minute): hralarm=True else : h...
-1
2016-07-11T15:06:01Z
[ "python" ]
python sparse matrix get maximum values and index
38,310,087
<p>I have a sparse matrix A(equal to 10 * 3 in dense), such as:</p> <pre><code>print type(A) &lt;class scipy.sparse.csr.csr_matrix&gt; print A (0, 0) 0.0160478743808 (0, 2) 0.0317314165078 (1, 2) 0.0156596521648 (1, 0) 0.0575683686558 (2, 2) 0.0107481166871 (3, 0) 0.0150580924929 (3, 2) 0.0297743235876 (4, 0) ...
1
2016-07-11T14:55:21Z
38,311,041
<p>This is a slight variation of the method you suggested in the question:</p> <pre><code>col_argmax = [A.getcol(i).A.argmax() for i in range(A.shape[1])] </code></pre> <p>(The <code>.A</code> attribute is equivalent to <code>.toarray()</code>.)</p> <p>A potentially more efficient alternative is</p> <pre><code>B = ...
0
2016-07-11T15:42:16Z
[ "python", "scipy", "sparse-matrix", "csr" ]
Data Transformation in Python
38,310,204
<p>I have the following DataFrame:</p> <pre><code>ID MONTHLY_QTY H1 M1 H1 M2 H1 M3 H1 M4 H2 M1 H2 M4 </code></pre> <p>I need to transform it to something like this:</p> <pre><code>ID col1 col2 col3 col4 H1 M1 M2 M3 M4 H2 M1 M2 </code></pre> <p>The number of distinct valu...
1
2016-07-11T15:01:12Z
38,310,269
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.cumcount.html" rel="nofollow"><code>cumcount</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot.html" rel="nofollow"><code>pivot</code></a> and if need remove <code>NaN</cod...
1
2016-07-11T15:04:01Z
[ "python", "pandas" ]
Data Transformation in Python
38,310,204
<p>I have the following DataFrame:</p> <pre><code>ID MONTHLY_QTY H1 M1 H1 M2 H1 M3 H1 M4 H2 M1 H2 M4 </code></pre> <p>I need to transform it to something like this:</p> <pre><code>ID col1 col2 col3 col4 H1 M1 M2 M3 M4 H2 M1 M2 </code></pre> <p>The number of distinct valu...
1
2016-07-11T15:01:12Z
38,312,174
<p>Starting with this <code>df</code>:</p> <pre><code> ID MONTHLY_QTY 0 H1 M1 1 H1 M2 2 H1 M3 3 H1 M4 4 H2 M1 5 H2 M4 dummies = pd.get_dummies(df["MONTHLY_QTY"]) df2 = df.join(dummies) df2.groupby(['ID' ] )['M1','M2', "M3", "M4" ].sum() M1 M2 ...
1
2016-07-11T16:49:07Z
[ "python", "pandas" ]
Most efficient way to return list from a groupby
38,310,265
<p>I have a 130M rows dataframe, here is a sample:</p> <pre><code> id id2 date value 0 33208381500016 1927637 2014-07-31 120.0 1 77874276700016 3418498 2014-11-22 10.5 2 77874276700016 1174018 2014-11-22 8.4 3 77874276700016 1174018 2014-11-20 1.4 4 77874276700016 164...
2
2016-07-11T15:03:45Z
38,310,833
<p>To get the unique dates, use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.SeriesGroupBy.unique.html" rel="nofollow"><code>SeriesGroupBy.unique()</code></a>. To count the number of unique <code>id2</code> in each group, use <a href="http://pandas.pydata.org/pandas-docs/stable/gen...
2
2016-07-11T15:32:01Z
[ "python", "list", "pandas", "dataframe", "grouping" ]
Type error "must be string, not datetime.datetime"
38,310,346
<p>I've got some error in my view and I don't have any idea, what is wrong:</p> <pre><code>from datetime import datetime for month_dict in finished_by_month: month_values.append(month_dict['total']) month_date = datetime.strptime(month_dict['month'], '%Y-%m-%d') </code></pre> <p>and when I try to see my temp...
-2
2016-07-11T15:07:38Z
38,312,806
<p>Assuming the error is occurring in strptime function, please make sure the value referenced by month_dict['month'] is a string and not in date time format. As you are trying to convert string to time in a particular format, value expected by the compiler is string.</p> <p>For more details on format of time and addi...
0
2016-07-11T17:28:49Z
[ "python", "django", "datetime" ]
Need help on list comprhensions. How to use several exclusions
38,310,392
<p>So what I'm looking for is the correct way to search a list and filter the items based on several other lists.</p> <pre><code>imageList = ['green_D.jpg', 'red_D.gif', 'orange_R.jpg', 'black_S.gif', 'folder_A', 'folder_B'] included_extensions = ['jpg', 'bmp', 'png', 'gif'] excluded_textures = ['_R.', '_A.', '_S.'] <...
0
2016-07-11T15:09:53Z
38,310,463
<p>In this case, I'd use a loop -- Cramming it all into a single list-comprehension is going to make the code harder to understand which isn't really what you want...:</p> <pre><code>imageList = ['green_D.jpg', 'red_D.gif', 'orange_R.jpg', 'black_S.gif', 'folder_A', 'folder_B'] included_extensions = ('jpg', 'bmp', 'pn...
2
2016-07-11T15:13:34Z
[ "python", "list-comprehension" ]
Need help on list comprhensions. How to use several exclusions
38,310,392
<p>So what I'm looking for is the correct way to search a list and filter the items based on several other lists.</p> <pre><code>imageList = ['green_D.jpg', 'red_D.gif', 'orange_R.jpg', 'black_S.gif', 'folder_A', 'folder_B'] included_extensions = ['jpg', 'bmp', 'png', 'gif'] excluded_textures = ['_R.', '_A.', '_S.'] <...
0
2016-07-11T15:09:53Z
38,310,468
<pre><code>imageList = ['green_D.jpg', 'red_D.gif', 'orange_R.jpg', 'black_S.gif', 'folder_A', 'folder_B'] included_extensions = ['jpg', 'bmp', 'png', 'gif'] excluded_textures = ['_R.', '_A.', '_S.'] print filter(lambda x:x[-3:] in included_extensions and x[-6:-3] not in excluded_textures,imageList) </code></pre>
1
2016-07-11T15:13:46Z
[ "python", "list-comprehension" ]
Need help on list comprhensions. How to use several exclusions
38,310,392
<p>So what I'm looking for is the correct way to search a list and filter the items based on several other lists.</p> <pre><code>imageList = ['green_D.jpg', 'red_D.gif', 'orange_R.jpg', 'black_S.gif', 'folder_A', 'folder_B'] included_extensions = ['jpg', 'bmp', 'png', 'gif'] excluded_textures = ['_R.', '_A.', '_S.'] <...
0
2016-07-11T15:09:53Z
38,310,501
<pre><code>In [16]: new_list = [img for img in imageList if any(img.endswith(good_ext) for ...: good_ext in included_extensions) and not any(bad_tex in img for bad_tex ...: in excluded_textures)] In [17]: new_list Out[17]: ['green_D.jpg', 'red_D.gif'] </code></pre> <p>If you really want to do this with list...
0
2016-07-11T15:15:34Z
[ "python", "list-comprehension" ]
"error return without exception set" for python list
38,310,402
<p>What does "Error return without exception set" commonly mean? I am trying to call a Python method that should return a list.</p> <pre><code> for facet in dispPart.FacetedBodies: #Tag facet_tag2=thisFctBody.Tag #calling this method returns an "error return without exception set" face_list=facet...
0
2016-07-11T15:10:19Z
38,334,638
<p>You shoud tell what third party Python module you are using - this error message implies there is something wrong in that code, not yours. (ok, from your link, it is "NXOpen Python API")</p> <p>Specifically, the third party module, interfacing with the Python C API returned an incorrect result, reporting an except...
0
2016-07-12T16:39:35Z
[ "python", "list" ]
How do I run through PDF files in a path, format and clean each one, and spit out regex with specific text from the individual files?
38,310,434
<p>I have a script that takes a PDF and formats it to HTML, cleans up the HTML tags and spits out a clean text. Then runs some regex to extract data from each PDF. Basically I'm having trouble figuring out how to iterate through all the files and run the cleanup, THEN run regex for each. My code looks something like...
0
2016-07-11T15:12:17Z
38,310,593
<p>The good way will be create a class which can handle each of your function for each instance of file you send to the class. </p> <pre><code>Class PDFParser: file = '' def __init__(self, myfile): file = myfile def get_html_response(self): //your code for pdf to html def run_regx(s...
0
2016-07-11T15:19:50Z
[ "python", "regex", "python-2.7", "pdf" ]
Python importlib import_module Relative Import of Module
38,310,519
<p>According to <a href="http://stackoverflow.com/questions/10675054/how-to-import-a-module-in-python-with-importlib-import-module">this answer</a>, you can use <code>importlib</code> to <code>import_module</code> using a relative import like so:</p> <pre><code>importlib.import_module('.c', 'a.b') </code></pre> <p>Wh...
0
2016-07-11T15:16:29Z
38,311,552
<p>The parent module needs to be imported before trying a relative import.</p> <p>You will have to add <code>ìmport sklearn.feature_extraction</code> before your call to import_module if you want it to work.</p> <p>Nice explanation here : <a href="http://stackoverflow.com/a/28154841/1951430">http://stackoverflow.com...
0
2016-07-11T16:10:47Z
[ "python", "python-3.x", "import", "python-importlib" ]
Confused by Django 404s for simple pages
38,310,529
<p>Im doing my first Django site myself after going through several tutorials and running into some errors that I can't figure out what the problem is as they are simple page requests.</p> <p>I was trying to make a category detail view e.g. 127.0.0.1:8000/news and Ive followed the same setup as other pages such as the...
0
2016-07-11T15:17:18Z
38,310,660
<p>When Django resolves the url <code>/about/</code>, it goes through your url patterns in order. It matches the <code>post_detail</code> url pattern, so runs the <code>post_view</code>, treating <code>about</code> as a slug. Since you don't have any posts with the slug <code>about</code>, you get the 404 error.</p> <...
6
2016-07-11T15:23:02Z
[ "python", "django" ]
Django template doesn't work with booleans?
38,310,591
<p>I have the following template that only should activate when <code>test</code> is <code>true</code>.</p> <pre><code>{% if test %} &lt;h1&gt;The value of test was {{ test }} &lt;/h1&gt; {% endif %} </code></pre> <p>In views.py, <code>test</code> is being set to <code>false</code>. However, in the resulting html,...
1
2016-07-11T15:19:43Z
38,526,836
<p>Pass the Boolean <code>False</code> instead of the string <code>"false"</code>. You can tell which one you're passing by seeing whether <code>{{ test }}</code> is being displayed as <code>False</code>, in which case it's a boolean, or <code>false</code>, in which case you're passing a string.</p>
0
2016-07-22T12:45:36Z
[ "python", "html", "django", "templates", "boolean" ]
How to use python requests with a server that has two IP addresses
38,310,650
<p>I have a Ubuntu server that has multiple IP addresses. As an example, how do I set the correct IP address for outbound requests in a library like python requests?</p>
1
2016-07-11T15:22:31Z
38,310,760
<p>By default, this is not handled at application level, but by the operating system. According to linux routing table, the OS will choose the appropriate interface depending on the destination IP you are trying to reach.</p> <p>You can edit linux routing table with the <code>ip route</code> command (<a href="http://l...
0
2016-07-11T15:27:56Z
[ "python", "ubuntu", "python-requests" ]
Apply operation to multiple variables
38,310,716
<p>I feel like this solution is overkill and I might not be using the builtins correctly.</p> <p>Can someone suggest a better way to apply the same operation to a list of variables?</p> <p>EDIT -- Or change them without re-assigning the values (if that's possible)</p> <pre><code>size = 150 free = 27 used = 123 size...
0
2016-07-11T15:25:42Z
38,310,777
<p>I would probably use a comprehension/generator expression rather than <code>list</code>, <code>map</code> and <code>lambda</code>:</p> <pre><code>size, free, used = (x * 1024 for x in (size, free, used)) </code></pre> <p>That said, if it really is advantageous to have those three names as distinct entities (rather...
3
2016-07-11T15:28:53Z
[ "python" ]
Apply operation to multiple variables
38,310,716
<p>I feel like this solution is overkill and I might not be using the builtins correctly.</p> <p>Can someone suggest a better way to apply the same operation to a list of variables?</p> <p>EDIT -- Or change them without re-assigning the values (if that's possible)</p> <pre><code>size = 150 free = 27 used = 123 size...
0
2016-07-11T15:25:42Z
38,310,887
<pre><code>size, free, used=[x*1024 for x in [size, free, used]] </code></pre>
0
2016-07-11T15:34:52Z
[ "python" ]
Apply operation to multiple variables
38,310,716
<p>I feel like this solution is overkill and I might not be using the builtins correctly.</p> <p>Can someone suggest a better way to apply the same operation to a list of variables?</p> <p>EDIT -- Or change them without re-assigning the values (if that's possible)</p> <pre><code>size = 150 free = 27 used = 123 size...
0
2016-07-11T15:25:42Z
38,310,926
<p>You could simply store your variables, which somehow seem like a compound, in a tuple or list like so:</p> <pre><code>mv = [1024, 27, 123] </code></pre> <p>Then, use list comprehension to apply your transformation to all of them:</p> <pre><code>mv = [i * 1024 for i in mv] </code></pre> <p>If you are using <code>...
0
2016-07-11T15:36:39Z
[ "python" ]
Apply operation to multiple variables
38,310,716
<p>I feel like this solution is overkill and I might not be using the builtins correctly.</p> <p>Can someone suggest a better way to apply the same operation to a list of variables?</p> <p>EDIT -- Or change them without re-assigning the values (if that's possible)</p> <pre><code>size = 150 free = 27 used = 123 size...
0
2016-07-11T15:25:42Z
38,311,625
<p>You can use "splat" unpacking to pass the items of a list or tuple to the NamedTuple constructor. Eg,</p> <pre><code>from collections import namedtuple TheTuple = namedtuple('TheTuple', ('size', 'free', 'used')) size = 150 free = 27 used = 123 t = (size, free, used) foo = TheTuple(*[1024 * x for x in t]) print(f...
1
2016-07-11T16:15:33Z
[ "python" ]
Difference between two methods of random point generation
38,310,737
<p>In order to do a monte carlo simulation to estimate expected distance between two random points in $n$ dimensional space I discovered the following two similar looking methods to generate random points seem to differ. I'm not able to figure out why.</p> <p>Method 1:</p> <pre><code>def expec_distance1(n, N = 10000)...
1
2016-07-09T05:06:36Z
38,310,738
<p>In Python 2, list comprehensions leak their loop variables.</p> <p>Since you're looping over <code>i</code> in your list comprehensions (<code>[u.rvs() for i in range(n)]</code>), that is the <code>i</code> used in <code>dist = (dist*i + euclidean_dist(x,y))/(i+1.0)</code>. (<code>i</code> always equals <code>n-1</...
2
2016-07-09T15:16:04Z
[ "python", "simulation", "uniform" ]
How to update Python libraries on Amazon Redshift?
38,310,816
<p>According to Redshift's <a href="http://docs.aws.amazon.com/redshift/latest/dg/udf-python-language-support.html" rel="nofollow">documentation</a> some Python libraries are already included in the clusters. However, I would like to use a later version of scipy for example.</p> <p>I have tried to CREATE OR REPLACE LI...
0
2016-07-11T15:31:01Z
38,314,738
<p>check out the below github repository mainted by awslabs. </p> <p><a href="https://github.com/awslabs/amazon-redshift-udfs/tree/master/bin/PipLibraryInstaller" rel="nofollow">https://github.com/awslabs/amazon-redshift-udfs/tree/master/bin/PipLibraryInstaller</a></p>
0
2016-07-11T19:30:09Z
[ "python", "user-defined-functions", "amazon-redshift" ]
What is the best way to save the comments collected from Facebook using Python?
38,310,850
<p>I'm collecting all the comments from some Facebook pages using Python and Facebook-SDK.</p> <p>Since I want to do Sentiment Analysis on these comments, what's the best way to save these texts, such that it's not needed any changing in the texts?</p> <p>I'm now saving the comments as a table and then as a CSV file....
1
2016-07-11T15:32:54Z
38,310,964
<p>If you have knowledge about the encoding of the data then, you can simply use pandas to read your csv as follow:</p> <pre><code>import pandas as pd pd.read_csv('filename.csv', encoding='encoding') </code></pre>
0
2016-07-11T15:38:26Z
[ "python", "facebook", "csv", "facebook-graph-api" ]
What is the best way to save the comments collected from Facebook using Python?
38,310,850
<p>I'm collecting all the comments from some Facebook pages using Python and Facebook-SDK.</p> <p>Since I want to do Sentiment Analysis on these comments, what's the best way to save these texts, such that it's not needed any changing in the texts?</p> <p>I'm now saving the comments as a table and then as a CSV file....
1
2016-07-11T15:32:54Z
38,317,231
<p>Have you tried this?</p> <p>Set default encoder at the top of your code</p> <pre><code>import sys reload(sys) sys.setdefaultencoding("ISO-8859-1") </code></pre> <p>or </p> <pre><code>pd.read_csv('file-name.csv', encoding = "ISO-8859-1") </code></pre>
2
2016-07-11T22:32:39Z
[ "python", "facebook", "csv", "facebook-graph-api" ]
What is the best way to save the comments collected from Facebook using Python?
38,310,850
<p>I'm collecting all the comments from some Facebook pages using Python and Facebook-SDK.</p> <p>Since I want to do Sentiment Analysis on these comments, what's the best way to save these texts, such that it's not needed any changing in the texts?</p> <p>I'm now saving the comments as a table and then as a CSV file....
1
2016-07-11T15:32:54Z
38,317,636
<p>I would say it really depends on many different factors such as:</p> <ul> <li>Size of the data</li> <li>What kind of analysis, specifically, are you anticipating that you'll be doing</li> <li>What format are you most comfortable working with the data</li> </ul> <p>For most of my data munging in python I like to do...
0
2016-07-11T23:13:47Z
[ "python", "facebook", "csv", "facebook-graph-api" ]
Python Project Structure, Imports
38,310,857
<p>I have the following python project setup:</p> <pre><code>/project /doc /config some_config.json /src /folderA __init__.py Databaseconnection.py ... /folderB __init__.py Calculator.py ... /main ...
1
2016-07-11T15:33:20Z
38,310,968
<p>Using <code>sys.path.insert()</code> gives python another directory to look at for modules to import. The directory <code>../../</code> adds the folder <code>/project</code>, but that is not where the modules exist. Use this instead:</p> <pre><code># Main.py import sys sys.path.insert(0,'../') # /src from folder...
0
2016-07-11T15:38:35Z
[ "python" ]
Why arent the individual words printed?
38,310,874
<p>I am writing a mini program and within my program there is a function which reads in a text file and returns the individual words from the sentence. However I am having trouble seeing the individual words printed even though I return them. I don't really get why unless I have a big problem with my whitespace. Can yo...
0
2016-07-11T15:34:02Z
38,311,186
<p>it seems you only have one word for each line in your file.</p> <pre><code>def read_file(user): with open(user + ".txt","r") as f: data = [ line.strip() for line in f.readlines() ] return list( set(data) ) </code></pre> <p>--update--- if you have more than one word in each line and separated by sp...
2
2016-07-11T15:50:13Z
[ "python" ]
Why arent the individual words printed?
38,310,874
<p>I am writing a mini program and within my program there is a function which reads in a text file and returns the individual words from the sentence. However I am having trouble seeing the individual words printed even though I return them. I don't really get why unless I have a big problem with my whitespace. Can yo...
0
2016-07-11T15:34:02Z
38,311,197
<p>If all you want is a list of each word that occurs in the text, you are doing far too much work. You want something like this:</p> <pre><code>unique_words = [] all_words = [] with open(file_name, 'r') as in_file: text_lines = in_file.readlines() # Read in all line from the file as a list. for line in text_lines:...
0
2016-07-11T15:51:04Z
[ "python" ]
Why arent the individual words printed?
38,310,874
<p>I am writing a mini program and within my program there is a function which reads in a text file and returns the individual words from the sentence. However I am having trouble seeing the individual words printed even though I return them. I don't really get why unless I have a big problem with my whitespace. Can yo...
0
2016-07-11T15:34:02Z
38,311,284
<p>You can simplify your code by using a <code>set</code> because it will only contain unique elements.</p> <pre><code>user_file = raw_input("enter a filename to read: ") #function to read any file def read_file(user): unique_words = set() csv_file = open(user + ".txt","r") main_file = csv_file.readlines(...
0
2016-07-11T15:56:03Z
[ "python" ]
Why arent the individual words printed?
38,310,874
<p>I am writing a mini program and within my program there is a function which reads in a text file and returns the individual words from the sentence. However I am having trouble seeing the individual words printed even though I return them. I don't really get why unless I have a big problem with my whitespace. Can yo...
0
2016-07-11T15:34:02Z
38,311,400
<p>In fact, I can not reproduce you problem. Given a proper CSV input file <sup>1)</sup> such as</p> <pre><code>a,b,c,d e,f,g,h i,j,k,l </code></pre> <p>your program prints this, which apart from the last <code>''</code> seems fine:</p> <pre><code>['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', ''] </co...
1
2016-07-11T16:02:08Z
[ "python" ]
How do I subset columns in a pandas dataframe from a list in another frame which includes NaNs?
38,310,889
<p>Here is the dataframe that needs subsetting:</p> <pre><code>df1: A B C 0 1 3 1 1 0 4 1 2 3 1 1 3 2 -6 1 4 8 1 -1 5 10 0 9 . . . . . . . . . . . . [Frame Continues] </code></pre> <p>My reference frame:</p> <pre><code>df2: Names ...
2
2016-07-11T15:34:53Z
38,311,050
<p>You can use <code>DataFrame.filter</code> to do this which'll automatically handle <code>NaN</code>s and makes it quite explicit your intent is subsetting the columns, eg:</p> <pre><code>df1.filter(df2.Names) </code></pre>
1
2016-07-11T15:43:05Z
[ "python", "pandas" ]
Extract from dynamic JSON response with Scrapy
38,310,986
<p>I want to extract the 'avail' value from the JSON output that look like this. </p> <pre><code>{ "result": { "code": 100, "message": "Command Successful" }, "domains": { "yolotaxpayers.com": { "avail": false, "tld": "com", "price": "49.95", ...
1
2016-07-11T15:39:16Z
38,311,052
<p>Currently, it tries to get the value by the <code>"('%s.com' % line)"</code> key.</p> <p>You need to do the string formatting correctly:</p> <pre><code>domain_name = "%s.com" % line.strip() item["avail"] = jsonresponse["domains"][domain_name]["avail"] </code></pre>
1
2016-07-11T15:43:07Z
[ "python", "json", "web-scraping", "scrapy", "web-crawler" ]
Extract from dynamic JSON response with Scrapy
38,310,986
<p>I want to extract the 'avail' value from the JSON output that look like this. </p> <pre><code>{ "result": { "code": 100, "message": "Command Successful" }, "domains": { "yolotaxpayers.com": { "avail": false, "tld": "com", "price": "49.95", ...
1
2016-07-11T15:39:16Z
38,311,171
<p>Assuming you are only expecting one result per response:</p> <pre><code>domain_name = list(jsonresponse['domains'].keys())[0] item["avail"] = jsonresponse["domains"][domain_name]["avail"] </code></pre> <p>This will work even if there is a mismatch between the domain in the file "test.txt" and the domain in the res...
0
2016-07-11T15:49:27Z
[ "python", "json", "web-scraping", "scrapy", "web-crawler" ]
Extract from dynamic JSON response with Scrapy
38,310,986
<p>I want to extract the 'avail' value from the JSON output that look like this. </p> <pre><code>{ "result": { "code": 100, "message": "Command Successful" }, "domains": { "yolotaxpayers.com": { "avail": false, "tld": "com", "price": "49.95", ...
1
2016-07-11T15:39:16Z
38,311,745
<p>To get the domain name from above json response you can use list comprehension , e.g:</p> <h2>domain_name = [x for x in jsonresponse.values()[0].keys()]</h2> <p>To get the "avail" value use same method, e.g:</p> <h2>avail = [x["avail"] for x in jsonresponse.values()[0].values() if "avail" in x]</h2> <p>to get th...
0
2016-07-11T16:22:45Z
[ "python", "json", "web-scraping", "scrapy", "web-crawler" ]
AFNetworking and Token from Django JWT
38,311,108
<p>I have used AFNetworking and I have connected to Django api before. </p> <p>Now problem is I am trying about token authentication in Django. </p> <p><a href="http://getblimp.github.io/django-rest-framework-jwt/" rel="nofollow">http://getblimp.github.io/django-rest-framework-jwt/</a></p> <p>I have tried these in t...
0
2016-07-11T15:45:51Z
38,311,378
<p>I got it now. Based on curl command, I need to write like this.</p> <pre><code>NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"]; if (token) { token = [NSString stringWithFormat:@"%@ %@", @"JWT", token]; [self.manager.requestSerializer setValue:token forHTTPHeaderField:@"Autho...
1
2016-07-11T16:00:29Z
[ "python", "django", "afnetworking", "jwt" ]
grouping rows python pandas
38,311,120
<p>say I have the following dataframe and, the index represents ages, the column names is some category, and the values in the frame are frequencies...</p> <p>Now I would like to group ages in various ways (2 year bins, 5 year bins and 10 year bins)</p> <pre><code>&gt;&gt;&gt; table_w 1 2 3 4 20 1000 ...
2
2016-07-11T15:46:30Z
38,311,271
<p>Use <code>pd.cut()</code> to create the age bins and group your dataframe with them.</p> <pre><code>import io import numpy as np import pandas as pd data = io.StringIO("""\ 1 2 3 4 20 1000 80 40 100 21 2000 40 100 100 22 3000 70 70 200 23 3000 100 90 100 24 2000 90 90 2...
7
2016-07-11T15:55:04Z
[ "python", "pandas", "dataframe" ]
Dropping column values that don't meet a requirement
38,311,156
<p>I have a pandas data frame with a 'date_of_birth' column. Values take the form <code>1977-10-24T00:00:00.000Z</code> for example.</p> <p>I want to grab the year, so I tried the following:</p> <pre><code>X['date_of_birth'] = X['date_of_birth'].apply(lambda x: int(str(x)[4:])) </code></pre> <p>This works if I am gu...
4
2016-07-11T15:48:38Z
38,311,379
<p>I think it would be better to just use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html#pandas.to_datetime" rel="nofollow"><code>to_datetime</code></a> to convert to <code>datetime</code> dtype, you can drop the invalid rows using <a href="http://pandas.pydata.org/pandas-docs/st...
2
2016-07-11T16:00:32Z
[ "python", "pandas" ]
Specifying both 'fields' and 'form_class' is not permitted
38,311,299
<p>I have the following form, which I want render it with Django crispy forms.</p> <p>This is my views.py</p> <pre><code>class RehabilitationSessionCreate(CreateView): model = RehabilitationSession form_class = RehabilitationSessionForm() success_url = reverse_lazy('rehabilitationsessions:list') fie...
0
2016-07-11T15:56:45Z
38,311,371
<p>As the error says, you cannot set both <code>form_class</code> and <code>fields</code> for your view. You can either set <code>form_class</code></p> <pre><code>class RehabilitationSessionCreate(CreateView): model = RehabilitationSession form_class = RehabilitationSessionForm # Not you should *not* have () ...
3
2016-07-11T16:00:21Z
[ "python", "django", "django-forms", "django-views" ]
scons -u and variantdirs
38,311,306
<p>I've been working with SCons for a while now and I'm facing a problem that I can't manage to resolve, I hope someone can help me. I created a dummy project that compiles a basic helloWorld (in main.cpp). What I want to do is compile my binary from 'test' folder using the scons -u command. All of my build is done in ...
1
2016-07-11T15:57:06Z
38,314,827
<p>Please check the <a href="http://scons.org/doc/production/HTML/scons-man.html" rel="nofollow">MAN page</a> again. The <code>-u</code> option will only build default targets at or below the current directory. This excludes your folder <code>sconsTest/build</code> when you're in <code>sconsTest/test</code>.</p> <p>Wh...
0
2016-07-11T19:36:18Z
[ "python", "c++", "build", "scons" ]
SublimeText3 cannot find Python modules (numpy) installed with MacPorts
38,311,410
<p>I installed Python 3.5 using MacPorts. I am trying to use SublimeText3 as an editor. (Anything better and more integrated tan ST3 for python development??)</p> <p>From the MacOSX terminal, I can 'import numpy' just fine, but SublimeText3 cannot find the packages. </p> <p>Is it because the python packages are in...
-1
2016-07-11T16:02:56Z
38,311,620
<p>First, you need to find out which python3 you are using in terminal. You can do this by running command <code>which python3</code>. Suppose the output is: <code>/Users/username/.anaconda3/bin/python3</code>.</p> <p>Second, try to set PYTHONPATH environment variable in Sublime's settings. Go to <code>Preferences -&g...
0
2016-07-11T16:15:14Z
[ "python", "numpy", "sublimetext3" ]
concurrent.futures.ProcessPoolExecutor vs multiprocessing.pool.Pool
38,311,431
<p>Please explain to me <strong>what is the difference</strong> between these two classes?</p> <ul> <li><a href="https://docs.python.org/3/library/concurrent.futures.html#module-concurrent.futures" rel="nofollow">concurrent.futures.ProcessPoolExecutor</a></li> <li><a href="https://docs.python.org/3/library/multiproces...
0
2016-07-11T16:04:04Z
38,311,560
<p>As stated in the documentation, <a href="https://docs.python.org/3/library/concurrent.futures.html#processpoolexecutor" rel="nofollow"><code>concurrent.futures.ProcessPoolExecutor</code></a> is a wrapper around <code>multiprocessing</code>. As such, the same limitations of <code>multiprocessing</code> apply (e.g. o...
1
2016-07-11T16:11:09Z
[ "python", "python-3.x", "concurrency", "parallel-processing", "multiprocessing" ]
Problems with SWIG, mingw32, distutils
38,311,483
<p>I have been trying to set up a Python 2.7 environment under Windows 7 so that I can compile a C++ extension for use in Python. Since I am new to this, I have downloaded a simple example <a href="https://gist.github.com/mattbierbaum/1189856" rel="nofollow">here</a> and have used the files verbatim. I also have a nu...
3
2016-07-11T16:06:34Z
38,364,331
<p>In this compilation step the input file is compiled as C++ code and the functions in symbol.cc will be given symbols that are incompatible with C (name mangling).</p> <blockquote> <p>C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\lib\site-packages\numpy\core\include -I. -IC:\Python27\include -IC:\Python27\PC...
1
2016-07-14T01:57:17Z
[ "python", "c++", "swig", "distutils", "mingw32" ]
2D Game Engine How Can I Organise Game Objects?
38,311,570
<p>Good Evening (from Europe).</p> <p>I'm trying to create a 2D game engine with python and pygame <br/>that will work similar with the <a href="https://unity3d.com/" rel="nofollow">Unity 3D</a>, but you'll be able to create only 2D games. <br/>To explain my problem i will show you some of my classes that you need<br/...
3
2016-07-11T16:11:49Z
38,369,269
<p>Place all your objects in a 2 dimensional grid where the grid represents your whole scene. Then you can easily iterate over only the ones visible on the screen. And collision detection becomes easier now.</p> <p>The size of the cells are up to you. Try different sizes an see which one works best</p>
0
2016-07-14T08:33:12Z
[ "python", "pygame" ]
When using tkinter in python, how to call a checkbox which is in a fuction in another function?
38,311,616
<p>For example, I have the following code in a.py file:</p> <pre><code>import tkinter def main(): top = tkinter.Tk() top.title("Main") Var = tkinter.IntVar() CheckBox = tkinter.Checkbutton(top, text="test", variable=Var) CheckBox.grid(column=1, row=1) startButton = tkinter.Button(top, text="S...
1
2016-07-11T16:15:12Z
38,312,678
<p><code>Var</code> is local to <code>a.py</code> so you must find make it accessible to <code>b.py</code>. The simple <code>import a</code> is not sufficient unless if you define Var in a.py this way:</p> <p><strong>a.py</strong></p> <pre><code>import tkinter # Must be done here otherwise we can not declare Var abo...
0
2016-07-11T17:20:06Z
[ "python", "checkbox", "tkinter" ]
When using tkinter in python, how to call a checkbox which is in a fuction in another function?
38,311,616
<p>For example, I have the following code in a.py file:</p> <pre><code>import tkinter def main(): top = tkinter.Tk() top.title("Main") Var = tkinter.IntVar() CheckBox = tkinter.Checkbutton(top, text="test", variable=Var) CheckBox.grid(column=1, row=1) startButton = tkinter.Button(top, text="S...
1
2016-07-11T16:15:12Z
38,314,165
<p>This is due to the fact that you have two instances of <code>Tk</code>. Tkinter is designed to have exactly onc instance at a time. Each instance has its own internal namespace, so variables in one instance are invisible to the other instance. </p>
0
2016-07-11T18:54:04Z
[ "python", "checkbox", "tkinter" ]
Optimizing Many Matrix Operations in Python / Numpy
38,311,794
<p>In writing some numerical analysis code, I have bottle-necked at a function that requires many Numpy calls. I am not entirely sure how to approach further performance optimization.</p> <p>Problem:</p> <p>The function determines error by calculating the following, </p> <p><a href="http://i.stack.imgur.com/gh1Es.pn...
1
2016-07-11T16:25:48Z
38,312,059
<p>There are specific functions from the implementation that could be off-loaded to <a href="https://github.com/pydata/numexpr/wiki/Numexpr-Users-Guide" rel="nofollow"><code>numexpr</code> module</a> which is known to be very efficient for arithmetic computations. For our case, specifically we could perform squaring, s...
3
2016-07-11T16:41:56Z
[ "python", "numpy", "optimization", "matrix", "cython" ]
Subscription discount history
38,311,842
<p>I am working on a billing history page to show customers, based on a braintree subscription. While the braintree api generally has all the information I need, I'm having trouble with <em>discounts</em>.</p> <p>In the braintree control panel, a subscription will show a 'history' section below the transaction section...
0
2016-07-11T16:28:42Z
38,333,397
<p><sub>Full disclosure: I work at Braintree. If you have any further questions, feel free to contact <a href="https://support.braintreepayments.com/" rel="nofollow">support</a>.</sub></p> <p>The Subscription result object has attributes <a href="https://developers.braintreepayments.com/reference/response/subscription...
1
2016-07-12T15:40:19Z
[ "python", "braintree" ]
Flip Pandas dataframe on column and create dictionary
38,311,872
<p>I have a Pandas dataframe with 2 columns, e.g.</p> <pre><code> name case 0 a 01 1 a 03 2 b 04 3 b 05 4 b 06 5 b 08 6 b 09 7 b 12 8 c 01 9 c 02 10 c 03 11 c 04 </code></pre> <p>What I need is a dictionary:</p> <pre><code>{"a": ["01", "03"], "b": ["04", "05", "06", "...
3
2016-07-11T16:30:41Z
38,311,984
<p>After performing the <code>groupby</code>, use <code>apply</code> to get a list, and then call <code>to_dict</code>:</p> <pre><code>df.groupby('name')['case'].apply(list).to_dict() </code></pre> <p>The resulting output:</p> <pre><code>{'a': ['01', '03'], 'c': ['01', '02', '03', '04'], 'b': ['04', '05', '06', '08'...
6
2016-07-11T16:37:16Z
[ "python", "pandas" ]
Flip Pandas dataframe on column and create dictionary
38,311,872
<p>I have a Pandas dataframe with 2 columns, e.g.</p> <pre><code> name case 0 a 01 1 a 03 2 b 04 3 b 05 4 b 06 5 b 08 6 b 09 7 b 12 8 c 01 9 c 02 10 c 03 11 c 04 </code></pre> <p>What I need is a dictionary:</p> <pre><code>{"a": ["01", "03"], "b": ["04", "05", "06", "...
3
2016-07-11T16:30:41Z
38,321,208
<p>For some perspective:</p> <pre><code>s = df.set_index('name').case {k: s.loc[k].tolist() for k in s.index.unique()} {'a': [1, 3], 'b': [4, 5, 6, 8, 9, 12], 'c': [1, 2, 3, 4]} </code></pre> <hr> <h3>Timing</h3> <p>Conclusion: @root's answer is faster.</p> <p><strong>Example Data</strong></p> <p><a href="http:/...
1
2016-07-12T06:13:00Z
[ "python", "pandas" ]
TensorFlow FullyConnected Tutorial: How are the trained weights used for Eval and Test?
38,311,935
<p>I've been looking through the TensorFlow <a href="https://github.com/tensorflow/tensorflow/blob/r0.9/tensorflow/examples/tutorials/mnist/fully_connected_feed.py" rel="nofollow">FullyConnected</a> tutorial. This also uses the helper code <a href="https://github.com/tensorflow/tensorflow/blob/r0.9/tensorflow/examples/...
1
2016-07-11T16:34:16Z
38,313,110
<p>TensorFlow creates a graph with the weights and biases. Roughly speaking while you train this neural net the weights and biases get changed so it produces expected outputs. The line 131 in <em>fully_connected_feed.py</em> (<code>with tf.Graph().as_default():</code>) is used to tell TensorFlow to use the default grap...
1
2016-07-11T17:46:28Z
[ "python", "neural-network", "tensorflow", "training-data" ]
How to move something to either left or right in python?
38,312,107
<p>Having a problem, lets say I have this code (easiest possible):</p> <pre><code>n=5 j=3 for i in range(n): print("kurt") for x in range(j): print("karl") </code></pre> <p>If I want this to be printed like a protocol, that is, I don't want them after each other, I want my second for-loop to be to the right o...
-1
2016-07-11T16:44:27Z
38,312,155
<p>Sure, just put them in one print statement.</p> <p>Here I've told it to loop for the maximum number (in this case <code>5</code>) and then if the loop has reached the minimum number (<code>3</code>) to stop printing the second one.</p> <pre><code>n = 5 j = 3 for i in range (max(n,j)): if i &lt; min(n,j): ...
2
2016-07-11T16:47:52Z
[ "python", "loops" ]
How to move something to either left or right in python?
38,312,107
<p>Having a problem, lets say I have this code (easiest possible):</p> <pre><code>n=5 j=3 for i in range(n): print("kurt") for x in range(j): print("karl") </code></pre> <p>If I want this to be printed like a protocol, that is, I don't want them after each other, I want my second for-loop to be to the right o...
-1
2016-07-11T16:44:27Z
38,312,251
<pre><code>from itertools import izip_longest first = ['kurt']*j second = ['karl']*n for l,r in izip_longest(first ,second ): print l,r </code></pre> <p>output:</p> <pre><code>kurt karl kurt karl kurt karl None karl None karl </code></pre> <p>if you want white space.</p> <pre><code>from itertools import izip_lo...
0
2016-07-11T16:53:14Z
[ "python", "loops" ]
How to move something to either left or right in python?
38,312,107
<p>Having a problem, lets say I have this code (easiest possible):</p> <pre><code>n=5 j=3 for i in range(n): print("kurt") for x in range(j): print("karl") </code></pre> <p>If I want this to be printed like a protocol, that is, I don't want them after each other, I want my second for-loop to be to the right o...
-1
2016-07-11T16:44:27Z
38,312,380
<p>Assuming that this printing of "kurt" and "karl" is just an example of a more complex problem you're trying to solve, a general strategy for this sort of problem is to use Python <a href="https://wiki.python.org/moin/Generators" rel="nofollow">generators</a> to run the two loops concurrently, and then combine the re...
0
2016-07-11T17:00:57Z
[ "python", "loops" ]
How to move something to either left or right in python?
38,312,107
<p>Having a problem, lets say I have this code (easiest possible):</p> <pre><code>n=5 j=3 for i in range(n): print("kurt") for x in range(j): print("karl") </code></pre> <p>If I want this to be printed like a protocol, that is, I don't want them after each other, I want my second for-loop to be to the right o...
-1
2016-07-11T16:44:27Z
38,312,429
<p>As I understood, you want to print the values of next loop in right of previous loop, you can achieve it by writing this:</p> <p>In python 2.7</p> <pre><code>for i, k in zip(range(n), range(j)): print "kurt", print "karl" </code></pre> <p>In python 3.x</p> <pre><code>for i, k in zip(range(n), range(j)): ...
1
2016-07-11T17:03:57Z
[ "python", "loops" ]
What's the difference between these two Quicksort partition functions?
38,312,247
<pre><code>def PartitionDemo(a,p,r): x=a[p] start=p end=r while start&lt;end : while start&lt;end and a[end]&gt;=x : end-=1 while start&lt;end and a[start]&lt;x : a[start]=a[end] start+=1 a[end]=a[start] a[start]=x return start def...
-3
2016-07-11T16:53:05Z
38,312,401
<p>The PartitionDemo has</p> <pre><code>while start&lt;end and a[start]&lt;x : </code></pre> <p>where Partition2 has</p> <pre><code>while low &lt; high and a[high] &lt; key: </code></pre> <p>so it looks like yours should be </p> <pre><code>while start&lt;end and a[end]&lt;x : </code></pre> <p>replacing the second...
1
2016-07-11T17:02:09Z
[ "python", "quicksort" ]
Regex in Django for configuring url patterns
38,312,336
<p>I'm making a browsable directory structure in Django, and I have made it using button forms and <code>GET</code> requests, however, I'm trying to achieve the same using links instead of buttons, and I'm confused with <em>regex</em>, infact I do not know a thing about it. I tried some stuff and other related answers ...
1
2016-07-11T16:58:06Z
38,313,569
<p>You need to define the <code>path</code> named capture group in your regex in order to be able to use <code>{{path}}</code> later. To match anything after <code>realTime/</code> you only need <code>.*</code>, you do not even need to define <code>$</code>:</p> <pre><code>url(r'^realTime/(?P&lt;path&gt;.*)', views.v...
1
2016-07-11T18:16:00Z
[ "python", "regex", "django" ]
Regex in Django for configuring url patterns
38,312,336
<p>I'm making a browsable directory structure in Django, and I have made it using button forms and <code>GET</code> requests, however, I'm trying to achieve the same using links instead of buttons, and I'm confused with <em>regex</em>, infact I do not know a thing about it. I tried some stuff and other related answers ...
1
2016-07-11T16:58:06Z
38,315,649
<p>In your urls.py use the following code </p> <pre><code>url(r'^realTime/(?P&lt;path&gt;.*)', views.view_real_time_index, name='view_real_time_index'), </code></pre> <p>And in your views.py you can retrieve and use "path" as:</p> <pre><code>def view_real_time_index(request, path) : print(path) #your code </c...
0
2016-07-11T20:26:48Z
[ "python", "regex", "django" ]
I want to authorize through vk.com with using python-social-auth and get error with redirect uri
38,312,387
<h3>Error</h3> <pre><code>{ "error":"invalid_request", "error_description":"redirect_uri is incorrect, check application redirect uri in the settings page" } </code></pre> <h3>settings.py</h3> <pre><code>AUTHENTICATION_BACKENDS = ( 'social.backends.vk.VKOAuth2', 'django.contrib.auth.backends.ModelBac...
2
2016-07-11T17:01:25Z
38,371,546
<p>I see network request and in it was param "redirect_uri" <a href="http://localhost:8000/complete/vk-oauth2/" rel="nofollow">http://localhost:8000/complete/vk-oauth2/</a>. I paste it in redirect uri on vk.com. And authorizing is ended successfully. To see request press f12 and got ot tab network (in Firefox).</p>
0
2016-07-14T10:16:49Z
[ "python", "django", "python-social-auth", "vk" ]
Can I import .csv files based on a partial filename?
38,312,452
<p>So the data that I need to work with comes as a set of 10 .csv files each with names of the following format:</p> <p>Example_datatype_date_IDnumber.csv</p> <p>Each of the 10 files requires different manipulation/analysis and I'd like to do it all with one python script. I can do it successfully with pandas but the...
0
2016-07-11T17:05:51Z
38,312,612
<p>If you put all files in one folder (assume c:\tmp), you could use regex and <code>glob</code> to find all files:</p> <pre><code>import glob path = r"c:\\tmp\\*.csv" for filePath in glob.glob(path): # read file and analysis file </code></pre> <p>or</p> <pre><code>import re import os pattern = r'\w+_\w+_\w+_\...
1
2016-07-11T17:15:55Z
[ "python", "csv", "pandas" ]
Can I import .csv files based on a partial filename?
38,312,452
<p>So the data that I need to work with comes as a set of 10 .csv files each with names of the following format:</p> <p>Example_datatype_date_IDnumber.csv</p> <p>Each of the 10 files requires different manipulation/analysis and I'd like to do it all with one python script. I can do it successfully with pandas but the...
0
2016-07-11T17:05:51Z
38,312,707
<p>You can use regular expressions to detect the datatype from the file name:</p> <pre><code>import os, re files = os.listdir("my_directory") for fname in files: m = re.search('[^_]+_([^_]+).*\csv', fname) if m: datatype = m.group(1) print fname print datatype </code></pre>
0
2016-07-11T17:21:45Z
[ "python", "csv", "pandas" ]
Can I import .csv files based on a partial filename?
38,312,452
<p>So the data that I need to work with comes as a set of 10 .csv files each with names of the following format:</p> <p>Example_datatype_date_IDnumber.csv</p> <p>Each of the 10 files requires different manipulation/analysis and I'd like to do it all with one python script. I can do it successfully with pandas but the...
0
2016-07-11T17:05:51Z
38,313,011
<pre><code>import os, re path_containing_csv_files = '/tmp/test' #contains &lt; example_int_12-12-16_1.csv, example_string_11-12-16_2.csv&gt; def process_int(filepath): #process int data here pass def process_string(filepath): #process string data here pass methods = {'int':process_int, '...
0
2016-07-11T17:40:43Z
[ "python", "csv", "pandas" ]
Show specific value in Textbox according to combobox selected value in python
38,312,494
<p>How can I show the combobox value in my textbox widget?</p> <p>Here is my coding, it said I need to put the event argument, so what event argument should I put in order to show my combobox value in my textbox widget?</p> <pre><code>from tkinter import * from tkinter import ttk class Application: def __init__(...
1
2016-07-11T17:08:06Z
38,316,934
<p>The problem is not about which event argument to pass to <code>textArea</code>() method: you rather have to fix the following errors:</p> <ol> <li>First of all, remove the call to <code>textArea()</code> inside <code>__init__()</code>, it is rather <code>combo()</code> that needs it.</li> <li>Inside <code>textArea...
1
2016-07-11T22:03:32Z
[ "python", "combobox", "tkinter", "textbox" ]
Save results to a variable
38,312,505
<p>I created N to combine test1 and test2 making it 1 line 10 digits <br/> <br/>How do I assign a variable that carries this whole function? So I could use <br/><code>print A</code> and it prints N 10 times. I need to use results in future for something else.<br/> Outside of the code below N prints the whole thing ju...
0
2016-07-11T17:09:03Z
38,312,638
<p>You'd be better off writing this as a function instead of storing the information in a variable.</p> <pre><code>def myFunction(): for i in range(10): test1 = stats.rv_discrete(name='test1', values=(numbers, probability)) test1_results = test1.rvs(size=8) test2 = stats.rv_discrete(name='t...
0
2016-07-11T17:18:10Z
[ "python", "variables", "printing" ]
Tkinter performance when packing many widgets
38,312,592
<p>I am making a GUI in python using Tkinter and have had some performance issues when packing many widgets onto the screen, for example packing a 50x50 grid of buttons takes a few seconds.</p> <p>It seems to be the process of drawing (or arranging?) the widgets onto the screen which takes the time. I have tried using...
2
2016-07-11T17:14:31Z
38,798,022
<p>As suggested in the comments, the best solution did end up being to use a canvas and draw onto it, rather than to pack so many widgets, which seems to have absolute limitations on its speed.</p> <p>I used the built-in buttons by effectively taking a screenshot to create images of the unclicked and clicked states. S...
0
2016-08-05T21:30:34Z
[ "python", "python-2.7", "user-interface", "tkinter" ]
How do I get the id of the last tweet using twython?
38,312,656
<p>what I want is to eliminate the last tweet, for that I use the following:</p> <pre><code> l = len(sys.argv) if l &gt;= 2: twid = sys.argv[1] else: twid = input("ID number of tweet to delete: ") try: tweet = twitter.destroy_status(id=twid) except TwythonError as e: print(e) </code></pre> <p>It ...
0
2016-07-11T17:18:56Z
38,381,809
<p>I think this can help you.</p> <pre><code>user_timeline=twitter.get_user_timeline(screen_name="BarackObama", count=20) for tweet in user_timeline: print tweet["id"] </code></pre> <p>It prints the 20 lastest tweets id of Barack Obama.</p> <p>Let me know if that is what you are looking for.</p>
0
2016-07-14T18:38:37Z
[ "python", "twitter", "twython" ]
How do I get the id of the last tweet using twython?
38,312,656
<p>what I want is to eliminate the last tweet, for that I use the following:</p> <pre><code> l = len(sys.argv) if l &gt;= 2: twid = sys.argv[1] else: twid = input("ID number of tweet to delete: ") try: tweet = twitter.destroy_status(id=twid) except TwythonError as e: print(e) </code></pre> <p>It ...
0
2016-07-11T17:18:56Z
38,922,845
<p>You can use get_user_timeline with your personal screen name to retrieve the tweet, and then access it with tweet[0] since it will be in the first index.</p> <pre><code>tweet = twitter.get_user_timeline( screen_name=YOUR_SCREEN_NAME, count=1) twitter.destroy_status(id=tweet[0]['id']) </code>...
0
2016-08-12T16:42:14Z
[ "python", "twitter", "twython" ]
Exceptions using django standalone with python3
38,312,660
<p>Trying to use django templates in stand-alone mode. I get these exceptions (below). New to python, wondering if anyone would be willing to help out.</p> <p>Django is used for templating in a script which is not shown here. However the exact same exceptions appear when launching it.</p> <pre><code>&gt;&gt;&gt; from...
1
2016-07-11T17:19:10Z
38,313,766
<p>After calling <code>settings.configure()</code>, you must call <code>django.setup()</code>.</p> <pre><code>import django from django.conf import settings settings.configure() django.setup() from django.template import Template, Context t = Template('My name is {{ my_name }}.') c=Context({'my_name': 'Mindaugas'}) t....
0
2016-07-11T18:29:01Z
[ "python", "django", "python-3.x" ]
printing 5 words before and after a specific word in a file in python
38,312,735
<p>I have a folder which contains some other folders and these folders contain some text files. (The language is Persian). I want to print 5 words before and after a keyword with the keyword in the middle of them. I wrote the code, but it gives the 5 words in the start and the end of the line and not the words around t...
0
2016-07-11T17:24:00Z
38,312,811
<p>You need to get the words indices based on your keyword's index. You can use <code>list.index()</code> method in order to get the intended index, then use a simple indexing to get the expected words:</p> <pre><code>for f in normal_text(folder_path): for line in f: if keyword in line: words = lin...
0
2016-07-11T17:29:06Z
[ "python", "nlp" ]
printing 5 words before and after a specific word in a file in python
38,312,735
<p>I have a folder which contains some other folders and these folders contain some text files. (The language is Persian). I want to print 5 words before and after a keyword with the keyword in the middle of them. I wrote the code, but it gives the 5 words in the start and the end of the line and not the words around t...
0
2016-07-11T17:24:00Z
38,312,815
<pre><code>def c(): y = "آرامش" text= normal_text(folder_path) # the first function to open and normalize the files for i in text: for line in i: split_line = line.split() if y in split_line: index = split_line.index(y) print (' '.join(spl...
-2
2016-07-11T17:29:17Z
[ "python", "nlp" ]
printing 5 words before and after a specific word in a file in python
38,312,735
<p>I have a folder which contains some other folders and these folders contain some text files. (The language is Persian). I want to print 5 words before and after a keyword with the keyword in the middle of them. I wrote the code, but it gives the 5 words in the start and the end of the line and not the words around t...
0
2016-07-11T17:24:00Z
38,312,894
<p>Try this. It splits the words. Then it calculates the amount to show before and after (with a minimum of however much is left, and a maximum of 5) and shows it.</p> <pre><code>words = line.split() if y in words: index = words.index(y) before = index - min(index, 5) after = index + min( len(words) - 1 - ...
0
2016-07-11T17:34:20Z
[ "python", "nlp" ]
converting a list with 0's and 1's to a bitarray (with bitarray module) and outputting to a binary file error
38,312,736
<p>I have a unique problem (at least as far as I can tell from the hours I've spent here on SO and out on google searches).</p> <p>I have a list of 0 and 1 integers of varying list length, for example:</p> <pre><code>[0, 1, 0, 0 ,1, 0, 0, 0, 0, 0, 0...] </code></pre> <p>I'm converting this list into a <code>bitarray...
2
2016-07-11T17:24:07Z
38,312,813
<p>You need to use one of the following methods to produce a <code>bytes</code> or <code>str</code> string object:</p> <ul> <li><code>.to01()</code> produces a string of <code>'0'</code> and <code>'1'</code> characters.</li> <li><code>.tobytes()</code> produces a <code>bytes</code> object with each sequence of 8 bits ...
1
2016-07-11T17:29:11Z
[ "python", "file", "binary", "output" ]
converting a list with 0's and 1's to a bitarray (with bitarray module) and outputting to a binary file error
38,312,736
<p>I have a unique problem (at least as far as I can tell from the hours I've spent here on SO and out on google searches).</p> <p>I have a list of 0 and 1 integers of varying list length, for example:</p> <pre><code>[0, 1, 0, 0 ,1, 0, 0, 0, 0, 0, 0...] </code></pre> <p>I'm converting this list into a <code>bitarray...
2
2016-07-11T17:24:07Z
38,313,147
<p>To pack zeros and ones into a binary bit-wise format, numpy's <code>packbits</code> can be used:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; x = np.packbits([1, 0, 0, 0 , 0, 0, 0, 1]) &gt;&gt;&gt; x array([129], dtype=uint8) </code></pre> <p><code>uint8</code> means that numpy is displaying each by...
1
2016-07-11T17:48:47Z
[ "python", "file", "binary", "output" ]
Testing a Flask app gives "working outside of application context" even though I create a context
38,312,757
<p>I want to test my Flask app. I create an app context with <code>current_app.app_context()</code> but still get a "working outside of application context error.</p> <p>My <code>app.py</code> and <code>tests.py</code> is on the same level in the same directory, but I am still getting this error below when I run <cod...
0
2016-07-11T17:25:28Z
38,312,919
<p>You need to set up the app context using an actual instance of your app. <code>current_app</code> is only valid once you're <em>already</em> in an app context.</p> <pre><code>from app import app with app.app_context(): </code></pre>
0
2016-07-11T17:36:08Z
[ "python", "testing", "flask" ]
remove dictionary quotation from pandas dataframe
38,312,995
<p>Below is the output of my dataframe:</p> <pre><code> 0 1 0 {"time": "2016-03-28T23:23:12Z" "target": "Raffi-Antilian"} 1 {"time": "2016-03-28T23:23:12Z" "target": "Caroline-Kaiser"} </code></pre> <p>How can I convert individual records from type diction...
3
2016-07-11T17:40:05Z
38,313,416
<p>You can <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a> with <code>sep=';'</code> if in file is <strong>not</strong> <code>;</code>, so all data are in one <code>Series</code>. Then convert <code>string</code> to <code>dictionary</code> by...
1
2016-07-11T18:05:48Z
[ "python", "file", "pandas", "dictionary", "dataframe" ]
remove dictionary quotation from pandas dataframe
38,312,995
<p>Below is the output of my dataframe:</p> <pre><code> 0 1 0 {"time": "2016-03-28T23:23:12Z" "target": "Raffi-Antilian"} 1 {"time": "2016-03-28T23:23:12Z" "target": "Caroline-Kaiser"} </code></pre> <p>How can I convert individual records from type diction...
3
2016-07-11T17:40:05Z
38,313,721
<pre><code>import json data = [] with open('filename', 'r') as f: for line in f: data.append(json.loads(line)) pd.DataFrame(data) </code></pre> <p>gives</p> <pre><code>Out[49]: target time 0 Raffi-Antilian 2016-03-28T23:23:12Z 1 Caroline-Kaiser 2016-03-28T23:23:12Z </cod...
3
2016-07-11T18:26:09Z
[ "python", "file", "pandas", "dictionary", "dataframe" ]
SoftLayer API - Configuration In GUI not available in API
38,313,131
<p>I am trying to test an order placement with these configurations:</p> <pre><code>pkgId = 253 prices = [ {'id': getItemPriceId(items, 'server', 'INTEL_XEON_2650_2_30')}, {'id': getItemPriceId(items, 'os', 'OS_UBUNTU_14_04_LTS_TRUSTY_TAHR_64_BIT')}, {'id': getItemPriceId(items, 'ram', 'RAM_64_GB_DDR3_1333_REG_2...
0
2016-07-11T17:47:47Z
38,313,412
<p>There is a location conflict for the item price: <strong>156517</strong>, this is not available for <strong>Paris 1</strong> and <strong>Dallas 10</strong> datacenter, to get more information about how item prices works, take a look the following article:</p> <ul> <li><a href="http://sldn.softlayer.com/blog/cmporte...
1
2016-07-11T18:05:18Z
[ "python", "softlayer" ]
Python 3.x C API: Do I have to free the memory after extracting a string from a PyObject?
38,313,153
<p>I extract strings from a <code>PyObject</code> pointer using:</p> <pre><code>char* str = PyBytes_AsString(PyUnicode_AsASCIIString(strObj)); </code></pre> <p>I'm wondering whether I have to free the memory after doing this. <a href="https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsASCIIString" rel="nofoll...
0
2016-07-11T17:49:33Z
38,313,287
<p>If you look at the documentation for <a href="https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsASCIIString" rel="nofollow"><code>PyUnicode_AsASCIIString</code></a>, you will see</p> <blockquote> <p><em>Return value: New reference.</em><br> Encode a Unicode object using ASCII and return the result as P...
0
2016-07-11T17:58:34Z
[ "python", "c", "arrays", "string", "python-3.x" ]
Python: search for a STR1 in a line and replace the whole line with STR2
38,313,182
<p>I have a file in which I need to search for <code>STR1</code> and replace the whole line containing <code>STR2</code>. For example the <code>file1</code> contains the following data</p> <pre><code>Name: John Height: 6.0 Weight: 190 Eyes: Blue </code></pre> <p>I need to search for <code>Name</code> in the above fil...
-1
2016-07-11T17:51:46Z
38,313,264
<p>You can use <code>string.find()</code> to determine if a string is within another string. <a href="https://docs.python.org/2/library/string.html#string.find" rel="nofollow">Related Python docs</a>.</p> <pre><code>#! /usr/bin/python import fileinput for line in fileinput.input("file1", inplace=True): if line.fin...
1
2016-07-11T17:57:05Z
[ "python", "string", "file", "replace", "io" ]
Python: search for a STR1 in a line and replace the whole line with STR2
38,313,182
<p>I have a file in which I need to search for <code>STR1</code> and replace the whole line containing <code>STR2</code>. For example the <code>file1</code> contains the following data</p> <pre><code>Name: John Height: 6.0 Weight: 190 Eyes: Blue </code></pre> <p>I need to search for <code>Name</code> in the above fil...
-1
2016-07-11T17:51:46Z
38,313,442
<p>Should do exactly what you want.</p> <pre><code>def replace_basic(key_to_replace, new_value, file): f = open(file, 'rb').readlines() with open(file, 'wb') as out: for line in f: if key_to_replace in line: out.write(new_value+'/n') #asuming that your format never changes t...
1
2016-07-11T18:07:23Z
[ "python", "string", "file", "replace", "io" ]
Quickbooks Online Authentication issue
38,313,212
<p>I'm trying to switch my website from using the v2 api with Quickbooks Online to v3, but I keep getting this:</p> <pre><code>&lt;IntuitResponse time="2016-07-10T18:53:00.651-07:00" xmlns="http://schema.intuit.com/finance/v3"&gt; &lt;Fault type="AUTHENTICATION"&gt; &lt;Error code="3200"&gt; &l...
1
2016-07-11T17:53:23Z
38,337,698
<p>Dev app keys in your code will work to connect to sandbox accounts. The base url will be sandbox-quickbooks.api.intuit.com which is correct but please check your keys in the config.</p> <p>Prod app keys in your code will work to connect to QBO Prod accounts. The base url will be quickbooks.api.intuit.com</p>
0
2016-07-12T19:47:52Z
[ "python", "google-app-engine", "oauth", "quickbooks", "quickbooks-online" ]
How to use multiple checked data-binds on a single radio button using KnockoutJS?
38,313,226
<p>The user needs to select one radio button. My label needs to have the value of the selected radio button to display later in a text box. I also need the value of the radio button to be stored in the Ajax "title" variable so that I can use it on the backend (Python - Flask). When I click my migrate button, it runs my...
0
2016-07-11T17:54:17Z
38,314,019
<p>Yes you can use multiple bindings on a single control, but what you are attempting to do is use multiple of the SAME binding on a single control. If you apply the same type of binding to the control knockout will select the second usage of the same binding. You probably don't want to do this. </p> <p>The value held...
0
2016-07-11T18:44:41Z
[ "javascript", "jquery", "python", "ajax", "knockout.js" ]
How to use multiple checked data-binds on a single radio button using KnockoutJS?
38,313,226
<p>The user needs to select one radio button. My label needs to have the value of the selected radio button to display later in a text box. I also need the value of the radio button to be stored in the Ajax "title" variable so that I can use it on the backend (Python - Flask). When I click my migrate button, it runs my...
0
2016-07-11T17:54:17Z
38,314,483
<p>You cannot have the same binding twice on one element, at least not with the built in bindings.</p> <p>Instead, you should structure your view models in a way that each function has access to the relevant scope.</p> <p>Typically, I tend to have a root or parent view model that wires up Ajax requests, and have smal...
0
2016-07-11T19:14:39Z
[ "javascript", "jquery", "python", "ajax", "knockout.js" ]
Python - Windows Network Security Authentication
38,313,257
<p>I'm currently writing a script where I need to gain access to another computer on my LAN while using administrative credentials that differ from the account I am logged in as. I attempted to use the <code>requests</code> module. </p> <p>Here is my code so far:</p> <pre><code>import requests with requests.Session(...
0
2016-07-11T17:56:53Z
38,570,618
<p><strong>Impacket</strong></p> <p>This 3rd party library is pretty useful for Windows related networking tasks. In this situation i would use their <code>wmiexec.py</code> script:</p> <p><a href="https://github.com/CoreSecurity/impacket/blob/impacket_0_9_15/examples/wmiexec.py" rel="nofollow">wmiexec.py</a></p> <b...
0
2016-07-25T14:35:04Z
[ "python", "windows", "security", "admin", "credentials" ]
manupulating a csv file and writing its output to a new csv file in python
38,313,288
<p>I have a simple file named saleem.csv which contains the following lines of csv information:</p> <pre><code>File,Run,Module,Name,,,,, General-0.sca,General-0-20160706-14:58:51-10463,MyNetwork.node[0].nic.phy,nbFramesWithInterference,0,NaN,NaN,NaN,NaN General-0.sca,General-0-20160706-14:58:51-10463,MyNetwork.node[...
0
2016-07-11T17:58:37Z
38,313,378
<p><strong><em>Edited to reflect revised question</em></strong></p> <p>Some problems I can see:</p> <p>P1: <code>writerows(...)</code></p> <pre><code>for row in dele: writecsv.writerows(dele) </code></pre> <p><code>writerows</code> takes a list of rows to write to the csv file. So it shouldn't be inside...
2
2016-07-11T18:03:46Z
[ "python", "csv" ]
manupulating a csv file and writing its output to a new csv file in python
38,313,288
<p>I have a simple file named saleem.csv which contains the following lines of csv information:</p> <pre><code>File,Run,Module,Name,,,,, General-0.sca,General-0-20160706-14:58:51-10463,MyNetwork.node[0].nic.phy,nbFramesWithInterference,0,NaN,NaN,NaN,NaN General-0.sca,General-0-20160706-14:58:51-10463,MyNetwork.node[...
0
2016-07-11T17:58:37Z
38,313,954
<p>I would suggest using the <a href="http://pandas.pydata.org/" rel="nofollow">pandas</a> library. </p> <p>It makes working with csv files very easy. </p> <pre><code>import pandas as pd #standard convention for importing pandas # reads the csv file into a pandas dataframe dataframe = pd.read_csv('saleem.csv') # m...
0
2016-07-11T18:40:27Z
[ "python", "csv" ]
Passing indexed list elements as key values for a dictionary in Python
38,313,293
<p>I am new to <em>python</em>, and am trying to make use of <code>string.format()</code> to pass indexed elements of a list as the key values for my dictionary. This will then be used in a <code>request</code>.</p> <p>To be more specific, the overarching idea for this is that the input for the list will be chosen/spo...
0
2016-07-11T17:59:14Z
38,313,457
<p>Your <code>intent</code> is a <a href="https://docs.python.org/3/tutorial/datastructures.html#dictionaries" rel="nofollow">dictionary</a> which doesn't have a <a href="https://docs.python.org/3.5/library/functions.html#format" rel="nofollow"><code>format</code></a> method. What you want to do instead, is format ever...
2
2016-07-11T18:08:29Z
[ "python", "dictionary" ]
Passing indexed list elements as key values for a dictionary in Python
38,313,293
<p>I am new to <em>python</em>, and am trying to make use of <code>string.format()</code> to pass indexed elements of a list as the key values for my dictionary. This will then be used in a <code>request</code>.</p> <p>To be more specific, the overarching idea for this is that the input for the list will be chosen/spo...
0
2016-07-11T17:59:14Z
38,314,102
<p>If I understand your question correctly . The following should be the desired output value for "intent" after formatting:</p> <pre><code>{'string1': 'value1[0]', 'string2': 'value2[1]', 'RelString': 'value3[2]'} </code></pre> <p>You can actually convert dictionary into string and then back to Dictionary throug...
0
2016-07-11T18:50:34Z
[ "python", "dictionary" ]
How to import the full package
38,313,322
<p>This is my app structure using python 3.5 </p> <pre><code>app __init__.py # running the code from here module __init__.py test.py # want access to this ^-- test_function() is here test2.py # and this one too </code></pre> <p>I am full aware I can access test with the ...
0
2016-07-11T18:00:38Z
38,313,680
<p>Few additional thoughts to <a href="http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python">Loading all modules in a folder in Python</a></p> <pre><code>$ tree . ├── mod │   ├── __init__.py │   ├── test.py └── run.py </code></pre> <p><strong>__init__.py...
1
2016-07-11T18:22:52Z
[ "python", "python-3.x" ]
Understanding the runtime of numpy.where and equivalent alternatives
38,313,400
<p>According to <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html</a>, if x and y are given and input arrays are 1-D, where is equivalent to <code>[xv if c else yv for (c,xv, yv) in zip(x!=0, 1/x, x)]</code>...
2
2016-07-11T18:04:40Z
38,313,504
<p>You can avoid division by zero while maintaining performance by using advanced indexing:</p> <pre><code>x = np.arange(-500, 500) result = np.empty(x.shape, dtype=float) # set the dtype to whatever is appropriate nonzero = x != 0 result[nonzero] = 1/x[nonzero] result[~nonzero] = 0 </code></pre>
1
2016-07-11T18:11:49Z
[ "python", "arrays", "numpy" ]
Understanding the runtime of numpy.where and equivalent alternatives
38,313,400
<p>According to <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html</a>, if x and y are given and input arrays are 1-D, where is equivalent to <code>[xv if c else yv for (c,xv, yv) in zip(x!=0, 1/x, x)]</code>...
2
2016-07-11T18:04:40Z
38,313,525
<p>If you for some reason want to bypass an error with <code>numpy</code> it might be worth looking into the <code>errstate</code> context:</p> <pre><code>x = np.array(range(-500, 500)) with np.errstate(divide='ignore'): #ignore zero-division error x = 1/x x[x!=x] = 0 #convert inf and NaN's to 0 </code></pre>
1
2016-07-11T18:12:59Z
[ "python", "arrays", "numpy" ]