title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
python3 print to string
39,823,303
<p>Using Python 3, I have a console application that I am porting to a GUI. The code has a bunch of print statements, something like this:</p> <p><code>print(' ', 'p', ' ', sep='', end='')</code></p> <p>(In actuality the positional parameters are actually returns from functions, and there may be more or less than 3, ...
0
2016-10-03T01:06:29Z
39,823,534
<p>Found the answer via string io. With this I don't have to emulate Print's handling of sep/end or even check for existence.</p> <pre><code>import io def print_to_string(*args, **kwargs): output = io.StringIO() print(*args, file=output, **kwargs) contents = output.getvalue() output.close() retur...
0
2016-10-03T01:46:21Z
[ "python", "string", "python-3.x", "stringio" ]
How to change rows to columns by date in pandas?
39,823,323
<p>I have a csv data file in following format, I want to change the rows to columns , but this conversion needs to be done per stock and per date.</p> <pre><code>Ticker,Indicator,Date,Value STOCK A,ACCRUALS,3/31/2005,-10.44 STOCK A,ACCRUALS,3/31/2006,0.44 STOCK A,AE,3/31/2005,3.97 STOCK A,AE,3/31/2006,3.67 STOCK A,ASE...
0
2016-10-03T01:09:39Z
39,823,373
<pre><code>Ticker,Indicator,Date,Value STOCK A,ACCRUALS,3/31/2005,-10.44 STOCK A,ACCRUALS,3/31/2006,0.44 STOCK A,AE,3/31/2005,3.97 STOCK A,AE,3/31/2006,3.67 STOCK A,ASETTO,3/31/2005,0.762 STOCK A,ASETTO,3/31/2006,0.9099 </code></pre> <p>Let's just say your data are in a dataframe called <code>df</code>:</p> <pre><cod...
0
2016-10-03T01:21:06Z
[ "python", "pandas" ]
Asking user to plot two columns in a csv file without him typing the entire column name?
39,823,350
<p>My current code:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>import pandas as pd df = pd.DataFrame.from_csv('data.csv',index_col=False) while True: ...
-1
2016-10-03T01:16:57Z
39,823,417
<p>One way to do is to use filter in pandas for that purpose.</p> <pre><code>df.filter(regex=(yaxis)) </code></pre> <p>It will display all the columns matching that substring of yaxis</p> <p>here is an example.</p> <pre><code>A = { 'Name': [ 'John', 'Andrew', 'Smith'] , 'Age' : [20,23,42]} A Out[19]: {'Age': [20, ...
0
2016-10-03T01:27:37Z
[ "python", "pandas" ]
How to return different types of arrays?
39,823,371
<p>The high level problem I'm having in C# is to make a single copy of a data structure that describes a robot control network packet (Ethercat), and then to use that single data structure to extract data from a collection of packets. </p> <p>The problem arises when attempting to use the data from the accumulated pac...
-1
2016-10-03T01:20:26Z
39,901,281
<p>The answer is to store the arrays in a collection of type <code>List&lt;dynamic&gt;</code></p> <p>The return type of function that returns elements from the collection should also be dynamic.</p> <p>Here is the <a href="http://stackoverflow.com/a/39901046/4462371">more complete answer</a> to my <a href="http://sta...
0
2016-10-06T16:32:08Z
[ "c#", "python", "arrays", "data-structures", "strong-typing" ]
Callback URL error when setting up webhook for messenger
39,823,415
<p>I'm trying to follow this <a href="https://blog.hartleybrody.com/fb-messenger-bot/" rel="nofollow">tutorial</a> to set a chatbot for messenger. I'm stuck on the webhook setup. I added the page token and verify token to heroku, but when I try to add the heroku URL as the callback URL I get </p> <blockquote> <p>The...
-1
2016-10-03T01:27:23Z
39,842,513
<p>The problem was the <code>PAGE_ACCESS_TOKEN</code> and <code>VERIFY_TOKEN</code> were not set. The tutorial said to use the command <code>heroku config:add</code> the correct command should be <code>heroku config:set</code>. </p>
0
2016-10-04T00:35:44Z
[ "python", "facebook", "bots" ]
Getting PostgreSQL percent_rank and scipy.stats.percentileofscore results to match
39,823,470
<p>I'm trying to QAQC the results of calculations that are done in a PostgreSQL database, using a python script to read in the inputs to the calculation and echo the calculation steps and compare the final results of the python script against the results from the PostgreSQL calculation. </p> <p>The calculations in the...
1
2016-10-03T01:35:44Z
39,824,105
<p>You can use <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rankdata.html" rel="nofollow"><code>scipy.stats.rankdata</code></a>. The following example reproduces the result shown at <a href="http://docs.aws.amazon.com/redshift/latest/dg/r_WF_PERCENT_RANK.html" rel="nofollow">http://docs.aws...
2
2016-10-03T03:12:36Z
[ "python", "postgresql", "scipy", "rank", "percentile" ]
I can not get my loop to end
39,823,570
<p>I am trying to create a higher or lower game in python but can't get my loop to end. it just keeps going. My code looks like this</p> <pre><code>a = 0 def ask(b, d, p): global a while a &lt; d: global question question = int(input()) if question &lt; b: print"bigger" ...
-4
2016-10-03T01:51:18Z
39,823,913
<p>Without knowing what the rest of the code is here is what I can offer.</p> <p>In the code provided you have <code>d1 == p1</code> but they are never called or assigned in that area so they will never change. Therefore your loop can never progress because they variables inside it do not control it.</p> <p>edit: I'm...
0
2016-10-03T02:42:14Z
[ "python", "python-2.7" ]
List comprehensions Conversion
39,823,593
<p>i started learning Python recently and i am facing difficulty converting the below piece of code into a list comprehension:</p> <pre><code> list = [] #An empty List for key,value in defaultDict.items():#iterate through the default dict for i in defaultDict[key]:#iterate through the list in the de...
1
2016-10-03T01:54:10Z
39,823,607
<p>Very straightforward: use a nested list comprehension to get all <code>i</code>s and a set to remove duplicates.</p> <pre><code>list(set([item for __, value in defaultDict.items() for item in value])) </code></pre> <p>Let's break it down:</p> <ul> <li><code>[item for key,value in defaultDict.items() for item in v...
4
2016-10-03T01:56:00Z
[ "python", "list", "list-comprehension", "defaultdict" ]
creating sum of odd indexes python
39,823,625
<p>I'm trying to create a function equal to the sum of every other digit in a list. For example, if the list is [0,1,2,3,4,5], the function should equal 5+3+1. How could I do this? My knowledge of Python does not extend much farther than while and for loops. Thanks. </p>
1
2016-10-03T01:58:31Z
39,823,637
<p>Here is a simple one-liner:</p> <pre><code>In [37]: L Out[37]: [0, 1, 2, 3, 4, 5] In [38]: sum(L[1::2]) Out[38]: 9 </code></pre> <p>In the above code, <code>L[1::2]</code> says "get ever second element in <code>L</code>, starting at index 1"</p> <p>Here is a way to do all the heavy lifting yourself:</p> <pre><c...
5
2016-10-03T02:00:33Z
[ "python", "for-loop", "while-loop", "sum" ]
creating sum of odd indexes python
39,823,625
<p>I'm trying to create a function equal to the sum of every other digit in a list. For example, if the list is [0,1,2,3,4,5], the function should equal 5+3+1. How could I do this? My knowledge of Python does not extend much farther than while and for loops. Thanks. </p>
1
2016-10-03T01:58:31Z
39,823,675
<pre><code>&gt;&gt;&gt; arr = [0,1,2,3,4,5] &gt;&gt;&gt; sum([x for idx, x in enumerate(arr) if idx%2 != 0]) 9 </code></pre> <p>This is just a list comprehension that only includes elements in <code>arr</code> that have an odd index.</p> <p>To illustrate in a traditional <code>for</code> loop:</p> <pre><code>&gt;&gt...
0
2016-10-03T02:04:58Z
[ "python", "for-loop", "while-loop", "sum" ]
Error pwd.getpwuid with google cloud storage
39,823,682
<p>I <code>pip install --upgrade google-cloud-storage -t libs</code> to my app engine app.</p> <p>In the appengine_config.py, I added: </p> <pre><code>vendor.add('libs') vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'libs')) </code></pre> <p>It works on app engine online, but not on app engine...
1
2016-10-03T02:05:38Z
39,824,494
<p>Not sure if this entirely answers your question, however, I am assuming that you are using <a href="https://cloud.google.com/appengine/docs/python/download" rel="nofollow">Google App Engine SDK</a> to launch the app locally on your machine. And this, uses a patched <code>os</code> module for sandboxing:</p> <pre><c...
2
2016-10-03T04:07:45Z
[ "python", "google-app-engine", "google-cloud-storage" ]
python: list of lists of matching dicts
39,823,688
<p>I have a few dicts like:</p> <p><code>a = [ { 'event_id': 1}, { 'event_id': 1}, { 'event_id': 1}, { 'event_id': 2}, { 'event_id': 2}, { 'event_id': 3} ]</code></p> <p>I want a list of lists, each sublist containing all the dicts with similar <code>event_id</code> values:</p> <p><code>[ [ { 'event_id': 1}, { 'even...
1
2016-10-03T02:07:01Z
39,823,731
<p><code>itertools.groupby</code> is perfect for this:</p> <pre><code>map(lambda x: list(x[1]), (itertools.groupby(a, lambda x: x['event_id']))) # =&gt; [[{'event_id': 1}, {'event_id': 1}, {'event_id': 1}], [{'event_id': 2}, {'event_id': 2}], [{'event_id': 3}]] </code></pre> <p>EDIT: As Justin Turner Arthur says in c...
2
2016-10-03T02:12:15Z
[ "python" ]
python: list of lists of matching dicts
39,823,688
<p>I have a few dicts like:</p> <p><code>a = [ { 'event_id': 1}, { 'event_id': 1}, { 'event_id': 1}, { 'event_id': 2}, { 'event_id': 2}, { 'event_id': 3} ]</code></p> <p>I want a list of lists, each sublist containing all the dicts with similar <code>event_id</code> values:</p> <p><code>[ [ { 'event_id': 1}, { 'even...
1
2016-10-03T02:07:01Z
39,823,739
<p>First, make a dictionary mapping <code>event_id</code> values to lists of dicts.</p> <pre><code>d = {} for dict_ in a: if dict_['event_id'] in d: d[dict_['event_id']].append(dict_) else: d[dict['event_id']] = [dict_] </code></pre> <p>Then make a list comprehension to gather them all into on...
0
2016-10-03T02:13:12Z
[ "python" ]
python: list of lists of matching dicts
39,823,688
<p>I have a few dicts like:</p> <p><code>a = [ { 'event_id': 1}, { 'event_id': 1}, { 'event_id': 1}, { 'event_id': 2}, { 'event_id': 2}, { 'event_id': 3} ]</code></p> <p>I want a list of lists, each sublist containing all the dicts with similar <code>event_id</code> values:</p> <p><code>[ [ { 'event_id': 1}, { 'even...
1
2016-10-03T02:07:01Z
39,837,004
<p>As <a href="http://stackoverflow.com/a/39823731/1843865">amadan suggests</a>, <code>itertools.groupby</code> is a great approach to this problem. It takes an iterable and a key function to group by. You'll first want to make sure your list is sorted by the same key so that groupby doesn't end up creating multiple gr...
2
2016-10-03T17:19:30Z
[ "python" ]
Python Image Processing Threading
39,823,742
<p>so I am working on a robotics project where we have to recognize a pattern on a wall and position our robot accordingly. I developed this image processing code on my laptop that grabbed an image, converted it to HSV, applied a bit-wise mask, used Canny edge Detection, and found contours. I thought I could just copy ...
1
2016-10-03T02:13:24Z
39,824,403
<p>You can profile the code using <code>cProfile</code> module. It will tell you what part of the program is the bottleneck.</p> <p>Python in CPython implementation has the Global Interpreter Lock (GIL). This means that even if your app is multithreaded, it will use only one of your CPUs. You can try <code>multiproces...
1
2016-10-03T03:56:57Z
[ "python", "multithreading", "python-3.x", "image-processing", "python-multithreading" ]
Catching Keypresses on Windows with Python using MSVCRT when terminal window not in Focus
39,823,758
<p>I want to be able to use the <code>msvcrt</code> package in python to catch keypresses via the <code>msvcrt.getch()</code> method but it appears the the terminal window needs to be in focus for it to work. Is there a way around this?</p>
0
2016-10-03T02:15:02Z
39,843,157
<p>I found a python wrapper for Ctypes as suggested by @IInspectable. It wraps the low_level Keyboard hooks with a nice monitor class.</p> <p><a href="https://github.com/ethanhs/pyhooked" rel="nofollow">https://github.com/ethanhs/pyhooked</a></p>
0
2016-10-04T02:10:49Z
[ "python", "windows", "keypress", "msvcrt", "getch" ]
haskell: recursive function that return the char in a tuple list with certain condition(compare)
39,823,833
<p>I'm learning recursive function in haskell that confused with such conditon:</p> <p>I got a tuple list here:</p> <pre><code>[(0.5,'!'),(1,'*'),(1.5,'#')] </code></pre> <p>What I want to do is input a number n and compare with fist number in each tuple of the list</p> <p>so suppose n=0.1, when it compared 0.5 and...
0
2016-10-03T02:27:55Z
39,823,923
<p><a href="https://en.wikibooks.org/wiki/Haskell/Lists_and_tuples" rel="nofollow">tuple</a> is different from array in Haskell</p> <pre><code>find :: Double -&gt; [(Double,Char)] -&gt; Char find d [] = ' ' find d (x:xs) | d &lt;= fst x = snd x | otherwise = find d xs </code></pre>
3
2016-10-03T02:43:30Z
[ "python", "haskell" ]
Python Tkinter Display Loading Animation While Performing Certain Tasks
39,823,834
<p>I have located this useful code for Tkinter animations from <a href="https://www.daniweb.com/programming/software-development/threads/396918/how-to-use-animated-gifs-with-tkinter" rel="nofollow">https://www.daniweb.com/programming/software-development/threads/396918/how-to-use-animated-gifs-with-tkinter</a> ,suppl...
0
2016-10-03T02:28:19Z
39,827,771
<p>You can use <code>Tk.after()</code> and <code>Tk.after_cancel()</code> to start and stop the animation:</p> <pre><code>timer_id = None def start_loading(n=0): global timer_id gif = giflist[n%len(giflist)] canvas.create_image(gif.width()//2, gif.height()//2, image=gif) timer_id = root.after(100, sta...
0
2016-10-03T08:54:21Z
[ "python", "animation", "tkinter" ]
both tow are unicode,but when compare,it doesn't work?
39,823,844
<pre><code># -*- coding: utf-8 -*- from bs4 import BeautifulSoup import urllib2 response = urllib2.urlopen('http://bbs.szhome.com/80300-0-0-0-3005.html') html = response.read() soup = BeautifulSoup(html) returntext = soup.find('dl',class_='fix').text print returntext if isinstance(returntext,unicode): print...
0
2016-10-03T02:30:06Z
39,823,871
<p>You need to <a href="https://docs.python.org/2/library/string.html#string.strip" rel="nofollow">strip</a> all newlines before comparison:</p> <pre><code>&gt;&gt;&gt; print returntext 暂无相关数据... &gt;&gt;&gt; print text 暂无相关数据... &gt;&gt;&gt; returntext u'\n\u6682\u65e0\u76f8\u5173\u6570\u636...
1
2016-10-03T02:35:32Z
[ "python", "unicode" ]
both tow are unicode,but when compare,it doesn't work?
39,823,844
<pre><code># -*- coding: utf-8 -*- from bs4 import BeautifulSoup import urllib2 response = urllib2.urlopen('http://bbs.szhome.com/80300-0-0-0-3005.html') html = response.read() soup = BeautifulSoup(html) returntext = soup.find('dl',class_='fix').text print returntext if isinstance(returntext,unicode): print...
0
2016-10-03T02:30:06Z
39,824,084
<p>They aren't both unicode, they just look that way to you because your display decodes text2 for you. In fact, <code>isinstance(text2,str)</code> shows that text2 is clearly a string, not unicode. </p> <p>Unicode was bolted onto python 2 and its usage is a little strange. <code>str</code> can hold any octet (typical...
0
2016-10-03T03:09:13Z
[ "python", "unicode" ]
Convert part of data frame into MultiIndex in Pandas
39,823,852
<p>I am having this form of data in XLS format:</p> <pre><code>+--------+---------+-------------+---------------+---------+ | ID | Branch | Customer ID | Customer Name | Balance | +--------+---------+-------------+---------------+---------+ | 111111 | Branch1 | 1 | Company A | 10 | +--------+--...
1
2016-10-03T02:31:58Z
39,824,870
<p>If need only <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_index.html" rel="nofollow"><code>sort_index</code></a>, use:</p> <pre><code>...
1
2016-10-03T05:04:53Z
[ "python", "pandas", "xls" ]
How to draw right angled triangle with python
39,823,862
<pre><code>def drawTri(a): b = (a*math.tan(45)) c = (a/math.cos(45)) t.forward(a) t.left(135) t.forward(c) t.left(135) t.forward(b) </code></pre> <p><img src="http://i.stack.imgur.com/anF4W.png" alt="enter image description here"></p>
0
2016-10-03T02:33:44Z
39,823,898
<pre><code>import turtle def drawTri(a): hyp = a * 2**0.5 s = turtle.Screen() t = turtle.Turtle() t.forward(a) t.left(135) t.forward(hyp) t.left(135) t.forward(a) </code></pre>
0
2016-10-03T02:39:34Z
[ "python", "turtle-graphics" ]
How to draw right angled triangle with python
39,823,862
<pre><code>def drawTri(a): b = (a*math.tan(45)) c = (a/math.cos(45)) t.forward(a) t.left(135) t.forward(c) t.left(135) t.forward(b) </code></pre> <p><img src="http://i.stack.imgur.com/anF4W.png" alt="enter image description here"></p>
0
2016-10-03T02:33:44Z
39,880,887
<p>The problem here is close to that described in <a href="http://stackoverflow.com/questions/32980003/basic-trigonometry-isnt-working-correctly-in-python/32980217">Basic trigonometry isn&#39;t working correctly in python</a></p> <p>The turtle module uses degrees for angles, the math module uses radians</p> <p>To cal...
0
2016-10-05T18:05:49Z
[ "python", "turtle-graphics" ]
How to draw right angled triangle with python
39,823,862
<pre><code>def drawTri(a): b = (a*math.tan(45)) c = (a/math.cos(45)) t.forward(a) t.left(135) t.forward(c) t.left(135) t.forward(b) </code></pre> <p><img src="http://i.stack.imgur.com/anF4W.png" alt="enter image description here"></p>
0
2016-10-03T02:33:44Z
39,906,499
<p>Who needs angles?</p> <pre><code>def drawTri(a): x, y = turtle.position() turtle.goto(x + a, 0) turtle.goto(0, y + a) turtle.goto(x, y) </code></pre>
0
2016-10-06T22:20:55Z
[ "python", "turtle-graphics" ]
Splitting sentences using nltk.sent_tokenize, it does not provide correct result
39,823,863
<p>I am trying to split some customers' comments to sentences using <code>nltk.sent_tokenize</code>. I already tried to solve some of the problems using the following code: </p> <pre><code>comment = comment.replace('?', '? ').replace('!', '! ').replace('..','.').replace('.', '. ') </code></pre> <p>But I do not know h...
0
2016-10-03T02:33:46Z
39,845,063
<p>Try using the Punkt Sentence Tokenizer. It is pre-trained to split sentences effectively and can easily be pickled into your code.</p>
0
2016-10-04T05:54:52Z
[ "python", "nlp", "nltk" ]
beautiful soup vs espn
39,823,864
<p>I'm working on scraping the espn nhl stats using beautifulsoup, trying to create something like</p> <blockquote> <p>PLAYER, TEAM, GP, G, A, PTS, +/-, PIM, PTS/G, SOG, PCT, GWG, G, A, G, A,</p> <p>Patrick Kane, RW, CHI, 82, 46, 60, 106, 17, 30, 1.29, 287, 16.0, 9, 17,...
0
2016-10-03T02:33:47Z
39,824,573
<p>You could append the player information into a list initially to represent the row and then join the list into a string as you write it to the file:</p> <pre><code>for tr in soup.select("#my-players-table tr[class*=player]"): row = [] for ob in range(1,15): ## -- Assuming player_info has the colu...
0
2016-10-03T04:19:27Z
[ "python", "python-2.7", "beautifulsoup" ]
TypeError: Calculating dot product in python
39,823,879
<p>I need to write a Python function that returns the sum of the pairwise products of listA and listB (the two lists will always have the same length and are two lists of integer numbers).</p> <p>For example, if listA = [1, 2, 3] and listB = [4, 5, 6], the dot product is 1*4 + 2*5 + 3*6, so the function should return:...
1
2016-10-03T02:36:48Z
39,823,889
<p>Remove the offending portion (attempting to subscript an int):</p> <pre><code>sum([listA[i]*listB[i] for i in range(len(listB))]) </code></pre>
1
2016-10-03T02:38:23Z
[ "python", "function", "python-3.x", "typeerror", "dot-product" ]
TypeError: Calculating dot product in python
39,823,879
<p>I need to write a Python function that returns the sum of the pairwise products of listA and listB (the two lists will always have the same length and are two lists of integer numbers).</p> <p>For example, if listA = [1, 2, 3] and listB = [4, 5, 6], the dot product is 1*4 + 2*5 + 3*6, so the function should return:...
1
2016-10-03T02:36:48Z
39,828,058
<p>Simply remove <code>[0]</code>, and it works:</p> <p><code>sum( [listA[i]*listB[i] for i in range(len(listB))] )</code></p> <p>More elegant and readable, do:</p> <p><code>sum(x*y for x,y in zip(listA,listB))</code></p> <p>Or even better:</p> <pre><code>import numpy numpy.dot(listA, listB) </code></pre>
0
2016-10-03T09:11:13Z
[ "python", "function", "python-3.x", "typeerror", "dot-product" ]
Installing Ansible via Pip on Windows 7. Getting ValueError
39,823,998
<p>Firstly some basic details:</p> <p>OS: Windows 7 Home x64</p> <p>Relevant libraries installed: </p> <p>.NET Framework 4.0, Windows SDK (in order to have visual c++ 2010 compiler)</p> <p>Python: 3.4 (tried 32 and 64 bit, same issue)</p> <p>Pip: 6.0.8</p> <p>I'm trying to install Ansible (via command prompt) but...
0
2016-10-03T02:55:55Z
39,825,576
<p>I guess your are on you own here, because there is no support for Python 3 in Ansible yet, neither for Windows as control machine.</p> <p><a href="http://docs.ansible.com/ansible/intro_installation.html#control-machine-requirements" rel="nofollow">Control Machine Requirements</a>:</p> <blockquote> <p>Currently A...
0
2016-10-03T06:23:20Z
[ "python", "windows", "pip", "ansible" ]
Initiate a call, record it, and play the recording back
39,824,121
<p>I am putting together a POC for a client that wants to do phone based testing. In the POC, we simply want to let the user enter a phone# on a web page. We would then display a question and call their number. We would record their response to the question and play it back to them.</p> <p>I can initiate the call, but...
0
2016-10-03T03:14:59Z
39,838,183
<p>Twilio developer evangelist here.</p> <p>When you create the call, you pass a URL to the call. That URL will be the one called when the user answers the phone. The response to that request should be the <a href="https://www.twilio.com/docs/api/twiml" rel="nofollow">TwiML</a> to instruct Twilio to <a href="https://w...
1
2016-10-03T18:32:29Z
[ "python", "twilio" ]
rock scissor paper program
39,824,145
<p>Here are code for writing rock scissors paper game in python. If I run the code, it works but, when it becomes tie, it outputs like this. Is there anyway I can eliminate print(round) when I get result of tie? I want to look it like as shown at bottom of example</p> <p>*********************ROUND #1******************...
0
2016-10-03T03:20:18Z
39,824,191
<p>I'd recommend creating a boolean <code>was_tied</code>, setting it to equal <code>False</code> at the start of the program, and setting it to either <code>True</code> or <code>False</code> at the end of each possible outcome. Then you can put your print-round code inside of an <code>if not was_tied</code> statement....
0
2016-10-03T03:27:29Z
[ "python" ]
rock scissor paper program
39,824,145
<p>Here are code for writing rock scissors paper game in python. If I run the code, it works but, when it becomes tie, it outputs like this. Is there anyway I can eliminate print(round) when I get result of tie? I want to look it like as shown at bottom of example</p> <p>*********************ROUND #1******************...
0
2016-10-03T03:20:18Z
39,824,230
<p>So I think you have a number of areas that could simplify this code, but for a quick solution, at this line: </p> <pre><code>print('*'*21 + 'ROUND #'+str(rounds) + '*'*21) print() </code></pre> <p>change it to:</p> <pre><code>if not previous_round_was_tie: print('*'*21 + 'ROUND #'+str(rounds) + '*'*21) pr...
0
2016-10-03T03:32:04Z
[ "python" ]
Python how to convert a value with shape (1000L, 1L) to the value of the shape (1000L,)
39,824,210
<p>I has a variable with a shape of (1000L, 1L), but the structure causes some errors for subsequent analysis. It needs to be converted to the one with the shape (1000L,). Let me be more specific. </p> <pre><code>import numpy as np a = np.array([1,2,3]) b = np.array([[1],[2],[3]]) </code></pre> <p>I want to convert b...
1
2016-10-03T03:30:05Z
39,824,444
<p>There are a lot of ways you could do that, such as indexing:</p> <pre><code>a = b[:, 0] </code></pre> <p>raveling:</p> <pre><code>a = numpy.ravel(b) </code></pre> <p>or reshaping:</p> <pre><code>a = numpy.reshape(b, (-1,)) </code></pre>
2
2016-10-03T04:00:19Z
[ "python", "numpy" ]
Having trouble creating a new file and then manipulating its contents
39,824,263
<p>My goal is to create a python program that will receive user input to open a specific file, copy the contents of that file into a new file (named by the user), and then remove all spaces and digits from the new file.</p> <p>I am successfully copying the contents of my 'sequence' file into a newly-created 'newsequen...
0
2016-10-03T03:35:08Z
39,824,307
<p>So I think you're making the mistake of writing to the file twice unnecessarily. Instead of writing to the file and then trying to read it and edit it, why don't you change the file while you are transcribing. I would change your function like this:</p> <pre><code>sequence = open(input("Choose sequence file: ")) na...
1
2016-10-03T03:42:27Z
[ "python" ]
Having trouble creating a new file and then manipulating its contents
39,824,263
<p>My goal is to create a python program that will receive user input to open a specific file, copy the contents of that file into a new file (named by the user), and then remove all spaces and digits from the new file.</p> <p>I am successfully copying the contents of my 'sequence' file into a newly-created 'newsequen...
0
2016-10-03T03:35:08Z
39,824,474
<p>Why don't you do this in one <code>for</code> loop ? </p> <p>Not tested:</p> <pre><code>file_in = open(input("Choose sequence file: ")) name = input('Enter name of new text file, without .txt: ') + '.txt' with open(name, 'a') as file_out: for line in file_in: line = ''.join(i for i in line if i.isdig...
0
2016-10-03T04:04:43Z
[ "python" ]
Multiprocessing and Selenium Python
39,824,273
<p>I have 3 drivers (Firefox browsers) and I want them to <code>do something</code> in a list of websites.</p> <p>I have a worker defined as:</p> <pre><code>def worker(browser, queue): while True: id_ = queue.get(True) obj = ReviewID(id_) obj.search(browser) if obj.exists(browser):...
4
2016-10-03T03:36:18Z
39,843,502
<p>You could try instantiating the browser in the worker:</p> <pre><code>def worker(queue): browser = webdriver.Chrome() try: while True: id_ = queue.get(True) obj = ReviewID(id_) obj.search(browser) if obj.exists(browser): print(obj.get_u...
1
2016-10-04T03:02:18Z
[ "python", "selenium", "python-multiprocessing" ]
Replace the first 3 white space coming with a character and ignore other white spaces in a text line with python
39,824,284
<p>I have this line text: </p> <pre><code>09-15-16 05:23:44 A:VCOM 09064 Port 4 Device 10400 Remote 1 10401 Link Up RP2009 </code></pre> <p>the output should be like this:</p> <pre><code>09-15-16|05:23:44|A:VCOM|09064|Port 4 Device 10400 Remote 1 10401 Link Up RP2009 </code></pre> <p>It should just replace the ...
0
2016-10-03T03:37:58Z
39,824,299
<p>You don't need regex for that. Just use <code>str.split</code> with a <code>maxsplit</code>:</p> <pre><code>&gt;&gt;&gt; s = '09-15-16 05:23:44 A:VCOM 09064 Port 4 Device 10400 Remote 1 10401 Link Up RP2009' &gt;&gt;&gt; *first, last = s.split(maxsplit=4) &gt;&gt;&gt; '|'.join(first) + '|' + last '09-15-16|05:2...
2
2016-10-03T03:41:21Z
[ "python", "regex" ]
Replace the first 3 white space coming with a character and ignore other white spaces in a text line with python
39,824,284
<p>I have this line text: </p> <pre><code>09-15-16 05:23:44 A:VCOM 09064 Port 4 Device 10400 Remote 1 10401 Link Up RP2009 </code></pre> <p>the output should be like this:</p> <pre><code>09-15-16|05:23:44|A:VCOM|09064|Port 4 Device 10400 Remote 1 10401 Link Up RP2009 </code></pre> <p>It should just replace the ...
0
2016-10-03T03:37:58Z
39,824,357
<p>Maybe try something like this: </p> <pre><code>text = "09-15-16 05:23:44 A:VCOM 09064 Port 4 Device 10400 Remote 1 10401 Link Up RP2009" text = text.replace(" ", "|", 3) text = text.replace(" ", "") text = text.replace(" ", "|", 1) </code></pre>
1
2016-10-03T03:50:05Z
[ "python", "regex" ]
Replace the first 3 white space coming with a character and ignore other white spaces in a text line with python
39,824,284
<p>I have this line text: </p> <pre><code>09-15-16 05:23:44 A:VCOM 09064 Port 4 Device 10400 Remote 1 10401 Link Up RP2009 </code></pre> <p>the output should be like this:</p> <pre><code>09-15-16|05:23:44|A:VCOM|09064|Port 4 Device 10400 Remote 1 10401 Link Up RP2009 </code></pre> <p>It should just replace the ...
0
2016-10-03T03:37:58Z
39,824,413
<p>you can try this</p> <p>*</p> <pre><code>str = '09-15-16 05:23:44 A:VCOM 09064 Port 4 Device 10400 Remote 1 10401 Link Up RP2009' idx=0 newStr ='' for token in str.split(' '): if(token!=''): if(idx &lt;4): newStr=newStr + token+'|' idx+=1 else: newStr = n...
1
2016-10-03T03:57:55Z
[ "python", "regex" ]
Replace the first 3 white space coming with a character and ignore other white spaces in a text line with python
39,824,284
<p>I have this line text: </p> <pre><code>09-15-16 05:23:44 A:VCOM 09064 Port 4 Device 10400 Remote 1 10401 Link Up RP2009 </code></pre> <p>the output should be like this:</p> <pre><code>09-15-16|05:23:44|A:VCOM|09064|Port 4 Device 10400 Remote 1 10401 Link Up RP2009 </code></pre> <p>It should just replace the ...
0
2016-10-03T03:37:58Z
39,824,676
<pre><code>import re print re.sub(r' +','|',text,4) </code></pre>
0
2016-10-03T04:37:27Z
[ "python", "regex" ]
How to implement SQL level expression for this hybrid property in SQLAlchemy?
39,824,292
<p>I have a ledger table and a corresponding python class. I defined the model using SQLAlchemy, as follows,</p> <pre><code>class Ledger(Base): __tablename__ = 'ledger' currency_exchange_rate_lookup = {('CNY', 'CAD'): 0.2} amount = Column(Numeric(10, 2), nullable=False) currency = Column(String, null...
0
2016-10-03T03:40:09Z
39,840,780
<p><code>cls.firstname</code> does not "refer to value", but the <code>Column</code>. <code>cls.firstname + " " + cls.lastname</code> in the <a href="http://docs.sqlalchemy.org/en/latest/orm/mapped_sql_expr.html#using-a-hybrid" rel="nofollow">example</a> produces a string concatenation SQL expression along the lines of...
1
2016-10-03T21:34:39Z
[ "python", "sqlalchemy", "descriptor" ]
Spark problems with imports in Python
39,824,381
<p>We are running a spark-submit command on a python script that uses Spark to parallelize object detection in Python using Caffe. The script itself runs perfectly fine if run in a Python-only script, but it returns an import error when using it with Spark code. I know the spark code is not the problem because it works...
8
2016-10-03T03:54:02Z
40,054,364
<p>You probably haven’t compiled the caffe python wrappers in your AWS environment. For reasons that completely escape me (and several others, <a href="https://github.com/BVLC/caffe/issues/2440" rel="nofollow">https://github.com/BVLC/caffe/issues/2440</a>) pycaffe is not available as a pypi package, and you have to ...
4
2016-10-15T02:33:56Z
[ "python", "apache-spark", "pyspark", "caffe", "pycaffe" ]
Replacing Elements in 3 dimensional Python List
39,824,469
<p>I've a Python list if converted to NumPy array would have the following dimensions: (5, 47151, 10)</p> <pre><code>np.array(y_pred_list).shape # returns (5, 47151, 10) len(y_pred_list) # returns 5 </code></pre> <p>I would like to go through every element and replace the element where:</p> <ul> <li>If the element...
0
2016-10-03T04:04:02Z
39,824,585
<p>To create an array with a value True if the element is >= 0.5, and False otherwise:</p> <pre><code>new_array = y_pred_list &gt;= 0.5 </code></pre> <p>use the .astype() method for Numpy arrays to make all True elements 1 and all False elements 0:</p> <pre><code>new_array.astype(int) </code></pre>
1
2016-10-03T04:21:54Z
[ "python", "arrays", "list", "numpy" ]
Replacing Elements in 3 dimensional Python List
39,824,469
<p>I've a Python list if converted to NumPy array would have the following dimensions: (5, 47151, 10)</p> <pre><code>np.array(y_pred_list).shape # returns (5, 47151, 10) len(y_pred_list) # returns 5 </code></pre> <p>I would like to go through every element and replace the element where:</p> <ul> <li>If the element...
0
2016-10-03T04:04:02Z
39,825,191
<pre><code>arr=np.array(y_pred_list) #list to narray arr[arr&lt;0.5]=0 # arr&lt;0.5 is a mask narray arr[arr&gt;=0.5]=1 y_pred_list=arr.tolist() # narray to list </code></pre>
-2
2016-10-03T05:42:11Z
[ "python", "arrays", "list", "numpy" ]
Replacing Elements in 3 dimensional Python List
39,824,469
<p>I've a Python list if converted to NumPy array would have the following dimensions: (5, 47151, 10)</p> <pre><code>np.array(y_pred_list).shape # returns (5, 47151, 10) len(y_pred_list) # returns 5 </code></pre> <p>I would like to go through every element and replace the element where:</p> <ul> <li>If the element...
0
2016-10-03T04:04:02Z
39,827,874
<p>ibredeson's answer is the way to go in your specific case. When you have an array a and want to construct an array b of the same shape which takes only two values, depending on a condition on a, consider using <code>np.where</code> (see <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" ...
0
2016-10-03T09:00:27Z
[ "python", "arrays", "list", "numpy" ]
Scipy sparse matrix to the power spare matrix
39,824,486
<p>I have a scipy.sparse.csc.csc_matrix. I want to use a power function on each element of this matrix such that each element is raise to the power itself. How should I do that?</p> <p>I tried this:</p> <pre><code>B.data ** B.data </code></pre> <p>But this removes 0 from the data</p>
0
2016-10-03T04:06:22Z
39,825,692
<p>I have no problems with that approach:</p> <pre><code>In [155]: B=sparse.random(10,10,.1,'csc') In [156]: B Out[156]: &lt;10x10 sparse matrix of type '&lt;class 'numpy.float64'&gt;' with 10 stored elements in Compressed Sparse Column format&gt; In [157]: B.data Out[157]: array([ 0.79437782, 0.74414493, 0.39...
1
2016-10-03T06:33:03Z
[ "python", "scipy" ]
python matplotlib legend linestyle '---'
39,824,599
<p>I need a way to make matplotlib linestyle '---'. 3's of '-'.</p> <pre><code>character description '-' solid line style '--' dashed line style '-.' dash-dot line style ':' dotted line style etc. </code></pre> <p>I can see '-' and '--' in the list, but on the right up side, my legend comes up l...
0
2016-10-03T04:25:24Z
39,824,845
<p>Use <code>mpt.legend(handlelength=3)</code> and <code>linestyle='--'</code></p> <pre><code>mpt.plot([1,2,3,4],[2,3,4,5],'r', linestyle='--') mpt.legend(["red dotted line"], handlelength=3) </code></pre>
0
2016-10-03T05:00:39Z
[ "python", "matplotlib" ]
ValueError: Cannot have number of splits n_splits=3 greater than the number of samples: 1
39,824,600
<p>I am trying this training modeling using train_test_split and a decision tree regressor:</p> <pre><code>import sklearn from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeRegressor from sklearn.model_selection import cross_val_score # TODO: Make a copy of the DataFrame, using ...
0
2016-10-03T04:25:28Z
39,824,687
<p>If the number of split is greater than number of sample, you will get the first error. Check the snippet from the <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/model_selection/_split.py#L315" rel="nofollow">source code</a> given below.</p> <pre><code>if self.n_splits &gt; n_samples: ...
0
2016-10-03T04:39:13Z
[ "python", "scikit-learn", "cross-validation", "sklearn-pandas" ]
introducing synchronous chained execution in celery workflow
39,824,624
<p>Suppose there are 4 tasks <code>T1</code>, <code>T2</code>, <code>T3</code>, <code>T4</code>. They are chained together as <code>T1.si() | T2.si() | T3.si() | T4.si()</code>. <code>T3</code> spawns further tasks <code>T30 .. T3n</code> asynchronously like <code>chord(T30,...,T3n)(reduce.s())</code>. I don't know <co...
1
2016-10-03T04:29:57Z
39,832,625
<p>I will improve @jenner-felton's comment a bit...</p> <p>You may call it like this:</p> <pre><code>chain(T1.s(), T2.s(), T3.s(T4.s())) </code></pre> <p>e.g. <code>T4.s()</code> passed as one of parameters to the T3 task.</p> <p>And T3 will run a <code>chord</code> itself with T4 passed as a callback.</p>
0
2016-10-03T13:17:29Z
[ "python", "asynchronous", "celery" ]
solving multiple equations with many variables and inequality constraints
39,824,681
<p>I am trying to solve a problem with many variables using scipy and linear programming. I have a set of variables X which are real numbers between 0.5 and 3 and I have to solve the following equations :</p> <pre><code>346 &lt;= x0*C0 + x1*C1 + x2*C2 +......xN*CN &lt;= 468 25 &lt;= x0*p0 + x1*p1 + x2*p2 +......xN*pN ...
1
2016-10-03T04:38:10Z
39,825,221
<p>This system of inequalities is not feasible: there is no solution that satisfies all constraints. You can see that from <code>res</code>:</p> <pre><code> fun: 0.42500000000000243 message: 'Optimization failed. Unable to find a feasible starting point.' nit: 28 status: 2 success: False x: nan </c...
3
2016-10-03T05:45:44Z
[ "python", "scipy", "linear-algebra", "linear-programming" ]
Filter list's elements by type of each element
39,824,683
<p>I have list with different types of data (string, int, etc.). I need to create a new list with, for example, only int elements, and another list with only string elements. How to do it?</p>
-1
2016-10-03T04:38:15Z
39,824,724
<p>You can accomplish this with <a href="https://docs.python.org/3.5/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>:</p> <pre><code>integers = [elm for elm in data if isinstance(elm, int)] </code></pre> <p>Where <code>data</code> is the data. What the above does is create a n...
1
2016-10-03T04:44:29Z
[ "python" ]
Filter list's elements by type of each element
39,824,683
<p>I have list with different types of data (string, int, etc.). I need to create a new list with, for example, only int elements, and another list with only string elements. How to do it?</p>
-1
2016-10-03T04:38:15Z
39,825,022
<p>Sort the list by type, and then use <code>groupby</code> to group it:</p> <pre><code>&gt;&gt;&gt; import itertools &gt;&gt;&gt; l = ['a', 1, 2, 'b', 'e', 9.2, 'l'] &gt;&gt;&gt; l.sort(key=lambda x: str(type(x))) &gt;&gt;&gt; lists = [list(v) for k,v in itertools.groupby(l, lambda x: str(type(x)))] &gt;&gt;&gt; list...
2
2016-10-03T05:22:25Z
[ "python" ]
python: could not broadcast input array from shape (3,1) into shape (3,)
39,824,700
<pre><code>import numpy as np def qrhouse(A): (m,n) = A.shape R = A V = np.zeros((m,n)) for k in range(0,min(m-1,n)): x = R[k:m,k] x.shape = (m-k,1) v = x + np.sin(x[0])*np.linalg.norm(x.T)*np.eye(m-k,1) V[k:m,k] = v R[k:m,k:n] = R[k:m,k:n]-(2*v)*(np.transpose(v)*...
-2
2016-10-03T04:40:27Z
39,825,046
<p><code>V[k:m,k] = v</code>; <code>v</code> has shape (3,1), but the target is (3,). <code>k:m</code> is a 3 term slice; <code>k</code> is a scalar.</p> <p>Try using <code>v.ravel()</code>. Or <code>V[k:m,[k]]</code>. </p> <p>But also understand why <code>v</code> has its shape.</p>
0
2016-10-03T05:25:01Z
[ "python", "numpy" ]
How to add a new column (Python list) to a Postgresql table?
39,824,748
<p>I have a Python list <code>newcol</code> that I want to add to an existing Postgresql table. I have used the following code:</p> <pre><code>conn = psycopg2.connect(host='***', database='***', user='***', password='***') cur = conn.cursor() cur.execute('ALTER TABLE %s ADD COLUMN %s text' % ('mytable', 'newcol')) con...
0
2016-10-03T04:47:24Z
39,825,439
<p><code>ALTER TABLE</code> only changes table schema -- in your case it will create the new column and initialize it with empty (NULL) values.</p> <p>To add list of values to this column you can do: <code>UPDATE TABLE &lt;table&gt; SET ...</code> in a loop.</p>
0
2016-10-03T06:11:04Z
[ "python", "postgresql" ]
Outer merge on large pandas DataFrames causes MemoryError---how to do "big data" merges with pandas?
39,824,952
<p>I have two pandas DataFrames <code>df1</code> and <code>df2</code> with a fairly standard format:</p> <pre><code> one two three feature A 1 2 3 feature1 B 4 5 6 feature2 C 7 8 9 feature3 D 10 11 12 feature4 E 13 14 15 feature5 F 16 17 1...
0
2016-10-03T05:16:27Z
39,825,139
<p>Try specifying a data type for the numeric columns to reduce the size of the existing data frames, such as: </p> <pre><code>df[['one','two', 'three']] = df[['one','two', 'three']].astype(np.int32) </code></pre> <p>This should reduce the memory significantly and will hopefully let you preform the merge. </p>
1
2016-10-03T05:36:28Z
[ "python", "pandas", "memory", "dataframe", "out-of-memory" ]
Outer merge on large pandas DataFrames causes MemoryError---how to do "big data" merges with pandas?
39,824,952
<p>I have two pandas DataFrames <code>df1</code> and <code>df2</code> with a fairly standard format:</p> <pre><code> one two three feature A 1 2 3 feature1 B 4 5 6 feature2 C 7 8 9 feature3 D 10 11 12 feature4 E 13 14 15 feature5 F 16 17 1...
0
2016-10-03T05:16:27Z
39,825,304
<p>You can try first filter <code>df1</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.unique.html" rel="nofollow"><code>unique</code></a> values, <code>merge</code> and last <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>con...
1
2016-10-03T05:55:28Z
[ "python", "pandas", "memory", "dataframe", "out-of-memory" ]
Vocabulary Processor function
39,825,043
<p>I am researching about embedding input for Convolution Neural Network and I understand Word2vec. However, in <a href="https://github.com/dennybritz/cnn-text-classification-tf/blob/master/train.py" rel="nofollow">CNN text classification</a>. dennybritz used function <code>learn.preprocessing.VocabularyProcessor</code...
0
2016-10-03T05:24:53Z
39,826,331
<p>Lets say that you have just two documents <code>I like pizza</code> and <code>I like Pasta</code>. Your whole vocabulary consists of these words <code>(I, like, pizza, pasta)</code> For every word in the vocabulary, there is an index associated like so (1, 2, 3, 4). Now given a document like <code>I like pasta</code...
2
2016-10-03T07:20:43Z
[ "python", "tensorflow", "text-classification" ]
Strange behaviour while reading data from Cassandra Columnfamily
39,825,307
<p>I am trying to do the following query on column-family using cqlsh (<code>cqlsh 5.0.1 | Cassandra 2.1.12 | CQL spec 3.2.1 | Native protocol v3</code>)</p> <p><strong>Query :</strong></p> <pre><code>select * from CassandraColumnFamily limit 10 </code></pre> <p>But it gives the following error</p> <p><strong>error...
1
2016-10-03T05:55:32Z
39,841,723
<p>I am not sure how large are the rows that you are trying to fetch, and how many there are. But when you are doing select in CQL without any condition on primary key, you are doing a range scan which is costly. Remember, this is not MySQL. Cassandra works at its best when you are doing lookups on specific row keys. <...
0
2016-10-03T22:59:52Z
[ "python", "cassandra", "datastax", "cassandra-2.0" ]
How to plot distribution with given mean and SD on a histogram in Python
39,825,328
<p>I have a following Pandas dataframe named Scores,following is the subset of it</p> <pre><code> 0 0 25.104179 1 60.908747 2 23.222238 3 51.553491 4 22.629690 5 53.338099 6 22.360882 7 26.515078 8 52.737316 9 40.235152 </code></pre> <p>When I plot a histogram it looks like following</p> <p><a href="h...
0
2016-10-03T05:57:46Z
39,825,502
<p>You can do something like this, </p> <pre><code>plt.hist( The histogram data) plt.plot( The distribution data ) plt.show() </code></pre> <p>The <code>plt.show</code> will show both figures embedded in a single figure.</p>
1
2016-10-03T06:16:38Z
[ "python", "matplotlib", "histogram" ]
Sqlalchemy User Product Reviews Relation model deisgn
39,825,375
<p>Need models so that a User can have a Products and Users can leave Reviews on Products made by other users. I was thinking having a one to many relationship from products to reviews but then how do which users left which review. This is what i have so far. </p> <pre><code>class User(db.Model, UserMixin): id = d...
0
2016-10-03T06:03:22Z
39,826,122
<p>I'm imagining setting it up like this (with the new one-to-many included as well - I think I've got that right). You should know the product's ID at the time you're creating the entry in the Python code, so you can simply add it in. I don't think you would necessarily need to create a relationship for that.</p> <...
0
2016-10-03T07:05:29Z
[ "python", "sql", "flask", "sqlalchemy", "flask-sqlalchemy" ]
Sqlalchemy User Product Reviews Relation model deisgn
39,825,375
<p>Need models so that a User can have a Products and Users can leave Reviews on Products made by other users. I was thinking having a one to many relationship from products to reviews but then how do which users left which review. This is what i have so far. </p> <pre><code>class User(db.Model, UserMixin): id = d...
0
2016-10-03T06:03:22Z
39,891,847
<p>You just need to add foreign keys for <code>User</code> and <code>Product</code> into your <code>Review</code> table:</p> <pre><code>class Review(db.Model): # ... product_id = db.Column(db.Integer, db.ForeignKey('product.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) </code></pre> <p>...
1
2016-10-06T09:02:08Z
[ "python", "sql", "flask", "sqlalchemy", "flask-sqlalchemy" ]
How to get all the tweets from the specific trend in twitter from tweepy
39,825,413
<p>I have a requirement to get all the tweets from the specific trend in twitter.</p> <pre><code>Ex: api.get_all_tweets(trend="ABCD") </code></pre> <p>How can I achieve this with tweepy?</p>
-2
2016-10-03T06:07:13Z
39,842,482
<p>There is no way to be guaranteed to capture all tweets. Twitter reserves the right to send you whatever they feel like. For something that is tweeted about infrequently like #upsidedownwalrus you'd probably get all of them, but for something that is a trending topic, you will only ever receive a sample.</p>
1
2016-10-04T00:31:55Z
[ "python", "twitter", "tweepy", "python-twitter" ]
How to get all the tweets from the specific trend in twitter from tweepy
39,825,413
<p>I have a requirement to get all the tweets from the specific trend in twitter.</p> <pre><code>Ex: api.get_all_tweets(trend="ABCD") </code></pre> <p>How can I achieve this with tweepy?</p>
-2
2016-10-03T06:07:13Z
39,843,708
<p>The <a href="https://dev.twitter.com/rest/public/rate-limits" rel="nofollow">Twitter API has limits</a> on what you can retrieve. If you require a census of posted Tweets, you'll need to pay for a service that provides such, but they are few and far between as they need to actively respect deletions.</p>
0
2016-10-04T03:30:54Z
[ "python", "twitter", "tweepy", "python-twitter" ]
Passing parameters from one SConstruct to another SConstruct using scons
39,825,526
<p>I have a C project built using SCons that links with a C library also built by Scons. Both the library and the project have there own SConstruct files. I read in <a href="http://stackoverflow.com/a/23898880/6198533">this topic</a> that you can call a SConstruct from another SConstruct in the same way as you would ca...
0
2016-10-03T06:19:00Z
39,830,811
<p>My guess is that you're searching for the "<code>-u</code>" or the "<code>-U</code>" option. Please consult the <a href="http://scons.org/doc/production/HTML/scons-man.html" rel="nofollow">MAN page</a> and have a pick for your needs.</p>
0
2016-10-03T11:44:09Z
[ "python", "scons" ]
Pandas reorder data
39,825,550
<p>This is probably an easy one using pivot, but since I am not adding the numbers (every row is unique) how should I go about doing this?</p> <p>Input:</p> <pre><code> Col1 Col2 Col3 0 123.0 33.0 ABC 1 345.0 39.0 ABC 2 567.0 100.0 ABC 3 123.0 82.0 PQR 4 345.0 10.0 PQR 5 789.0 ...
1
2016-10-03T06:21:12Z
39,825,566
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pivot.html" rel="nofollow"><code>pivot</code></a>:</p> <pre><code>print (df.pivot(index='Col1', columns='Col3', values='Col2')) Col3 ABC PQR XYZ Col1 123.0 33.0 82.0 NaN 345.0 39.0 10.0 9...
1
2016-10-03T06:23:00Z
[ "python", "pandas", "dataframe" ]
scrapy - spider module def functions not getting invoked
39,825,740
<p>My intention is to invoke start_requests method to login to the website. After login, scrape the website. Based on the log message, I see that 1. But, I see that start_request is not invoked. 2. call_back function of the parse is also not invoking. </p> <p>Whats actually happening is spider is only loading the url...
0
2016-10-03T06:36:13Z
39,828,899
<p>Scrapy already has form request manager called <code>FormRequest</code>.</p> <p>In most of the cases it will find the correct form by itself. You can try:</p> <pre><code>&gt;&gt;&gt; scrapy shell "https://www.zauba.com/import-gold/p-1-hs-code.html" from scrapy import FormRequest login_data={'name':'mylogin', 'pass...
-1
2016-10-03T09:56:15Z
[ "python", "authentication", "web-scraping", "scrapy", "scrapy-spider" ]
scrapy - spider module def functions not getting invoked
39,825,740
<p>My intention is to invoke start_requests method to login to the website. After login, scrape the website. Based on the log message, I see that 1. But, I see that start_request is not invoked. 2. call_back function of the parse is also not invoking. </p> <p>Whats actually happening is spider is only loading the url...
0
2016-10-03T06:36:13Z
39,841,383
<p>I figured out the crapy mistake i did!!!! </p> <p><strong>I didn't place the functions inside the class. Thats why .... things didnt work as expected. Now, I added a tab space to all the fuctions and things started to work fine</strong></p> <p>Thanks @user2989777 and @Granitosaurus for coming forward to deb...
0
2016-10-03T22:28:10Z
[ "python", "authentication", "web-scraping", "scrapy", "scrapy-spider" ]
How to send FCM notification at specific time?
39,825,989
<p>I can be able to send FCM notifications to single or multiple devices through <a href="https://github.com/olucurious/PyFCM/tree/master/pyfcm" rel="nofollow">PyFCM</a> instantly.</p> <pre><code># Send to single device. from pyfcm import FCMNotification push_service = FCMNotification(api_key="&lt;api-key&gt;") # OR...
0
2016-10-03T06:55:49Z
39,826,064
<p>If you're looking for a public API of FCM for a scheduled push or a payload parameter where you can set the push date, unfortunately, there's nothing like it as of the moment. </p> <p>You must implement your own App Server and implement the scheduled push yourself (also mentioned it <a href="http://stackoverflow.co...
0
2016-10-03T07:01:30Z
[ "python", "firebase-cloud-messaging", "pyfcm" ]
Filtering through numpy arrays by one row's information
39,825,997
<p>I am asking for help on filtering through numpy arrays. I currently have a numpy array which contains the following information:</p> <pre><code>[[x1_1, x1_2, ..., x1_n], [x2_1, x2_2, ..., x2_n], [y1, y2, ..., yn] </code></pre> <p>ie. the array is essentially a dataset where <em>x1, x2</em> are features (coordinate...
2
2016-10-03T06:56:47Z
39,826,070
<p>You can use:</p> <pre><code>import numpy as np d = np.array([[0.1, 0.2, 0.3], [-0.1,-0.2,-0.3], [1,1,-1]]) print (d) [[ 0.1 0.2 0.3] [-0.1 -0.2 -0.3] [ 1. 1. -1. ]] #select last row by d[-1] print (d[-1]&gt;0) [ True True False] print (d[:,d[-1]&gt;0]) [[ 0.1 0.2] [-0.1 -0.2] [ 1. 1. ]] </code></pr...
3
2016-10-03T07:01:59Z
[ "python", "arrays", "numpy", "filter" ]
what is means reconstruct object or recreate object in python?
39,826,016
<p>I am trying to understand difference between <code>__str__</code> and <code>__repr__</code> and following <a href="http://stackoverflow.com/questions/1436703/difference-between-str-and-repr-in-python/2626364#2626364">Difference between __str__ and __repr__ in Python</a> </p> <p>In the answer it says <code>__repr__<...
2
2016-10-03T06:58:17Z
39,826,109
<p>Perhaps a simple example will help clarify:</p> <pre><code>class Object: def __init__(self, a, b): self.a = a self.b = b def __repr__(self): return 'Object({0.a!r}, {0.b!r})'.format(self) </code></pre> <p>This object has two parameters defined in <code>__init__</code> and a sensib...
2
2016-10-03T07:04:28Z
[ "python", "python-3.x" ]
How to move file from one folder to another folder same ftp using python
39,826,120
<p>How move files from one folder to another folder in same ftp using python i used this code but it doesn't work out </p> <pre><code>ftp=FTP("host") ftp.login("user name","password") def downloadFiles(path,destination): try: ftp.cwd(path) #clone path to destination ftp.dir(destination) ...
-2
2016-10-03T07:05:14Z
39,826,207
<p>I would suggest using the excellent python file system abstraction <a href="https://pypi.python.org/pypi/fs" rel="nofollow">pyfs</a> as you can see from the <a href="http://docs.pyfilesystem.org/en/latest/interface.html" rel="nofollow">documents</a> all of the file systems, once mounted, have <code>copy</code>, <cod...
0
2016-10-03T07:13:12Z
[ "python", "ftp" ]
SWIG tutorial problems
39,826,248
<p>I'm trying to follow the swig tutorial but I've got stuck, right now I'm using:</p> <ul> <li>Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32</li> <li>Vs2015 x64, Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23918 for x64</li> <li>SWIG Version 3.0.10</li> </ul>...
1
2016-10-03T07:15:51Z
39,827,046
<p>The name of the dynamic-linked module for SWIG should begin with an underscore, in this case <code>_example.pyd</code>. The SWIG generated Python file is looking for the module named <code>_example</code>, see beginning of that file:</p> <pre><code>from sys import version_info if version_info &gt;= (2, 6, 0): d...
1
2016-10-03T08:07:12Z
[ "python", "c++", "windows", "visual-studio-2015", "swig" ]
conda stuck on Proceed ([y]/n)? when updating packages etc
39,826,250
<p>I just downloaded Anaconda 4.2.0 (with python 3.5.2) for Mac OS X. Whenever I try to update any packages etc, my ipython console presents the package dependencies and displays "Proceed ([y]/n)?" but does not take any inputs. E.g. I press enter, or y-enter etc. and nothing happens. Here's an example:</p> <pre><code>...
0
2016-10-03T07:16:03Z
39,841,757
<p>You can launch shell commands with the <code>!</code> operator in ipython, but you can't interact with them after the process has launched.</p> <p>Therefore, you could:</p> <ol> <li>execute your conda command outside of your ipython session (IOW, a normal shell); or</li> <li>pass the <code>--yes</code> flag. e.g.:...
0
2016-10-03T23:05:59Z
[ "python", "ipython", "anaconda", "spyder", "graphlab" ]
conda stuck on Proceed ([y]/n)? when updating packages etc
39,826,250
<p>I just downloaded Anaconda 4.2.0 (with python 3.5.2) for Mac OS X. Whenever I try to update any packages etc, my ipython console presents the package dependencies and displays "Proceed ([y]/n)?" but does not take any inputs. E.g. I press enter, or y-enter etc. and nothing happens. Here's an example:</p> <pre><code>...
0
2016-10-03T07:16:03Z
40,022,547
<p>If you add a '--yes' at the end of the command it works. For example:</p> <pre><code>&gt;&gt;&gt;!conda install seaborn --yes </code></pre>
0
2016-10-13T13:35:27Z
[ "python", "ipython", "anaconda", "spyder", "graphlab" ]
Model in Django 1.9. TypeError: __init__() got multiple values for argument 'verbose_name'
39,826,485
<p>I have Python 3.5 and Django 1.9 try to do the next</p> <pre><code>class Question(models.Model): def __init__(self, *args, question_text=None, pub_date=None, **kwargs): self.question_text = question_text self.pub_date = pub_date question_text = models.CharField(max_length=200, verbose_name="Question") pub_d...
0
2016-10-03T07:31:42Z
39,826,574
<p>You don't need to override <code>__init__</code> in Django. Django is doing everything for you, you just need to define your models and you are fine.</p> <p>But the error you are getting because <code>pub_date = models.DateTimeField('date_published', verbose_name="Date")</code> here you are setting <code>verbose_na...
3
2016-10-03T07:37:40Z
[ "python", "django" ]
Model in Django 1.9. TypeError: __init__() got multiple values for argument 'verbose_name'
39,826,485
<p>I have Python 3.5 and Django 1.9 try to do the next</p> <pre><code>class Question(models.Model): def __init__(self, *args, question_text=None, pub_date=None, **kwargs): self.question_text = question_text self.pub_date = pub_date question_text = models.CharField(max_length=200, verbose_name="Question") pub_d...
0
2016-10-03T07:31:42Z
39,826,634
<p>I believe you should not override <code>__init__()</code> here (as @vishes_shell supposed too). Instead of this, if you want to made some customization of instances initialization, you can add classmethod <code>create</code> to the model. Here is documentation: <a href="https://docs.djangoproject.com/en/1.10/ref/mod...
0
2016-10-03T07:41:48Z
[ "python", "django" ]
Tensorflow: how it trains the model?
39,826,514
<p>Working on Tensorflow, the first step is build a data graph and use session to run it. While, during my practice, such as the <a href="https://www.tensorflow.org/versions/r0.9/tutorials/mnist/beginners/index.html#Training" rel="nofollow">MNIST tutorial</a>. It firstly defines <em>loss</em> function and the <em>optim...
0
2016-10-03T07:33:12Z
39,828,841
<p>You do pass information about your structure to Tensorflow when you define your loss with:</p> <pre><code>loss = tf.reduce_mean(cross_entropy, name='xentropy_mean') </code></pre> <p>Notice that with Tensorflow you build a graph of operations, and every operation you use in your code is a node in the graph.</p> <p...
0
2016-10-03T09:52:23Z
[ "python", "tensorflow" ]
Cross validation with particular dataset lists with Python
39,826,538
<p>I know sklearn has nice method to get cross validation scores:</p> <pre><code> from sklearn.model_selection import cross_val_score clf = svm.SVC(kernel='linear', C=1) scores = cross_val_score(clf, iris.data, iris.target, cv=5) scores </code></pre> <p>I'd like to know scores with specific training and test...
2
2016-10-03T07:34:52Z
39,826,758
<p>This is exactly two lines of code:</p> <pre><code>for tr, te in zip(train_list, test_list): svm.SVC(kernel='linear', C=1).train(X[tr, :], y[tr]).score(X[te, :], y[te]) </code></pre> <p>See <a href="http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC.score" rel="nofollow"><code...
1
2016-10-03T07:49:21Z
[ "python", "machine-learning", "scikit-learn" ]
Cross validation with particular dataset lists with Python
39,826,538
<p>I know sklearn has nice method to get cross validation scores:</p> <pre><code> from sklearn.model_selection import cross_val_score clf = svm.SVC(kernel='linear', C=1) scores = cross_val_score(clf, iris.data, iris.target, cv=5) scores </code></pre> <p>I'd like to know scores with specific training and test...
2
2016-10-03T07:34:52Z
39,826,951
<p>My suggestion is to use <a href="http://scikit-learn.org/0.17/modules/generated/sklearn.cross_validation.KFold.html" rel="nofollow">kfold cross validation</a> like below. In this case, you will get both train, test indices for a particular split along with the accuracy score.</p> <pre><code>from sklearn import svm ...
1
2016-10-03T08:01:31Z
[ "python", "machine-learning", "scikit-learn" ]
loop stuck on first page
39,826,586
<p>Been using beautiful soup to iterate through pages, but for whatever reason I can't get the loop to advance beyond the first page. it seems like it should be easy because it's a text string, but it seems to loop back, maybe it's my structure not my text string?</p> <p>Here's what I have:</p> <pre><code>import csv...
0
2016-10-03T07:38:46Z
39,827,063
<p>You are changing the URL many times before you are opening it the first time, due to an indentation error. Try this:</p> <p><code>for gr in groups: url = "...some_url..." page = urllib2.urlopen(url) ...everything else should be indented....</code></p>
0
2016-10-03T08:08:24Z
[ "python", "python-2.7", "scripting", "beautifulsoup" ]
loop stuck on first page
39,826,586
<p>Been using beautiful soup to iterate through pages, but for whatever reason I can't get the loop to advance beyond the first page. it seems like it should be easy because it's a text string, but it seems to loop back, maybe it's my structure not my text string?</p> <p>Here's what I have:</p> <pre><code>import csv...
0
2016-10-03T07:38:46Z
39,828,579
<p>Your code indenting was mostly at fault. Also it would be wise to actually use the CSV library you imported, this will automatically wrap the player names in quotes to avoid any commas inside from ruining the csv structure.</p> <p>This works by looking for the link to the next page and extracting the starting count...
1
2016-10-03T09:37:16Z
[ "python", "python-2.7", "scripting", "beautifulsoup" ]
calculating delta time between records in dataframe
39,826,720
<p>I have an interesting problem, I am trying to calculate the delta time between records done at different locations.</p> <pre><code>id x y time 1 x1 y1 10 1 x1 y1 12 1 x2 y2 14 2 x4 y4 8 2 x5 y5 12 </code></pre> <p>I am trying to get some thing like</p> <pre><code>id x y time delta 1 x1 y1 10 4 1 x2 y2 14 ...
2
2016-10-03T07:47:05Z
39,829,090
<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop_duplicates.html" rel="nofollow"><code>drop_duplicates</code></a> with <code>groupby</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.diff.html" rel="nof...
1
2016-10-03T10:06:06Z
[ "python", "pandas", "dataframe", "spark-dataframe", "pyspark-sql" ]
calculating delta time between records in dataframe
39,826,720
<p>I have an interesting problem, I am trying to calculate the delta time between records done at different locations.</p> <pre><code>id x y time 1 x1 y1 10 1 x1 y1 12 1 x2 y2 14 2 x4 y4 8 2 x5 y5 12 </code></pre> <p>I am trying to get some thing like</p> <pre><code>id x y time delta 1 x1 y1 10 4 1 x2 y2 14 ...
2
2016-10-03T07:47:05Z
39,829,093
<p>@jezrael thank you for the hints, it was very useful, here is the code </p> <pre><code>import pandas as pd df = pd.read_csv("sampleInput.txt", header=None,usecols=[0,1,2,3], names=['id','x','y','time'],sep="\t") delta = df.groupby(['id','x','y']).first().reset_index() delta['delta'] = delta.groupby('id')['time'].di...
0
2016-10-03T10:06:16Z
[ "python", "pandas", "dataframe", "spark-dataframe", "pyspark-sql" ]
Using an existing python3 install with anaconda/miniconda
39,826,735
<p>With <code>python3</code> previously installed via <code>homebrew</code> on macOS, I just downloaded <code>miniconda</code> (via <code>homebrew cask</code>), which brought in another full python setup, I believe.</p> <p>Is it possible to install anaconda/miniconda <strong>without</strong> reinstalling python? And, ...
0
2016-10-03T07:48:01Z
39,827,107
<p>Anaconda comes with python for you but do not remove the original python that comes with the system -- many of the operating system's libs depend on it.</p> <p>Anaconda manages its python executable and packages in its own (conda) directory. It changes the system path so the python inside the conda directory is the...
0
2016-10-03T08:11:19Z
[ "python", "homebrew", "anaconda", "miniconda", "homebrew-cask" ]
Display image in Grayscale using vispy
39,826,807
<p>i'm working with a spatial light modulator (SLM) which is connected as a second monbitor. The SLM has tzo recive 8-bit grayscale images. I am currently working with vispy to display the images on the SLM, but i'm not shore if they are diplayed correctly. Is there any possibility to display an image on grayscale usi...
0
2016-10-03T07:52:27Z
39,843,353
<p>You can transform your picture from RGB to gray (see <a href="http://stackoverflow.com/questions/12201577/how-can-i-convert-an-rgb-image-into-grayscale-in-python" title="rgba2gray">this post</a>) and then use the 'grays' colormap.</p> <pre><code>import sys from vispy import scene from vispy import app import numpy ...
0
2016-10-04T02:40:42Z
[ "python", "vispy" ]
How to average and compress data using django?
39,826,859
<p>This class has volts &amp; frequency that are calculated every minute. I want to take the average of each (volts, frequency ... etc) every 15 minutesof the recorded data and time ].</p> <p>Should I do it in SQL or it can be done by django?</p> <pre><code>class LogsN (models.Model): syv = models.ForeignKey (smo...
0
2016-10-03T07:55:48Z
39,826,966
<p>I think you are looking for this <a href="https://docs.djangoproject.com/en/1.10/topics/db/aggregation/" rel="nofollow">https://docs.djangoproject.com/en/1.10/topics/db/aggregation/</a></p> <pre><code>LogsN.objects.all().aggregate(Avg('val')) </code></pre>
0
2016-10-03T08:02:40Z
[ "python", "sql", "django", "aggregation" ]
How to average and compress data using django?
39,826,859
<p>This class has volts &amp; frequency that are calculated every minute. I want to take the average of each (volts, frequency ... etc) every 15 minutesof the recorded data and time ].</p> <p>Should I do it in SQL or it can be done by django?</p> <pre><code>class LogsN (models.Model): syv = models.ForeignKey (smo...
0
2016-10-03T07:55:48Z
39,835,296
<p>As posted by Sardorbek (I cannot comment yet): according to <a href="https://docs.djangoproject.com/en/1.10/topics/db/aggregation/" rel="nofollow">https://docs.djangoproject.com/en/1.10/topics/db/aggregation/</a> :</p> <pre><code>LogsN.objects.all().aggregate(Avg('val'))['val__avg'] </code></pre> <p>Just remember ...
0
2016-10-03T15:35:16Z
[ "python", "sql", "django", "aggregation" ]
Use list of integer type in a loop in python
39,826,961
<p>I have the following code:</p> <pre><code>a=[] b=[] for s in range(10): dw = s%5 if dw == 1: WD = random.randint(60,100) DD =[int(round(dc*WD,0)) for dc in [.2,.2,.2,.2,.2]] for k in range(5): a.append(DD[k]) print a TCV = DD[dw] DDPT = [int(roun...
-8
2016-10-03T08:02:07Z
39,827,020
<p><code>DDPT</code> is an array of integers, as evidenced in this line:</p> <p><code>DDPT = [int(round(pt*TCV)) for pt in [.3,.5,.2]]</code></p> <p><code>DDPT[PT]</code> is some integer, and you are trying to iterate through that. Hence the error.</p> <p>I would recommend giving your variables more descriptive name...
4
2016-10-03T08:05:19Z
[ "python" ]
How can I get Spark to see code in a different module?
39,827,165
<p>I have complicated function that I run over a dataset in spark using the map function. It is in a different python module. When map is called, the executor nodes do not have that code and then the map function fails.</p> <pre><code>s_cobDates = getCobDates() #returns a list of dates sb_dataset = sc.broadcast(datase...
1
2016-10-03T08:15:44Z
39,836,437
<p>It is possible to dynamically distribute Python modules using <code>SparkContext.addPyFile</code></p> <pre><code>modules_to_distribute = ["foo.py", "bar.py"] for module in modules_to_distribute: sc.addPyFile(module) </code></pre> <p>All files distributed this way are placed on the Python path and accessible t...
0
2016-10-03T16:42:44Z
[ "python", "apache-spark", "pyspark" ]
How can I get Spark to see code in a different module?
39,827,165
<p>I have complicated function that I run over a dataset in spark using the map function. It is in a different python module. When map is called, the executor nodes do not have that code and then the map function fails.</p> <pre><code>s_cobDates = getCobDates() #returns a list of dates sb_dataset = sc.broadcast(datase...
1
2016-10-03T08:15:44Z
39,878,043
<p>Well the above answer works, it falls down if your modules are part of a package. Instead, its possible to zip your modules and then add the zip file to your spark context and then they have the correct package name.</p> <pre><code>def ziplib(): libpath = os.path.dirname(__file__) # this should point to your p...
0
2016-10-05T15:25:16Z
[ "python", "apache-spark", "pyspark" ]
way to update multiple different sub documents with different values within single document in mongodb using python
39,827,194
<p>I am working in Python with pandas dataframes and currently my dataframe is :</p> <pre><code>product_id mock_test_id q_id q_correct_option language_id is_corr is_p is_m 2790 2999 1 1 1 1 1 1 2790 2999 2 1 ...
0
2016-10-03T08:17:07Z
39,828,415
<p>Using one query you can set the same value to multiple objects of an array but to set different value to different objects you have to hit multiple queries.</p> <p>In the case if you want to update multiple objects with same value then in that case use <strong>{multi: true}</strong> option.</p> <pre><code> db....
1
2016-10-03T09:28:57Z
[ "python", "mongodb", "pandas", "dataframe" ]
Multiple images in a ttk label widget
39,827,233
<p>With ttk labels, it is possible to specify multiple images which are displayed according to the label's state. But I can't make it work. Here is the code.</p> <pre><code>from tkinter import * from tkinter.ttk import * BITMAP0 = """ #define zero_width 24 #define zero_height 32 static char zero_bits[] = { 0x00,0x00,...
1
2016-10-03T08:19:56Z
39,829,722
<p>I find the docs a bit confusing but it looks like you want <code>'hover'</code> instead of <code>'active'</code>.</p> <p>I am not aware of any source explaining which state flags are automatically set in which wigdets in which conditions. What I did here was to place the mouse cursor over the label and then query t...
1
2016-10-03T10:43:06Z
[ "python", "tkinter", "label", "ttk" ]
I can not import caffe in pycharm but i can import in terminal. Why?
39,827,242
<p>I want to import caffe. I can import it in terminal but not in pycharm.</p> <p>I have tried some suggestions like adding <code>include /usr/local/cuda-7.0/lib64</code> to <code>/user/etc/ld.so.conf</code> file but still it can not import this module. However, I think this is not a good solution as I am using the CP...
0
2016-10-03T08:20:24Z
39,892,292
<p>I installed caffe using pycharm terminal too but it did not work. Finally I added <code>sys.path.extend([/home/user/caffe-master/python])</code> to python consule and meanwhile I wrote the following in my code.</p> <pre><code> import sys sys.path.append("/home/user/caffe-master/python/") import caffe </code></pre...
0
2016-10-06T09:25:29Z
[ "python", "pycharm", "caffe" ]
Problems extending pandas Panels dynamically, DataFrame by DataFrame
39,827,247
<p>I want to construct a pandas panel dynamically, using the following - simplified - code:</p> <pre><code>import pandas as pd rows=range(0,3) pl=pd.Panel() for i in range(0,3): pl[i]=pd.DataFrame() for j in rows: pl[i].set_value(j,'test_value','test') </code></pre> <p>Which seems to work fine. But w...
0
2016-10-03T08:20:46Z
39,827,374
<p>Use two for loops to solve this problem:</p> <pre><code>import pandas as pd rows=range(0,3) pl=pd.Panel() #first for loop to create dataframe for i in range(0,3): pl[i]=pd.DataFrame() #Second for loop to assign values for i in range(0,3): for j in rows: pl[i].set_value(j,'test_value','test')...
1
2016-10-03T08:29:34Z
[ "python", "pandas" ]
Pandas dataframe: how to plot candlesticks
39,827,273
<p>I have following data in dataframe to plot candlesticks. </p> <pre><code> open high close low date 2013-10-08 3.21 3.28 3.27 3.20 2013-10-09 3.25 3.28 3.26 3.22 2013-10-10 3.26 3.27 3.23 3.21 2013-10-11 3.25 3.28 3.27 3.23 2013-10-14 3.28 3.35 ...
0
2016-10-03T08:22:44Z
39,827,331
<p>If the index is not a <code>datetime</code> (use <code>df.index.dtype</code> to find out which type it is), you can change the type to a datetime by using:</p> <pre><code>df.index = pd.to_datetime(df.index) </code></pre> <p>(assuming your dataframe is called <code>df</code>)</p>
0
2016-10-03T08:26:40Z
[ "python", "pandas", "matplotlib", "dataframe" ]
Read JSON Multiple Values into Bash Variable - not able to use any 3rd party tools like jq etc
39,827,359
<p>This has been asked a million times and I know there are a million solns. However im restricted in that I cant install anything on this client server , so I have whatever bash can come up with :)</p> <p>I'm referencing <a href="http://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools">Parsing JSON wi...
1
2016-10-03T08:28:41Z
39,827,466
<p>It's simple using <code>Python</code>.</p> <p><strong>Example</strong></p> <pre><code>$ python -c 'import sys, json; print json.load(sys.stdin)["rows"][0]["Egroup"]' &lt;demo.json [u'ALPHA', u'BETA', u'GAMA', u'DELTA'] </code></pre>
0
2016-10-03T08:35:57Z
[ "python", "json", "bash", "perl", "shell" ]
Read JSON Multiple Values into Bash Variable - not able to use any 3rd party tools like jq etc
39,827,359
<p>This has been asked a million times and I know there are a million solns. However im restricted in that I cant install anything on this client server , so I have whatever bash can come up with :)</p> <p>I'm referencing <a href="http://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools">Parsing JSON wi...
1
2016-10-03T08:28:41Z
39,829,199
<p>Perl 1-liner using JSON module:</p> <pre><code>perl -lane 'use JSON; my $data = decode_json($_); print join( ",", @{ $data-&gt;{rows}-&gt;[0]-&gt;{Egroup} } )' demo.json </code></pre> <p><strong>Output</strong></p> <pre><code>ALPHA,BETA,GAMA,DELTA </code></pre> <p>If you do not have <a href="http://search.cpan.o...
0
2016-10-03T10:12:29Z
[ "python", "json", "bash", "perl", "shell" ]
How to add a form as field attribute in a django ModelForm
39,827,397
<p>I have a ModelForm for a Product object set up like this: </p> <pre><code>class ProductForm(forms.ModelForm): compositon_choices = ((2L, u'Calcium (100mg)'), (3L, u'Iron (500mg)')) composition_selection = forms.\ MultipleChoiceField(widget=forms.CheckboxSelectMultiple, ...
0
2016-10-03T08:30:57Z
39,835,031
<p>Finally I understand what I did wrong. To make subforms in Django one needs formsets. In my case i needed two different types of formsets because I had two different relationships that I wanted to change from one form. </p> <ul> <li>one to many relationship</li> <li>many to many relationship</li> </ul> <p>dependi...
0
2016-10-03T15:20:43Z
[ "python", "django", "django-models", "django-forms" ]
Difference between the import(s) in python
39,827,449
<p>What is the difference between:</p> <pre><code>from class_name import function_name </code></pre> <p>and:</p> <pre><code>import class_name </code></pre> <p>Please specify if for the first one only the <code>function_name</code> is imported and for the second the full class.</p>
-1
2016-10-03T08:34:29Z
39,827,609
<p>You can't import single methods from a class, only classes from modules or functions from modules. Please see <a href="http://stackoverflow.com/questions/8502287/how-to-import-only-the-class-methods-in-python">this</a> question and <a href="https://docs.python.org/3/tutorial/modules.html" rel="nofollow">this tutoria...
0
2016-10-03T08:44:35Z
[ "python", "python-import" ]
Send terminal input data when restarting a program (python)
39,827,526
<p>My script asks for input from the terminal first thing:</p> <pre><code>ans = raw_input("Do thing A (1) / Do thing B (2)") </code></pre> <p>Then runs the code and restarts itself when an exception arises.</p> <pre><code>def restart_program(): python = sys.executable os.execl(python, python, * sys.argv) </...
1
2016-10-03T08:39:50Z
39,828,030
<p>like others mentioned in comments, try to run your python script via shell script using while loop, smthng like (first run wo cmd line arguments):</p> <pre><code>arg='' while true do python restart.py $arg arg='1' sleep 1800 done </code></pre> <p>and in your python code check if argument was provided:...
0
2016-10-03T09:09:27Z
[ "python", "terminal", "restart" ]