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
rolling mean with increasing window
39,468,228
<p>I have a range</p> <pre><code>np.arange(1,11) # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] </code></pre> <p>and for each element, <em>i</em>, in my range I want to compute the average from element <em>i=0</em> to my current element. the result would be something like:</p> <pre><code>array([ 1. , 1.5, 2. , 2.5, 3. , 3.5...
2
2016-09-13T10:50:52Z
39,468,415
<p>This seems to be the simplest, although it may become inefficient if <em>x</em> is very large:</p> <pre><code>x = range(1,11) [np.mean(x[:i+1]) for i in xrange(0,len(x))] </code></pre>
1
2016-09-13T11:02:06Z
[ "python", "pandas", "numpy" ]
rolling mean with increasing window
39,468,228
<p>I have a range</p> <pre><code>np.arange(1,11) # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] </code></pre> <p>and for each element, <em>i</em>, in my range I want to compute the average from element <em>i=0</em> to my current element. the result would be something like:</p> <pre><code>array([ 1. , 1.5, 2. , 2.5, 3. , 3.5...
2
2016-09-13T10:50:52Z
39,469,185
<p>Here's a vectorized approach -</p> <pre><code>a.cumsum()/(np.arange(a.size)+1) </code></pre> <p>Please note that to make sure the results are floating pt numbers, we need to add in at the start :</p> <pre><code>from __future__ import division </code></pre> <p>Alternatively, we can use <code>np.true_divide</code>...
1
2016-09-13T11:43:05Z
[ "python", "pandas", "numpy" ]
Program hang with asyncio
39,468,252
<p>Here is my code:</p> <pre><code>import asyncio, socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('', 1234)) sock.setblocking(False) queue = asyncio.Queue() def sock_reader(): print(sock.recv(1024)) # x = yield from queue def test_sock_reader(): sock = socket.socket(socket.AF...
2
2016-09-13T10:52:31Z
39,469,604
<p>The problem is a combination of syntax and API definition.</p> <p>First of, refer to the <a href="https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.add_reader">documentation of <code>add_reader</code></a>, which states that it expects a <em>callback</em>. It is not obvious from the ...
5
2016-09-13T12:02:35Z
[ "python", "python-3.5", "python-asyncio" ]
Assign group name to kivy graphic instruction
39,468,389
<p>This seems like it should be really simple, yet I have failed to find a way to do it.</p> <p>In order to iterate over the instructions on my canvas, I am supposed to use <code>canvas.get_group()</code> method. In order to do that, I first need to assign a group name to whichever instructions I intend to iterate ove...
0
2016-09-13T11:00:12Z
39,468,603
<p>Use <code>InstructionGroup()</code>. This is an example from kivy documentations:</p> <pre><code>blue = InstructionGroup() blue.add(Color(0, 0, 1, 0.2)) blue.add(Rectangle(pos=self.pos, size=(100, 100))) green = InstructionGroup() green.add(Color(0, 1, 0, 0.4)) green.add(Rectangle(pos=(100, 100), size=(100, 100)))...
0
2016-09-13T11:12:26Z
[ "python", "kivy", "kivy-language" ]
Assign group name to kivy graphic instruction
39,468,389
<p>This seems like it should be really simple, yet I have failed to find a way to do it.</p> <p>In order to iterate over the instructions on my canvas, I am supposed to use <code>canvas.get_group()</code> method. In order to do that, I first need to assign a group name to whichever instructions I intend to iterate ove...
0
2016-09-13T11:00:12Z
39,476,851
<p>This is an answer to my own question which I was able to find.</p> <p>So, i have found (<a href="http://stackoverflow.com/questions/36230958/how-do-i-reference-ids-of-children-within-a-canvas-in-kivy">from here</a>) that Instructions (and many other classes in the canvas scope) have a <code>group</code> property, n...
0
2016-09-13T18:33:21Z
[ "python", "kivy", "kivy-language" ]
Memory allocation in python
39,468,407
<p>I create a list with three elements named l after that I copy all the content of the list into the list y. But when I print the address of them in the memory I don't understand why this is not the same address. Why y is not a reference of l, and if I want that y will be a reference of l so that they will have the sa...
-2
2016-09-13T11:01:30Z
39,468,435
<p>Because a slice of a list creates a new list. id returns the address of each list.</p>
0
2016-09-13T11:03:00Z
[ "python", "memory" ]
Memory allocation in python
39,468,407
<p>I create a list with three elements named l after that I copy all the content of the list into the list y. But when I print the address of them in the memory I don't understand why this is not the same address. Why y is not a reference of l, and if I want that y will be a reference of l so that they will have the sa...
-2
2016-09-13T11:01:30Z
39,468,440
<p><code>[:]</code> copies the content of <code>l</code> to a new list <code>y</code>, so they need to be in different addresses. To make <code>y</code> a reference of <code>l</code>, simply write</p> <pre><code>y = l </code></pre>
2
2016-09-13T11:03:09Z
[ "python", "memory" ]
Memory allocation in python
39,468,407
<p>I create a list with three elements named l after that I copy all the content of the list into the list y. But when I print the address of them in the memory I don't understand why this is not the same address. Why y is not a reference of l, and if I want that y will be a reference of l so that they will have the sa...
-2
2016-09-13T11:01:30Z
39,468,652
<p>A good point is that if you write this statement</p> <pre><code>l = [8,12,3], </code></pre> <p>Python creates a pointer from the object <code>l</code> to a list <code>[8, 12, 3]</code>. </p> <p>In case you make this statement</p> <pre><code>y = l, </code></pre> <p>Then the object <code>y</code> points to <code>...
0
2016-09-13T11:14:39Z
[ "python", "memory" ]
ttk label doesn't behave properly
39,468,535
<p>A ttk Label which contains a bitmap image doesn't behave properly when I change the image's foreground color. Only ttk Labels have this problem. Tkinter labels works properly.</p> <p>Here is the code:</p> <pre><code>import tkinter as tk import tkinter.ttk as ttk BITMAP0 = """ #define zero_width 24 #define zero_he...
1
2016-09-13T11:08:12Z
39,488,578
<p>Try to reassign the changed image to label:</p> <pre><code>def change_color(n): img.config(foreground=color[n%4]) label.config(image=img) # reassign the changed image to label root.after(1000, change_color, n+1) </code></pre>
2
2016-09-14T10:50:26Z
[ "python", "python-3.x", "tkinter", "ttk" ]
TensorFlow freeze_graph.py: The name 'save/Const:0' refers to a Tensor which does not exist
39,468,640
<p>I am currently trying to export a trained TensorFlow model as a ProtoBuf file to use it with the TensorFlow C++ API on Android. Therefore, I'm using the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py" rel="nofollow"><code>freeze_graph.py</code></a> script.</p> ...
1
2016-09-13T11:14:08Z
39,476,154
<p>The <code>--filename_tensor_name</code> flag is used to specify the name of a placeholder tensor created when you construct a <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/state_ops.html#Saver" rel="nofollow"><code>tf.train.Saver</code></a> for your model.*</p> <p>In your original program, you ...
1
2016-09-13T17:49:41Z
[ "python", "tensorflow", "protocol-buffers", "google-protobuf" ]
Figure out if called from function without main guard
39,468,658
<p>If a module is imported from a script without a main guard (<code>if __name__ == '__main__':</code>), doing any kind of parallelism in some function in the module will result in an infinite loop on Windows. Each new process loads all of the sources, now with <code>__name__</code> not equal to <code>'__main__'</code>...
0
2016-09-13T11:15:00Z
39,471,519
<p>Since you're using <code>multiprocessing</code>, you can also use it to detect if you're the main process or a child process. However, these features are not documented and are therefore just implementation details that could change without warning between python versions. </p> <p>Each process has a <code>name</cod...
1
2016-09-13T13:37:32Z
[ "python", "windows", "multithreading" ]
Match Current date with CSV file and print the matches
39,468,735
<p>hi so im writing a python script to send a birthday mail kind of thing . But im stuck in middle . i Have a csv file containing names and there birthdays and already wrote a code to get the current date ,</p> <pre><code>#Import Date import datetime CurrentDate = datetime.datetime.now().date() CurrentDate = CurrentDa...
1
2016-09-13T11:19:17Z
39,468,887
<p>Just group them in a list and output whatever you want:</p> <pre><code>import csv from datetime import datetime today = datetime.now().date().strftime("%d-%B-%Y") with open("b.csv") as f: has_birthday = [user for user, birthday in csv.reader(f) if birthday == today] print(has_birthday) </code></pre> <p>Ou...
1
2016-09-13T11:27:47Z
[ "python", "date", "csv", "datetime", "smtp" ]
Match Current date with CSV file and print the matches
39,468,735
<p>hi so im writing a python script to send a birthday mail kind of thing . But im stuck in middle . i Have a csv file containing names and there birthdays and already wrote a code to get the current date ,</p> <pre><code>#Import Date import datetime CurrentDate = datetime.datetime.now().date() CurrentDate = CurrentDa...
1
2016-09-13T11:19:17Z
39,661,606
<p>Thank you everyone , So after doing some work and after getting all your helps , i was able to resolve this </p> <pre><code>import csv from datetime import datetime today = datetime.now().date().strftime("%d-%B-%Y") while True: with open("InputFile.csv") as d: has_birthday = [user for user, birthday, gender...
0
2016-09-23T13:08:25Z
[ "python", "date", "csv", "datetime", "smtp" ]
Easiest way to parallelise a call to map?
39,468,860
<p>Hey I have some code in Python which is basically a World Object with Player objects. At one point the Players all get the state of the world and need to return an action. The calculations the players do are independent and only use the instance variables of the respective player instance.</p> <pre><code>while True...
1
2016-09-13T11:26:02Z
39,469,046
<p>The most straightforward way is to use <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.map" rel="nofollow">multiprocessing.Pool.map</a> (which works just like <code>map</code>):</p> <pre><code>import multiprocessing pool = multiprocessing.Pool() def do_stuf...
2
2016-09-13T11:36:15Z
[ "python", "python-3.x", "parallel-processing" ]
Accessing ReferenceProperty values in a one to many relation from a referenced key in Appengine?
39,468,952
<p>I am using AppEngine in Python and I have two Models using ndb :</p> <pre><code># Post model class WikiPost(ndb.Model) : url = ndb.StringProperty(required = True) content = ndb.TextProperty(required = True) date = ndb.DateProperty(auto_now_add = True) </code></pre> <p>Second Model</p> <pre><code>cla...
0
2016-09-13T11:31:20Z
39,469,095
<p><code>r_post</code> is a key, so you can just call <code>.get()</code> on it.</p> <pre><code>referenced_wikipost = my_wikipostversion_instance.r_post.get() </code></pre>
0
2016-09-13T11:38:55Z
[ "python", "google-app-engine", "app-engine-ndb" ]
list search obj with index number
39,469,002
<pre><code>stations = ['Schagen', 'Heerhugowaard', 'Alkmaar', 'Castricum', 'Zaandam', 'Amsterdam Sloterdijk', 'Amsterdam Centraal', 'Amsterdam Amstel', 'Utrecht Centraal', '’s-Hertogenbosch', 'Eindhoven', 'Weert', 'Roermond', 'Sittard', 'Maastricht'] </code></pre> <p>I tried this:</p> <pre><code>print(sations.index...
-5
2016-09-13T11:33:38Z
39,469,329
<p>If you want to find an object, you can use <code>index()</code>. For example</p> <pre><code>index = 0 if "Zaandam" in stations: index = stations.index("Zaandam") print(stations[index]) </code></pre> <p>The index of <code>Zaandam</code> is being logged to the variable <code>index</code> and then it's logged ind...
0
2016-09-13T11:49:39Z
[ "python", "list", "python-3.x" ]
Convert date from yyyymmddHHMMSS format
39,469,132
<p>I would like to read two columns (columns 0, 4) of the following ascii file and plot them. One contains the date in yyymmddHHMMSS format which I would like to covert to a date number.</p> <pre><code># Date RMS.I RMS.Q Cal.I Cal.Q 20121220220000 1.45485 1.42051 1.26393 1.29448 20121220230000 1.4...
2
2016-09-13T11:40:33Z
39,469,791
<p>You can import as a <a href="http://docs.scipy.org/doc/numpy/user/basics.rec.html" rel="nofollow">structured array</a> as follow:</p> <pre><code>mydate, myvar = np.loadtxt('infile.txt', comments="#", skiprows=1, usecols=(0,4), unpack=True, dtype=[('date', '|S10'), ('floatmio', float)]) </code></pre> <p>it will imp...
1
2016-09-13T12:12:06Z
[ "python", "numpy" ]
Cannot set Allow quoted newlines property in bigquery using python?
39,469,308
<p>I cannot able to enable property "Allow quoted newlines" in google bigquery load job.</p> <pre><code>configuration = { 'load': { 'createDisposition': create_disposition, 'destinationTable': { 'projectId': destination_project, 'datasetId': destination_d...
0
2016-09-13T11:48:30Z
39,488,929
<p>Try to remove the row configuration['load']['quote'] = ''</p> <p>If you want to allow quoted newlines, you have to specify a non-empty quote char.</p>
0
2016-09-14T11:08:29Z
[ "python", "python-2.7", "google-bigquery", "google-api-client", "google-api-python-client" ]
Adding the header to a csv file
39,469,325
<p>I have a csv file with the dimensions <code>100*512</code> , I want to process it further in <code>spark</code>. The problem with the file is that it doesn't contain header i.e <code>column names</code> . I need these column names for further ETL in <code>machine learning</code> . I have the column names in another...
-1
2016-09-13T11:49:22Z
39,469,456
<p>Unix:</p> <pre><code>cat header_file.csv data_file.csv &gt; data_file.csv </code></pre> <p>Windows:</p> <pre><code>type header_file.csv data_file.csv &gt; data_file.csv </code></pre>
1
2016-09-13T11:56:04Z
[ "python", "csv" ]
Adding the header to a csv file
39,469,325
<p>I have a csv file with the dimensions <code>100*512</code> , I want to process it further in <code>spark</code>. The problem with the file is that it doesn't contain header i.e <code>column names</code> . I need these column names for further ETL in <code>machine learning</code> . I have the column names in another...
-1
2016-09-13T11:49:22Z
39,469,474
<p>First read your csv file:</p> <pre><code>from pandas import read_csv df = read_csv('test.csv') </code></pre> <p>If there are two columns in your dataset(column a, and column b) use: </p> <pre><code>df.columns = ['a', 'b'] </code></pre> <p>Write this new dataframe to csv </p> <pre><code>df.to_csv('test_2.c...
1
2016-09-13T11:56:53Z
[ "python", "csv" ]
Adding the header to a csv file
39,469,325
<p>I have a csv file with the dimensions <code>100*512</code> , I want to process it further in <code>spark</code>. The problem with the file is that it doesn't contain header i.e <code>column names</code> . I need these column names for further ETL in <code>machine learning</code> . I have the column names in another...
-1
2016-09-13T11:49:22Z
39,469,491
<p>you can use it :</p> <pre><code> import csv with open('names.csv', 'w') as csvfile: fieldnames = ['first_name', 'last_name'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'}) wr...
1
2016-09-13T11:57:41Z
[ "python", "csv" ]
Adding the header to a csv file
39,469,325
<p>I have a csv file with the dimensions <code>100*512</code> , I want to process it further in <code>spark</code>. The problem with the file is that it doesn't contain header i.e <code>column names</code> . I need these column names for further ETL in <code>machine learning</code> . I have the column names in another...
-1
2016-09-13T11:49:22Z
39,469,561
<p>Bit a old way ...</p> <p><strong>Content of demo.csv before columns:</strong></p> <pre><code>4444,Drowsy,bit drowsy 45888,Blurred see - hazy,little seeing vision 45933,Excessive upper pain,pain problems 112397013,air,agony 76948002,pain,agony </code></pre> <p><strong>Content of xyz.txt :</strong></p> <pre><code>...
0
2016-09-13T12:00:18Z
[ "python", "csv" ]
Tensorflow - shape error when reading data from file
39,469,395
<p>I am trying to train a single layer perceptron (basing my code on <a href="https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/multilayer_perceptron.py" rel="nofollow">this</a>) on the following data file in tensor flow:</p> <pre><code>1,1,0.05,-1.05 1,1,0.1,-1.1 .... </code><...
0
2016-09-13T11:52:40Z
39,469,609
<p>Your graph expects X to be a tensor of shape (?, 3). Your example data is of the shape (3,) i.e. a 1 dimensional vector of length 3. Either reshape example to (1, 3), or pass a batch of examples in one shot (e.g. 10, giving a shape of (10, 3))</p>
1
2016-09-13T12:02:41Z
[ "python", "tensorflow" ]
You have 3 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth
39,469,409
<p>I've just created Django project and ran server. It works fine but showed me warnings like</p> <pre><code>You have 14 unapplied migration(s)... </code></pre> <p>Then I ran</p> <pre><code>python manage.py migrate </code></pre> <p>in the terminal. It worked fine but showed me this</p> <pre><code>?: (1_7.W001) MID...
-1
2016-09-13T11:53:18Z
39,470,150
<p>So my problem was that I used wrong python version for migration.</p> <pre><code>python3.5 manage.py migrate </code></pre> <p>solves problem</p>
2
2016-09-13T12:29:46Z
[ "python", "django", "pycharm" ]
Allow only one flask request for a particular route
39,469,431
<p>I have a flask app which uses angularjs front end. I make the http request through $http service. As shown in the code below.</p> <pre><code>$http.post('/updateGraph', $scope.graphingParameters).success(function(response) { $scope.graphingParameters.graph = response.graph; $scope.listUnits = JSON.pa...
0
2016-09-13T11:54:31Z
39,469,624
<p>You could look at implementing a task or work queue using something like Redis and <a href="http://python-rq.org" rel="nofollow"><code>python-rq</code></a>.</p> <p>Essentially, when the route is run, rather than perform your work immediately, you queue a task (in this case, to update your graph) to run asynchronous...
0
2016-09-13T12:03:48Z
[ "jquery", "python", "angularjs", "ajax", "flask" ]
Allow only one flask request for a particular route
39,469,431
<p>I have a flask app which uses angularjs front end. I make the http request through $http service. As shown in the code below.</p> <pre><code>$http.post('/updateGraph', $scope.graphingParameters).success(function(response) { $scope.graphingParameters.graph = response.graph; $scope.listUnits = JSON.pa...
0
2016-09-13T11:54:31Z
39,536,266
<p>From your description of the situation, this is something that would be better solved on the client side.</p> <p>I would just set a flag (define it on a global or class level) if there's a request already ongoing for that task. For example:</p> <pre><code>if (processing) { return; } processing = true; $http.po...
0
2016-09-16T16:31:22Z
[ "jquery", "python", "angularjs", "ajax", "flask" ]
store complex dictionary in pandas dataframe
39,469,643
<p>This question follows my previous one.it's a mother dictionary of the one before <strong><a href="http://stackoverflow.com/questions/39458806/store-dictionary-in-pandas-dataframe">store dictionary in pandas dataframe</a></strong></p> <p>I have a dictionary </p> <pre><code> dictionary_example={'New York':{1234:{'c...
1
2016-09-13T12:04:58Z
39,471,338
<p>The previously provided solution, as you quote, is not a very neat one. This one is more readable and provides the solution for your current problem. If possible you should reconsider your data structure though...</p> <pre><code>df = pd.DataFrame() question_ids = [0,1,2] </code></pre> <p>Create a dataframe with a ...
2
2016-09-13T13:28:25Z
[ "python", "json", "pandas", "dictionary", "dataframe" ]
TypeError: expected string or bytes-like object pandas variable
39,469,711
<p>I have dataset like this</p> <pre><code>import pandas as pd df = pd.DataFrame({'word': ['abs e learning ', 'abs e-learning', 'abs e&amp;learning', 'abs elearning']}) </code></pre> <p>I want to get </p> <pre><code> word 0 abs elearning 1 abs elearning 2 abs elearning 3 abs elearning </code></pre> <p...
1
2016-09-13T12:08:29Z
39,469,848
<p><code>df['word']</code> is a list. Converting to string just destroys your list.</p> <p>You need to apply regex on each member:</p> <pre><code>for r, map in re_map.items(): df['word'] = [re.sub(r, map, e) for e in df['word']]: </code></pre> <p>classical alternate method without list comprehension:</p> <pre><...
1
2016-09-13T12:15:13Z
[ "python", "regex" ]
I can print a local variable but not return it (python 2.7)
39,469,812
<p>EDIT: Adding in </p> <pre><code>upperline = [] lowerline = [] </code></pre> <p>above the <code>for</code> loop seems to allow the function to be called once as expected, but not more than once. If called a second time the following error will be thrown:</p> <pre><code>transitenergy = (float(upperline[1]) - float(...
0
2016-09-13T12:13:08Z
39,472,654
<p>The solution lies in in the fact that the datafile was kept open. Adding the line <code>datafile.seek(0)</code> to the function i.e.</p> <pre><code>def crossreference(datafile, lookuppointers): pointers = [(int(lookuppointers[0]) - 1), (int(lookuppointers[1]) - 1)] lowerpointer = min(pointers) upperpoin...
0
2016-09-13T14:35:12Z
[ "python", "python-2.7", "function", "for-loop" ]
Multiple Mixins and properties
39,469,841
<p>I am trying to create a mixin class that has it's own properties, but as the class has no <strong>init</strong> to initialize the "hidden" variable behind the property.</p> <pre><code>class Software: __metaclass__ = ABCMeta @property def volumes(self): return self._volumes @volumes.setter...
0
2016-09-13T12:14:58Z
39,471,186
<p>Ok so here is what I came up with, I am open to other answers, if I have made this way over complicated.</p> <pre><code>class Software: @property def volumes(self): return self._volumes @volumes.setter def volumes(self, value): pass def __init__(self): self._volumes = No...
0
2016-09-13T13:20:48Z
[ "python", "mixins" ]
Multiple Mixins and properties
39,469,841
<p>I am trying to create a mixin class that has it's own properties, but as the class has no <strong>init</strong> to initialize the "hidden" variable behind the property.</p> <pre><code>class Software: __metaclass__ = ABCMeta @property def volumes(self): return self._volumes @volumes.setter...
0
2016-09-13T12:14:58Z
39,471,532
<p>Yes, that's wildly overcomplicated. A class (including mixins) should only be responsible for calling the <em>next</em> implementation in the MRO, not marshalling all of them. Try:</p> <pre><code>class Software: @property def volumes(self): return self._volumes @volumes.setter def volumes(s...
0
2016-09-13T13:38:15Z
[ "python", "mixins" ]
Numpy in1D multiple evaluation statements
39,469,936
<p>I'm trying to use numpy as opposed to nested for loops and trying to find if a value is within a particular tolerance.</p> <p>The code in python using the nested loops works fine and I do get the results I'm looking for but unfortunately is not scalable and takes a couple of hours when the size of the list is 200k ...
0
2016-09-13T12:19:09Z
39,482,725
<p>If I copy-n-paste your <code>a</code> I get a 4x16 array of strings</p> <pre><code>In [37]: a Out[37]: array([['id1', '8988', '7997', '210.0', '240.0', '180', '300', '7000.0', '9038', '8938', '8047', '7947', '231.0', '189.0', '8400.0', '5600.0'], .... dtype='&lt;U6') </code></pre> <p>A...
0
2016-09-14T04:55:11Z
[ "python", "numpy", "evaluation" ]
Numpy in1D multiple evaluation statements
39,469,936
<p>I'm trying to use numpy as opposed to nested for loops and trying to find if a value is within a particular tolerance.</p> <p>The code in python using the nested loops works fine and I do get the results I'm looking for but unfortunately is not scalable and takes a couple of hours when the size of the list is 200k ...
0
2016-09-13T12:19:09Z
39,483,404
<p>As hpaulj says, first get rid of the <code>id</code>'s.</p> <p>Second, why are your tolerances and your values in the same array? If you had <code>min_tol</code> and <code>max_tol</code> in separate arrays, you could do this much more easily.</p> <p>You probably need something like (after removing the <code>id</co...
0
2016-09-14T05:58:17Z
[ "python", "numpy", "evaluation" ]
Install Python 3.5.2, but pip for Python 2.6
39,469,953
<p>VPS-server was a version Python 2.6, I installed version Python 3.5.2. When I try to install some packages with help <code>pip</code>, I got errors.</p> <p>During installation packages:</p> <pre><code>DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future versi...
1
2016-09-13T12:20:10Z
39,470,070
<p>if you haven't pip in server you can use <a href="https://bootstrap.pypa.io/get-pip.py" rel="nofollow">get-pip</a> file:</p> <p>after install python usually installed pip and you can run by <code>pip3</code> command</p> <p>for example you can use:</p> <pre><code>pip3 install netaddr </code></pre>
1
2016-09-13T12:26:04Z
[ "python", "centos", "pip" ]
Install Python 3.5.2, but pip for Python 2.6
39,469,953
<p>VPS-server was a version Python 2.6, I installed version Python 3.5.2. When I try to install some packages with help <code>pip</code>, I got errors.</p> <p>During installation packages:</p> <pre><code>DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future versi...
1
2016-09-13T12:20:10Z
39,470,072
<p>Upgrading pip manually solved this issue for me once. <a href="https://pip.pypa.io/en/stable/installing/#upgrading-pip" rel="nofollow" title="Upgrad pip">Update pip Documentation</a></p> <blockquote> <p>pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4 downloaded from python.org, but you...
0
2016-09-13T12:26:08Z
[ "python", "centos", "pip" ]
VMWare pyvmomi 6.0.0 : Operation not supported
39,469,985
<p>I am using VMWare's pyvmomi to manage my ESXI's virtual machines </p> <p>I'm using :</p> <p><strong>pyvmomi-6.0.0</strong> with <strong>python 2.7.5</strong> to clone a VM on</p> <p><strong>VMWare ESXi 6.0.0 Update 1</strong> which is managed by</p> <p><strong>vCenter Server 6</strong></p> <p>Using pyvmomi, i c...
1
2016-09-13T12:22:06Z
39,470,594
<p>It appears this is because VMWARE has disabled many operations when directly connected to the ESXi.</p> <p>Apparently, i should have connected to my vCenterServer in order to properly clone my VM.</p>
1
2016-09-13T12:52:19Z
[ "python", "vmware", "vsphere", "esxi", "pyvmomi" ]
Matplotlib is ignoring the given colourmap
39,470,003
<p>This is my plot:</p> <p><a href="http://i.stack.imgur.com/7q3zW.png" rel="nofollow"><img src="http://i.stack.imgur.com/7q3zW.png" alt="enter image description here"></a></p> <p>This is supposed to be a surface plot. As you can see that has somewhat failed. Particularly it is ignoring passed colour map.</p> <p>It ...
0
2016-09-13T12:22:57Z
39,472,348
<p>Your code is fine, and the plot shown is a surface plot. You can tell because lines in the background are behind blueish areas. Remove the alpha settings, consider using a different cmap or specify a custom range for your colorbar to fit your data range.</p>
0
2016-09-13T14:19:23Z
[ "python", "matplotlib" ]
Initialize a Flask-WhooshAlchemy index when using the app factory pattern
39,470,007
<p>I am developing an app with Flask using the <a href="http://flask.pocoo.org/docs/0.11/patterns/appfactories/#factories-extensions" rel="nofollow">application factory pattern</a>. Initializing the Whoosh index doesn't work, because <code>current_app</code> cannot be used without setting up an app context explicitly. ...
1
2016-09-13T12:23:11Z
39,474,075
<p><a href="http://stackoverflow.com/questions/19437883/when-scattering-flask-models-runtimeerror-application-not-registered-on-db-w">You can't use <code>current_app</code> outside an application context.</a> An application context exists during a request, or when explicitly created with <code>app.app_context()</code>...
0
2016-09-13T15:42:51Z
[ "python", "flask" ]
Python Overflow Error: iter index too large
39,470,012
<p>I have a problem with big iterator in for loop in the code below. It generates floats by reading a string list containing numbers.</p> <pre><code>def float_generator(tekstowe): x = '' for c in tekstowe: if c != ' ': x += c else: out = float(x) ...
3
2016-09-13T12:23:20Z
39,470,311
<p>Looks like <code>tekstowe</code> is a sequence type that only implements <code>__getitem__</code>, not <code>__iter__</code>, so it's using the Python iterator wrapper that calls <code>__getitem__</code> with 0, then 1, 2, 3, etc., until <code>__getitem__</code> raises <code>IndexError</code>.</p> <p>As an implemen...
4
2016-09-13T12:36:59Z
[ "python", "loops", "iterator" ]
Convert iteration to map
39,470,080
<p>I've got the following code:</p> <pre><code>@classmethod def load(self): with open('yaml/instruments.yaml', 'r') as ymlfile: return {v['name']: Instrument(**v) for (v) in list(yaml.load_all(ymlfile))} </code></pre> <p>I'd like to load these in parallel using something like:</p> <pre><code>return Threa...
0
2016-09-13T12:26:40Z
39,472,176
<p>Simple solution is to define a top level simple worker function for use in the executor:</p> <pre><code>def make_instrument_pair(d): return d['name'], Instrument(**d) </code></pre> <p>Then change:</p> <pre><code>@classmethod def load(self): with open('yaml/instruments.yaml', 'r') as ymlfile: retur...
1
2016-09-13T14:09:53Z
[ "python", "python-3.x" ]
read file with variable number of columns in python
39,470,115
<p>I'm reading a file with a variable number of columns, say 3 fixed columns + unknown/variable number of columns:</p> <pre><code>21 48 77 15 33 15 K12 78 91 17 64 58 24 R4 C16 R8 12 45 78 Y66 87 24 25 10 33 75 18 19 64 CF D93 </code></pre> <p>I want to store the first three column entries in specific lists/arrays, b...
1
2016-09-13T12:28:20Z
39,470,189
<p>you can use this code :</p> <pre><code>import os, sys import numpy as np fi = open("input.dat", "r") fo = open("output.dat", "w") culumn_3 = [] for line in fi: line = line.strip() columns = line.split() A00 = str(columns[0]) A01 = str(columns[1]) A02 = str(columns[2]) culumn_3.append(str(co...
1
2016-09-13T12:31:58Z
[ "python", "file", "multiple-columns" ]
read file with variable number of columns in python
39,470,115
<p>I'm reading a file with a variable number of columns, say 3 fixed columns + unknown/variable number of columns:</p> <pre><code>21 48 77 15 33 15 K12 78 91 17 64 58 24 R4 C16 R8 12 45 78 Y66 87 24 25 10 33 75 18 19 64 CF D93 </code></pre> <p>I want to store the first three column entries in specific lists/arrays, b...
1
2016-09-13T12:28:20Z
39,470,258
<p>I think following snippet code can help you. Also, you can edit this code for your project.</p> <pre><code>f = open("input.dat") line = f.readline().strip() # get the first line in line while line: # while a line exists in the file f columns = line.split('separator') # get all the columns while columns: ...
0
2016-09-13T12:34:25Z
[ "python", "file", "multiple-columns" ]
read file with variable number of columns in python
39,470,115
<p>I'm reading a file with a variable number of columns, say 3 fixed columns + unknown/variable number of columns:</p> <pre><code>21 48 77 15 33 15 K12 78 91 17 64 58 24 R4 C16 R8 12 45 78 Y66 87 24 25 10 33 75 18 19 64 CF D93 </code></pre> <p>I want to store the first three column entries in specific lists/arrays, b...
1
2016-09-13T12:28:20Z
39,470,337
<p>String split allows to limit number of extracted parts, so you can do following:</p> <pre><code>A00, A01, A02, rest = line.split(" ", 3) </code></pre> <p>Example:</p> <pre><code>print "1 2 3 4 5 6".split(" ", 3) ['1', '2', '3', '4 5 6'] </code></pre>
1
2016-09-13T12:38:24Z
[ "python", "file", "multiple-columns" ]
Python Code Error
39,470,177
<p>What's wrong with this program in Python? </p> <p>I need to take an integer input(N) - accordingly, I need to create an array of (N)integers, taking integers also as input. Finally, I need to print the sum of all the integers in the array.</p> <p>The input is in this format: </p> <pre><code>5 4 6 8 18 96 </code>...
-3
2016-09-13T12:31:03Z
39,470,214
<p><code>split()</code> returns a list which you are trying to convert to an integer. You probably wanted to convert everything in the list to an integer:</p> <pre><code>N = [int(i) for i in input().split()] </code></pre> <p>You can also use <code>map</code>:</p> <pre><code>N = list(map(int, input().split())) </code...
6
2016-09-13T12:32:42Z
[ "python" ]
Python Code Error
39,470,177
<p>What's wrong with this program in Python? </p> <p>I need to take an integer input(N) - accordingly, I need to create an array of (N)integers, taking integers also as input. Finally, I need to print the sum of all the integers in the array.</p> <p>The input is in this format: </p> <pre><code>5 4 6 8 18 96 </code>...
-3
2016-09-13T12:31:03Z
39,470,315
<p>You code fails because str.split() returns a list. <a href="https://docs.python.org/2/library/stdtypes.html#str.split" rel="nofollow">From the Python documentation</a></p> <blockquote> <p>Return a list of the words in the string, using sep as the delimiter string</p> </blockquote> <p>If your input is a series ...
1
2016-09-13T12:37:26Z
[ "python" ]
Python Code Error
39,470,177
<p>What's wrong with this program in Python? </p> <p>I need to take an integer input(N) - accordingly, I need to create an array of (N)integers, taking integers also as input. Finally, I need to print the sum of all the integers in the array.</p> <p>The input is in this format: </p> <pre><code>5 4 6 8 18 96 </code>...
-3
2016-09-13T12:31:03Z
39,470,385
<p>You could use sys module to take the input when calling the program and a lambda function to convert the string items in list to integers. You could also make use of the built-in sum function. Something like that:</p> <pre><code>#!/usr/bin/env python import sys s = sum(i for i in map(lambda x: int(x), sys.argv[1]....
2
2016-09-13T12:40:43Z
[ "python" ]
Sqlalchemy json column - how to preform a contains query
39,470,239
<p>I have the following table in mysql(5.7.12):</p> <pre><code>class Story(db.Model): sections_ids = Column(JSON, nullable=False, default=[]) </code></pre> <p><em>sections_ids</em> is basicly a list of integers [1, 2, ...,n]. I need to get all rows where sections_ids contains X. I tried the following:</p> <pre><...
0
2016-09-13T12:33:34Z
39,470,478
<p>Use <a href="https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-contains" rel="nofollow"><code>JSON_CONTAINS(json_doc, val[, path])</code></a>:</p> <pre><code>from sqlalchemy import func # JSON_CONTAINS returns 0 or 1, not found or found. Not sure if MySQL # likes integer values in WH...
1
2016-09-13T12:46:02Z
[ "python", "mysql", "json", "sqlalchemy" ]
Spark can't read an Orc table (returns empty table)
39,470,316
<p>Do I have to do anything special to be able to read Orc tables with Spark?</p> <p>I have two table copies in txt and orc. When reading txt table everything is ok. When reading orc table I get no errors but spark returns an empty table. </p> <p>Here is my code in python:</p> <pre><code>import pyspark CONF = (pyspa...
1
2016-09-13T12:37:26Z
39,470,577
<p>Can you try adding the database name before the table name as a.table_name</p>
0
2016-09-13T12:51:24Z
[ "python", "apache-spark", "orc" ]
Spark can't read an Orc table (returns empty table)
39,470,316
<p>Do I have to do anything special to be able to read Orc tables with Spark?</p> <p>I have two table copies in txt and orc. When reading txt table everything is ok. When reading orc table I get no errors but spark returns an empty table. </p> <p>Here is my code in python:</p> <pre><code>import pyspark CONF = (pyspa...
1
2016-09-13T12:37:26Z
39,477,515
<p>I don't think there is anything specific for ORC. can you run query on hive and make sure data is read properly. The empty table might be because hive cannot read the data the way you defined.</p>
0
2016-09-13T19:21:31Z
[ "python", "apache-spark", "orc" ]
Get reference of function inside function for usage in prototype/creation function
39,470,486
<p>I have two nested functions: The outer creates a creation method / prototype, the inner will create a concrete example of that prototype:</p> <pre><code>class Example: def __init__(self, str): self.str = str def make_prototype(proto_name): def make_example(example_name): return Example(prot...
0
2016-09-13T12:46:23Z
39,470,759
<p>You can use <code>__call__</code> class method. Your example would look like this:</p> <pre><code>class Example: def __init__(self, str, proto): self.str = str self.proto = proto class MakePrototype(): def __init__(self, name): self.name = name def __call__(self, proto_name): ...
1
2016-09-13T13:00:44Z
[ "python" ]
How do I define a complex type in an Avro Schema
39,470,557
<p>I have reviewed avro documentation as well as several examples online (and similar StackOverflow questions). I then attempted to define an avro schema, and had to progressively back out fields to determine what my issue was (the error message from the avro library in python was not as helpful as one would hope). I...
0
2016-09-13T12:50:17Z
39,472,234
<p>I was able to resolve the issue with the following schema:</p> <pre><code>{ "namespace" : "com.example", "name" : "methodEvent", "type" : "record", "fields" : [ {"name": "method", "type": "string"}, {"name": "code", "type": "int"}, {"name": "reason", "type": "string"} { "name": "siteI...
0
2016-09-13T14:13:18Z
[ "python", "json", "avro" ]
How do I define a complex type in an Avro Schema
39,470,557
<p>I have reviewed avro documentation as well as several examples online (and similar StackOverflow questions). I then attempted to define an avro schema, and had to progressively back out fields to determine what my issue was (the error message from the avro library in python was not as helpful as one would hope). I...
0
2016-09-13T12:50:17Z
39,482,927
<p>Avro's python implementation represents unions differently than their JSON encoding: it "unwraps" them, so the <code>siteId</code> field is expected to be just the string, without the wrapping object. See below for a few examples.</p> <h3>Valid JSON encodings</h3> <p>Non-null <code>siteid</code>:</p> <pre><code>{...
0
2016-09-14T05:16:51Z
[ "python", "json", "avro" ]
how to select part.surface in abaqus using python script
39,470,645
<p>How do I select the surfaces on part in Abaqus? I have tried:</p> <pre><code>tubePart.surface(faces = tubePart.faces[4:8],name = 'innerFaces') </code></pre> <p>but it keeps saying part object has no attribute surface.</p>
0
2016-09-13T12:54:35Z
39,472,795
<p>Ideally, you should create a new surface by calling <code>Surface()</code> function (not <code>surface()</code>), i.e.</p> <pre><code>tubePart.Surface(...) </code></pre> <p>Secondly, there must be <code>side1Faces</code> instead of <code>faces</code> (thanks to agentp for comment). Thus, the final peace of code sh...
1
2016-09-13T14:42:07Z
[ "python", "abaqus" ]
nan cost in tensorflow training perceptron
39,470,802
<p>I am trying to train a single layer perceptron (basing my code on <a href="https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/multilayer_perceptron.py" rel="nofollow">this</a>) on the following data file in tensor flow:</p> <pre><code>1,1,0.05,-1.05 1,1,0.1,-1.1 .... </code><...
0
2016-09-13T13:02:36Z
39,472,292
<p>Is this one example at a time? I would go batches and increase batch size to 128 or similar, as long as you are getting nans.</p> <p>When I am getting nans it is usually either of the three: - batch size too small (in your case then just 1) - log(0) somewhere - learning rate too high and uncapped gradients</p>
1
2016-09-13T14:16:21Z
[ "python", "tensorflow" ]
How to wait for coroutines to complete synchronously within method if event loop is already running?
39,470,824
<p>I'm trying to create a Python-based CLI that communicates with a web service via websockets. One issue that I'm encountering is that requests made by the CLI to the web service intermittently fail to get processed. Looking at the logs from the web service, I can see that the problem is caused by the fact that freque...
0
2016-09-13T13:03:12Z
39,472,811
<p>You could use a <code>set</code> of tasks:</p> <pre><code>self._send_request_tasks = set() </code></pre> <p>Schedule the tasks using <code>ensure_future</code> and clean up using <code>add_done_callback</code>:</p> <pre><code>def send_request(self, request: str) -&gt; None: task = asyncio.ensure_future(self._...
1
2016-09-13T14:42:54Z
[ "python", "python-3.x", "python-asyncio" ]
Python merge list concating unique values as comma seperated
39,470,941
<p>I am trying to get this to work. </p> <p>Here is my data:</p> <p>data.csv</p> <pre><code>id,fname,lname,education,gradyear,attributes 1,john,smith,mit,2003,qa 1,john,smith,harvard,207,admin 1,john,smith,ft,212,master 2,john,doe,htw,2000,dev </code></pre> <p>Trying to use this code. Found this code on the Interne...
0
2016-09-13T13:08:34Z
39,471,208
<p>You can change the definition of <code>join_rows</code> to</p> <pre><code>import itertools def join_rows(rows): return [(e[0] if i &lt; 3 else ','.join(e)) for (i, e) in enumerate(zip(*rows))] </code></pre> <p>What this does is to zip all entries belonging to the same id into tuples. For the first 3 tuples, t...
3
2016-09-13T13:21:42Z
[ "python" ]
Get intersection of list elements with different sublist datatypes
39,470,994
<p>I have two lists, which contains list elements, e.g:</p> <pre><code>list1 = [['placeholder1', {'data': 'data1'}], ['placeholder2', {'data': 'data2'}], ['placeholder2', {'data': 'data1'}]] list2 = [['placeholder2', {'data': 'data2'}], ['placeholder3', {'data': 'data5'}]] intersection_result = [['placeholder2', {'da...
1
2016-09-13T13:11:09Z
39,471,364
<p>If my understanding is correct, you can get the intersection by checking and selecting <a href="https://docs.python.org/3/library/functions.html#any" rel="nofollow"><code>any()</code></a> of the elements in the smallest list which are equal to ones in the larger one.</p> <p>With a comprehension, this would look lik...
3
2016-09-13T13:29:51Z
[ "python", "list", "python-3.x", "intersection", "python-3.5" ]
Get intersection of list elements with different sublist datatypes
39,470,994
<p>I have two lists, which contains list elements, e.g:</p> <pre><code>list1 = [['placeholder1', {'data': 'data1'}], ['placeholder2', {'data': 'data2'}], ['placeholder2', {'data': 'data1'}]] list2 = [['placeholder2', {'data': 'data2'}], ['placeholder3', {'data': 'data5'}]] intersection_result = [['placeholder2', {'da...
1
2016-09-13T13:11:09Z
39,471,590
<p>A simple solution, which would be <strong>independent of the structure of your data</strong>. You can generate <a href="http://stackoverflow.com/questions/16735786/how-to-generate-unique-equal-hash-for-equal-dictionaries">signature hashes</a> (using json or pformat) for your data, and find common hashes in both list...
1
2016-09-13T13:40:43Z
[ "python", "list", "python-3.x", "intersection", "python-3.5" ]
Ansible installation using cygwin - error [Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-lJqIyR/cffi/]
39,471,023
<p>I was trying to install Ansible in Cygwin, but I am getting the following error.</p> <p>I have even reinstalled pythonsetup tools yet still I am getting this error:</p> <pre><code>$ pip install ansible Requirement already satisfied (use --upgrade to upgrade): ansible in /usr/lib/python2.7/site-packages/ansible-2.1...
0
2016-09-13T13:12:42Z
39,471,336
<p>Run Cygwin Setup and check <code>Devel</code> branch for installation. </p> <hr> <p>It should be obvious from the error message that you need to install a compiler. In cases like this run Cygwin Setup and type the missing component name (<code>gcc</code>) to locate the package. In case of <code>gcc</code> requirem...
0
2016-09-13T13:28:03Z
[ "python", "cygwin", "ansible" ]
Selecting a combobox option with a <div> tag using Selenium and Python
39,471,097
<p>I have been trying to automate some really boring stuff (because of how tedious I have been making mistakes and I want to reduce them as close as zero as I can), in essence I got assets that have to be entered into our system one by one through a horrible process. This is my problem right now:</p> <p>My objective i...
0
2016-09-13T13:16:25Z
39,471,316
<p>Your problem is that this element is not <code>Select</code> but <code>&lt;div&gt;</code>, so you cannot use Selenium's Select class.</p> <p>I don't see page which you are working at, but i suppose that <code>&lt;div&gt;</code> with id = ctl00_CPH1_cmbClasses_DropDown is element which you have to click on to show d...
0
2016-09-13T13:26:57Z
[ "python", "selenium" ]
Selecting a combobox option with a <div> tag using Selenium and Python
39,471,097
<p>I have been trying to automate some really boring stuff (because of how tedious I have been making mistakes and I want to reduce them as close as zero as I can), in essence I got assets that have to be entered into our system one by one through a horrible process. This is my problem right now:</p> <p>My objective i...
0
2016-09-13T13:16:25Z
39,471,567
<p>Before this make sure your drop-down is visible because there is a div with display:none., the second div.</p> <p>Assuming dropdown is visible, use the following xpath to match 'CELL PHONES'</p> <pre><code>browser.find_element_by_xpath('//div/ul[@class='rcbList']/li[@class='rcbItem'][.='CELL PHONES']') </code></pr...
0
2016-09-13T13:39:21Z
[ "python", "selenium" ]
Selecting a combobox option with a <div> tag using Selenium and Python
39,471,097
<p>I have been trying to automate some really boring stuff (because of how tedious I have been making mistakes and I want to reduce them as close as zero as I can), in essence I got assets that have to be entered into our system one by one through a horrible process. This is my problem right now:</p> <p>My objective i...
0
2016-09-13T13:16:25Z
39,475,038
<p>After some tinkering and great advice from everyone that posted here, this is the solution that worked for me:</p> <pre><code>dropArrow = browser.find_element_by_id('ctl00_CPH1_cmbClasses_Arrow') dropArrow.click() time.sleep(1) dropdown1 = browser.find_element_by_xpath('//*[@id="ctl00_CPH1_cmbClasses_DropDown"]/div...
1
2016-09-13T16:38:46Z
[ "python", "selenium" ]
How to find a particular row of a pascals triangle in python?
39,471,161
<p>Here is a snapshot of my code to write a pascal's triangle up to n rows into a file named "<strong>pascalrow.txt</strong>" after which it takes a row number as an input, and if that row is found, it reopens the file, finds the row number and displays the whole row.</p> <p>It is kind of working but..as soon as I <st...
0
2016-09-13T13:19:09Z
39,471,466
<p>The fact that your code works at all is amazing. </p> <p>You write a stringed list to a line in a file, then read the file and look at the line character by character. So, by a miracle, you find line 8 because the first 8 you find is a character in '[1, 8, 28...]' Of course, it fails for row, e.g. 6, and anything a...
1
2016-09-13T13:34:35Z
[ "python", "python-3.x", "pascals-triangle" ]
Selenium Page down by ActionChains
39,471,163
<p>I have a problem using function to scroll down using PageDown key via Selenium's ActionChains in python 3.5 on Ubuntu 16.04 x64.</p> <p>What I want is that my program scrolls down by PageDown twice, so it reaches bottom at the end and so I can have selected element always visible. Tried making another function usin...
0
2016-09-13T13:19:22Z
39,472,743
<p>Maybe, if you think it has to do with the action chains you can just do it like this:</p> <p>body = browser.find_element_by_css_selector('body') body.send_keys(Keys.PAGE_DOWN)</p> <p>Hope it works!</p>
0
2016-09-13T14:39:17Z
[ "python", "selenium", "ubuntu" ]
Sorting Angularjs ng-repeat by date
39,471,200
<p>I am relatively new to AngularJS. Could use some help</p> <p>I have a table with the following info</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;th&gt;&lt;span ng-click="sortType = 'first_name'; sortReverse = !sortReverse"&gt;Referral Name&lt;/span&gt;&lt;/th&gt; &lt;th&gt;&lt;span ng-click="sortType = 'date';...
0
2016-09-13T13:21:18Z
39,471,490
<p>As you have noticed, the value you receive is type of string and therefore it is sorted alphabetically. You need to convert it into Date() beforehand. So basically what you need is to loop over the array of data you got and add a new property (or replace existing one) with a new Date object:</p> <pre><code>referral...
0
2016-09-13T13:35:54Z
[ "python", "html", "angularjs", "sorting" ]
Sorting Angularjs ng-repeat by date
39,471,200
<p>I am relatively new to AngularJS. Could use some help</p> <p>I have a table with the following info</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;th&gt;&lt;span ng-click="sortType = 'first_name'; sortReverse = !sortReverse"&gt;Referral Name&lt;/span&gt;&lt;/th&gt; &lt;th&gt;&lt;span ng-click="sortType = 'date';...
0
2016-09-13T13:21:18Z
39,471,561
<p>Ideally you'd have a sortable object for date. One candidate is an isoformatted date:</p> <pre><code>i["date"] = i["date"].isoformat() </code></pre> <p>Now sorting should work just fine but it'll display wonky. So you'll need to use a date filter to format it on the UI:</p> <pre><code>&lt;table&gt; &lt;tr&gt; ...
1
2016-09-13T13:39:14Z
[ "python", "html", "angularjs", "sorting" ]
Parameter passed in save() difficult to understand
39,471,280
<p>I am learning Django from a most recommended and beneficial book named 'Django By Example'. There is a project called Bookmark. I am now stuck in the forms part which is for downloading the image and saving image object to the database. I could understand validation part(clean_url) and also downloading part. I could...
0
2016-09-13T13:25:29Z
39,701,714
<pre><code>image = super(ImageCreateForm, self).save(commit=False) </code></pre> <p>In this statement we are assigning super function to a variable image.</p> <p>super method is called with ImageCreateForm. Then whatever is returned with super() method, we call the save() method of forms.ModelForm with commit=False.<...
1
2016-09-26T11:32:44Z
[ "python", "django", "python-3.x", "django-models", "django-forms" ]
How to make all possible combinations of a word in Python
39,471,284
<p>I have a txt file with all of the letters in the alphabet that looks like this:</p> <p>a</p> <p>b</p> <p>c</p> <p>etc..</p> <p>I also have a word list of words that is only 3 letters long:</p> <p>ago</p> <p>age</p> <p>bat</p> <p>bag</p> <p>etc...</p> <p>I want to create a list that prints out all of the c...
0
2016-09-13T13:25:36Z
39,471,476
<p>as @Farhan.K put in the comments, what you are looking for is a string method that creates a new string from an iterable: <code>join</code> </p> <p>Join is a method of a string where it joins an iterable containing strings with that original string in-between them. for example if you have a list of words that are t...
0
2016-09-13T13:35:18Z
[ "python", "string", "list", "replace", "letter" ]
How to make all possible combinations of a word in Python
39,471,284
<p>I have a txt file with all of the letters in the alphabet that looks like this:</p> <p>a</p> <p>b</p> <p>c</p> <p>etc..</p> <p>I also have a word list of words that is only 3 letters long:</p> <p>ago</p> <p>age</p> <p>bat</p> <p>bag</p> <p>etc...</p> <p>I want to create a list that prints out all of the c...
0
2016-09-13T13:25:36Z
39,471,480
<p>This will generate a list of all combinations for a given word:</p> <pre><code>from string import ascii_lowercase word = "ago" combos = [] for i in xrange(len(word)): for l in ascii_lowercase: combos.append( word[:i]+l+word[i+1:] ) </code></pre>
1
2016-09-13T13:35:31Z
[ "python", "string", "list", "replace", "letter" ]
How to make all possible combinations of a word in Python
39,471,284
<p>I have a txt file with all of the letters in the alphabet that looks like this:</p> <p>a</p> <p>b</p> <p>c</p> <p>etc..</p> <p>I also have a word list of words that is only 3 letters long:</p> <p>ago</p> <p>age</p> <p>bat</p> <p>bag</p> <p>etc...</p> <p>I want to create a list that prints out all of the c...
0
2016-09-13T13:25:36Z
39,471,524
<p>here with list comprehension</p> <pre><code>[b+'g'+e for b in alphabet for e in alphabet] </code></pre> <p>and you can define alphabet with another list comprehension</p> <pre><code>alphabet=[chr(c) for c in range(ord('a'),ord('z')+1)] </code></pre> <p>perhaps not much shorter than writing char by char...</p>
0
2016-09-13T13:37:50Z
[ "python", "string", "list", "replace", "letter" ]
How to make all possible combinations of a word in Python
39,471,284
<p>I have a txt file with all of the letters in the alphabet that looks like this:</p> <p>a</p> <p>b</p> <p>c</p> <p>etc..</p> <p>I also have a word list of words that is only 3 letters long:</p> <p>ago</p> <p>age</p> <p>bat</p> <p>bag</p> <p>etc...</p> <p>I want to create a list that prints out all of the c...
0
2016-09-13T13:25:36Z
39,471,542
<p>You need nested loops for starters. When you get the grip of what you actually trying to do, then you can see the itertools package. </p> <p>With the code that you have provided, you should need something like:</p> <pre><code>s = list('ago') the_list=[] with open("alfabeth.txt", "r", encoding = "utf-8") as letters...
0
2016-09-13T13:38:31Z
[ "python", "string", "list", "replace", "letter" ]
How to make all possible combinations of a word in Python
39,471,284
<p>I have a txt file with all of the letters in the alphabet that looks like this:</p> <p>a</p> <p>b</p> <p>c</p> <p>etc..</p> <p>I also have a word list of words that is only 3 letters long:</p> <p>ago</p> <p>age</p> <p>bat</p> <p>bag</p> <p>etc...</p> <p>I want to create a list that prints out all of the c...
0
2016-09-13T13:25:36Z
39,472,337
<p>I figured it out! With a neat while loop too. So proud. Posting answer here anyway.</p> <pre><code> allakombi=[] s= list("söt")#startord characters=[] with open("alfabetet.txt", "r", encoding = "utf-8") as bokstäver: for rad in bokstäver: bokstav = rad.strip() characters....
0
2016-09-13T14:18:39Z
[ "python", "string", "list", "replace", "letter" ]
How to make all possible combinations of a word in Python
39,471,284
<p>I have a txt file with all of the letters in the alphabet that looks like this:</p> <p>a</p> <p>b</p> <p>c</p> <p>etc..</p> <p>I also have a word list of words that is only 3 letters long:</p> <p>ago</p> <p>age</p> <p>bat</p> <p>bag</p> <p>etc...</p> <p>I want to create a list that prints out all of the c...
0
2016-09-13T13:25:36Z
39,472,405
<p>You need a few nested loops to get the combinations, as an example:</p> <pre class="lang-python prettyprint-override"><code>from string import ascii_lowercase words = ["ago"] combs = [] for word in words: for i, letter in enumerate(word): for l in ascii_lowercase: tmp = list(word) ...
0
2016-09-13T14:22:33Z
[ "python", "string", "list", "replace", "letter" ]
Python array[0:1] not the same as array[0]
39,471,344
<p>I'm using Python to split a string of 2 bytes <code>b'\x01\x00'</code>. The string of bytes is stored in a variable called <code>flags</code>.</p> <p>Why when I say <code>flags[0]</code> do I get <code>b'\x00'</code> but when I say <code>flags[0:1]</code> I get the expected answer of <code>b'\x01'</code>.</p> <p>S...
-1
2016-09-13T13:28:46Z
39,471,400
<p>Yes, you should get the same thing. In both cases <code>b'\x01'</code>. <code>flags</code> is probably not what you think it is.</p> <pre><code>&gt;&gt;&gt; flags = b'\x01\x00' &gt;&gt;&gt; flags[0] '\x01' &gt;&gt;&gt; flags[0:1] '\x01' </code></pre>
-1
2016-09-13T13:31:44Z
[ "python", "python-3.x", "indexing", "bytestring" ]
Python array[0:1] not the same as array[0]
39,471,344
<p>I'm using Python to split a string of 2 bytes <code>b'\x01\x00'</code>. The string of bytes is stored in a variable called <code>flags</code>.</p> <p>Why when I say <code>flags[0]</code> do I get <code>b'\x00'</code> but when I say <code>flags[0:1]</code> I get the expected answer of <code>b'\x01'</code>.</p> <p>S...
-1
2016-09-13T13:28:46Z
39,471,402
<p>In Python 3, <code>bytes</code> is a sequence type containing <em>integers</em> (each in the range 0 - 255) so indexing to a specific index gives you an integer.</p> <p>And just like slicing a list produces a new list object for the slice, so does slicing a <code>bytes</code> object produce a new <code>bytes</code>...
5
2016-09-13T13:31:44Z
[ "python", "python-3.x", "indexing", "bytestring" ]
unable to execute Celery beat the second time
39,471,380
<p>I am using Celery beat for getting the site data after every 10 seconds. Therefore I update the settings in my Django project. I am using rabbitmq with celery.</p> <p><strong>settings.py</strong></p> <pre><code># This is the settings file # Rabbitmq configuration BROKER_URL = "amqp://abcd:abcd@localhost:5672/abcd"...
1
2016-09-13T13:30:39Z
39,471,965
<p>The exception tells you what the error is: your task expects a positional argument, but you do not provide any arguments in your schedule definition.</p> <pre><code>CELERYBEAT_SCHEDULE = { # Executes every Monday morning at 7:30 A.M 'update-app-data': { 'task': 'myapp.tasks.fetch_data_task', ...
1
2016-09-13T13:59:23Z
[ "python", "django", "celery", "django-celery", "celerybeat" ]
Calling a function from a script, re-import all packages?
39,471,558
<p>Say I have some script, with a function <code>my_function</code>. Now, this function needs several packages. So, let's say the file looks like this:</p> <pre><code>import package_A import package_B def my_function(): do_something </code></pre> <p>Now, if I want to use this function somewhere else, I may say <...
0
2016-09-13T13:39:08Z
39,471,667
<p>You can have several scripts calling each other can can import several packages in each script and it won't throw up an error until you have packages that are required for the functions in that script.</p> <p><a href="http://stackoverflow.com/questions/15696461/import-python-script-into-another">Found this link whi...
-1
2016-09-13T13:44:09Z
[ "python", "import" ]
PyQt - Draw rectangle behind a widget
39,471,592
<p>I have a QStackedWidget with a QLineEdit and a couple other widgets inside of it. This QStackedWidget is fairly dynamic - you can move it within its layout by clicking/dragging, change its current widget by right clicking it, etc.</p> <p>I'd like to draw a simple, gray rectangle or a gray rounded rectangle around t...
0
2016-09-13T13:40:52Z
39,477,210
<p>Depending on how your clicking/dragging is implemented, you should just be able to place the <code>QStackedWidget</code> inside another <code>QFrame</code>, or put a <code>QFrame</code> inside your <code>QStackedWidget</code> and put all the other controls inside the <code>QFrame</code>. <code>QFrame</code>'s suppo...
1
2016-09-13T19:00:43Z
[ "python", "pyqt", "draw" ]
Python interpolation data list of lists
39,471,625
<p>I have got this data:</p> <pre><code>X = [[10, 6, 0], [8, 6, 0], [4, 3, 0]] Y = [[29, 28, 27], [26, 25, 24], [23, 22, 21]] </code></pre> <p>I need to interpolate between values in X. for instance:</p> <pre><code>D = np.linspace(10,0,num = 6) Out:[ 0. 2. 4. 6. 8. 10.] </code></pre> <p>So result should ...
2
2016-09-13T13:42:12Z
39,474,665
<p>Use <code>zip</code>. Also, it looks like you want to reverse the sublists. Maybe something like:</p> <pre><code>points = np.linspace(0,10,num = 6) cols = (points,) + tuple(np.interp(points,x[::-1],y[::-1]) for x,y in zip(X,Y)) np.stack(cols,axis=1) </code></pre> <p>which has output:</p> <pre><code>array([[ 0....
2
2016-09-13T16:15:40Z
[ "python", "interpolation" ]
SoftLayer API: How to specify OS Reload with RAID options?
39,471,640
<p>Using the Python SoftLayer library, I've been attempting to submit an OS reload via the SoftLayer API to get consistent disk setup for provisioned servers. These servers have either RAID10 or RAID1 setup, using all available disks in the array. Upon initial provisioning, the servers are setup properly. </p> <p>When...
0
2016-09-13T13:42:42Z
39,472,073
<p>That is the expected behavior for reload, the partitions are applied only to the first disk and it is not possible to specify RAID configuration via API for reload.</p> <p>You have two options to mantain your RAID configuration:</p> <p>1.- Do not specify any partition configuration for the reload, so the OS of you...
0
2016-09-13T14:05:09Z
[ "python", "softlayer" ]
How to randomly remove a percentage of items from a list
39,471,676
<p>I have two lists of equal length, one is a data series the other is simply a time series. They represent simulated values measured over time.</p> <p>I want to create a function that removes a set percentage or fraction from both lists but at random. I.e. if my fraction is 0.2, I want to randomly remove 20% of the i...
0
2016-09-13T13:44:39Z
39,471,736
<pre><code>import random a = [0,1,2,3,4,5,6,7,8,9] b = [0,1,4,9,16,25,36,49,64,81] frac = 0.2 # how much of a/b do you want to exclude # generate a list of indices to exclude. Turn in into a set for O(1) lookup time inds = set(random.sample(list(range(len(a))), int(frac*len(a)))) # use `enumerate` to get list indi...
6
2016-09-13T13:47:39Z
[ "python", "list" ]
How to randomly remove a percentage of items from a list
39,471,676
<p>I have two lists of equal length, one is a data series the other is simply a time series. They represent simulated values measured over time.</p> <p>I want to create a function that removes a set percentage or fraction from both lists but at random. I.e. if my fraction is 0.2, I want to randomly remove 20% of the i...
0
2016-09-13T13:44:39Z
39,471,869
<p>If <code>a</code> and <code>b</code> are not very large, you could get away with using <code>zip</code>:</p> <pre><code>import random a = [0,1,2,3,4,5,6,7,8,9] b = [0,1,4,9,16,25,36,49,64,81] frac = 0.2 # how much of a/b do you want to exclude ab = list(zip(a,b)) # a list of tuples where the first element is fr...
0
2016-09-13T13:54:09Z
[ "python", "list" ]
How to randomly remove a percentage of items from a list
39,471,676
<p>I have two lists of equal length, one is a data series the other is simply a time series. They represent simulated values measured over time.</p> <p>I want to create a function that removes a set percentage or fraction from both lists but at random. I.e. if my fraction is 0.2, I want to randomly remove 20% of the i...
0
2016-09-13T13:44:39Z
39,471,907
<p>You can also operate the <em>zipped</em> a and b sequence, get the random sample of the indexes (to maintain the original order of items) and <em>unzip</em> into <code>a_new</code> and <code>b_new</code> again:</p> <pre><code>import random a = [0,1,2,3,4,5,6,7,8,9] b = [0,1,4,9,16,25,36,49,64,81] frac = 0.2 c =...
0
2016-09-13T13:56:08Z
[ "python", "list" ]
How to randomly remove a percentage of items from a list
39,471,676
<p>I have two lists of equal length, one is a data series the other is simply a time series. They represent simulated values measured over time.</p> <p>I want to create a function that removes a set percentage or fraction from both lists but at random. I.e. if my fraction is 0.2, I want to randomly remove 20% of the i...
0
2016-09-13T13:44:39Z
39,471,911
<pre><code>import random a = [0,1,2,3,4,5,6,7,8,9] b = [0,1,4,9,16,25,36,49,64,81] frac = 0.2 # how much of a/b do you want to exclude new_a, new_b = [], [] for i in range(len(a)): if random.random()&gt;frac: # with probability, add an element from `a` and `b` to the output new_a.append(a[i]) ...
0
2016-09-13T13:56:27Z
[ "python", "list" ]
How to randomly remove a percentage of items from a list
39,471,676
<p>I have two lists of equal length, one is a data series the other is simply a time series. They represent simulated values measured over time.</p> <p>I want to create a function that removes a set percentage or fraction from both lists but at random. I.e. if my fraction is 0.2, I want to randomly remove 20% of the i...
0
2016-09-13T13:44:39Z
39,471,950
<pre><code>l = len(a) n_drop = int(l * n) n_keep = l - n_drop ind = [1] * n_keep + [0] * n_drop random.shuffle(ind) new_a = [ e for e, i in zip(a, ind) if i ] new_b = [ e for e, i in zip(b, ind) if i ] </code></pre>
0
2016-09-13T13:58:28Z
[ "python", "list" ]
How to randomly remove a percentage of items from a list
39,471,676
<p>I have two lists of equal length, one is a data series the other is simply a time series. They represent simulated values measured over time.</p> <p>I want to create a function that removes a set percentage or fraction from both lists but at random. I.e. if my fraction is 0.2, I want to randomly remove 20% of the i...
0
2016-09-13T13:44:39Z
39,471,997
<pre><code>from random import randint as r a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] b = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] percentage = 0.3 g = (r(0, len(a)-1) for _ in xrange(int(len(a) * (1-percentage)))) c, d = [], [] for i in g: c.append(a[i]) d.append(b[i]) a, b = c, d print a print b </code></pre>
1
2016-09-13T14:01:03Z
[ "python", "list" ]
How to compare two columns of two different dataframes whose columns are not unique?
39,471,817
<p>I'm having two different dataframes : df1 and df2</p> <pre><code>df1 : Id lkey 0 foo foo 1 bar bar 2 baz baz 3 foo foo 4 bar bar ...
0
2016-09-13T13:51:32Z
39,472,100
<pre><code>&gt;&gt;&gt; (df1 .merge(df2[['rkey', 'value']].drop_duplicates(), left_on='lkey', right_on='rkey', how='left') .drop('rkey', axis='columns') .rename(columns={'value': 'match'}) ) Id lkey match 0 foo foo aaa 1 bar bar bbb 2 baz baz ccc 3 foo foo aaa 4 bar bar bbb 5 ...
2
2016-09-13T14:06:42Z
[ "python", "pandas", "dataframe" ]
Data not saving SQLite3 python3.4
39,471,877
<p>I am currently trying to create a sqlite database of peoples names and ip While my code seems to work when I run it the data doesn't show up when I run <code>SELECT * from ips;</code> in terminal after running <code>SQLite3 ips</code> Below is my code. Both it and the <code>SELECT * from ips;</code> are running in ~...
1
2016-09-13T13:54:26Z
39,471,952
<p>It doesn't look like you are committing to the database. You need to commit before closing the connection in order to actually save your changes to the database.</p> <p><code>database.commit()</code></p>
1
2016-09-13T13:58:42Z
[ "python", "sql", "sqlite", "sqlite3", "python-3.4" ]
Is it possible to limit mocked function calls count?
39,471,928
<p>I have encountered a problem when I write a unit test. This is a chunck from an unit test file:</p> <pre><code>main.obj = MainObj.objects.create(short_url="a1b2c3") with unittest.mock.patch('prj.apps.app.models.base.generate_url_string', return_value="a1b2c3") as mocked_generate_url_string: obj.generate_short_...
0
2016-09-13T13:57:22Z
39,472,541
<p>Define a generator that first yields the fixed value, then yields the return value of the real function (which is passed as an argument to avoid calling the patched value).</p> <pre><code>def mocked(x): yield "a1b2c3" while True: yield x() </code></pre> <p>Then, use the generator as the side effect...
3
2016-09-13T14:29:07Z
[ "python", "django", "unit-testing", "django-models", "mocking" ]
Tkinter grid method
39,471,932
<p>I'm using Tkinter to create a GUI for my computer science coursework based on steganography. I'm using the <code>.grid()</code> function on the widgets in my window to lay them out, however I can't get this particular part to look how I want it to.</p> <p>Here's what my GUI currently looks like: <a href="http://img...
-1
2016-09-13T13:57:31Z
39,472,278
<p>I recommend breaking your UI down into logical sections, and laying out each section separately. </p> <p>For example, you clearly have two distinct sections: the image and button on the left, and the other widgets on the right. Start by creating containers for those two groups:</p> <pre><code>import Tkinter as tk ...
0
2016-09-13T14:15:38Z
[ "python", "tkinter" ]
Plotting projectile motion of 1 y-position values vs. 2 x-position values using matplotlib and numpy
39,471,954
<p>Hi i'm trying to get a plot of the trajectory of a mass under projectile motion. One with a force acting on the horizontal axis and one without (basically 2 sets of x values plotted against a 1 set of y-values). Here's what i have so far.. I'm new to programming and i can't seem to figure out where this went wrong....
0
2016-09-13T13:58:48Z
39,472,745
<p>I went through your code since i am new to <code>matplotlib</code> and wanted to play a bit with it. The only mistake i found is in the for loop where you do <code>for a in t:</code> but end up passing <code>t</code> to the functions instead of <code>a</code>.</p> <pre><code>import numpy as np import matplotlib.pyp...
0
2016-09-13T14:39:29Z
[ "python", "numpy", "matplotlib", "plot", "projectile" ]
Reproducible builds in python
39,471,960
<p>I need to ship a compiled version of a python script and be able to prove (using a hash) that the compiled file is indeed the same as the original one.</p> <p>What we use so far is a simple:</p> <pre><code>find . -name "*.py" -print0 | xargs -0 python2 -m py_compile </code></pre> <p>The issue is that this is not ...
4
2016-09-13T13:59:11Z
39,472,343
<p>Compiled Python files include a four-byte magic number and the four-byte datetime of compilation. This probably accounts for the discrepancies you are seeing.</p> <p>If you omit bytes 5-8 from the checksumming process then you should see constant checksums for a given version of Python.</p> <p>The format of the <c...
6
2016-09-13T14:19:07Z
[ "python", "binary-reproducibility" ]
How to animate the colorbar in matplotlib
39,472,017
<p>I have an animation where the range of the data varies a lot. I would like to have a <code>colorbar</code> which tracks the max and the min of the data (i.e. I would like it not to be fixed). The question is how to do this.</p> <p>Ideally I would like the <code>colorbar</code> to be on its own axis.</p> <p>I have ...
5
2016-09-13T14:02:24Z
39,596,853
<p>While I'm not sure how to do this specifically using an <code>ArtistAnimation</code>, using a <code>FuncAnimation</code> is fairly straightforward. If I make the following modifications to your "naive" version 1 it works.</p> <p><strong>Modified Version 1</strong></p> <pre><code>import numpy as np import matplotl...
1
2016-09-20T14:31:36Z
[ "python", "animation", "matplotlib", "colorbar" ]
Each row sharey individually?
39,472,115
<p>I have a two-by-two plot that I am creating dynamically. In the first row I want to plot density functions, in the second row CDFs. I want </p> <ul> <li>each of the columns to share x</li> <li>each of the rows to share y</li> </ul> <p>That is, two objects aligned vertically have the same x-axis, and two plots alig...
0
2016-09-13T14:07:25Z
39,472,960
<p>What about something like this, where all axes are built individually:</p> <pre><code>x1 = np.arange(5) y1 = np.arange(3, 8) ax1 = plt.subplot(223) ax1.plot(x1, y1) ax1.set_title("ax1") x2 = np.arange(5, 10) y2 = np.arange(3, 8) ax2 = plt.subplot(224, sharey=ax1) ax2.plot(x2, y2) ax2.set_title("ax2") #plt.setp(ax2...
0
2016-09-13T14:49:42Z
[ "python", "matplotlib" ]
Each row sharey individually?
39,472,115
<p>I have a two-by-two plot that I am creating dynamically. In the first row I want to plot density functions, in the second row CDFs. I want </p> <ul> <li>each of the columns to share x</li> <li>each of the rows to share y</li> </ul> <p>That is, two objects aligned vertically have the same x-axis, and two plots alig...
0
2016-09-13T14:07:25Z
39,474,426
<p>The <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplots" rel="nofollow">pyplot.subplots documentation</a> describes the <code>'col'</code> and <code>'row'</code> options for the <code>sharex</code> and <code>sharey</code> kwargs. In particular, I think you want:</p> <pre><code>fig, axes = ...
1
2016-09-13T16:01:16Z
[ "python", "matplotlib" ]
Scrapy: Exclude content inside script tags in the HTML body
39,472,207
<p>I am currently extracting the entire text inside the body tag (excluding spacing like \r\n) using the following code:</p> <pre><code>full_text = response.xpath('normalize-space(/html/body)').extract() </code></pre> <p>The problem is this is picking up javascript inside script tags within body.</p> <p>Do you know ...
-1
2016-09-13T14:11:50Z
39,476,990
<p>you can follow the answer on this question <a href="http://stackoverflow.com/a/19780110/2204978">Scraping text without javascript code using scrapy</a></p> <pre><code>from w3lib.html import remove_tags, remove_tags_with_content input = hxs.select('//div[@id="content"]').extract() output = remove_tags(remove_tags_w...
1
2016-09-13T18:44:22Z
[ "python", "xpath", "scrapy" ]
Pandas: Add Series to DataFrame ordered by column
39,472,287
<p>I am sure this was asked before, but I couldn't find it. I want to add a Series as a new column to the DataFrame. All the Series Index names are contained in one column of the DataFrame, but the Dataframe has more rows than the Series.</p> <pre><code>DataFrame: 0 London 231 1 Beijing 328 12 New York 920 3 Singapore...
0
2016-09-13T14:16:07Z
39,472,789
<ol> <li>set <code>index</code> to city names for both <code>df</code> and <code>series</code></li> <li>combine via pandas <code>merge</code></li> </ol> <hr> <pre><code>import pandas as pd cities = ['London', 'Beijing', 'New York', 'Singapore'] df_data = { 'col_1': [0,1,12,3], 'col_2': [231, 328, 920, 1003]...
0
2016-09-13T14:41:58Z
[ "python", "pandas", "dataframe", "merge", "series" ]
Pandas: Add Series to DataFrame ordered by column
39,472,287
<p>I am sure this was asked before, but I couldn't find it. I want to add a Series as a new column to the DataFrame. All the Series Index names are contained in one column of the DataFrame, but the Dataframe has more rows than the Series.</p> <pre><code>DataFrame: 0 London 231 1 Beijing 328 12 New York 920 3 Singapore...
0
2016-09-13T14:16:07Z
39,473,929
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html" rel="nofollow">pandas.DataFrame.merge()</a></p> <pre><code>df = pd.DataFrame({'A': [0,1,12,3], 'B': ['London', 'Beijing', 'New York', 'Singapore'], 'C': [231, 328, 920, 1003] }) A B C 0 0 L...
0
2016-09-13T15:35:20Z
[ "python", "pandas", "dataframe", "merge", "series" ]
Pandas: Add Series to DataFrame ordered by column
39,472,287
<p>I am sure this was asked before, but I couldn't find it. I want to add a Series as a new column to the DataFrame. All the Series Index names are contained in one column of the DataFrame, but the Dataframe has more rows than the Series.</p> <pre><code>DataFrame: 0 London 231 1 Beijing 328 12 New York 920 3 Singapore...
0
2016-09-13T14:16:07Z
39,496,867
<p>based on @Joe R solution with some modificaiton. say, df is your DataFrame and s is your Series</p> <pre><code>s = s.to_frame().reset_index() df = df.merge(s,how='left',left_on=df['B'],right_on=s['index']).ix[:,[0,1,3]] </code></pre>
0
2016-09-14T18:00:19Z
[ "python", "pandas", "dataframe", "merge", "series" ]
Reusing the same layers for training and testing, but creating different nodes
39,472,359
<p>I'm trying to (re)train AlexNet (based on the code <a href="http://www.cs.toronto.edu/~guerzhoy/tf_alexnet/" rel="nofollow">found here</a>) for a particular binary classification problem. Since my GPU is not very powerful, I settled on a batch size of 8 for training. This size determines the shape of the input tenso...
0
2016-09-13T14:19:53Z
39,495,101
<p>Use <code>shape=None</code>for your placeholders: <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/io_ops.html#placeholder" rel="nofollow">placeholder doc</a></p> <p>This way you can feed any shape of data. Another (worse) option is to recreate your graph for testing with the shapes that you need,...
0
2016-09-14T16:08:31Z
[ "python", "tensorflow" ]