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
Python - Key detection with simple modules
38,843,224
<p>I'm trying to make a text editor for MicroPython. This 'nano'-like(or vim) text editor should be able to run <em>on</em> the device, what I'm not looking for is modules that would not run on the <strong>ESP8266</strong>.</p> <p>What I'm using at the moment is simple modules such as '<em>sys</em>' and '<em>os</em>'...
0
2016-08-09T06:07:04Z
38,844,113
<p><strong>EDIT: Added some content of the links to improve the answer</strong></p> <p>Extract of libs that MicroPython have</p> <p><strong>Builtin Functions</strong></p> <p><code>cmath</code> – mathematical functions for complex numbers</p> <p><code>gc</code> – control the garbage collector</p> <p><code>math<...
1
2016-08-09T06:58:46Z
[ "python", "text", "editor", "esp8266", "micropython" ]
O_NONBLOCK does not raise exception in Python
38,843,278
<p>I am trying to write a "cleaner" program to release a potential writer which is blocked at a named pipe (because no reader is reading from the pipe). However, the cleaner itself <strong>should not</strong> block when no writer is blocked writing to the pipe. In other words, the "cleaner" must return/terminate immedi...
0
2016-08-09T06:10:43Z
38,860,390
<p>This solution is incorrect.</p> <pre><code>while True: buffer = os.read(ph, BUFFER_SIZE) if len(buffer) &lt; BUFFER_SIZE: break </code></pre> <p>This will not actually read everything, it will only read until it gets a partial read. Remember: You are only guaranteed to fill the buffer with regular...
0
2016-08-09T21:03:44Z
[ "python", "linux", "system-calls" ]
Bug with radiobutton - tkinter
38,843,391
<p>I use Tkinter for make a GUI. I have a window with 2 radiobutton ('Yes' and 'No'), but when I select one, it don't run the script :</p> <pre><code>root = Tk() Button(root, text='TEST', command=root.quit).pack() root.mainloop() master = Tk() v = IntVar() Radiobutton(master, text='Yes', variable=v, value=0).pack(...
0
2016-08-09T06:17:04Z
38,843,749
<ol> <li>You have initiated several <code>Tk()</code> systems, but there should be only one.</li> <li>If you want to get a new window then use <code>Toplevel()</code></li> <li>No code is executed after <code>mainloop()</code> except for events. The code continues to "flow" after <code>mainloop</code> only after closing...
1
2016-08-09T06:38:14Z
[ "python", "tkinter" ]
Trying to make a development instance for a Python pyramid project
38,843,404
<p>So I have this Python pyramid-based application, and my development workflow has basically just been to upload changed files directly to the production area.</p> <p>Coming close to launch, and obviously that's not going to work anymore.</p> <p>I managed to edit the connection strings and development.ini and point ...
2
2016-08-09T06:17:54Z
38,844,340
<p>The first thing you should do, if it's not the case, is version control your project. I'd recommend using git.</p> <p>In addition to the benefits of managing the changes made to the application when developing, it will aldo make it easier to share copies between developers... or with the production deployment. Inde...
2
2016-08-09T07:13:00Z
[ "python", "pyramid", "pylons" ]
Trying to make a development instance for a Python pyramid project
38,843,404
<p>So I have this Python pyramid-based application, and my development workflow has basically just been to upload changed files directly to the production area.</p> <p>Coming close to launch, and obviously that's not going to work anymore.</p> <p>I managed to edit the connection strings and development.ini and point ...
2
2016-08-09T06:17:54Z
38,886,655
<p>Here's how I managed my last Pyramid app:</p> <p>I had both a <code>development.ini</code> and a <code>production.ini</code>. I actually had a <code>development.local.ini</code> in addition to the other two - one for local development, one for our "test" system, and one for production. I used git for version contr...
1
2016-08-11T03:11:20Z
[ "python", "pyramid", "pylons" ]
I'm trying to create ashapefile of x,y coordinates from a txt. file but am getting the following error
38,843,492
<p>Traceback (most recent call last): File "C:\Users\Brett\Desktop\Jefferson_final.py", line 31, in point = arcpy.Point(coordinate[0],coordinate[1]) IndexError: list index out of range</p> <p>Here is my script</p> <pre><code>import arcpy import fileinput import os import string arcpy.env.workspace = "C:\Users\...
-2
2016-08-09T06:23:01Z
38,843,661
<p>You are not opening the file input_data and reading the input data from it then splitting the data.</p> <pre><code>inputname = r"C:\Users\Brett\Desktop\San Clemente\San Clemente Lat Long.txt" inputdata = [l.spilt(',') for l in open(inputname).readlines()] </code></pre> <p>Should get you further - you will also hav...
2
2016-08-09T06:32:50Z
[ "python", "arcpy", "arcmap" ]
Function templates in python
38,843,599
<p>I would like to know how would I use similar code to <strong>template &lt; typename T></strong> in python, as it is used in the C++ code example:</p> <pre><code>template &lt;typename T&gt; unsigned int counting_bit(unsigned int v){ v = v - ((v &gt;&gt; 1) &amp; (T)~(T)0/3); // temp v...
-1
2016-08-09T06:29:47Z
38,843,653
<p>Just pass the type to the function.</p> <p>For example, see this (useless) function:</p> <pre><code>def converter(x, required_type): return required_type(x) converter('1', int) converter('1', float) </code></pre>
2
2016-08-09T06:32:34Z
[ "python", "c++", "templates", "function-templates" ]
Function templates in python
38,843,599
<p>I would like to know how would I use similar code to <strong>template &lt; typename T></strong> in python, as it is used in the C++ code example:</p> <pre><code>template &lt;typename T&gt; unsigned int counting_bit(unsigned int v){ v = v - ((v &gt;&gt; 1) &amp; (T)~(T)0/3); // temp v...
-1
2016-08-09T06:29:47Z
38,843,744
<p>Python is strongly, dynamically typed.</p> <p><strong>Dynamic</strong> typing means that runtime objects have a type, as opposed to static typing where variables have a type</p> <p><strong>Strong</strong> typing means that the type of a value doesn't suddenly change. A string containing only digits doesn't magica...
0
2016-08-09T06:37:55Z
[ "python", "c++", "templates", "function-templates" ]
Function templates in python
38,843,599
<p>I would like to know how would I use similar code to <strong>template &lt; typename T></strong> in python, as it is used in the C++ code example:</p> <pre><code>template &lt;typename T&gt; unsigned int counting_bit(unsigned int v){ v = v - ((v &gt;&gt; 1) &amp; (T)~(T)0/3); // temp v...
-1
2016-08-09T06:29:47Z
38,844,698
<p>DeepSpace's answer could be embellished to make things more C++-like by using Python's closures to do something like the following to create functions for specific types by applying the template. It also shows how easy it is in Python to obtain and use the type of another variable. </p> <pre><code>def converter_tem...
1
2016-08-09T07:33:42Z
[ "python", "c++", "templates", "function-templates" ]
Converts a date from the form yyyy/mm/dd to the form month_name day, year
38,843,636
<pre><code>MONTHS = ['January', 'February', 'Match', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def date_convert(s): y = s[:4] m = int(s[5:-3]) d = s[8:] if m &lt; 10: nm = int(m[1:]) month_name = MONTHS[nm - 1] else: mon...
-2
2016-08-09T06:31:50Z
38,844,057
<p>Try this:</p> <pre><code>from datetime import datetime d = "2000/06/24" date_obj = datetime.strptime(d, "%Y/%m/%d") formatted_date = datetime.strftime(date_obj, "%B %d %Y") print(formatted_date) </code></pre> <p>So you can make d as a variable to be passed as an argument in the function you are using. </p> <pre>...
0
2016-08-09T06:55:27Z
[ "python" ]
Converts a date from the form yyyy/mm/dd to the form month_name day, year
38,843,636
<pre><code>MONTHS = ['January', 'February', 'Match', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def date_convert(s): y = s[:4] m = int(s[5:-3]) d = s[8:] if m &lt; 10: nm = int(m[1:]) month_name = MONTHS[nm - 1] else: mon...
-2
2016-08-09T06:31:50Z
38,844,084
<p>Usually you don't parse/reformat/convert dates in Python manually. There are many beautiful functions and even modules for that. The problem is that the date conversion process though may seem simple is complicated and error prone. That's why it is not reimplemented every time, but implemented in so many details as...
0
2016-08-09T06:57:05Z
[ "python" ]
Converts a date from the form yyyy/mm/dd to the form month_name day, year
38,843,636
<pre><code>MONTHS = ['January', 'February', 'Match', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def date_convert(s): y = s[:4] m = int(s[5:-3]) d = s[8:] if m &lt; 10: nm = int(m[1:]) month_name = MONTHS[nm - 1] else: mon...
-2
2016-08-09T06:31:50Z
38,844,170
<pre><code>MONTHS = ['January', 'February', 'Match', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def date_convert(s): y = s[:4] m = int(s[5:-3]) d = s[8:] month_name = MONTHS[m-1] result= month_name + ' ' + d + ' ' + y return result s = '2000/06/24' ...
0
2016-08-09T07:02:47Z
[ "python" ]
The sum of indexes within nested lists. Adding elements from separate lists
38,843,761
<p>Just doing an exercise question as follows: Take a ' number square' as a parameter and returns a list of the <strong>column sums</strong>.</p> <p>e.g</p> <pre><code>square = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] ] </code></pre> <p>Result should be =</p> <pre><code>[28, 32, 36, 40] </cod...
1
2016-08-09T06:38:41Z
38,843,801
<p>It should be <code>col_sum += square[j][i]</code> since you want to access the element at position <code>j</code> of the list at position <code>i</code>.</p>
1
2016-08-09T06:40:46Z
[ "python", "python-3.x" ]
The sum of indexes within nested lists. Adding elements from separate lists
38,843,761
<p>Just doing an exercise question as follows: Take a ' number square' as a parameter and returns a list of the <strong>column sums</strong>.</p> <p>e.g</p> <pre><code>square = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] ] </code></pre> <p>Result should be =</p> <pre><code>[28, 32, 36, 40] </cod...
1
2016-08-09T06:38:41Z
38,844,035
<p>You should change the line of summing to:</p> <pre><code>col_sum += square[j][i] </code></pre> <p>because square[j] is the <code>j'th</code> row (list), but you need the current column, which is the <code>i'th</code> element in that row.</p> <p>But here is my solution using <code>sum</code> and list comprehension...
1
2016-08-09T06:54:28Z
[ "python", "python-3.x" ]
The sum of indexes within nested lists. Adding elements from separate lists
38,843,761
<p>Just doing an exercise question as follows: Take a ' number square' as a parameter and returns a list of the <strong>column sums</strong>.</p> <p>e.g</p> <pre><code>square = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16] ] </code></pre> <p>Result should be =</p> <pre><code>[28, 32, 36, 40] </cod...
1
2016-08-09T06:38:41Z
38,844,252
<p>A more simpler solution would be to <em>transpose</em> the list of lists with <code>zip</code> and take the <code>sum</code> across each new sublist:</p> <pre><code>def column_sums(square): return [sum(i) for i in zip(*square)] </code></pre> <p><code>zip(*square)</code> <em>unpacks</em> the list of lists and r...
2
2016-08-09T07:08:06Z
[ "python", "python-3.x" ]
passing a 2D array from python to swagger
38,843,886
<p>I am confused by why this doesn't work. Here is my swagger.yaml part where it defines what a result is. The code that links to this returns an array of arrays: </p> <blockquote> <p>[[string,float],....]</p> </blockquote> <p>when i switch this array to </p> <blockquote> <p>[string,string,...]</p> </blockquot...
1
2016-08-09T06:45:32Z
38,982,663
<p>Nested arrays were not permitted in swagger until 2.0.</p> <p>If you are using 1.2 or earlier then you cannot directly nest arrays. See <a href="http://docs.swagger.io/spec.html" rel="nofollow">section 4.3.3</a> of the 1.2 spec, specifically it indicates 'A container MUST NOT be nested in another container.'</p> <...
2
2016-08-16T19:07:08Z
[ "python", "multidimensional-array", "swagger" ]
Matching geographic time series to known ways
38,844,131
<p>I just started a project where I have a set of path data (given as points with timestamp) and want to match this data to given ways and points from other databases (such as openstreetmap). My task is to determine if a record matches a stored way and to correct for possible distortions in the data. The data size of m...
0
2016-08-09T06:59:58Z
38,845,058
<p>With the help from another user I found the answer to my question. The topic I was looking for is called map matching, and I found a Github page that gives an overview and some code to work with: <a href="https://github.com/graphhopper/map-matching" rel="nofollow">https://github.com/graphhopper/map-matching</a></p>...
0
2016-08-09T07:52:36Z
[ "python", "geolocation", "computational-geometry" ]
Send data from django to html
38,844,310
<p>I want to get data from database and send that to html page using django-python.</p> <p>What I'm doing in python file is</p> <pre><code>def module1(request): table_list=student.objects.all() context={'table_list' : table_list} return render(request,'index.html',context) </code></pre> <p>And in htm...
0
2016-08-09T07:11:13Z
38,845,084
<p>So far as we don't see your <code>student</code> model (which should be in your <code>models.py</code> and be imported in your <code>vievs.py</code>) and your code doesn't throw any exceptions it seems that your <code>table_list</code> is empty. To iterate it in more convenient way you can use built in <code>for ......
0
2016-08-09T07:54:48Z
[ "python", "html", "django" ]
filtering out some lines
38,844,451
<p>I have a text file (a.txt). here a small part of that:</p> <pre class="lang-none prettyprint-override"><code>ENSG00000060642.6 0,023999998 0,015999999 0,666666667 0,006410256 0,006410256 1,000000073 0,016393442 0,016393442 1 0,020202022 0,030303031 1,499999908 ENSG00000149136.3 0,03508772 0,01754386 0,5 0,0...
2
2016-08-09T07:19:45Z
38,844,494
<pre><code>for line in open('a.txt').read().splitlines(): if '#DIV/0!' not in line: print(line) </code></pre>
0
2016-08-09T07:21:38Z
[ "python", "file" ]
filtering out some lines
38,844,451
<p>I have a text file (a.txt). here a small part of that:</p> <pre class="lang-none prettyprint-override"><code>ENSG00000060642.6 0,023999998 0,015999999 0,666666667 0,006410256 0,006410256 1,000000073 0,016393442 0,016393442 1 0,020202022 0,030303031 1,499999908 ENSG00000149136.3 0,03508772 0,01754386 0,5 0,0...
2
2016-08-09T07:19:45Z
38,844,654
<pre><code>new_file = open('output.txt' , 'w') for line in open('a.txt').read().splitlines(): if '#DIV/0!' not in line: new_file.write(line) new_file.close() </code></pre>
0
2016-08-09T07:31:12Z
[ "python", "file" ]
filtering out some lines
38,844,451
<p>I have a text file (a.txt). here a small part of that:</p> <pre class="lang-none prettyprint-override"><code>ENSG00000060642.6 0,023999998 0,015999999 0,666666667 0,006410256 0,006410256 1,000000073 0,016393442 0,016393442 1 0,020202022 0,030303031 1,499999908 ENSG00000149136.3 0,03508772 0,01754386 0,5 0,0...
2
2016-08-09T07:19:45Z
38,844,890
<pre><code>with open('a.txt') as f, open('b.txt', 'w') as new_file: new_file.writelines([line for line in f if '#DIV/0!' not in line]) </code></pre> <hr> <p>Edit:</p> <p>This method is probably the fastest. But as discussed with @martineau earlier, it could not be the best answer here depending of the size your ...
1
2016-08-09T07:44:20Z
[ "python", "file" ]
filtering out some lines
38,844,451
<p>I have a text file (a.txt). here a small part of that:</p> <pre class="lang-none prettyprint-override"><code>ENSG00000060642.6 0,023999998 0,015999999 0,666666667 0,006410256 0,006410256 1,000000073 0,016393442 0,016393442 1 0,020202022 0,030303031 1,499999908 ENSG00000149136.3 0,03508772 0,01754386 0,5 0,0...
2
2016-08-09T07:19:45Z
38,844,988
<p>You could do it this way which is incremental (so it doesn't read the entire file into memory at one time):</p> <pre><code>from itertools import ifilter with open('a.txt', 'r') as inf, open('new.txt', 'w') as outf: outf.writelines(ifilter(lambda line: '#DIV/0!' not in line, inf)) </code></pre>
1
2016-08-09T07:49:02Z
[ "python", "file" ]
yowsup2 no module named _sqlite3
38,844,477
<p>I'm having the below error when I try to run the yowsup-cli command to send a message. This is the command I'm running: </p> <pre><code>yowsup-cli demos -c /etc/yowsup-cli.conf -s 'phone number' "text" </code></pre> <p>I'm running it on Linux CentOS 5.11 which comes with python 2.4 preinstalled. I installed python...
0
2016-08-09T07:20:51Z
38,847,994
<p>I managed to fix it by copying the module manually to the below path:</p> <pre><code>cp build/lib.linux-x86_64-2.7/_sqlite3.so /usr/lib/python2.7/lib-dynload/ </code></pre>
0
2016-08-09T10:14:03Z
[ "python", "yowsup" ]
CGI GET PHP to Python
38,844,501
<p>I currently have a HTML/PHP form redirect variables and it's values to Python via GET:</p> <pre><code> &lt;/script&gt; &lt;form id="form" target="_blank" style="display:none;" action="result.py" method="get"&gt; &lt;/form&gt; </code></pre> <p>The output of which results looking like this: <a href="http:...
0
2016-08-09T07:22:00Z
38,844,657
<p>You want to use Python via CGI? It's been supported for a very long time.</p> <p>This tutorial should set you on the right path: <a href="http://www.tutorialspoint.com/python/python_cgi_programming.htm" rel="nofollow">http://www.tutorialspoint.com/python/python_cgi_programming.htm</a></p> <p>It answers your questi...
0
2016-08-09T07:31:22Z
[ "php", "python", "cgi" ]
Can I convert an Odoo browse object to JSON
38,844,651
<p>I'm trying to integrate <code>reactjs</code> with <code>Odoo</code>, and successfully created components. Now my problem is that I cant get the JSON via odoo. The odoo programmer has to write special api request to make this happen. This is taking more time and code repetitions are plenty. </p> <p>I tried may sugge...
1
2016-08-09T07:31:08Z
38,847,214
<p>maybe this will help you:</p> <p>Step 1: Create js that runs reqiest to <code>/example_link</code></p> <p>Step 2: Create controller who listens that link <code>@http.route('/example_link', type="json")</code></p> <p>Step 3: return from that function json <code>return json.dumps(res)</code> where res is python dic...
0
2016-08-09T09:40:31Z
[ "python", "json", "odoo-8" ]
How to update user password in Django Rest Framework?
38,845,051
<p>I want to ask that following code provides updating password but I want to update password after current password confirmation process. So what should I add for it? Thank you.</p> <pre><code>class UserPasswordSerializer(ModelSerializer): class Meta: model = User fields = [ 'password' ] ext...
1
2016-08-09T07:52:05Z
38,846,554
<p>I believe that using a modelserializer might be an overkill. This simple serializer &amp; view should work.</p> <pre><code>class ChangePasswordSerializer(serializers.Serializer): """ Serializer for password change endpoint. """ old_password = serializers.CharField(required=True) new_password = s...
1
2016-08-09T09:11:27Z
[ "python", "django", "django-rest-framework" ]
np_utils.to_categorical Reverse
38,845,097
<pre><code>from keras.utils import np_utils uniques, ids = np.unique(arr, return_inverse=True) coded_array = np_utils.to_categorical(ids, len(uniques)) encode_dict ={} for i,j in zip(arr,coded_array): encode_dict[i] = j if len(encode_dict)==len(np.unique(arr)): break return coded_array,enc...
1
2016-08-09T07:55:30Z
38,845,674
<p>You can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.argmax.html" rel="nofollow"><code>np.argmax</code></a> to retrieve back those <code>ids</code> and then simply indexing into <code>uniques</code> should give you the original array. Thus, we would have an implementation, like so -</p> <p...
0
2016-08-09T08:29:22Z
[ "python", "numpy", "keras" ]
Saving and searching data with Tkinter entry boxes
38,845,134
<p>This might be a strange question because I am new to Python.</p> <p>I am trying to create form in Python which data can be entered into boxes and saved, then opened again. I'm currently using Tkinter to create a Gui which has entry boxes and buttons:</p> <pre><code>import sys from tkinter import * def mstore(): p...
0
2016-08-09T07:57:55Z
38,846,532
<p><strong>Hello Gregulimy!</strong></p> <p>I have simplified your code and made it do what you want it to do. I have left comments explaining what the code does. If you have any questions about what I have done feel free to ask!</p> <pre><code>from tkinter import * def mstore(text): file = open("file.txt", "w")...
0
2016-08-09T09:10:30Z
[ "python", "tkinter" ]
Error Reading CSV file using Python, Flask
38,845,176
<p>I'm very new to python and flask. I simply wanted to read a CSV file but it's giving me an error of "FileNotFoundError: [Errno 2] No such file or directory: 'Dog-Data.csv'" everytime I try to run run.py</p> <p>Here are my file order</p> <pre><code>DD\ static\ (bunch of image files) templates\ ...
0
2016-08-09T08:00:27Z
38,845,332
<p>Have you tried to give the full path instead of just a relative path?</p> <p>Python sometimes takes the working directory as a "home" path, which might or might not be the same as your <code>view.py</code> is situated in.</p>
0
2016-08-09T08:08:20Z
[ "python", "csv", "parsing", "flask" ]
Error Reading CSV file using Python, Flask
38,845,176
<p>I'm very new to python and flask. I simply wanted to read a CSV file but it's giving me an error of "FileNotFoundError: [Errno 2] No such file or directory: 'Dog-Data.csv'" everytime I try to run run.py</p> <p>Here are my file order</p> <pre><code>DD\ static\ (bunch of image files) templates\ ...
0
2016-08-09T08:00:27Z
38,845,483
<p>ok so really simple mistake that took hours for me to solve. I should be passing it from the root folder which means I should've put</p> <pre><code>data_file = open('app/Dog-Data.csv') </code></pre> <p>and now it works. T__T</p>
0
2016-08-09T08:17:33Z
[ "python", "csv", "parsing", "flask" ]
Get string inside brackets
38,845,217
<p>I want to fetch the string inside the square bracket, which is given as array</p> <pre><code>u16 arrayName_1[8][7] </code></pre> <p>I have python code which can find the 1-Dimensional array and get the character inside squre brackets.</p> <pre><code>var = 'u16 arrayName_1[8]' index = re.split('\[(.*?)\]', str(var...
1
2016-08-09T08:02:35Z
38,845,325
<p>You may use your own pattern in <a href="https://docs.python.org/2/library/re.html#re.findall" rel="nofollow"><strong><code>re.findall</code></strong></a> to grab all the contents inside <code>[...]</code>:</p> <pre><code>import re var = 'u16 arrayName_1[8][7]' index = re.findall(r'\[(.*?)\]', var) print(index) # =...
3
2016-08-09T08:08:06Z
[ "python", "regex", "string" ]
How to sum up a column in numpy
38,845,265
<p>i got a dataframe which i convert in an array (that is a testscenario because i have problems with the results in pandas). Now i want to sum up one column.</p> <p>I have the following code:</p> <pre><code>import sys import pandas as pd import numpy as np import os from tkinter import * #data_rbu = np.genfromtxt(...
1
2016-08-09T08:04:30Z
38,845,303
<p>do it directly in pandas:</p> <pre><code>data_rbu = pd.read_excel('tmp_fakt_daten.xlsx') summe1 = data_rbu['KW_WERT'] + data_rbu['NETTO_EURO'] # gets you a series summe1.sum() # gets you the total sum (if that's what you are after) </code></pre>
1
2016-08-09T08:06:51Z
[ "python", "pandas", "numpy" ]
How to sum up a column in numpy
38,845,265
<p>i got a dataframe which i convert in an array (that is a testscenario because i have problems with the results in pandas). Now i want to sum up one column.</p> <p>I have the following code:</p> <pre><code>import sys import pandas as pd import numpy as np import os from tkinter import * #data_rbu = np.genfromtxt(...
1
2016-08-09T08:04:30Z
38,845,691
<p>As you said the values are in array:</p> <pre><code>In[10]:arr Out[10]: array([['ZPAF', '2015-12-10', '2015-12-31', 'T-HOME ICP', 'B', 1001380363.0, 'B60ETS', 0.15, 18.9, 'SDH'], ['ZPAF', '2015-12-10', '2015-12-31', 'T-HOME ICP', 'B', 1001380363.0, 'B60ETS', 0.145, 18.27, 'SDH'], ['ZP...
1
2016-08-09T08:30:13Z
[ "python", "pandas", "numpy" ]
Can you permanently change python code by input?
38,845,273
<p>I'm still learning python and am currently developing an API (artificial personal assistant e.g. Siri or Cortana). I was wondering if there was a way to update code by input. For example, if I had a list- would it be possible to PERMANENTLY add a new item even after the program has finished running.</p> <p>I read t...
-3
2016-08-09T08:04:49Z
38,845,353
<p>There are planty of methods how you can make your data persistent. It depends on the task, on the environment etc. Just a couple examples:</p> <ul> <li>Files (JSON, DBM, Pickle)</li> <li>NoSQL Databases (Redis, MongoDB, etc.)</li> <li>SQL Databases (both serverless and client server: sqlite, MySQL, PostgreSQL etc.)...
0
2016-08-09T08:10:02Z
[ "python" ]
Can you permanently change python code by input?
38,845,273
<p>I'm still learning python and am currently developing an API (artificial personal assistant e.g. Siri or Cortana). I was wondering if there was a way to update code by input. For example, if I had a list- would it be possible to PERMANENTLY add a new item even after the program has finished running.</p> <p>I read t...
-3
2016-08-09T08:04:49Z
38,845,480
<p><strong>Hello J Nowak</strong></p> <p>I think what you want to do is save the input data to a file (Eg. txt file). You can view the link below which will show you how to read and write to a text file.</p> <p><a href="http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python" rel="nofollow">How to...
1
2016-08-09T08:17:22Z
[ "python" ]
How do I check the version of wxPython installed on my server?
38,845,293
<p>I have Python and WxPython installed. I want to check what is the version of WxPython installed.</p> <p>Didn't find the answer on <a href="https://wxpython.org/" rel="nofollow">https://wxpython.org/</a></p>
-1
2016-08-09T08:06:13Z
38,845,342
<p>Just like you would with every other Python library:</p> <p><code>pip show WxPython</code></p> <p>As I don't have this library installed, I can only suggest that some libraries also provide a <code>__version__</code> or <code>version()</code> attribute.</p> <p><strong>EDIT</strong>: <a href="http://stackoverflow....
1
2016-08-09T08:09:21Z
[ "python", "wxpython" ]
How do I check the version of wxPython installed on my server?
38,845,293
<p>I have Python and WxPython installed. I want to check what is the version of WxPython installed.</p> <p>Didn't find the answer on <a href="https://wxpython.org/" rel="nofollow">https://wxpython.org/</a></p>
-1
2016-08-09T08:06:13Z
38,845,635
<p>Do as follows:</p> <pre><code>&gt;&gt;&gt; import wx &gt;&gt;&gt; wx.version() '3.0.2.0 msw (classic)' &gt;&gt;&gt; wx.__version__ '3.0.2.0' </code></pre> <p>If you want a one-liner on the command-line without using pip:</p> <pre><code>python -c "import wx;print wx.__version__" </code></pre>
0
2016-08-09T08:27:34Z
[ "python", "wxpython" ]
(Python Newbie) Following e-book "A Byte of Python" - Issue with first program
38,845,378
<p>Hoping some one can help me out with an issue I have with my first program from the e-book "A byte of Python". </p> <p>The e-book is based on Python 2.7. </p> <p>Program: zip a source directory and format it with a particular "Name" and place it in the destination directory. </p> <p>The E-Books code to do this ta...
0
2016-08-09T08:11:30Z
38,845,424
<p>You are constructing the command wrongly!</p> <pre><code>zip_command = "zip -r {0}".format(target) + " " + " ".join(source) # Result: zip -r /root/Documents/Backup &lt;space&gt; /root/Documents/test </code></pre>
1
2016-08-09T08:14:28Z
[ "python", "python-2.7" ]
install python-kerberos on windows
38,845,389
<p>I'm trying to install kerberos on windows, I download Zip package and in Kerberos folder I run this command : python setup.py install but I got this error :</p> <pre><code>error: command 'C:\\Users\\aicha\\AppData\\Local\\Programs\\Common\\Microsoft\ \Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit st...
0
2016-08-09T08:12:13Z
38,885,020
<p>A possible solution may be found here: <a href="http://stackoverflow.com/questions/21345000/python-kerberos-1-1-1-tar-gz-install-failure-on-windows">Python Kerberos-1.1.1.tar.gz Install Failure on Windows</a></p> <p>Basically, python kerberos is not supported on Windows, so you will have to use kerberos-sspi instea...
1
2016-08-10T23:17:06Z
[ "python", "windows", "kerberos" ]
Can I create a loop to update SQL database?
38,845,435
<p>I have 6 tables in my <code>sql.db</code> file. And I was wondering if it would be possible to create a loop to go through each column within this 6 tables, and convert the values to <code>NULL</code> if the cell value is <code>-</code></p> <p><strong>Code I currently have</strong></p> <pre><code>for each_item in ...
0
2016-08-09T08:15:02Z
38,846,889
<p>Ok, there are quite a few problems in your code. Let's address each at a time:</p> <ol> <li><code>pd.DataFrame.to_sql</code> stands for <code>your_dataframe.to_sql</code> in this case, <code>df.to_sql</code>. It is a method on a <code>DataFrame</code> object, and that object is the <code>DataFrame</code> you create...
1
2016-08-09T09:26:43Z
[ "python", "sql", "pandas", "sqlalchemy" ]
How to convert JSON into dataframe
38,845,474
<p>Any ideas on how to transform this JSON file into a usable dataframe format:</p> <pre><code>pd.read_json("http://api.census.gov/data/2014/acsse/variables.json") </code></pre> <p>Here's how the table should look: <a href="http://api.census.gov/data/2014/acsse/variables.html" rel="nofollow">http://api.census.gov/dat...
1
2016-08-09T08:17:00Z
38,845,756
<p>Say you start with</p> <pre><code>df = pd.read_json("http://api.census.gov/data/2014/acsse/variables.json") </code></pre> <p>The problem is that the column is of dicts:</p> <pre><code>In [28]: df.variables.head() Out[28]: AIANHH {u'concept': u'Selectable Geographies', u'pred... ANRC {u'concept': u'Select...
3
2016-08-09T08:33:13Z
[ "python", "json", "pandas", "census" ]
AttributeError: 'module' object has no attribute 'doc
38,845,494
<p>i am a beginner and i trying to model system dynamic model using python programming.the problem is when i trying to print the components of the sd model, the error message comes out like this: </p> <pre><code>"AttributeError: 'module' object has no attribute 'doc'" </code></pre> <p>my code:</p> <pre><code>import ...
-1
2016-08-09T08:18:18Z
38,845,875
<p>As far as understand from the git repo, the <code>doc()</code> method is inside <code>Class PySD</code>. Also, <code>read_vensim</code> returns an instance of this class. </p> <p>So your problem should get solved if you directly use <code>educationmodel.doc()</code>.</p>
0
2016-08-09T08:38:54Z
[ "python", "python-2.7", "ipython" ]
AttributeError: 'module' object has no attribute 'doc
38,845,494
<p>i am a beginner and i trying to model system dynamic model using python programming.the problem is when i trying to print the components of the sd model, the error message comes out like this: </p> <pre><code>"AttributeError: 'module' object has no attribute 'doc'" </code></pre> <p>my code:</p> <pre><code>import ...
-1
2016-08-09T08:18:18Z
40,115,667
<p>That may be my fault - I had to move the <code>.doc()</code> function to the model object instead of the components object as a way to work towards including Vensim macros properly. If it's still an issue, may want to update to the latest release (0.7.4). If that doesn't help either, then we may have to fix somethin...
0
2016-10-18T18:39:15Z
[ "python", "python-2.7", "ipython" ]
PyXB: Cannot instantiate abstract type
38,845,528
<p>I try to do my first steps with PyXB but have the problem, that I cannot create the element paket. I have gone through the samples but can't find any more information on how to handle this. If the abstract element is one level deeper there seems a solution, but here it is on top level.</p> <p>Can somebody help me w...
0
2016-08-09T08:20:53Z
38,850,396
<p>The type <strong>paket</strong> is abstract, but this type is used in an element declaration against which the <strong>v4:paket</strong> element is validated. This is not allowed for abstract types. Abstract types can only be derived, and their concrete derived type used for validation.</p> <p>If you have control o...
1
2016-08-09T12:12:41Z
[ "python", "xml", "xsd", "abstract", "pyxb" ]
Error communicating with the remote browser It may have died
38,845,545
<p>I know this question has been asked many times and i have checked those but could not find solution .Above error is not frequent only sometimes i get it , so i am not able figure out why it is occurring .After executing below lines of code</p> <pre><code> driver.get(first_url) #here i open forst url the perform...
0
2016-08-09T08:22:13Z
38,846,799
<p>Because the below line will close your browser if it has only one tab open.</p> <pre><code># remove that line and run your code. You will not see this error again. driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w') </code></pre>
1
2016-08-09T09:21:45Z
[ "python", "selenium", "selenium-webdriver" ]
Is there a decorator equivalent to PyXll `@xl_func(macro=True)` with xlwings?
38,845,707
<p>Is there a decorator equivalent to PyXll <code>@xl_func(macro=True)</code> with xlwings? </p> <p>This would allow to interact with the entire workbook in Excel? </p> <p>A dummy example: <code>=test()</code> in cell 'E5' returns an error: </p> <pre><code>@xw.func def test(): wb = xw.Book.caller() wb.sheets...
0
2016-08-09T08:31:10Z
38,848,719
<p>Yes, <code>xw.sub</code>, from the <a href="http://docs.xlwings.org/en/stable/udfs.html#macros" rel="nofollow">docs</a>:</p> <pre><code>import xlwings as xw @xw.sub def my_macro(): """Writes the name of the Workbook into Range("A1") of Sheet 1""" wb = xw.Book.caller() wb.sheets[0].range('A1').value = w...
0
2016-08-09T10:50:10Z
[ "python", "xlwings" ]
Django: "request" does not contain the 'method' (POST/GET)
38,845,737
<p>I've created a [seemingly] straightforward form for customers, however, after the user submits the form, when i try to check the returning request m- I'm getting :</p> <p><strong>Exception Type: AttributeError Exception Value: 'QueryDict' object has no attribute 'method'</strong></p> <p>when i checked I saw that t...
0
2016-08-09T08:32:35Z
38,847,604
<pre><code>def institutionapply(request): ... if request.method == 'POST': ... form = institutionapply(request.POST) </code></pre> <p>Replace <code>institutionapply</code> with <code>institutionform</code>.</p>
3
2016-08-09T09:57:51Z
[ "python", "django", "django-forms", "django-views" ]
Ascending read from csv and update csv using python
38,845,789
<p>I want to know whether it is possible to read the <code>.csv</code> file with specific <code>row</code>, after reading the row. I want to delete that specific row and update the <code>.csv</code> file with next row gets ascended. Assuming the <code>.csv</code> file has headers. If it is possible than how? Ex. below ...
0
2016-08-09T08:34:42Z
38,850,877
<p>You could use <code>StringIO</code> to keep the contents in memory and then write them to the desired file at the end.</p> <pre><code>from io import StringIO import csv filename = 'sample.csv' out_data = StringIO() # Read CSV data to memory with open(filename, 'r', newline='') as in_file: writer = csv.writer(...
0
2016-08-09T12:32:30Z
[ "python", "csv" ]
How to divide python datetime-span into equally spaced time-intervals?
38,845,802
<p>I am having two dates, just like:</p> <pre><code>date_a = datetime.datetime(2016, 8, 9, 8, 24, 30, 993352) date_b = datetime.datetime(2016, 8, 9, 7, 24, 30, 993352) </code></pre> <p>What I want is getting a list of timestamps with a five minute interval that lies between those two dates. With the above two dates t...
-1
2016-08-09T08:35:05Z
38,845,911
<p>Not extremely pythonic, but clean and concise:</p> <pre><code>from datetime import timedelta delta = timedelta(minutes=5) five_min_timestamps = [] date_x = date_a while date_x &lt; date_b: date_x += timedelta(minutes=5) five_min_timestamps.append(date_x) </code></pre> <p>Another option is to use list compreh...
2
2016-08-09T08:40:44Z
[ "python", "datetime" ]
How to divide python datetime-span into equally spaced time-intervals?
38,845,802
<p>I am having two dates, just like:</p> <pre><code>date_a = datetime.datetime(2016, 8, 9, 8, 24, 30, 993352) date_b = datetime.datetime(2016, 8, 9, 7, 24, 30, 993352) </code></pre> <p>What I want is getting a list of timestamps with a five minute interval that lies between those two dates. With the above two dates t...
-1
2016-08-09T08:35:05Z
38,845,954
<p>Defining a function that returns a list of intervals between low time <code>a</code> and top time <code>b</code>. </p> <pre><code>def print_time(a, b, inter): tmp = a + datetime.timedelta(0,interval) # sum an interval of inter secs list = [] while tmp &lt; b: list.add(tmp) tmp = tmp + dateti...
0
2016-08-09T08:42:30Z
[ "python", "datetime" ]
How to divide python datetime-span into equally spaced time-intervals?
38,845,802
<p>I am having two dates, just like:</p> <pre><code>date_a = datetime.datetime(2016, 8, 9, 8, 24, 30, 993352) date_b = datetime.datetime(2016, 8, 9, 7, 24, 30, 993352) </code></pre> <p>What I want is getting a list of timestamps with a five minute interval that lies between those two dates. With the above two dates t...
-1
2016-08-09T08:35:05Z
38,846,755
<p>You can also look into using <a href="https://labix.org/python-dateutil#head-cf004ee9a75592797e076752b2a889c10f445418" rel="nofollow"><code>rrule</code> module from <code>dateutil</code></a>:</p> <blockquote> <p>The rrule module offers a small, complete, and very fast, implementation of the recurrence rules doc...
1
2016-08-09T09:19:59Z
[ "python", "datetime" ]
Can't update ballot date in UpdateView in django
38,845,806
<p>I designed a model:</p> <pre><code>class Sitting(models.Model): sit_date = models.DateField(blank=False) cut_off_date = models.DateField(null=True, blank=True) ballot_date = models.DateField(null=True, blank=True) sess_no = models.ForeignKey(Session, on_delete=models...
0
2016-08-09T08:35:13Z
38,845,904
<p>You explicitly override the ballot_date and cut_off_date fields every time you save. If you don't want that, maybe you need to put a check there?</p> <pre><code>def save(self, *args, **kwargs): if not self.cut_off_date: self.cut_off_date = self.get_cut_off_date() if not self.ballot_date: sel...
1
2016-08-09T08:40:31Z
[ "python", "django" ]
What is the most Pythonic way to shorten this proportioning method?
38,846,132
<p>I'm looking for a way for shorten <code>find_equivalent()</code> proportioning method in most Pythonic way.</p> <p>if <code>y</code> number is not in range <code>0 - 2000</code> method should return <code>0</code>. Otherwise, method should find the range of the <code>y</code> and return the equal number to the rang...
-3
2016-08-09T08:50:59Z
38,846,320
<p>You should calculate the return value.</p> <p>But still if you want to know how it should be done, then here is the way that I think is most appropriate, will update if I find something better.</p> <pre><code>range_value = [ {'min':100,'max':200,'val_return':1} , {'min':200,'max':300,'val_return':2} ,..... ] for _...
-1
2016-08-09T09:00:18Z
[ "python" ]
What is the most Pythonic way to shorten this proportioning method?
38,846,132
<p>I'm looking for a way for shorten <code>find_equivalent()</code> proportioning method in most Pythonic way.</p> <p>if <code>y</code> number is not in range <code>0 - 2000</code> method should return <code>0</code>. Otherwise, method should find the range of the <code>y</code> and return the equal number to the rang...
-3
2016-08-09T08:50:59Z
38,846,356
<p>I would suggest to use two lists, one containing the values for the range and the other containing the return values, i.e.</p> <pre><code>rangelist = [0, 1, 34, 67, 100 (etc)] returnlist = [18, 17, 16 (etc)] </code></pre> <p>Then, you can find the entry of <code>rangelist</code> closest to your <code>y</code> and ...
0
2016-08-09T09:02:14Z
[ "python" ]
What is the most Pythonic way to shorten this proportioning method?
38,846,132
<p>I'm looking for a way for shorten <code>find_equivalent()</code> proportioning method in most Pythonic way.</p> <p>if <code>y</code> number is not in range <code>0 - 2000</code> method should return <code>0</code>. Otherwise, method should find the range of the <code>y</code> and return the equal number to the rang...
-3
2016-08-09T08:50:59Z
38,846,358
<p>You can just <em>calculate</em> your numbers:</p> <pre><code>if 0 &lt; y &lt;= 200: return 18 - ((y - 1) // 33) elif 200 &lt; y &lt;= 500: return 12 - ((y - 201) // 100) elif 500 &lt; y &lt;= 1000: return 9 - ((y - 501) // 667)) elif 1000 &lt; y &lt;= 2000: return 6 - ((y - 501) // 1333) return 0 </code...
6
2016-08-09T09:02:18Z
[ "python" ]
Python Eventlet spawn not executing concurrently
38,846,147
<p>I have following two versions of code using eventlet. The expectation is that the 2 spawn_n calls will execute concurrently, but thats not the case. The execution happens serially.</p> <pre><code>import eventlet import threading import datetime from eventlet.green import urllib2 def hello(name): print eventle...
1
2016-08-09T08:51:28Z
38,870,068
<pre><code>def fun(tag): print('{0} begin'.format(tag)) eventlet.sleep(0.1) # pretty much the same as running HTTP request and throwing results away print('{0} end'.format(tag)) t1 = time.time() pool.spawn(fun, 'Turtle') pool.spawn(fun, 'Achilles') pool.waitall() tt = time.time() - t1 print('Total time: {0:.2f}...
0
2016-08-10T09:58:25Z
[ "python", "eventlet" ]
python stream handler for multiple servers
38,846,262
<p>There are servers running in multiple locations,I need to stream the application log data from these servers to a <strong>ZMQ</strong>(Zero Message Queue) using <strong>python stream handler</strong>.How do i use the stream handler to get this done? I have already referred the Python Handlers documentation <a href="...
0
2016-08-09T08:57:41Z
38,847,231
<p>You can post your logs from different servers as <code>json</code> to the ZMQ iteratively. For the ZMQ make a PyZMQ application which will have a message handler, listening to your incoming json from these servers. Then as per requirement the incoming json data can be processed and stored in a file (or wherever you ...
0
2016-08-09T09:41:12Z
[ "python", "logging" ]
Python3 - wifi library does not run with Cell.all("wlan0")
38,846,295
<p>I'm trying to use wifi library for python3 (<a href="https://wifi.readthedocs.io/en/latest/index.html" rel="nofollow">https://wifi.readthedocs.io/en/latest/index.html</a>) but when I use Cell.all("wlan0") I get this error:</p> <pre><code>Microsoft Windows [Versione 10.0.10586] (c) 2015 Microsoft Corporation. Tutti ...
0
2016-08-09T08:59:04Z
38,846,996
<p>You get this error because you are running Windows. The wifi library is only designed for Linux systems as described in the documentation.</p>
0
2016-08-09T09:31:17Z
[ "python", "python-3.x", "wifi" ]
How to club dictionaries?
38,846,335
<p>I've two dictionaries as below.</p> <pre><code>d1 = { "user1":{"key1":"val1","key2":"val2"}, "user2":{"key3":"val3","key4":"val4"} } d2 = { "admin":{ "user1":{"key5":"val5","key6":"val6"}, "user3":{"key7":"val7","key8":"val8"} } } </code></pre> <p>Final dictiona...
-3
2016-08-09T09:01:09Z
38,847,100
<p>You can take a copy of the first dictionary, then iterate over the other - creating a default empty dictionary, then updating it with the contents of d2, eg:</p> <pre><code>d3 = d1.copy() for k, v in d2['admin'].iteritems(): d3.setdefault(k, {}).update(v) </code></pre> <p>Gives you output of:</p> <pre><code>{...
1
2016-08-09T09:36:03Z
[ "python", "python-2.7", "dictionary" ]
How much time should the mouse left button be held?
38,846,373
<p>If you want to detect a Bot that is clicking on a button when he has to, could you look how long the left button stays down before being up again? I mean a script like this one (python):</p> <pre><code>import win32api, win32con win32api.SetCursorPos((x,y)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0...
1
2016-08-09T09:02:52Z
38,913,260
<p>Yes, bots can and are detected this way.</p> <p>Yes, adding a random offset to the click speed, delay, mouse path, movement speed, and many more things is the standard solution to circumvent this kind of detection. There are many other ways to detect bots though.</p> <p>To get an average click speed, write a short...
0
2016-08-12T08:23:35Z
[ "python", "security", "artificial-intelligence" ]
Where to place example data in python package?
38,846,395
<p>I'm setting up my first Python package, and I want to install it with some example data so that users can run the code straight off. In case it's relevant my package is on github and I'm using pip.</p> <p>At the moment my example data is being installed with the rest of the package into site_packages/, by setting <...
0
2016-08-09T09:03:42Z
38,846,673
<p>You can put your example data in the repository in <code>examples</code> folder next to your project sources and exclude it from package with <code>prune examples</code> in your manifest file.</p> <p>There is actually no universal and standard advice for that. Do whatever suits your needs.</p>
1
2016-08-09T09:16:19Z
[ "python", "install" ]
nose2.main() verbose output
38,846,535
<p>I'm writing a separate nose2 tests.py for my program and because I want it to run on both Windows and Linux fairly seamlessly I've decided to forgo using the normal commandline nose2 and instead import it in the file and run it from there.</p> <pre><code>if __name__ == '__main__': import nose2 nose2.main() ...
0
2016-08-09T09:10:41Z
38,848,397
<p>Since the <code>PluggableTestProgram</code> class <a href="http://nose2.readthedocs.io/en/latest/dev/main.html?highlight=verbosity" rel="nofollow">accepts the same parameters</a> of <code>unittest.TestProgram</code>, you can pass <code>verbosity</code> to the <code>main</code> function as such:</p> <pre><code>nose2...
1
2016-08-09T10:35:55Z
[ "python", "nose2" ]
Python pandas producing error when trying to access 'DATE' column on large data set
38,846,590
<p>I have a file with 3'502'379 rows and 3 columns. The following script is supposed to be executed but raises and error in the date handling line:</p> <pre><code>import matplotlib.pyplot as plt import numpy as np import csv import pandas path = 'data_prices.csv' data = pandas.read_csv(path, sep=';') data['DATE'] = p...
1
2016-08-09T09:12:51Z
38,846,829
<p>the <code>'\ufeffDATE'</code> in the first column name shows that your CSV file has a <a href="https://en.wikipedia.org/wiki/Byte_order_mark#Representations_of_byte_order_marks_by_encoding" rel="nofollow">UTF-16 Byte Order Mark (BOM) signature</a> so it must be read accordingly.</p> <p>so try this when reading your...
4
2016-08-09T09:23:29Z
[ "python", "date", "datetime", "pandas", "dataframe" ]
pandas update dataframe values if cell contains '-'
38,846,642
<p>I have a pandas Dataframe which has 46 columns, and 6 rows. </p> <pre><code>Index Column1 Column2 Column3 Column4 ... # Cant type all 46 columns. 2012 5626 fooo - barrr 2013 5655h booo - barr 2014 5626d zooo - - LTM 56 ...
2
2016-08-09T09:15:05Z
38,846,678
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html" rel="nofollow"><code>replace</code></a>:</p> <pre><code>print (df.replace({'-': 0})) Index Column1 Column2 Column3 Column4 0 2012 5626 fooo 0 barrr 1 2013 5655h booo 0 barr 2 20...
3
2016-08-09T09:16:37Z
[ "python", "pandas" ]
pandas update dataframe values if cell contains '-'
38,846,642
<p>I have a pandas Dataframe which has 46 columns, and 6 rows. </p> <pre><code>Index Column1 Column2 Column3 Column4 ... # Cant type all 46 columns. 2012 5626 fooo - barrr 2013 5655h booo - barr 2014 5626d zooo - - LTM 56 ...
2
2016-08-09T09:15:05Z
38,846,680
<p>use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html" rel="nofollow"><code>replace</code></a> to replace that specific value with another one:</p> <pre><code>In [71]: df.replace('-',0, inplace=True) df Out[71]: Index Column1 Column2 Column3 Column4 0 2012 5626 f...
3
2016-08-09T09:16:39Z
[ "python", "pandas" ]
Login with python module requests
38,846,846
<p>I need to log me in a website with requests, but all I have try don't work :</p> <pre><code>from bs4 import BeautifulSoup as bs import requests s = requests.session() url = 'https://www.ent-place.fr/CookieAuth.dll?GetLogon?curl=Z2F&amp;reason=0&amp;formdir=5' def authenticate(): headers = {'username': 'myuser...
0
2016-08-09T09:24:43Z
38,847,208
<p>You can just try this.</p> <p>Your login url is not correct, you can check the network requests in browser's developer tools.</p> <pre><code>import requests payload = { 'username': 'user', 'password': 'pass' } with requests.Session() as s: p = s.post('https://www.ent-place.fr/CookieAuth.dll?Logon', d...
0
2016-08-09T09:40:22Z
[ "python", "python-requests" ]
Login with python module requests
38,846,846
<p>I need to log me in a website with requests, but all I have try don't work :</p> <pre><code>from bs4 import BeautifulSoup as bs import requests s = requests.session() url = 'https://www.ent-place.fr/CookieAuth.dll?GetLogon?curl=Z2F&amp;reason=0&amp;formdir=5' def authenticate(): headers = {'username': 'myuser...
0
2016-08-09T09:24:43Z
38,847,342
<p>These are the parameters your should be supplying.</p> <pre><code>curl:Z2F flags:0 forcedownlevel:0 formdir:5 username:yourusername password:yourpassword SubmitCreds.x:57 SubmitCreds.y:23 SubmitCreds:Ouvrir une session </code></pre>
0
2016-08-09T09:45:37Z
[ "python", "python-requests" ]
How to install Python3 to custom path using Chocolatey?
38,846,874
<p>I'm installing Python 3 with <a href="https://chocolatey.org/" rel="nofollow">Chocolatey</a>, which installs into <code>C:\ProgramData\chocolatey\lib\python3</code>:</p> <pre><code>&gt; choco install python3 </code></pre> <p>Is there any way I can get Python3 to install into <code>C:\Python35</code> instead?</p> ...
3
2016-08-09T09:26:06Z
38,847,127
<p>There is a possibility to override <code>--installargs</code> like this:</p> <pre><code>&gt; choco install python3 -y --override --installarguments "'/quiet InstallAllUsers=1 TargetDir=c:\Python35'" </code></pre> <p>You might see some (access denied) errors (guess Python 3.5.1 Package is broken) but overall it se...
2
2016-08-09T09:37:15Z
[ "python", "python-3.x", "chocolatey" ]
asyncio scheduling callback at specific time
38,846,962
<p>In the following code, the callback() is not called at the repsective time(now+0.2and now+0.1) and also stopper() ,what is wrong here</p> <pre><code> def callback(n,loop): print('Callback {} invoked at {}'.format(n,loop.time())) def stopper(loop): print("Stopper invoked at {}".format(loop.ti...
0
2016-08-09T09:29:33Z
38,848,943
<p><code>.call_later(delay, cb, *args)</code> requires <code>delay</code> parameters, time delta in seconds (<code>float</code>).</p> <p>But you pass <code>now + delay</code> to these calls.</p> <p>Either drop <code>now</code> or replace <code>.call_later()</code> with <code>.call_at()</code>.</p>
2
2016-08-09T11:00:43Z
[ "python", "python-asyncio" ]
How to create selective patches from an image based on the objects identified
38,847,116
<p>I have created a numpy matrix with all elements initialized to zeros as shown:</p> <pre><code>[[[0 0 0 0] [0 0 0 0] [0 0 0 0] ... </code></pre> <p>This is to resemble an image of the screenshot of a webpage which is of the size 1200 X 1000.</p> <p>I have identified a few rectangular region of interest for d...
-4
2016-08-09T09:36:49Z
38,847,417
<p>a very naive approach</p> <pre><code>maxY, maxX = np.shape(theMatrix) for curY in range(0,maxY): for curX in range(0,maxX): print theMatrix[curY,curX], print " " </code></pre>
0
2016-08-09T09:49:02Z
[ "python", "numpy", "image-processing", "conv-neural-network" ]
How to create selective patches from an image based on the objects identified
38,847,116
<p>I have created a numpy matrix with all elements initialized to zeros as shown:</p> <pre><code>[[[0 0 0 0] [0 0 0 0] [0 0 0 0] ... </code></pre> <p>This is to resemble an image of the screenshot of a webpage which is of the size 1200 X 1000.</p> <p>I have identified a few rectangular region of interest for d...
-4
2016-08-09T09:36:49Z
38,847,826
<p>You can just use the plot function to plot a 2D-array. Take for example:</p> <pre><code>import numpy as np import matplotlib.pyplot as pyplot x = np.random.rand(3, 2) </code></pre> <p>which will yield us </p> <pre><code>array([[ 0.53255518, 0.04687357], [ 0.4600085 , 0.73059902], [ 0.7153942 , 0....
0
2016-08-09T10:07:24Z
[ "python", "numpy", "image-processing", "conv-neural-network" ]
OpenCV error on spyder
38,847,201
<p>I want to use OpenCV with python on spyder. <br>But error occured when I run a simple code.<br></p> <pre><code>import cv2 img = cv2.imread('pi.png',0) cv2.imshow('image', img) cv2.waitKey(0) dcv2.destroyAllwindows() </code></pre> <p><strong>Error</strong></p> <blockquote> <p>This application failed to start bec...
0
2016-08-09T09:40:13Z
38,865,986
<p>I didn't understand the answer.( <a href="http://stackoverflow.com/questions/30483753/python-app-xcb-plugin-fail">stackoverflow.com/questions/30483753/python-app-xcb-plugin-fail</a> )</p> <p>But, the problem is solved from changing condition when I reinstall OpenCV</p> <p>Installation is referred to <a href="https...
0
2016-08-10T06:39:48Z
[ "python", "opencv", "ubuntu", "anaconda", "spyder" ]
Sending payload for GET request in python
38,847,317
<p>To filter the output, I can send a JSON to the API, like :</p> <pre><code>curl -X GET https://api.mysite.com/user \ -H "Authorization: XXXXX" \ -H "Content-Type: application/json" -d '{ "q": { "name": { "eq": "0aslam0" } } }' </code></pre> <p>The above works just ...
0
2016-08-09T09:44:45Z
38,847,431
<p>When you use <code>-d</code>, the data is sent as a request <em>body</em>. <code>params</code> sends a URL query string, so that's the wrong argument to use.</p> <p>Note that packaging along a request body with a <code>GET</code> method is technically a violation of the HTTP RFCs.</p> <p>You'd have to send your re...
0
2016-08-09T09:49:35Z
[ "python", "python-2.7", "get", "python-requests" ]
Commit multiple SVN repositories using a Python script?
38,847,353
<p>I've been doing a lot of script-powered mass-updates to dozens of project folders at once, lately. Unfortunately, my pointy-haired boss insists that each folder be committed to TortoiseSVN separately after one of these bulk edits - he wants every folder to have a different revision number. Me being the automation fi...
0
2016-08-09T09:46:25Z
38,848,059
<p>Correct syntax of the call function turned out to be </p> <pre><code>subprocess.call(["svn", "commit", filepath, '-m "&lt;commit message here&gt;"'], shell = True) </code></pre>
0
2016-08-09T10:17:46Z
[ "python", "svn", "command-line", "tortoisesvn" ]
Django - exception handling best practice and sending customized error message
38,847,441
<p>I am starting to think about appropriate exception handling in my Django app, and my goal is to make it as user-friendly, as possible. By user-friendliness, I imply that the user must always get a detailed clarification as to what exactly went wrong. Following on <a href="http://stackoverflow.com/questions/9797253/d...
2
2016-08-09T09:50:11Z
38,847,585
<p>The status codes are very well defined in the HTTP standard. You can find a <a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes" rel="nofollow">very readable list on Wikipedia</a>. Basically the errors in the 4XX range are errors made by the client, i.e. if they request a resource that doesn't exist, et...
1
2016-08-09T09:57:16Z
[ "python", "json", "ajax", "django" ]
Django - exception handling best practice and sending customized error message
38,847,441
<p>I am starting to think about appropriate exception handling in my Django app, and my goal is to make it as user-friendly, as possible. By user-friendliness, I imply that the user must always get a detailed clarification as to what exactly went wrong. Following on <a href="http://stackoverflow.com/questions/9797253/d...
2
2016-08-09T09:50:11Z
38,849,047
<p>First of all you should think on what errors you want to expose:</p> <ul> <li><p>Usually 4xx errors (Errors that are attributed to the client-side) are disclosed so the user may correct the request.</p></li> <li><p>On the other side, 5xx errors (Errors that are attributed to the server-side) are usually only presen...
3
2016-08-09T11:06:19Z
[ "python", "json", "ajax", "django" ]
Python3 - use/wrap R function
38,847,573
<p>I'm using python 3.4.3 under ubuntu 14.04 and would like to use call R code to obtain some results. I know the existence of some packages such as pyper and rpy2 but they look compatible only with python2. By typing 'sudo pip3 install rpy2' I get the follow</p> <pre><code>Exception information: Traceback (most recen...
0
2016-08-09T09:56:30Z
38,847,651
<p>rpy is in fact compatible with both Python 2 and Python 3. <a href="http://rpy2.readthedocs.io/en/version_2.8.x/overview.html#requirements" rel="nofollow">http://rpy2.readthedocs.io/en/version_2.8.x/overview.html#requirements</a></p> <blockquote> <p>Requirements</p> <p>Currently the development is done on UN...
0
2016-08-09T10:00:01Z
[ "python", "python-3.x", "wrapper" ]
Django can't find static files
38,847,647
<p>I'm trying to deploy my Django project on <a href="https://www.digitalocean.com" rel="nofollow">Digital Ocean</a>. I've chosen Django App droplet to make it more simple. </p> <p>Then I've simply installed requirements, replace their <code>django_project</code> to my project. </p> <p>The problem is that static file...
2
2016-08-09T09:59:46Z
38,848,485
<p>Try specifying STATIC_ROOT as following:</p> <pre><code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # Note that number of times os.path.dirname is used depends on # to reach top of your project directory. here # Static Files STATIC_ROOT = join(os.path.dirname(BASE_DIR), ...
0
2016-08-09T10:39:32Z
[ "python", "django", "nginx", "static", "gunicorn" ]
Django can't find static files
38,847,647
<p>I'm trying to deploy my Django project on <a href="https://www.digitalocean.com" rel="nofollow">Digital Ocean</a>. I've chosen Django App droplet to make it more simple. </p> <p>Then I've simply installed requirements, replace their <code>django_project</code> to my project. </p> <p>The problem is that static file...
2
2016-08-09T09:59:46Z
38,849,152
<p>If your log file is showing nginx looking for files to server but from the wrong location then it because you nginx file has not be updated since your last change.</p> <p><a href="http://nginx.org/en/docs/beginners_guide.html#control" rel="nofollow">Reload your nginx configuration</a> and it should start serving fi...
1
2016-08-09T11:11:21Z
[ "python", "django", "nginx", "static", "gunicorn" ]
Convert float to string without scientific notation and false precision
38,847,690
<p>I want to print some floating point numbers so that they're always written in decimal form (e.g. <code>12345000000000000000000.0</code> or <code>0.000000000000012345</code>, not in <a href="https://en.wikipedia.org/wiki/Scientific_notation" rel="nofollow">scientific notation</a>, yet I'd want to keep the 15.7 decima...
27
2016-08-09T10:01:59Z
38,847,691
<p>Unfortunately it seems that not even the new-style formatting with <code>float.__format__</code> supports this. The default formatting of <code>float</code>s is the same as with <code>repr</code>; and with <code>f</code> flag there are 6 fractional digits by default:</p> <pre><code>&gt;&gt;&gt; format(0.0000000005,...
21
2016-08-09T10:01:59Z
[ "python", "python-3.x", "floating-point", "number-formatting", "python-2.x" ]
Convert float to string without scientific notation and false precision
38,847,690
<p>I want to print some floating point numbers so that they're always written in decimal form (e.g. <code>12345000000000000000000.0</code> or <code>0.000000000000012345</code>, not in <a href="https://en.wikipedia.org/wiki/Scientific_notation" rel="nofollow">scientific notation</a>, yet I'd want to keep the 15.7 decima...
27
2016-08-09T10:01:59Z
38,950,952
<p>If you are ready to lose your precision arbitrary by calling <code>str()</code> on the float number, then it's the way to go:</p> <pre><code>import decimal def float_to_string(number, precision=20): return '{0:.{prec}f}'.format( decimal.Context(prec=100).create_decimal(str(number)), prec=precis...
1
2016-08-15T07:29:26Z
[ "python", "python-3.x", "floating-point", "number-formatting", "python-2.x" ]
Convert float to string without scientific notation and false precision
38,847,690
<p>I want to print some floating point numbers so that they're always written in decimal form (e.g. <code>12345000000000000000000.0</code> or <code>0.000000000000012345</code>, not in <a href="https://en.wikipedia.org/wiki/Scientific_notation" rel="nofollow">scientific notation</a>, yet I'd want to keep the 15.7 decima...
27
2016-08-09T10:01:59Z
38,983,595
<p>If you are satisfied with the precision in scientific notation, then could we just take a simple string manipulation approach? Maybe it's not terribly clever, but it seems to work (passes all of the use cases you've presented), and I think it's fairly understandable:</p> <pre><code>def float_to_str(f): float_st...
13
2016-08-16T20:09:16Z
[ "python", "python-3.x", "floating-point", "number-formatting", "python-2.x" ]
Convert float to string without scientific notation and false precision
38,847,690
<p>I want to print some floating point numbers so that they're always written in decimal form (e.g. <code>12345000000000000000000.0</code> or <code>0.000000000000012345</code>, not in <a href="https://en.wikipedia.org/wiki/Scientific_notation" rel="nofollow">scientific notation</a>, yet I'd want to keep the 15.7 decima...
27
2016-08-09T10:01:59Z
39,000,705
<p>Interesting question, to add a little bit more of content to the question, here's a litte test comparing @Antti Haapala and @Harold solutions outputs:</p> <pre><code>import decimal import math ctx = decimal.Context() def f1(number, prec=20): ctx.prec = prec return format(ctx.create_decimal(str(number)), ...
0
2016-08-17T15:27:39Z
[ "python", "python-3.x", "floating-point", "number-formatting", "python-2.x" ]
Convert float to string without scientific notation and false precision
38,847,690
<p>I want to print some floating point numbers so that they're always written in decimal form (e.g. <code>12345000000000000000000.0</code> or <code>0.000000000000012345</code>, not in <a href="https://en.wikipedia.org/wiki/Scientific_notation" rel="nofollow">scientific notation</a>, yet I'd want to keep the 15.7 decima...
27
2016-08-09T10:01:59Z
39,002,207
<p>I think <code>rstrip</code> can get the job done.</p> <pre><code>a=5.4321654321e-08 '{0:.40f}'.format(a).rstrip("0") # float number and delete the zeros on the right # '0.0000000543216543210000004442039220863003' # there's roundoff error though </code></pre> <p>Let me know if that works for you.</p>
0
2016-08-17T16:48:00Z
[ "python", "python-3.x", "floating-point", "number-formatting", "python-2.x" ]
Exporting R data.frame/tbl to Google BigQuery table
38,847,743
<p>I know it's possible to import Google BigQuery tables to R through <code>bigrquery</code> library. But is it possible to export tables/data frames created in R to Google BigQuery as new tables? </p> <p>Basically, is there an R equivalent of Python's <code>temptable.insert_data(df)</code> or <code>df.to_sql()</code>...
0
2016-08-09T10:03:48Z
39,119,230
<p>It looks like <code>bigrquery</code> package does the job through <code>insert_upload_job()</code>. In package documentation it says this function </p> <p><em>> is only suitable for relatively small datasets</em></p> <p>but it doesn't specify any size limits. For me, it's been working for tens of thousands of rows...
0
2016-08-24T09:19:18Z
[ "python", "dataframe", "google-bigquery" ]
Variable amount of Corners for a Polygon in Tkinter
38,847,857
<p>Busy fooling around with Tkinter, and was wondering if there was a way to create a polygon with a variable amount of corners? I'm trying to write a program that involves the user inputting a certain number of coordinates, and then a polygon with edges at those points is drawn on a canvas. Since I am unaware of the a...
0
2016-08-09T10:08:36Z
38,849,370
<p>You can pass an array of coordinates as long as they are pairs. eg:</p> <pre><code># triangle canvas.create_polygon([150,100, 100,150, 150,150], fill="red") # square canvas.create_polygon([0,0, 50,0, 50,50, 0,50], fill="black") </code></pre>
3
2016-08-09T11:23:40Z
[ "python", "tkinter", "tkinter-canvas" ]
Importing pyplot in a Jupyter Notebook
38,847,900
<p>Running Python 2.7 and trying to get plotting to work the tutorials recommend the below command.</p> <pre><code>from matplotlib import pyplot as plt </code></pre> <p>Works fine when run from the command line</p> <pre><code>python -c "from matplotlib import pyplot as plt" </code></pre> <p>but I get an error when ...
1
2016-08-09T10:10:08Z
38,851,858
<p>You can also use the <code>%matplotlib inline</code> magic, but it has to be preceded by the pure <code>%matplotlib</code> line:</p> <p><strong>Works (figures in new window)</strong></p> <pre><code>%matplotlib import matplotlib.pyplot as plt </code></pre> <p><strong>Works (inline figures)</strong></p> <pre><code...
2
2016-08-09T13:16:09Z
[ "python", "matplotlib", "jupyter", "jupyter-notebook" ]
Implementing SJCL .frombits in python
38,847,927
<p>I'm trying to rewrite some JS (which uses the SJCL library) in Python using pycrypto. I'm having trouble figuring out how to implement the following code</p> <pre><code>aes = new sjcl.cipher.aes( this.key ); bits = sjcl.codec.utf8String.toBits( text ); cipher = sjcl.mode.ccm.encrypt( aes, bits, iv ); cipherIV = sjc...
0
2016-08-09T10:10:59Z
38,858,852
<p>If you look closely at this code you should see that it is self-contained. SJCL's "bits" (native binary data representation) are not needed after this code has run. This internal data is given into the encryption and concatenation functions, and the result is then converted back to a "normal" Base64-encoded string w...
1
2016-08-09T19:23:12Z
[ "javascript", "python", "cryptography", "pycrypto", "sjcl" ]
choose n cluster for chemical fingerprint
38,847,940
<p>Hello I am trying to cluster chemical fingerprint</p> <p>I am using rdkit which provide a hierarchical method for cluster, the problem is that I know the number of cluster I want to have 13 clusters so I am using kmean method based on tanimoto similarity score with scikit</p> <p>here is my code :</p> <pre><code>s...
1
2016-08-09T10:11:34Z
38,848,272
<p>I think the problem in clustering is how to choose appropriate k. Your problem may be resolve as follows:</p> <ol> <li><p>determine the appropriate k-clusters number. You can use some methods such as Elbow,... refer the link below -- <a href="https://datasciencelab.wordpress.com/2013/12/27/finding-the-k-in-k-means...
0
2016-08-09T10:29:45Z
[ "python", "cluster-analysis", "rdkit" ]
Center align outputs in ipython notebook
38,848,219
<p>I want to center align the outputs (which includes text and plots) in my <code>ipython notebook</code>. Is there a way in which I can add styling in the same notebook for the same? Code or screenshot examples would greatly help.</p>
1
2016-08-09T10:26:23Z
38,859,920
<p>Try running this in a code-cell to override the default CSS for an output cell:</p> <pre><code>from IPython.display import display, HTML CSS = """ .output { align-items: center; } """ HTML('&lt;style&gt;{}&lt;/style&gt;'.format(CSS)) </code></pre> <p><strong>Example</strong> <a href="http://i.stack.imgur.com...
2
2016-08-09T20:33:42Z
[ "python", "css", "ipython", "ipython-notebook", "jupyter-notebook" ]
Python remove customized stop words from pandas dataframe
38,848,222
<p>I was following the next question: <a href="http://stackoverflow.com/questions/29523254/python-remove-stop-words-from-pandas-dataframe/38846564">Python remove stop words from pandas dataframe</a></p> <p>but it doesnt work for me for a customized stop words list, check out this code:</p> <pre><code> pos_tweets = [(...
0
2016-08-09T10:26:50Z
38,848,260
<p>You need assign output back to column <code>tweet</code>:</p> <pre><code>test['tweet'] = test['tweet'].apply(lambda x: [item for item in x if item not in stop]) print (test) tweet col2 0 [i, this] positive 1 [th...
0
2016-08-09T10:29:14Z
[ "python", "pandas", "dataframe" ]
How to use tornado coroutines in this case?
38,848,363
<p>I have created tornado server which accepts python and matlab code and executes it. Here is server code.</p> <pre><code>from zmq.eventloop.zmqstream import ZMQStream from zmq.eventloop import ioloop ioloop.install() from functools import partial from tornado import web, gen, escape from tornado import options, htt...
2
2016-08-09T10:34:11Z
38,863,406
<p>The unfortunately cryptic error message "'NoneType' object is not iterable" means that you are calling <code>set_result</code> more than once on the same <code>Future</code> object. I don't know much about zmq or the jupyter kernel interfaces, but my guess is that either the IDs returned by the <code>execute</code> ...
0
2016-08-10T02:39:04Z
[ "python", "asynchronous", "tornado", "jupyter", "coroutine" ]
Apply function on each column in a pandas dataframe
38,848,411
<p>How I can write following function in more pandas way:</p> <pre><code> def calculate_df_columns_mean(self, df): means = {} for column in df.columns.columns.tolist(): cleaned_data = self.remove_outliers(df[column].tolist()) means[column] = np.mean(cleaned_data) ret...
-1
2016-08-09T10:36:21Z
38,848,528
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow"><code>dataFrame.apply(func, axis=0)</code></a>:</p> <pre><code># axis=0 means apply to columns; axis=1 to rows df.apply(numpy.sum, axis=0) # equiv to df.sum(0) </code></pre>
1
2016-08-09T10:41:15Z
[ "python", "pandas", "dataframe" ]
Apply function on each column in a pandas dataframe
38,848,411
<p>How I can write following function in more pandas way:</p> <pre><code> def calculate_df_columns_mean(self, df): means = {} for column in df.columns.columns.tolist(): cleaned_data = self.remove_outliers(df[column].tolist()) means[column] = np.mean(cleaned_data) ret...
-1
2016-08-09T10:36:21Z
38,848,624
<p>It seems to me that the iteration over the columns is unnecessary:</p> <pre><code>def calculate_df_columns_mean(self, df): cleaned_data = self.remove_outliers(df[column].tolist()) return cleaned_data.mean() </code></pre> <p>the above should be enough assuming that <code>remove_outliers</code> still returns...
2
2016-08-09T10:45:48Z
[ "python", "pandas", "dataframe" ]
except NameError not working
38,848,453
<p>I am trying to make a listool module.</p> <p>I am trying to make a checking function which checks the availability of an item in a list.</p> <p>Here is my non-working code:</p> <pre><code>def check(lst, item): try: if item in lst: return "Requested Item In List" else: r...
-1
2016-08-09T10:38:18Z
39,112,820
<p><code>NameError</code> typically indicates that the variable you are trying to reference does not exist. If you look at your error message, it says <code>name 'example_list' is not defined</code>. This should tell you, I tried to use <code>example_list</code> but the program couldn't find it. Most reasons for this a...
0
2016-08-24T00:53:07Z
[ "python", "list", "python-3.x", "module", "availability" ]
Sortin apache log with Python
38,848,537
<p>For example I have this simple apache log:</p> <pre><code>192.168.1.1 GET /index.php 192.168.1.1 GET /pilt.png 192.168.1.1 GET /index.php 192.168.1.5 GET /index.php 192.168.1.5 GET /pilt.png 192.168.1.7 GET /index.php 192.168.1.7 GET /index.php 192.168.1.7 GET /index.php 192.168.1.7 GET /kaust/index.php 192.168.1.7...
0
2016-08-09T10:41:48Z
38,848,878
<p>This is how it will be done : </p> <pre><code>x = open('PATH_TO_FILE').read() from itertools import groupby from operator import itemgetter x = x.split('\n') for i in range(len(x)): x[i] = x[i].split(' ') j = 0 for elt, items in groupby(x, itemgetter(0)): j += 1 k = 0 print elt, items for i i...
0
2016-08-09T10:58:31Z
[ "python", "apache", "python-2.7" ]
Sortin apache log with Python
38,848,537
<p>For example I have this simple apache log:</p> <pre><code>192.168.1.1 GET /index.php 192.168.1.1 GET /pilt.png 192.168.1.1 GET /index.php 192.168.1.5 GET /index.php 192.168.1.5 GET /pilt.png 192.168.1.7 GET /index.php 192.168.1.7 GET /index.php 192.168.1.7 GET /index.php 192.168.1.7 GET /kaust/index.php 192.168.1.7...
0
2016-08-09T10:41:48Z
38,849,169
<p>You can use <code>defaultdict(int)</code> for your purpose :</p> <pre><code>from collections import defaultdict my_dict = defaultdict(int) w = open("C:\\Users\\xxx\\Desktop\\test.txt", "r") for line in w: ip = line.split(' ')[0] my_dict[ip]+=1 my_dict # defaultdict(&lt;class 'int'&gt;, {'192.168.1.7': 5, ...
0
2016-08-09T11:11:55Z
[ "python", "apache", "python-2.7" ]
ValueError: all the input arrays must have same number of dimensions
38,848,759
<p>I'm having a problem with <code>np.append</code>.</p> <p>I'm trying to duplicate the last column of 20x361 matrix <code>n_list_converted</code> by using the code below:</p> <pre><code>n_last = [] n_last = n_list_converted[:, -1] n_lists = np.append(n_list_converted, n_last, axis=1) </code></pre> <p>But I get erro...
1
2016-08-09T10:52:32Z
38,850,126
<p>(n,) and (n,1) are not the same shape. Try casting the vector to an array by using the <code>[:, None]</code> notation:</p> <pre><code>n_lists = np.append(n_list_converted, n_last[:, None], axis=1) </code></pre> <p>Alternatively, when extracting <code>n_last</code> you can use</p> <pre><code>n_last = n_list_conve...
1
2016-08-09T12:00:13Z
[ "python", "arrays", "numpy", "append" ]
ValueError: all the input arrays must have same number of dimensions
38,848,759
<p>I'm having a problem with <code>np.append</code>.</p> <p>I'm trying to duplicate the last column of 20x361 matrix <code>n_list_converted</code> by using the code below:</p> <pre><code>n_last = [] n_last = n_list_converted[:, -1] n_lists = np.append(n_list_converted, n_last, axis=1) </code></pre> <p>But I get erro...
1
2016-08-09T10:52:32Z
38,850,254
<p>The reason why you get your error is because a "1 by n" matrix is different from an array of length n.</p> <p>I recommend using <code>hstack()</code> and <code>vstack()</code> instead. Like this:</p> <pre><code>import numpy as np a = np.arange(32).reshape(4,8) # 4 rows 8 columns matrix. b = a[:,-1:] ...
1
2016-08-09T12:06:37Z
[ "python", "arrays", "numpy", "append" ]
ValueError: all the input arrays must have same number of dimensions
38,848,759
<p>I'm having a problem with <code>np.append</code>.</p> <p>I'm trying to duplicate the last column of 20x361 matrix <code>n_list_converted</code> by using the code below:</p> <pre><code>n_last = [] n_last = n_list_converted[:, -1] n_lists = np.append(n_list_converted, n_last, axis=1) </code></pre> <p>But I get erro...
1
2016-08-09T10:52:32Z
38,855,679
<p>If I start with a 3x4 array, and concatenate a 3x1 array, with axis 1, I get a 3x5 array:</p> <pre><code>In [911]: x = np.arange(12).reshape(3,4) In [912]: np.concatenate([x,x[:,-1:]], axis=1) Out[912]: array([[ 0, 1, 2, 3, 3], [ 4, 5, 6, 7, 7], [ 8, 9, 10, 11, 11]]) In [913]: x.shape,x[:,-1...
1
2016-08-09T16:09:05Z
[ "python", "arrays", "numpy", "append" ]