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
The JSON sent by Firebase is invalid
39,942,360
<pre><code>{ name: 'anonymous', text: 'Hello' } { name: 'anonymous', text: 'How are you' } { name: 'anonymous', text: 'I am fine' } </code></pre> <p>This code is returned by Firebase and I'm getting the error <code>No JSON object could be decoded</code>. I think this has to do something with the validity of the JSON f...
-3
2016-10-09T10:09:48Z
39,944,089
<p>This is not a valid JSON and I think that your <code>firebase2.js</code> is at fault here.</p> <p>Instead of this:</p> <pre><code>{ name: 'anonymous', text: 'Hello' } { name: 'anonymous', text: 'How are you' } { name: 'anonymous', text: 'I am fine' } </code></pre> <p>It should output this:</p> <pre><code>[ { "...
1
2016-10-09T13:20:35Z
[ "python", "json", "node.js", "firebase", "firebase-cloud-messaging" ]
The JSON sent by Firebase is invalid
39,942,360
<pre><code>{ name: 'anonymous', text: 'Hello' } { name: 'anonymous', text: 'How are you' } { name: 'anonymous', text: 'I am fine' } </code></pre> <p>This code is returned by Firebase and I'm getting the error <code>No JSON object could be decoded</code>. I think this has to do something with the validity of the JSON f...
-3
2016-10-09T10:09:48Z
39,944,273
<p>I got my error after some debugging.</p> <pre><code>ref.on("child_added", function(snapshot, prevChildKey) { var newPost = snapshot.val(); newPost = JSON.stringify(newPost); //this line corrected my error }); </code></pre> <p>The following line removed the error:</p> <pre><code>newPost = JSON.stringify...
0
2016-10-09T13:40:30Z
[ "python", "json", "node.js", "firebase", "firebase-cloud-messaging" ]
Two separate lists with corresponding numbers. How to detect them remove them from the list?
39,942,391
<p>I'm looking to create a program which randomly generates coins on an 8x8 grid. I've got two lists being created (one list for the X co-ordinate and list for the Y co-ordinate). On these lists, the two co-ordinates cannot be the same. It's difficult to explain, so here's what I mean by example:</p> <pre><code>[1,...
0
2016-10-09T10:12:52Z
39,942,447
<p>Your board is small enough that you can simply generate all possibilities, take a sample, and then transpose into the desired separate lists for X and Y.</p> <pre><code>possibilities = [(a,b) for a in range(10) for b in range(10)] places = random.sample(possibilities, 10) x,y = zip(*places) </code></pre>
1
2016-10-09T10:18:50Z
[ "python", "arrays", "list", "python-3.x" ]
Two separate lists with corresponding numbers. How to detect them remove them from the list?
39,942,391
<p>I'm looking to create a program which randomly generates coins on an 8x8 grid. I've got two lists being created (one list for the X co-ordinate and list for the Y co-ordinate). On these lists, the two co-ordinates cannot be the same. It's difficult to explain, so here's what I mean by example:</p> <pre><code>[1,...
0
2016-10-09T10:12:52Z
39,942,462
<p>You want to generate random coordinates, but you also want to reject any pair of coordinates that already appears in the list. (Incidentally, instead of two separate lists of integers, I would suggest using one list of ordered pairs, i.e., tuples of two integers.)</p> <p>One way to reject duplicates would be to sea...
0
2016-10-09T10:20:03Z
[ "python", "arrays", "list", "python-3.x" ]
Two separate lists with corresponding numbers. How to detect them remove them from the list?
39,942,391
<p>I'm looking to create a program which randomly generates coins on an 8x8 grid. I've got two lists being created (one list for the X co-ordinate and list for the Y co-ordinate). On these lists, the two co-ordinates cannot be the same. It's difficult to explain, so here's what I mean by example:</p> <pre><code>[1,...
0
2016-10-09T10:12:52Z
39,942,483
<p>Don't create two lists with coordinates, at least not initially. That only makes it harder to detect duplicates.</p> <p>You could either create <em>tuples</em> with coordinates so you can detect duplicates, or even produce a range of integers that represent your coordinates in sequence, then sample from those. The ...
1
2016-10-09T10:22:06Z
[ "python", "arrays", "list", "python-3.x" ]
Two separate lists with corresponding numbers. How to detect them remove them from the list?
39,942,391
<p>I'm looking to create a program which randomly generates coins on an 8x8 grid. I've got two lists being created (one list for the X co-ordinate and list for the Y co-ordinate). On these lists, the two co-ordinates cannot be the same. It's difficult to explain, so here's what I mean by example:</p> <pre><code>[1,...
0
2016-10-09T10:12:52Z
39,942,503
<pre><code>cordX = [x for x in range(10)] cordY = cordX[:] random.shuffle(cordX) random.shuffle(cordY) </code></pre>
0
2016-10-09T10:23:47Z
[ "python", "arrays", "list", "python-3.x" ]
How to prevent python requests from percent encoding URLs contain semicolon?
39,942,481
<p>I want to post some data to a url like <code>http://www.google.com/;id=aaa</code><br> I use follow codes:</p> <pre><code>url = 'http://www.google.com/;id=aaa' r = requests.post(url, headers=my_headers, data=my_data, timeout=10) </code></pre> <p>Unfortunately, I find <code>requests</code> just cut my uri to <code>h...
-1
2016-10-09T10:22:02Z
39,943,455
<p><a href="https://tools.ietf.org/html/rfc2616#section-3.2.2" rel="nofollow">RFC 2616, section 3.2.2</a> specifies the syntax of an HTTP URL as:</p> <pre class="lang-none prettyprint-override"><code>http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]] </code></pre> <p>It also says:</p> <blockquote>...
0
2016-10-09T12:09:21Z
[ "python", "http", "python-requests" ]
Python - Concatenating
39,942,600
<p>I'm going crazy with the following code which should be really easy but doesn't work :/</p> <pre><code>class Triangulo_String: _string = '' _iteraciones = 0 _string_a_repetir = '' def __init__(self, string_a_repetir, iteraciones): self._string_a_repetir = string_a_repetir self._ite...
0
2016-10-09T10:33:59Z
39,942,667
<p>The relevant bit is in this part:</p> <pre><code>for i in range(0, self._iteraciones, 1): self._string = self._string_a_repetir + self._string + '\n' </code></pre> <p>Let’s go through the iterations one by one:</p> <pre><code># Initially _string = '' _string_a_repetir = '*' _iteraciones = 3 # i = 0 _string...
3
2016-10-09T10:40:20Z
[ "python" ]
Connecting Raspberry pi with iPhone / iPad application
39,942,649
<p>I'm working on home automation using raspberry pi and all i want to do controll my home electricity using mobile application, this is my project ,I'm new to networking i want to know what is the best way to communicate to my electric device using mobile , e.g I wrote a code for electronics in python and now i want t...
0
2016-10-09T10:38:15Z
39,942,791
<p>I think this would be the process which could take some efforts to do it.But i will guide you through some of the steps you can process.</p> <ol> <li><p>You have to build a web server for communicating between raspberry pi and iPhone.Since you know python , Django or Flask would be the go to way.Create web server t...
0
2016-10-09T10:55:11Z
[ "python", "ios", "iphone" ]
Creating kivy behavior that dispatches event bubbling same way as on_touch_down
39,942,694
<p>Let's start with basic example:</p> <pre><code>class OuterWidget(Widget): def on_touch_down(self, touch): if self.collide_point(*touch.pos): print('on_touch_down', self) return True # doesn't dispatch to InnerWidget return super().on_touch_down(touch) class InnerWidget...
1
2016-10-09T10:42:40Z
39,947,141
<p>The Widget class handles its events to all its children like this:</p> <p>(copied from widget.py)</p> <pre><code>def on_touch_down(self, touch): '''Receive a touch down event. :Parameters: `touch`: :class:`~kivy.input.motionevent.MotionEvent` class Touch received. The touch is in parent...
1
2016-10-09T18:36:20Z
[ "python", "kivy" ]
Function return value of x instead of y
39,942,745
<p>f(x) represents the function of a triangular waveform. In which you input the value x and it returns you the associated y value. However my function returns x every time instead of y. For example f(1) should give 2/pi instead of 1.</p> <pre><code>def f(x): y=x if x in arange(-math.pi,-math.pi/2): ...
0
2016-10-09T10:50:14Z
39,942,785
<p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html" rel="nofollow"><code>numpy.arange</code></a> returns an array of non-consecutive numbers. <code>in</code> operation against it will return <code>True</code> only if the left-hand operand belong to those numbers.</p> <p>You'd better to u...
1
2016-10-09T10:55:05Z
[ "python", "function" ]
Function return value of x instead of y
39,942,745
<p>f(x) represents the function of a triangular waveform. In which you input the value x and it returns you the associated y value. However my function returns x every time instead of y. For example f(1) should give 2/pi instead of 1.</p> <pre><code>def f(x): y=x if x in arange(-math.pi,-math.pi/2): ...
0
2016-10-09T10:50:14Z
39,942,793
<p>The 'in' keyword only checks if the searched element lies in the list. Here, your list contains only values in the step of 1. Perhaps the value of x is not an integral step. Hence, the corrected function would be:</p> <pre><code>def f(x): y=x if x&gt;-math.pi and x&lt;-math.pi/2: y=(-2/math.pi)*x-...
0
2016-10-09T10:55:22Z
[ "python", "function" ]
how to split input line in custom format in python
39,942,786
<p>10.223.157.186 - - [15/Jul/2009:15:50:35 -0700] "GET /assets/js/lowpro.js HTTP/1.1" 200 10469</p> <p>i have to take input as given below and have it as %h %l %u %t \"%r\" %>s %b</p> <p>so that i can have 7 arguments :</p> <p>%h is the IP address of the client</p> <p>%l is identity of the client, or "-" if it's u...
-4
2016-10-09T10:55:06Z
39,943,333
<p>Take the input as a string. Assuming that the identity of the user can have spaces, but the username cannot,</p> <pre><code>import re full_string = input() #python3 # First split at any one of [, ] or " contents=re.split('[|]|"',full_string) # Now, contents[0] = %h %l %u # contents[1] = %t # contents[2] = %r...
0
2016-10-09T11:57:31Z
[ "python", "python-3.x", "input" ]
Reading core_properties using python-docx
39,942,877
<p>I'm trying to read the last_saved_by attribute on docx files. I've followed the comments on Github, and from <a href="http://stackoverflow.com/questions/22625022/reading-coreproperties-keywords-from-docx-file-with-python-docx">this question</a>. It seems that support has been added, but the documentation isn't very ...
0
2016-10-09T11:06:15Z
39,943,146
<p>Figured out where I was going wrong, for those that want to know:</p> <pre><code>from docx import Document import docx document = Document('mine.docx') core_properties = document.core_properties print(core_properties.author) </code></pre> <p>There'll be a more succinct way of doing this, I'm sure (importing docx ...
1
2016-10-09T11:37:33Z
[ "python", "python-3.x", "word-2010", "python-docx" ]
Reading core_properties using python-docx
39,942,877
<p>I'm trying to read the last_saved_by attribute on docx files. I've followed the comments on Github, and from <a href="http://stackoverflow.com/questions/22625022/reading-coreproperties-keywords-from-docx-file-with-python-docx">this question</a>. It seems that support has been added, but the documentation isn't very ...
0
2016-10-09T11:06:15Z
39,943,416
<p>If the only thing you need from the <code>docx</code> module is <code>Document</code>, then you only need to use</p> <pre><code>from docx import Document </code></pre> <p>If you use more than that, you could use</p> <pre><code>import docx document = docx.Document() </code></pre> <p>importing specific names from ...
0
2016-10-09T12:05:19Z
[ "python", "python-3.x", "word-2010", "python-docx" ]
Why do I have to close the shell for my script to work? (writing to text files)
39,942,948
<p>I have the following code in a .py file: </p> <pre><code>f = open('exampleTextFile.txt', 'w') f.write('This is a sentence.') f.close </code></pre> <p>I open it up and press F5 to run.</p> <p>The IDLE shell opens up and runs the code without a hitch. But then when I find the text file in my directory and open it...
1
2016-10-09T11:14:37Z
39,942,977
<p>Your file is not closed properly. You forgot the parenthesis:</p> <pre><code>f.close() </code></pre>
0
2016-10-09T11:18:17Z
[ "python", "python-2.7" ]
Why do I have to close the shell for my script to work? (writing to text files)
39,942,948
<p>I have the following code in a .py file: </p> <pre><code>f = open('exampleTextFile.txt', 'w') f.write('This is a sentence.') f.close </code></pre> <p>I open it up and press F5 to run.</p> <p>The IDLE shell opens up and runs the code without a hitch. But then when I find the text file in my directory and open it...
1
2016-10-09T11:14:37Z
39,943,053
<p>You can prevent these mistakes by using the <code>open</code> context manager</p> <pre><code>with open('exampleTextFile.txt', 'w') as f: f.write('This is a sentence.') # file automatically closed </code></pre> <p>This has the additional benefit that the file will be closed on errors too:</p> <pre><code>with o...
2
2016-10-09T11:26:26Z
[ "python", "python-2.7" ]
Get first letter of index?
39,943,132
<p>I have a pandas dataframe <code>df</code> that looks like this:</p> <pre><code> population n France 66.03 Italy 59.83 </code></pre> <p>I want to get the first letter of the index label, for each row, and set it as a new column so that I can start doing analysis with it. How can I do this?</p>...
0
2016-10-09T11:35:30Z
39,943,399
<p>I think there's nothing wrong with what you're doing. There are two things which you may do differently</p> <ol> <li>use lambda or list comprehension instead of the named function</li> <li>set the index directly instead of reseting it.</li> </ol> <p>Like this:</p> <pre><code>df1.n.apply(lambda x: x[0]) </code></p...
0
2016-10-09T12:03:41Z
[ "python", "pandas" ]
Get first letter of index?
39,943,132
<p>I have a pandas dataframe <code>df</code> that looks like this:</p> <pre><code> population n France 66.03 Italy 59.83 </code></pre> <p>I want to get the first letter of the index label, for each row, and set it as a new column so that I can start doing analysis with it. How can I do this?</p>...
0
2016-10-09T11:35:30Z
39,943,412
<p>You could use the <a href="http://pandas.pydata.org/pandas-docs/version/0.18.1/generated/pandas.Index.get_level_values.html#pandas-index-get-level-values" rel="nofollow"><code>get_level_values</code> method</a> to obtain the index label. Then <a href="http://pandas.pydata.org/pandas-docs/stable/text.html#indexing-wi...
1
2016-10-09T12:05:12Z
[ "python", "pandas" ]
how to get a python value from input type hidden in jquery
39,943,209
<p>I have this code:</p> <pre><code>&lt;div class="popup" data-popup="popup-1"&gt; &lt;div class="popup-inner"&gt; {{=form.custom.begin}} &lt;div style="display:none"&gt; &lt;input id="co_srid" type="hidden" value='{{=form.custom.widget.service_request_id}}' /&gt; {{=for...
0
2016-10-09T11:44:00Z
39,943,344
<p>I changed</p> <pre><code>value='{{=form.custom.widget.service_request_id}}' </code></pre> <p>to</p> <pre><code>value='{{=get_data.service_request_id}}' </code></pre>
0
2016-10-09T11:58:46Z
[ "jquery", "python", "web2py" ]
How to set optimality gap in PULP-OR with CBC solver?
39,943,236
<p>I want to set the optimality gap when calculating a solution between the optimal and the actual solution. </p> <p>I use PuLP version 1.6.1 and I want to pass the parameter of gap to the solver. Does anyone have an example or an idea on how to approach this issue. </p> <p>The documentation that can be found here:</...
0
2016-10-09T11:47:37Z
39,943,517
<p>The documentation exactly shows you how to pass options to the solvers. Maybe not all of cbcs options are supported, but pulp's code shows, that the task you want is handled by the argument <code>fracGap</code>.</p> <pre><code>class COIN_CMD(LpSolver_CMD): """The COIN CLP/CBC LP solver now only uses cbc ...
0
2016-10-09T12:17:00Z
[ "python", "optimization", "linear-programming", "pulp" ]
From subprocess.Popen to multiprocessing
39,943,281
<p>I got a function that invokes a process using <code>subprocess.Popen</code> in the following way:</p> <pre><code> def func(): ... process = subprocess.Popen(substr, shell=True, stdout=subprocess.PIPE) timeout = {"value": False} timer = Timer(timeout_sec, kill_proc, [process, time...
0
2016-10-09T11:52:47Z
39,944,459
<p>Just add the index to your <code>Popen</code> call and create a <a href="https://docs.python.org/3.6/library/multiprocessing.html" rel="nofollow">worker pool</a> with as many CPU cores you have available.</p> <pre><code>import multiprocessing def func(index): .... process = subprocess.Popen(substr + " --in...
0
2016-10-09T14:03:52Z
[ "python", "multiprocessing" ]
I can't use the sorted function to sort a two elements tuple list in descending numerical order then in ascending alphabetical order in case of a tie
39,943,307
<p>I used the sorted() function to sort a list of tuples, as it is shown below. the output is in descending order as wanted for the second elements (numbers). but what I really want is to sort the tuples in ascending alphabetical order in case of a tie.</p> <p>Help please. </p> <pre><code>sorted(word_Count, key = ite...
0
2016-10-09T11:54:33Z
39,943,342
<p>You can use the <code>sorted()</code> function along with <a href="http://www.diveintopython.net/power_of_introspection/lambda_functions.html" rel="nofollow"><code>lambda</code></a> as:</p> <pre><code>&gt;&gt;&gt; sorted(word_count, key=lambda x: (-x[1], x[0])) [('butter', 2), ('a', 1), ('betty', 1), ('bit', 1), ('...
3
2016-10-09T11:58:43Z
[ "python", "function", "sorting", "tuples" ]
I can't use the sorted function to sort a two elements tuple list in descending numerical order then in ascending alphabetical order in case of a tie
39,943,307
<p>I used the sorted() function to sort a list of tuples, as it is shown below. the output is in descending order as wanted for the second elements (numbers). but what I really want is to sort the tuples in ascending alphabetical order in case of a tie.</p> <p>Help please. </p> <pre><code>sorted(word_Count, key = ite...
0
2016-10-09T11:54:33Z
39,943,441
<p>You could use <code>list.sort</code> twice, since, according to <code>list.sort</code>'s docstring, it is in place:</p> <pre><code>L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*; </code></pre> <p>So, to sort your list, you could do</p> <pre><code>&gt;&gt;&gt; word_count.sort() &gt;&gt;&gt; wo...
0
2016-10-09T12:07:29Z
[ "python", "function", "sorting", "tuples" ]
How to keybind the return to the "=" code: Python
39,943,509
<p>I am trying to keybind the enter key to "=".</p> <p>With the code I have now, I get an error when i put in two numbers and press enter, the error is:</p> <pre><code>Exception in Tkinter callback Traceback (most recent call last): line 1550, in __call__ return self.func(*args) line 68, in &lt;lambda&gt; root.bind(...
0
2016-10-09T12:15:56Z
40,003,769
<p>This should work. I've also got rid of the second window that wasn't needed</p> <pre><code>from __future__ import division from functools import partial from math import * import tkinter as tk from tkinter import * #root=Tk() class Calculator(tk.Tk): def __init__(self): tk.Tk.__init__(self) ...
0
2016-10-12T16:30:28Z
[ "python", "user-interface", "tkinter", "calculator" ]
passing argument from python to subprocess.popen
39,943,519
<p>I have this code:</p> <pre><code>from subprocess import Popen link="abc" theproc = Popen([sys.executable, "p1.py",link]) </code></pre> <p>I want to send the variable "link" to p1.py, and p1.py will print it.</p> <p>something like this. here is p1.py:</p> <pre><code>print "in p1.py link is "+ link </code></pre> ...
-2
2016-10-09T12:17:09Z
39,943,630
<p>I'm assuming <code>python</code> refers to Python 2.x on your system.</p> <p>Retrieve the command line argument in <code>p1.py</code> using <code>sys.argv</code>:</p> <pre><code>import sys if not len(sys.argv) &gt; 1: print "Expecting link argument." else: print "in p1.py link is " + sys.argv[1] </code></...
0
2016-10-09T12:29:15Z
[ "python", "subprocess", "popen" ]
passing argument from python to subprocess.popen
39,943,519
<p>I have this code:</p> <pre><code>from subprocess import Popen link="abc" theproc = Popen([sys.executable, "p1.py",link]) </code></pre> <p>I want to send the variable "link" to p1.py, and p1.py will print it.</p> <p>something like this. here is p1.py:</p> <pre><code>print "in p1.py link is "+ link </code></pre> ...
-2
2016-10-09T12:17:09Z
39,943,673
<p>You have to parse the command line arguments in your <code>p1.py</code> to get it in a variable:</p> <pre><code>import sys try: link = sys.argv[1] except IndexError: print 'argument missing' sys.exit(1) </code></pre>
0
2016-10-09T12:33:55Z
[ "python", "subprocess", "popen" ]
python, dictionary in a data frame, sorting
39,943,547
<p>I have a python data frame called wiki, with the wikipedia information for some people. Each row is a different person, and the columns are : 'name', 'text' and 'word_count'. The information in 'text' has been put in dictionary form (keys,values), to create the information in the column 'word_count'.</p> <p>If I w...
0
2016-10-09T12:20:00Z
39,944,248
<p>If the name column is unique, then you can change the column to the index of the <code>DataFrame</code> object:<code>wiki.set_index("name", inplace=True)</code>. Then you can get the value by: <code>wiki.at['Barack Obama', 'word_count']</code>.</p> <p>With your code:</p> <pre><code>row = wiki[wiki['name'] == 'Bara...
2
2016-10-09T13:37:06Z
[ "python", "sorting", "pandas", "dictionary", "dataframe" ]
Maximum recursion depth exceeded in python
39,943,560
<p>I am trying to make power function by recursion. But I got run time error like Maximum recursion depth exceeded. I will appreciate any help!! Here is my code.</p> <pre><code> def fast_power(a,n): if(n==0): return 1 else: if(n%2==0): return fast_power(fast_power(a,n/2),2) el...
0
2016-10-09T12:20:54Z
39,943,590
<p>You should use <code>n // 2</code> instead of <code>n / 2</code>:</p> <pre><code>&gt;&gt;&gt; 5 // 2 2 &gt;&gt;&gt; 5 / 2 2.5 </code></pre> <p>(At least in python3)</p> <p>The problem is that once you end up with floats it takes quite a while before you end up at <code>0</code> by dividing by <code>2</code>:</p> ...
2
2016-10-09T12:23:43Z
[ "python", "function", "recursion" ]
Maximum recursion depth exceeded in python
39,943,560
<p>I am trying to make power function by recursion. But I got run time error like Maximum recursion depth exceeded. I will appreciate any help!! Here is my code.</p> <pre><code> def fast_power(a,n): if(n==0): return 1 else: if(n%2==0): return fast_power(fast_power(a,n/2),2) el...
0
2016-10-09T12:20:54Z
39,949,967
<p>I believe @Bakuriu's explanation of the problem is incomplete. Not his reimplementation, but his explanation of your bug(s). You might convince yourself of this by replacing <code>/</code> with <code>//</code> in your original code and try:</p> <pre><code>fast_power(2, 2) </code></pre> <p>it still exceeds the st...
0
2016-10-10T00:45:04Z
[ "python", "function", "recursion" ]
Deploying Django project on Linux
39,943,598
<p>Comming from PHP(without frameworks), I don't quite understand how deploying works in Python. I have completed my simple Django version: <em>(1, 10, 1, 'final', 1)</em> blog project and all I have to do is put it online. I am using linux openSUSE distro and virtualenv</p> <p>I have access to a mysql database with p...
0
2016-10-09T12:25:03Z
39,943,657
<p>I would recommend you to use Git instead of FTP protocol. As you are using Linux you can easily connect to your SO using ssh.</p> <p>About the deployment, I would recommend you to use GUnicorn for a WSGI way. It's not hard to deploy with, but if you get in trouble you can use the official Django documentation for d...
0
2016-10-09T12:32:06Z
[ "python", "mysql", "django" ]
Deploying Django project on Linux
39,943,598
<p>Comming from PHP(without frameworks), I don't quite understand how deploying works in Python. I have completed my simple Django version: <em>(1, 10, 1, 'final', 1)</em> blog project and all I have to do is put it online. I am using linux openSUSE distro and virtualenv</p> <p>I have access to a mysql database with p...
0
2016-10-09T12:25:03Z
39,944,002
<p>Check what version of Python is installed on the server hosting your account and if there's option for ssh access.</p> <p>Host.bg and Bulgarian hosting providers in general fail to keep up with most things other than php and mysql. With shared plans they avoid installing anything new too.</p> <p>I'd say contact su...
0
2016-10-09T13:11:36Z
[ "python", "mysql", "django" ]
Python Spacy beginner : similarities function
39,943,687
<p>In the tutorial example of spaCy in Python the results of <code>apples.similarity(oranges)</code> is <code>0.39289959293092641</code> instead of <code>0.7857989796519943</code></p> <p>Any reasons for that? Original docs of the tutorial <a href="https://spacy.io/docs/" rel="nofollow">https://spacy.io/docs/</a> A t...
1
2016-10-09T12:35:17Z
39,984,831
<p>That appears to be a bug in spacy.</p> <p>Somehow <code>vector_norm</code> is incorrectly calculated. </p> <pre><code>import spacy import numpy as np nlp = spacy.load("en") # using u"apples" just as an example apples = nlp.vocab[u"apples"] print apples.vector_norm # prints 1.4142135381698608, or sqrt(2) print np.s...
1
2016-10-11T19:05:07Z
[ "python", "nlp", "spacy" ]
Select from dataframe the last n records before event appears
39,943,736
<p>Suppose I have the following pandas Dataframe:</p> <pre><code> name timestamp 1 event1 9/2016 13:47:49 1 event2 9/2016 13:47:55 1 event3 9/2016 13:49:30 1 event4 9/2016 13:50:49 1 trigger 9/2016 13:51:49 ...
1
2016-10-09T12:40:40Z
39,944,108
<p>You can create a group variable based on the <code>cumsum</code> of whether <code>name</code> column is equal to <code>trigger</code> condition and then take the last three records for each group (the last group needs to be filtered out due to the fact that there is no <code>trigger</code> after it):</p> <pre><code...
3
2016-10-09T13:22:11Z
[ "python", "pandas", "select", "dataframe" ]
Remove Quotation marks from a dictionary
39,943,765
<p>I have a dictionary of bigrams, obtained by importing a csv and transforming it to a dictionary:</p> <pre><code>bigram_dict = {"('key1', 'key2')": 'meaning', "('key22', 'key13')": 'mean2'} </code></pre> <p>I want keys' dictionary to be without quotation marks, i.e.:</p> <pre><code>desired_bigram_dict={('key1', 'k...
2
2016-10-09T12:42:49Z
39,943,787
<p>You can <a href="https://docs.python.org/2/library/ast.html#ast.literal_eval" rel="nofollow"><em>literal_eval</em></a> each key and reassign:</p> <pre><code>from ast import literal_eval bigram_dict = {"('key1', 'key2')": 'meaning', "('key22', 'key13')": 'mean2'} for k,v in bigram_dict.items(): bigram_dict[li...
3
2016-10-09T12:46:02Z
[ "python", "nltk" ]
Remove Quotation marks from a dictionary
39,943,765
<p>I have a dictionary of bigrams, obtained by importing a csv and transforming it to a dictionary:</p> <pre><code>bigram_dict = {"('key1', 'key2')": 'meaning', "('key22', 'key13')": 'mean2'} </code></pre> <p>I want keys' dictionary to be without quotation marks, i.e.:</p> <pre><code>desired_bigram_dict={('key1', 'k...
2
2016-10-09T12:42:49Z
39,943,789
<p>This can be done using a dictionary comprehension, where you call <a href="https://docs.python.org/3/library/ast.html#ast.literal_eval">literal_eval</a> on the key:</p> <pre><code>from ast import literal_eval bigram_dict = {"('key1', 'key2')": 'meaning', "('key22', 'key13')": 'mean2'} res = {literal_eval(k): v for...
6
2016-10-09T12:46:20Z
[ "python", "nltk" ]
Finding the date in a year if i have a given number in Python
39,943,809
<p>I have two integers, one represents the year and one is the number of the day in that year. Example: 2004 and 68</p> <p>I have to find a way to turn the 68 into 8.03.2004</p> <p>I just started using <strong>Python</strong> and I don't really know how to use the datetime command. If anyone could give me some tips i...
0
2016-10-09T12:48:40Z
39,943,858
<p>You can use <code>datetime.timedelta</code> to advance from the beggining of year:</p> <pre><code>from datetime import datetime, timedelta # we start from day 1, not day 0, so we need to substract one day print(datetime(2004, 1, 1) + timedelta(days=68 - 1)) # 2004-03-08 00:00:00 </code></pre>
3
2016-10-09T12:54:53Z
[ "python", "date", "datetime" ]
Finding the date in a year if i have a given number in Python
39,943,809
<p>I have two integers, one represents the year and one is the number of the day in that year. Example: 2004 and 68</p> <p>I have to find a way to turn the 68 into 8.03.2004</p> <p>I just started using <strong>Python</strong> and I don't really know how to use the datetime command. If anyone could give me some tips i...
0
2016-10-09T12:48:40Z
39,943,887
<p>One way to calculate it:</p> <pre><code>import datetime year = 2004 day_of_year = 68 print datetime.date(year,1,1) + datetime.timedelta(days=day_of_year-1) </code></pre>
1
2016-10-09T12:57:55Z
[ "python", "date", "datetime" ]
Get the particular rows in Python
39,943,874
<p>I have two csv files. </p> <p>One is as follows:</p> <pre><code>"CONS_NO","DATA_DATE","KWH_READING","KWH_READING1","KWH" "1652714033","2015/1/12","4747.3800","4736.8000","10.5800" "3332440062","2015/1/12","408.6800","407.8200","0.8600" "7804314033","2015/1/12","1794.3500","1792.5000","1.8500" "0114314033","2015/1/...
-1
2016-10-09T12:56:31Z
39,947,950
<p>You can merge the two <code>DataFrame</code> using the merge method in <code>pandas</code>.</p> <p>I change your example data to the following:</p> <p><code>test1.csv</code> is:</p> <pre><code>"CONS_NO","DATA_DATE","KWH_READING","KWH_READING1","KWH" "1652714033","2015/1/12","4747.3800","4736.8000","10.5800" "3332...
0
2016-10-09T20:00:22Z
[ "python", "csv", "pandas", "numpy" ]
Django specific permissions for users
39,943,917
<p>for example i have a model with booleanfield</p> <pre><code>class Item(BaseModel): name = models.CharField(max_length=255) pending = models.BooleanField(default=False) </code></pre> <p>if user creates new item from admin panel pending field is false and this item won't display on website until other user ...
-1
2016-10-09T13:01:55Z
39,944,511
<p>There are a number of ways to implement this, depending on how you are ultimately going to end up using it. The most straightforward is to add a foreignkey on your Item to the user (assuming you use django auth).</p> <pre><code>from django.contrib.auth.models import User class Item(BaseModels): created_by = mod...
0
2016-10-09T14:09:47Z
[ "python", "django" ]
Cannot install obspy correctly
39,943,974
<p>It could be that obspy is installed, but I've missed a step off the installation process somewhere or some other issue. But in any case I followed the instructions as per this <a href="https://github.com/obspy/obspy/wiki/Installation-on-Mac-OS-X-using-Macports" rel="nofollow">link</a> and since I already have instal...
0
2016-10-09T13:08:00Z
39,962,538
<p>If you are using anaconda, you will need to install <code>obspy</code> using <code>conda install</code></p> <p><code>conda install --channel https://conda.anaconda.org/obspy obspy</code></p> <hr> <p><strong>TL;DR</strong></p> <p>Since it is not in their default repository, you need to use the search function to ...
0
2016-10-10T16:17:50Z
[ "python", "installation", "anaconda" ]
Python. What str.attribute could be used in key argument of method sort? set.sort(key)
39,944,003
<p>I'm a newbie just reading Lutz, so the example is partly from that book:</p> <pre><code>l = ['aBe', 'ABD', 'abc'] #the following listing works ok l.sort(key=str.lower) l &gt;&gt;&gt;['abc', 'ABD', 'aBe'] </code></pre> <p>And the quesition is what str.attribute could be used in that case?</p> <pre><code>l.sort(key...
1
2016-10-09T13:11:38Z
39,944,097
<p>As I commented, the key must be a callable, to do what you are trying to do you could use a <em>lambda</em> with chained <code>str.replace</code> calls like <code>x.replace("B","a").replace("e","a")</code> but a better solution would be to use <em>str.translate</em>:</p> <pre><code>tbl = {ord("B"):"a", ord("e"):"a...
2
2016-10-09T13:21:22Z
[ "python", "sorting", "set" ]
How to set timeout for thread in case of no response and terminate the thread?
39,944,011
<p>Let's say we have a code sample as below which prints <code>hello, world</code> after 5 seconds. I want a way to check if <code>Timer</code> thread took more than 5 seconds then terminate the thread.</p> <pre><code>from threading import Timer from time import sleep def hello(): sleep(50) print "hello, wor...
1
2016-10-09T13:13:06Z
39,944,130
<p>You can use <code>signal</code> and call its <code>alarm</code> method. An exception (which you can handle) will be raised after the timeout time has passed. See an (incomplete) example below. </p> <pre><code>import signal class TimeoutException (Exception): pass def signalHandler (signum, frame): raise T...
2
2016-10-09T13:25:36Z
[ "python", "multithreading" ]
Checkbutton and Scale conflict
39,944,055
<p>I have a problem with my Checkbutton widget. Every time I select it the slider on the scale widget above moves by itself to 1, deselecting the Checkbutton widget will set the Scale widget to 0. Both widgets are not intended to be related with each other in any way yet for some reason changing values in one of them a...
-1
2016-10-09T13:16:37Z
39,945,467
<p>The <code>variable=</code> parameter to Tk widgets MUST be a Tk variable (created by Tk.IntVar() or similar calls). Your code passes Q and RS, which are ordinary Python variables; the one Tk variable you create is pointless, because you never use it anywhere. Tk variables have a special ability not possessed by Py...
0
2016-10-09T15:49:05Z
[ "python", "tkinter" ]
Read a title in HTML with Python script
39,944,082
<p>I have a small problem, I want to read a title in a HTML document, this is working so far, that I get the result of the string. Im using the libraray bs4 BeautifulSoup and urllib.request.</p> <p><a href="http://i.stack.imgur.com/YuATM.png" rel="nofollow"><img src="http://i.stack.imgur.com/YuATM.png" alt="HTML Code"...
-2
2016-10-09T13:19:17Z
39,944,182
<p>Without example code it's hard to give you an exact solution, but you can use <code>h2.get_text(strip=true)</code> where <code>h2</code> is a variable pointing to the <code>h2</code> element yo want to print out.</p> <p>This is the documentation on <code>get_text()</code> - <a href="https://www.crummy.com/software/...
0
2016-10-09T13:31:00Z
[ "python", "html", "beautifulsoup", "urllib", "bs4" ]
Read a title in HTML with Python script
39,944,082
<p>I have a small problem, I want to read a title in a HTML document, this is working so far, that I get the result of the string. Im using the libraray bs4 BeautifulSoup and urllib.request.</p> <p><a href="http://i.stack.imgur.com/YuATM.png" rel="nofollow"><img src="http://i.stack.imgur.com/YuATM.png" alt="HTML Code"...
-2
2016-10-09T13:19:17Z
39,944,219
<p>It is my understanding that you have the text content of an h2 tag in a variable, and you want to strip whitespace. So you can use <code>strip=true</code> in bs4 or <code>title = title.strip()</code>. </p>
0
2016-10-09T13:34:27Z
[ "python", "html", "beautifulsoup", "urllib", "bs4" ]
How to set sigalarm to repeat over and over again in linux?
39,944,232
<p>I'm trying to make alarm work over and over again.</p> <p>My handler is</p> <pre><code>def handler_SIGALRM(signum, frame): print "waiting" signal.alarm(2) </code></pre> <p>The alarm work only once, even though every time I set it again. In my code I also use sigchld and sys.exit after the child working.</...
0
2016-10-09T13:35:20Z
39,944,349
<p>You put your <code>signal.alarm(2)</code> in a wrong place. See my example below.</p> <pre><code>import time import signal class TimeoutException (Exception): pass def signalHandler (signum, frame): raise TimeoutException () timeout_duration = 5 signal.signal (signal.SIGALRM, signalHandler) for i in...
0
2016-10-09T13:48:53Z
[ "python", "cygwin", "signals", "posix" ]
Reading a textfile into a String
39,944,293
<p>I'm just starting to learn python and have a textfile that looks like this:</p> <pre><code>Hello World Hello World </code></pre> <p>And I want to add the numbers '55' to the beggining and end of every string that starts with 'hello'</p> <p>The numbers '66' to the beggining and every of every string that start...
1
2016-10-09T13:42:19Z
39,944,332
<p>You are reading the whole file at once with <code>.read()</code>.</p> <p>You can read it line by line in a <code>for</code> loop.</p> <pre><code>new_file = [] fp = open("test.txt", "r") for line in fp: line = line.rstrip("\n") # The string ends in a newline # str.rstrip("\n") rem...
2
2016-10-09T13:47:17Z
[ "python" ]
Reading a textfile into a String
39,944,293
<p>I'm just starting to learn python and have a textfile that looks like this:</p> <pre><code>Hello World Hello World </code></pre> <p>And I want to add the numbers '55' to the beggining and end of every string that starts with 'hello'</p> <p>The numbers '66' to the beggining and every of every string that start...
1
2016-10-09T13:42:19Z
39,944,350
<p>You need to iterate over each line of the file in order to get the desired result. In your code you are using <code>.read()</code>, instead use <code>.readlines()</code> to get list of all lines.</p> <p>Below is the sample code:</p> <pre><code>lines = [] with open("test.txt", "r") as f: for line in f.readline...
0
2016-10-09T13:48:54Z
[ "python" ]
Reading a textfile into a String
39,944,293
<p>I'm just starting to learn python and have a textfile that looks like this:</p> <pre><code>Hello World Hello World </code></pre> <p>And I want to add the numbers '55' to the beggining and end of every string that starts with 'hello'</p> <p>The numbers '66' to the beggining and every of every string that start...
1
2016-10-09T13:42:19Z
39,944,413
<p>once you have read the file:</p> <pre><code>read_file = read_file.replace('hello','55hello55') </code></pre> <p>It'll replace all hellos with 55hello55</p> <p>and use <code>with open(text.txt, 'r' ) as file_hndler:</code></p>
0
2016-10-09T13:57:43Z
[ "python" ]
Reading a textfile into a String
39,944,293
<p>I'm just starting to learn python and have a textfile that looks like this:</p> <pre><code>Hello World Hello World </code></pre> <p>And I want to add the numbers '55' to the beggining and end of every string that starts with 'hello'</p> <p>The numbers '66' to the beggining and every of every string that start...
1
2016-10-09T13:42:19Z
39,944,564
<p>To read a <strong>text</strong> file, I recommend the following way which is compatible with Python 2 &amp; 3:</p> <pre><code>import io with io.open("test", mode="r", encoding="utf8") as fd: ... </code></pre> <p>Here, I make the assumption that your file use uft8 encoding.</p> <p>Using a <code>with</code> st...
0
2016-10-09T14:14:39Z
[ "python" ]
Python 2.7 Yahoo Finance No Definition Found
39,944,314
<p>Hope you are well. I'm Using Python 2.7 and new at it. I'm trying to use yahoo finance API to get information from stocks, here is my code:</p> <pre><code>from yahoo_finance import Share yahoo = Share('YHOO') print yahoo.get_historical('2014-04-25', '2014-04-29') </code></pre> <p>This code thoug works once out of...
0
2016-10-09T13:45:28Z
39,944,347
<p>This is a <em>server-side error</em>. The <code>query.yahooapis.com</code> service appears to be handled by a cluster of machines, and some of those machines appear to be misconfigured. This could be a temporary problem.</p> <p>I see the same error when accessing the API directly using curl:</p> <pre><code>$ curl ...
1
2016-10-09T13:48:41Z
[ "python", "yql", "yahoo-api", "yahoo-finance" ]
How to group set of time under distinct date from csv file
39,944,390
<p>hi i have just gotten a set of time and date data from csv file using regex:</p> <pre><code>datePattern = re.compile(r"(\d+/\d+/\d+\s+\d+:\d+)") for i, line in enumerate(open('sample_data.csv')): for match in re.finditer(datePattern, line): date.append(match.groups()); </code></pre> <p>the output is [(...
-2
2016-10-09T13:54:05Z
39,944,613
<p>Try this regex:</p> <pre><code>r"(\d+/\d+/\d+)\s+(\d+:\d+)" </code></pre> <p><a href="https://repl.it/DrqS/2" rel="nofollow">Python code</a> follows, I have used dictionary of lists for such grouping</p> <pre><code>import re datePattern = re.compile(r"(\d+/\d+/\d+)\s+(\d+:\d+)") dateDict =dict() for i, li...
0
2016-10-09T14:19:29Z
[ "python", "regex" ]
Add shifted integers to list
39,944,453
<p>I have a list of integers, which I would like to inflate to include both the current integers, and their values shifted by +1 and -1.</p> <p>For example, if I have :</p> <pre><code>l1 = [3, 9, 15] </code></pre> <p>I would like the result to be (the order doesn't matter) :</p> <pre><code>l2 = [2, 3, 4, 8, 9, 10, ...
0
2016-10-09T14:03:17Z
39,944,520
<p>How about this:</p> <pre><code>l1 = [3, 9, 15] l2 = [i+j for i in l1 for j in (-1, 0, 1)] print (l2) </code></pre> <p>gives:</p> <pre><code>[2, 3, 4, 8, 9, 10, 14, 15, 16] </code></pre>
3
2016-10-09T14:10:20Z
[ "python", "list", "python-3.x", "numpy" ]
Add shifted integers to list
39,944,453
<p>I have a list of integers, which I would like to inflate to include both the current integers, and their values shifted by +1 and -1.</p> <p>For example, if I have :</p> <pre><code>l1 = [3, 9, 15] </code></pre> <p>I would like the result to be (the order doesn't matter) :</p> <pre><code>l2 = [2, 3, 4, 8, 9, 10, ...
0
2016-10-09T14:03:17Z
39,944,623
<p>You may use list comprehension with <a href="http://pythoncentral.io/pythons-range-function-explained/" rel="nofollow"><code>range()</code></a> as:</p> <pre><code>&gt;&gt;&gt; [item + i for item in l1 for i in range(-1, 2)] [2, 3, 4, 8, 9, 10, 14, 15, 16] </code></pre>
0
2016-10-09T14:20:47Z
[ "python", "list", "python-3.x", "numpy" ]
Add shifted integers to list
39,944,453
<p>I have a list of integers, which I would like to inflate to include both the current integers, and their values shifted by +1 and -1.</p> <p>For example, if I have :</p> <pre><code>l1 = [3, 9, 15] </code></pre> <p>I would like the result to be (the order doesn't matter) :</p> <pre><code>l2 = [2, 3, 4, 8, 9, 10, ...
0
2016-10-09T14:03:17Z
39,944,636
<p>With numpy is something like this</p> <pre><code>value=1 p = np.array([3, 9, 15]) p = np.append(p,[[[i+value,i-value] for i in p]]) </code></pre> <p>with output sorted:</p> <pre><code>[2, 3, 4, 8, 9, 10, 14, 15, 16] </code></pre> <p>but you want with value 2 show for example in <strong>3</strong> [1,3,5] or [1,2...
0
2016-10-09T14:21:20Z
[ "python", "list", "python-3.x", "numpy" ]
Pickle load: ImportError: No module named doc2vec_ext
39,944,487
<p>This is the structure I'm dealing with:</p> <pre><code>src/ processing/ station_level/ train_paragraph_vectors.py doc2vec_ext.py word_embeddings_station_level.py </code></pre> <p>I have trained and stored a model in <code>word_embeddings_station_level.py</code> like this:</p> <pre>...
0
2016-10-09T14:07:01Z
39,946,944
<p>When saving and loading binary data like a pickle, you need to use binary mode, not text mode.</p> <pre><code>model.save(open(model_file, "wb")) # 'b' for binary </code></pre>
0
2016-10-09T18:17:26Z
[ "python", "pickle", "gensim" ]
"Last modified by" (user name, not time) attribute for xlsx using Python
39,944,495
<p>I need to be able to view the "last modified by" attribute for xlsx files using Python. I've been able to do for docx files, and was hoping that the architecture would be similar enough to use on other Office applications, but unfortunately not. Does anybody know of a similar module for xlsx?</p> <p>This is the scr...
0
2016-10-09T14:08:31Z
39,944,616
<pre><code>import os filename = "C:\\test.xlsx" statsbuf = os.stat(filename) print "modified:",statsbuf.st_mtime f = os.path.getmtime('C:\\test.xlsx') print f </code></pre> <p>since the beginning </p>
0
2016-10-09T14:20:01Z
[ "python", "excel", "xlsx", "python-docx" ]
What to do when Jupyter suddenly hangs?
39,944,576
<p>I'm using Jupyter notebook 4.0.6 on OSX El Capitan. </p> <p>Once in a while I'll start running a notebook and the cell will simply hang, with a <code>[ * ]</code> next to it and no output.</p> <p>When this happens, I find that only killing Jupyter at the command line and restarting it solves the problem. Relaunchi...
0
2016-10-09T14:16:02Z
39,946,960
<p>I use Jupyter Notebook 4.2.3 on OSX El Capitan, so I might not be really helpful, but at least I can try to guess. </p> <p>[*] basically means that something is going on, so if you are running a script with some complicated computations, you'd better wait a little bit. </p> <p>To make sure, you may try to use a lo...
0
2016-10-09T18:18:46Z
[ "python", "osx", "jupyter-notebook" ]
.clear() for list not working - python
39,944,586
<p>I am writing some code that is supposed to find the prime factorization of numbers. The main function increments through numbers; I'm doing that because I want to use the code to conduct timing experiments. I don't mind it not being super-efficient, part of the project for me will be making it more efficient myself....
0
2016-10-09T14:17:15Z
39,944,681
<p>Python's <code>list</code> does not have a <code>clear</code> method until Python 3.x. Your code will not work in Python 2.x or earlier. You can either create a new list or delete all the contents of the old list.</p> <pre><code>#create a new list primfac = [] #or delete all the contents of the old list del primf...
0
2016-10-09T14:26:35Z
[ "python", "list", "runtime-error" ]
.clear() for list not working - python
39,944,586
<p>I am writing some code that is supposed to find the prime factorization of numbers. The main function increments through numbers; I'm doing that because I want to use the code to conduct timing experiments. I don't mind it not being super-efficient, part of the project for me will be making it more efficient myself....
0
2016-10-09T14:17:15Z
39,944,686
<p>The <code>list.clear()</code> method was added in Python 3.3. The equivalent can be achieved in earlier versions by <code>del primfac[:]</code> instead.</p>
3
2016-10-09T14:26:50Z
[ "python", "list", "runtime-error" ]
Is there a really efficient (FAST) way to read large text files in python?
39,944,594
<p>I am looking to open and fetch data from a large text file in python as fast as possible (<strong>It almost has 62603143 lines - size 550MB</strong>). As I don't want to stress my computer, I am doing it by following way ,</p> <pre><code>import time start = time.time() for line in open(filePath): #considering d...
-3
2016-10-09T14:18:03Z
39,944,662
<p>No, there is no faster way of processing a file line by line, not from Python.</p> <p>Your bottleneck is <em>your hardware</em>, not how you read the file. Python is already doing everything it can (using a buffer to read the file in larger chunks before splitting into newlines).</p> <p>I suggest upgrading your di...
0
2016-10-09T14:25:08Z
[ "python", "python-2.7", "text-files" ]
Finding average in a file
39,944,637
<p>One of the things I'm supposed to do is find the average inflation from data in a file I was given. It gives the <code>year</code>, <code>interest</code>, and <code>inflation</code>, with all the numbers below it. Looks something like this.</p> <pre><code>year interest inflation 1900 4.61 8.1 </code></pre> <p>...
0
2016-10-09T14:21:21Z
39,944,678
<p>Your condition for appending to the header will never be met as <code>header += 1</code> is under the condition <code>header != 1</code> and <code>header</code>'s initial value is <code>1</code>. Therefore you are looping over the array and doing nothing. At the end of your method where you calculate the average, yo...
0
2016-10-09T14:26:25Z
[ "python", "average", "mean" ]
Finding average in a file
39,944,637
<p>One of the things I'm supposed to do is find the average inflation from data in a file I was given. It gives the <code>year</code>, <code>interest</code>, and <code>inflation</code>, with all the numbers below it. Looks something like this.</p> <pre><code>year interest inflation 1900 4.61 8.1 </code></pre> <p>...
0
2016-10-09T14:21:21Z
39,944,684
<p>You are initalizing <code>header = 1</code>, and you initialize the value of <code>infl</code> and <code>inflation</code> after checking if <code>header</code> is not one, hence, <code>avgInflation = sum(inflation)/len(inflation)</code> is effectively becoming: </p> <p><code>avgInflation = sum(0/len(0))</code></p> ...
0
2016-10-09T14:26:45Z
[ "python", "average", "mean" ]
Finding average in a file
39,944,637
<p>One of the things I'm supposed to do is find the average inflation from data in a file I was given. It gives the <code>year</code>, <code>interest</code>, and <code>inflation</code>, with all the numbers below it. Looks something like this.</p> <pre><code>year interest inflation 1900 4.61 8.1 </code></pre> <p>...
0
2016-10-09T14:21:21Z
39,944,705
<p>As I see you initiate variable <code>header</code> as 1 outside the for loop. Inside the for loop you check if the <code>header</code> is not equal to 1 and not do anything if it equals to 1. For loop never goes inside the <code>if header !=1:</code> It just iterates over your whole file and goes out of for loop w...
-1
2016-10-09T14:28:51Z
[ "python", "average", "mean" ]
Finding average in a file
39,944,637
<p>One of the things I'm supposed to do is find the average inflation from data in a file I was given. It gives the <code>year</code>, <code>interest</code>, and <code>inflation</code>, with all the numbers below it. Looks something like this.</p> <pre><code>year interest inflation 1900 4.61 8.1 </code></pre> <p>...
0
2016-10-09T14:21:21Z
39,944,987
<p>How about this?</p> <pre><code>def myTest(file): with open ('filename', 'r') as f: inflation = [] header = 1 for line in f: if header == 1: header += 1 continue else: infl = line.split(",")[2] inflati...
1
2016-10-09T14:57:30Z
[ "python", "average", "mean" ]
tring to export to csv file input from user in Tkinter
39,944,699
<p>I have code to take user import from Tkinter and put in a csv file. In the Tkinter window I can use pack to setup my input boxes but don't like the it and want to use grid instead. The following code works for pack but I can't figure out how to do it grid. Sorry I am one month into learing the language. Here is th...
0
2016-10-09T14:28:11Z
39,944,831
<p>Use grid try think is like use a table, you asign the tkinterObjects in a "table" and then asign row/column, something like this.</p> <pre><code>class App(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.pack() self.output() def output(self): firstNa...
0
2016-10-09T14:41:56Z
[ "python", "tkinter" ]
Python multiprocessing: Simple job split across many processes
39,944,824
<h3>EDIT</h3> <p>The proposed code actually worked! I was simply running it from within an IDE that wasn't showing the outputs. </p> <p>I'm leaving the question up because the comments/answers are instructive</p> <hr> <p>I need to split a big job across many workers. In trying to figure out how to do this, I used ...
0
2016-10-09T14:41:19Z
39,945,045
<p>Maybe it's your first time with multiprocessing? Do you wait for the processes to exit or do you exit the main processes before your processes have time to complete there job?</p> <pre><code>from multiprocessing import Process from string import ascii_letters from time import sleep def job(chunk): done = chun...
1
2016-10-09T15:04:43Z
[ "python", "multiprocessing" ]
Printing html like contents form a textarea using beautifulsoup
39,944,843
<p>We can get the text inside a tag using the get_text() function in BeautifulSoup. But what if the text area contains some html like code.</p> <p>Example:</p> <pre><code>from bs4 import BeautifulSoup html = "&lt;html&gt;&lt;h1&gt;#include &lt;stdio.h&gt;&lt;/h1&gt;&lt;/html&gt;" soup = BeautifulSoup(html,"lxml") pri...
0
2016-10-09T14:42:57Z
39,944,873
<p>The problem is the lt and gt signs should be escaped like below:</p> <pre><code>from bs4 import BeautifulSoup html = "&lt;html&gt;&lt;h1&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/h1&gt;&lt;/html&gt;" soup = BeautifulSoup(html,"lxml") print(soup.h1.get_text()) </code></pre> <p>Which would then give you:</p> <pre><c...
1
2016-10-09T14:45:09Z
[ "python", "html", "beautifulsoup" ]
Webdriver Timeout Exception
39,944,879
<p>I try to understand where is the problem in code:</p> <pre><code>class WebTest(unittest.TestCase): @classmethod def setUpClass(cls): binary = FirefoxBinary('/home/andrew/Downloads/firefox 45/firefox') cls.browser = webdriver.Firefox(firefox_binary=binary) cls.wait = WebDriverWait(cls.browser, 10) c...
-2
2016-10-09T14:46:00Z
39,947,669
<p>A <code>TimeoutException</code> can be received without having any logical or syntantic errors with your code.</p> <p><code>TimeoutException</code>s will be raised when the <code>wait.until</code> expected conditions aren't found.</p> <p>Some things I have found to help:</p> <ul> <li>Isolate the xpath by using ch...
0
2016-10-09T19:29:16Z
[ "python", "unit-testing", "selenium", "selenium-webdriver" ]
Django: How to properly make shopping cart? ( Array string field )
39,944,880
<p>Lately I've been needing to create a server-side shopping cart for my website that can have products inside. I could add cart and product in session cookies, but I prefer to add it to my custom made User model, so it can stay when the user decides to log out and log back in.</p> <p>Since I'm making a shopping cart,...
1
2016-10-09T14:46:05Z
39,945,128
<p>I'd suggest using DB relationships instead of storing a string or an array of strings for this problem.</p> <p>If you solve the problem using DB relationships, you'll need to use a <a href="https://docs.djangoproject.com/es/1.10/topics/db/examples/many_to_many/" rel="nofollow">ManyToManyField</a>.</p> <pre><code>c...
2
2016-10-09T15:13:38Z
[ "python", "django" ]
How to find adjacent pairs in a sequence, python
39,944,923
<p>For one of my assignments, I have to write a code that will look for adjacent pairs in a sequence. If there are no pairs in the sequence, the output has to be None. Could be a list, string, whatever. The code that I have only worked for half of the test files (the true ones), yet I am having trouble passing the fals...
-1
2016-10-09T14:50:51Z
39,945,109
<p>Loop through <code>xs</code> starting from the <em>second</em> item, and compare to the previous item:</p> <pre><code>def neighboring_twins(xs): for i in range(1, len(xs)): if xs[i] == xs[i-1]: return True return False </code></pre>
0
2016-10-09T15:11:23Z
[ "python", "python-3.x" ]
Strip string values in a dictionary and convert it to a float. Values contain numbers separated by space
39,944,982
<p>I have a dictionary setup with the following data:</p> <p><img src="http://i.stack.imgur.com/onSzu.jpg" alt="image of dictionary with values"></p> <p>where its values are a list of <strong>strings</strong>:</p> <pre><code>['2 1 0\n', '3 0 1\n', '4 0 3\n' .... ] ['-3.85995e-17 1.26224e+00 2.63053e-01\n'] </co...
1
2016-10-09T14:57:14Z
39,951,489
<p>You would probably have to find a library that handles such data to do it for you, I'm not aware of any native python method to convert a string into a list of floats. If you're looking to save space, it'd probably just be easiest to write your own function that takes one of your values and returns a list of floats....
0
2016-10-10T04:52:58Z
[ "python", "string", "dictionary" ]
Strip string values in a dictionary and convert it to a float. Values contain numbers separated by space
39,944,982
<p>I have a dictionary setup with the following data:</p> <p><img src="http://i.stack.imgur.com/onSzu.jpg" alt="image of dictionary with values"></p> <p>where its values are a list of <strong>strings</strong>:</p> <pre><code>['2 1 0\n', '3 0 1\n', '4 0 3\n' .... ] ['-3.85995e-17 1.26224e+00 2.63053e-01\n'] </co...
1
2016-10-09T14:57:14Z
39,975,028
<p>Thanks Xorgon!</p> <p>I also tried using list comprehensions as follows:</p> <pre><code>Connectivity = ['2 1 0\n', '3 0 1\n', '4 0 3\n'] aaa = [k.strip() for k in Connectivity] bbb = [k.split() for k in aaa] ccc = [[float(j) for j in i] for i in bbb] </code></pre> <p>But is there a faster way? The reason be...
0
2016-10-11T10:12:55Z
[ "python", "string", "dictionary" ]
Tensorflow reshape on convolution output gives TypeError
39,945,037
<p>When I try to reshape the output of a convolution using <code>tf.reshape()</code>, I get a TypeError</p> <pre><code>TypeError: Expected binary or unicode string, got -1 </code></pre> <p>The model I have written is:</p> <pre><code>with tf.name_scope('conv1'): filter = tf.Variable(tf.truncated_normal([5, 5, 1, ...
1
2016-10-09T15:03:53Z
39,945,609
<p>I had to do this before. Change this</p> <pre><code>shape = h2.get_shape() </code></pre> <p>to this:</p> <pre><code>shape = h2.get_shape().as_list() </code></pre>
0
2016-10-09T16:01:24Z
[ "python", "tensorflow" ]
Widget alignment in kivy
39,945,095
<p>i'm new in kivy and python and i would like to knkow what's wrong in my code. I want to align a Label widget and a TextInput widget in a same layout. In other words, the two widgets have to start from the same x coordinate! In my example, i set the same x coordinate in pos_hint('center_x':0.5), but the widgets aren'...
0
2016-10-09T15:10:30Z
39,945,516
<p>This is what you want If I'm right about what you mean.</p> <pre><code>self.add_widget(Label(text="Hello", size_hint=(None, None), pos_hint={'center_x':0.4, 'center_y':0.5})) self.add_widget(TextInput(text="MyText", multiline=False, size_hint=(0.1,0.05), pos_hint={'center_x':0.5, 'center_y':0.5})) </code></pre> <p...
0
2016-10-09T15:53:02Z
[ "python", "user-interface", "layout", "widget", "kivy" ]
How to create hierarchical columns in pandas?
39,945,122
<p>I have a pandas dataframe that looks like this:</p> <pre><code> rank_2015 num_2015 rank_2014 num_2014 .... num_2008 France 8 1200 9 1216 .... 1171 Italy 11 789 6 788 .... 654 </code></pre> <p>Now I want to draw a bar chart ...
0
2016-10-09T15:12:50Z
39,945,309
<p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/text.html#extracting-substrings" rel="nofollow"><code>str.extract</code></a> with the regex pattern <code>(.+)_(\d+)</code> to convert the columns to a DataFrame:</p> <pre><code>cols = df.columns.str.extract(r'(.+)_(\d+)', expand=True) # 0 ...
1
2016-10-09T15:33:20Z
[ "python", "pandas" ]
How to create hierarchical columns in pandas?
39,945,122
<p>I have a pandas dataframe that looks like this:</p> <pre><code> rank_2015 num_2015 rank_2014 num_2014 .... num_2008 France 8 1200 9 1216 .... 1171 Italy 11 789 6 788 .... 654 </code></pre> <p>Now I want to draw a bar chart ...
0
2016-10-09T15:12:50Z
39,945,320
<p>Probably you don't need re-shaping your dataset, it can be achieved easier.</p> <ol> <li>Create new dataset, which contains <code>num_</code> data only</li> <li>Rename columns</li> <li>Plot sum</li> </ol> <p>Dummy data:</p> <p><a href="http://i.stack.imgur.com/gzPeAm.png" rel="nofollow"><img src="http://i.stack.i...
1
2016-10-09T15:33:57Z
[ "python", "pandas" ]
Getting the ratio of a in b
39,945,155
<p>This is the current code I have, the issue is clearly that I can't divide strings by strings, but I'm unsure of how to go about editing the code to get it to run.</p> <pre><code>def Fraction(c, s): #Returns the fraction of 's' formed by 'c'. return c / s print(Fraction("a", "ababab")) </code></pre> <p>In t...
-1
2016-10-09T15:17:27Z
39,945,245
<p>Apparently you want a ratio here; a number between 0.0 and 1.0 indicating what percentage of a larger string is using a smaller string:</p> <pre><code>def ratio(c, s): return (float(s.count(c) * len(c))) / len(s) </code></pre> <p>Demo:</p> <pre><code>&gt;&gt;&gt; def ratio(c, s): ... return (float(s.count...
0
2016-10-09T15:26:32Z
[ "python", "python-3.x" ]
Ho do i make one to many relations in list of tuples
39,945,162
<p>I have a list consisting of tuples like the following:</p> <pre><code>m = [('a', 'b', 'c', 'd'), (1, 2, 3, 4), ('alpha', 'beta', 'gamma', 'eta')] </code></pre> <p>how can i get the following output:</p> <pre><code>['c', 3, 'gamma'] </code></pre> <p>need only for 'c' and not for rest of the elements a,b,d</p>
0
2016-10-09T15:18:18Z
39,945,357
<p>Variable 'm' contains list of tuples, there are 3 tuples considered as 3 items in list. </p> <p>Variable 'n' takes each element (tuple) in the list and prints its value according to its index number.</p> <pre><code>m = [('a', 'b', 'c', 'd'), (1, 2, 3, 4), ('alpha', 'beta', 'gamma', 'eta')] for n in m: print (n...
1
2016-10-09T15:37:19Z
[ "python", "list", "python-3.x", "tuples" ]
Unable to click-iterate through elements using selenium
39,945,175
<p>Im trying to click-iterate through google-translate element but the code isnt working </p> <pre><code>from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import ...
1
2016-10-09T15:19:11Z
39,945,554
<pre><code>from selenium import webdriver from selenium.webdriver.common.by import By import time driver = webdriver.Chrome() driver.maximize_window() driver.get("https://www.tripadvisor.com.br/ShowUserReviews-g1-d8729164-r425802060-TAP_Portugal-World.html") gt= driver.find_elements(By.CSS_SELECTOR,".googleTranslation...
1
2016-10-09T15:56:07Z
[ "python", "selenium", "web-scraping" ]
Why does `set_index` create an index label for the column name?
39,945,178
<p>I have a CSV file which begins like this:</p> <pre><code>Year,Boys,Girls 1996,333490,315995 1997,329577,313518 1998,325903,309998 </code></pre> <p>When I read it into pandas and set an index, it isn't doing quite what I expect:</p> <pre><code>df = pd.read_csv('../data/myfile.csv') df.set_index('Year', inplace=Tru...
2
2016-10-09T15:19:34Z
39,945,278
<p>You should set the name attribute of your index to <code>None</code>:</p> <pre><code>df.index.names = [None] df.head() # Boys Girls #1996 333490 315995 #1997 329577 313518 #1998 325903 309998 </code></pre> <p>As for retrieving the data for <code>1998</code>, simply lose the quotes:</p> <pre><cod...
2
2016-10-09T15:29:42Z
[ "python", "pandas" ]
Add game loop to tornado server in python
39,945,256
<p>I've got a standard <code>tornado</code> application in <code>python</code>.</p> <p>I am going to be making a game server using tornado's <code>websockets</code>.</p> <p>The problem is, I need a game loop running on the server, to do things.</p> <p>I could create a web handler '/startserver' and add the following...
0
2016-10-09T15:27:08Z
39,945,966
<p>You could just start it in the background like:</p> <pre><code>@gen.coroutine def game_loop(): while True: # Whatever your game loop does. print("tick") yield gen.sleep(1) if __name__ == "__main__": app = make_app() app.listen(8888) loop = tornado.ioloop.IOLoop.current() ...
1
2016-10-09T16:40:26Z
[ "python", "loops", "tornado" ]
Python SSHTunnel w/ Paramiko - CLI works, but not in script
39,945,269
<p><em>Context:</em><br> I'm trying to connect to a remote MySQL install through SSH and in Python. I'm using paramiko and SSHTunnel, and currently on py 2.7.</p> <p>I have had success connecting and querying records in the remote DB using bash shell, paramiko's forward.py, and even SSHTunnel's CLI command.</p> <p><...
0
2016-10-09T15:28:53Z
39,946,827
<p>Found the answer!</p> <p>It turns out that the script continues to execute before the connection is established. Therefore MySQLDB tries to connect to the port mapping before the tunnel is fully established.</p> <p>A simple:</p> <pre><code>import time ... sleep(1) ... </code></pre> <p>Does the trick.</p> <p>In...
0
2016-10-09T18:05:33Z
[ "python", "mysql", "ssh" ]
Removing first character in a String leaves whitespace
39,945,294
<p>I have a textfile that looks like this:</p> <pre><code>6 Hello World </code></pre> <p>I'm reading it in as such:</p> <pre><code>with open("test.txt") as fp: for line in fp: l = line.split(" ") print(l) </code></pre> <p>Which prints me the entire string:</p> <pre><code>6 Hello World </code></...
1
2016-10-09T15:31:33Z
39,945,307
<p>That's because <code>newStr.replace(newStr[0],"")</code> is the same as <code>newStr.replace(" ","")</code> which replaces every instance of a single space with an empty string. </p> <p>What you want is <code>lstrip</code> which removes all leading whitespaces from your string.</p> <p>More so, to be less verbose...
1
2016-10-09T15:33:05Z
[ "python" ]
Removing first character in a String leaves whitespace
39,945,294
<p>I have a textfile that looks like this:</p> <pre><code>6 Hello World </code></pre> <p>I'm reading it in as such:</p> <pre><code>with open("test.txt") as fp: for line in fp: l = line.split(" ") print(l) </code></pre> <p>Which prints me the entire string:</p> <pre><code>6 Hello World </code></...
1
2016-10-09T15:31:33Z
39,945,350
<p>An alternative, if you want to skip the replacing altogether (and assuming that all of your data follows this pattern) is just to take everything from the second element of the list returned by the <code>.strip()</code> on, using <code>join</code> and slicing, as in:</p> <pre><code>l = " ".join(line.split(" ")[1:])...
0
2016-10-09T15:36:32Z
[ "python" ]
Writing multiple rows into CSV file
39,945,349
<p>I'm trying to write multiple rows in to a CSV file using python and I've been working on this code for a while to piece together how to do this. My goal here is simply to use the oxford dictionary website, and web-scrape the year and words created for each year into a csv file. I want each row to start with the year...
0
2016-10-09T15:36:28Z
39,946,104
<p>You really shouldn't parse html with a regex. That said, here's how to modify your code to produce a csv file of all the words found. </p> <p>Note: for unknown reasons the list of result word varies in length from one execution to the next.</p> <pre><code>import csv import os import re import requests import urlli...
3
2016-10-09T16:54:50Z
[ "python", "csv", "web-scraping" ]
python: numpy-equivalent of list.pop?
39,945,410
<p>Is there a numpy method which is equivalent to the builtin <code>pop</code> for python lists? popping obviously doenst work on numpy arrays, and I want to avoid a list conversion.</p>
0
2016-10-09T15:42:49Z
39,945,494
<p>There is no <code>pop</code> method for NumPy arrays, but you could just use basic slicing (which would be efficient since it returns a view, not a copy):</p> <pre><code>In [104]: y = np.arange(5); y Out[105]: array([0, 1, 2, 3, 4]) In [106]: last, y = y[-1], y[:-1] In [107]: last, y Out[107]: (4, array([0, 1, 2,...
3
2016-10-09T15:51:13Z
[ "python", "arrays", "list", "numpy", "pop" ]
keras import error no attribute 'getdlopenflags'
39,945,443
<p>I am new to <code>keras</code>, and I have downloaded <code>theano</code>, <code>scipy</code> and <code>numpy</code> modules, but when I want to <code>import keras</code>, the command window tells me that </p> <pre><code>"Using TensorFlow backend. Traceback (most recent call last): File "F:\eclipse\dasd\aaa\aaaa.py...
0
2016-10-09T15:45:26Z
39,945,942
<p>Keras is using Tensorflow by default. You need to explicitly switch to Theano, see the <a href="https://keras.io/backend/" rel="nofollow">official documentation</a> for the current procedure, for example by setting the environment variable <code>KERAS_BACKEND</code> to <code>theano</code>.</p>
0
2016-10-09T16:38:26Z
[ "python", "machine-learning", "theano", "keras" ]
How to verify only the elements names in a dictionary object?
39,945,475
<p>I have a VERY big dictionary in python and when I type dict.items(dic_name) it shows up so many stuff (matrix, vectors, etc). I just would like to see the elements names. What should I do?</p> <p>For example when I have a list I type names (<code>my.list</code>) and it just displays the list elements name. Is ther...
-2
2016-10-09T15:49:33Z
39,945,633
<p>Well, if you only keys, ask for keys, not items :</p> <pre><code>my_dict.keys() </code></pre> <p>If you strictly need it to be a list you can do :</p> <pre><code>my_list = list(my_dict.keys()) </code></pre> <p>Now if you want to iterate through them:</p> <p>in python 2:</p> <pre><code>for k in my_dict.iterkeys...
1
2016-10-09T16:04:51Z
[ "python", "python-2.7", "python-3.x" ]
Callback not called if it is a class method
39,945,584
<p>Python newbie question: the callback method <code>handlePackets</code> never gets called if it is a class method. If it is not in a class it works fine. What can I do?</p> <pre><code>class Receiver: def __enter__(self): self.serial_port = serial.Serial('/dev/ttyUSB0', 115200) self.xbee = ZigBee...
0
2016-10-09T15:59:23Z
39,945,648
<p>I can bet it is because, whatever is calling your callback from within <code>ZigBee</code> is failing silently. The interpreter calls your function with 2 parameters, but as you have defined it -- it takes only one.</p> <pre><code>def handlePackets(self, data): #^^^^ </code></pre>
0
2016-10-09T16:05:47Z
[ "python", "python-2.7" ]
Callback not called if it is a class method
39,945,584
<p>Python newbie question: the callback method <code>handlePackets</code> never gets called if it is a class method. If it is not in a class it works fine. What can I do?</p> <pre><code>class Receiver: def __enter__(self): self.serial_port = serial.Serial('/dev/ttyUSB0', 115200) self.xbee = ZigBee...
0
2016-10-09T15:59:23Z
39,945,716
<p>I had to add <code>self</code> as first parameter to packetHandler. This is required for all class methods and I forgot to put it in.</p>
0
2016-10-09T16:12:56Z
[ "python", "python-2.7" ]
PolarColor map plot of grid data in Pyhton
39,945,601
<p>I want to plot a color map of a grid data, grid in polar form. In data, r ranges from 1 to 2 and theta 0 to 360. I want map like this:</p> <p><a href="http://i.stack.imgur.com/NEFQ0.png" rel="nofollow"><img src="http://i.stack.imgur.com/NEFQ0.png" alt="enter image description here"></a> I plotted like this </p>...
1
2016-10-09T16:00:44Z
39,946,574
<p>As pointed out <a href="http://stackoverflow.com/a/6457331/6935985">here</a>, <code>pcolormesh()</code> is useful for this.</p> <pre><code>import matplotlib.pyplot as plt import numpy as np theta = np.linspace(0, 2*np.pi, 36) r = np.linspace(1, 2, 12) R, THETA = np.meshgrid(r, theta) Z = np.sin(THETA) * R plt.su...
1
2016-10-09T17:41:55Z
[ "python", "matlab", "matplotlib" ]
Converting input string of integers to list, then to ints in python?
39,945,615
<p>I want the user to input an integer (6 digits long, so 123456 rather than just 1), and then convert that input into a list, <code>[1,2,3,4,5,6]</code>.</p> <p>I tried this:</p> <pre><code>user_input = list(input("Please enter an 8 digit number") numbers = [int(i) for i in user_input] </code></pre> <p>I want to be...
2
2016-10-09T16:02:32Z
39,945,689
<p>In Python 2.7, <code>input()</code> returns an integer. To read input as a string use the function <code>raw_input()</code> instead. Alternatively, you can switch to Python 3 and where <code>input()</code> always returns a string.</p> <p>Also your solution isn't very neat in case the user is providing numbers with ...
1
2016-10-09T16:10:20Z
[ "python" ]
Converting input string of integers to list, then to ints in python?
39,945,615
<p>I want the user to input an integer (6 digits long, so 123456 rather than just 1), and then convert that input into a list, <code>[1,2,3,4,5,6]</code>.</p> <p>I tried this:</p> <pre><code>user_input = list(input("Please enter an 8 digit number") numbers = [int(i) for i in user_input] </code></pre> <p>I want to be...
2
2016-10-09T16:02:32Z
39,945,704
<p>Function <code>input</code> behaves quite differently in Python 2 and in Python 3.</p> <p>This seems to be Python 2. In Python 2, <code>input</code> evaluates entered data as Python code. If only digits are entered, <code>input</code> will return one integer. Converting that to a list is not possible, hence the err...
1
2016-10-09T16:11:54Z
[ "python" ]
Adding values from a dataframe-A A.column1 by matching values in A.column2 to the B.column1 name of another dataframe B
39,945,643
<p>I have two dataframes (df) A and B. df A has a column called 'Symbol' with non-unique stock-ticker-symbols as values in random order and the corresponding amount of buy or sell quantities in another column called 'Shares'; it is indexed by non-negative integers. df B, indexed by dates in the same date-order as df A ...
0
2016-10-09T16:05:22Z
39,946,054
<p>first of all, I highly suggest you to read <a href="http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples">how-to-make-good-reproducible-pandas-examples</a></p> <p>I think you could use pivot such has:</p> <pre><code>B = A.pivot('Date','Symbol','Shares') </code></pre> <p>Since ...
0
2016-10-09T16:49:42Z
[ "python", "pandas", "join", "dataframe" ]
TfidfVectorizer: ValueError: not a built-in stop list: russian
39,945,693
<p>I try to apply TfidfVectorizer with russian stop words </p> <pre><code>Tfidf = sklearn.feature_extraction.text.TfidfVectorizer(stop_words='russian' ) Z = Tfidf.fit_transform(X) </code></pre> <p>and i get</p> <pre><code>ValueError: not a built-in stop list: russian </code></pre> <p>When i use english stop words t...
0
2016-10-09T16:10:47Z
39,945,754
<p>could you guys read <a href="http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.TfidfVectorizer.html" rel="nofollow">documentation</a> first before posting?</p> <blockquote> <p>stop_words : string {‘english’}, list, or None (default)</p> <p>If a string, it is passed to _chec...
1
2016-10-09T16:16:19Z
[ "python", "tf-idf" ]
httplib.HTTPSConnection issue : CERTIFICATE_VERIFY_FAILED
39,945,702
<p>I'm trying to access a website with httplib library but i'm getting this error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)</p> <pre><code>c = httplib.HTTPSConnection('IP', 443) c.request(method,url); </code></pre> <p>Because the certificate is self-signed. How can I disable the certifi...
0
2016-10-09T16:11:45Z
39,945,733
<p><a href="http://stackoverflow.com/questions/5319430/how-do-i-have-python-httplib-accept-untrusted-certs">How do I have python httplib accept untrusted certs?</a></p> <pre><code>httplib.HTTPSConnection(hostname, timeout=5, context=ssl._create_unverified_context()) </code></pre>
2
2016-10-09T16:14:45Z
[ "python" ]
Reading a pre-formatted file using read() in python
39,945,719
<p>I am trying to build a mini text based game just as a first project in python. I decided to write my story and content in text files. I am designing the game such that each character from the file is read and immediately printed out to the screen. </p> <pre><code>def load_Intro(): liOb = open('loadgame.txt','r') wh...
0
2016-10-09T16:13:28Z
39,945,776
<p>Why try to read character by character? Read it all into the buffer at once, and then display it character by character</p> <pre><code>import sys import time liOb = open('loadgame.txt','r') content=str(liOb.read()) for i in range(len(content)): sys.stdout.write(content[i]) time.sleep(0.002) sys.stdout...
0
2016-10-09T16:19:10Z
[ "python", "python-3.x", "python-3.5" ]
Fixing return format for my function
39,945,808
<p>The code for my function works correctly, but it is not returning the function in the format I would like. The function counts seed values in a 2nd sequence and then is supposed to return the seed counts as a list of integers. It is returning the seed counts but on separate lines rather then in a list. Here is my co...
1
2016-10-09T16:23:02Z
39,945,945
<p>I think your code does not work. Try this:</p> <pre><code>def count_each(seeds,xs): from collections import Counter counter_dict = dict(Counter(xs)) count = [] for s in seeds: count.append(counter_dict[s]) print count if __name__ == "__main__": count_each([10,20],[10,20,30,10]) ...
0
2016-10-09T16:38:39Z
[ "python", "list", "format", "sequence" ]