I have the following (simplified) dataframe: df = pd.DataFrame({'X': [1, 2, 3, 4, 5,6,7,8,9,10], 'Y': [10,20,30,40,50,-10,-20,-30,-40,-50], 'Z': [20,18,16,14,12,10,8,6,4,2]},index=list('ABCDEFGHIJ')) Which gives the following: X Y Z A 1 10 20 B 2 20
I want to append a numpy array(matrix) into an array through a loop data=[[2 2 2] [3 3 3]] Weights=[[4 4 4] [4 4 4] [4 4 4]] All=np.array([]) for i in data: #i=[2 2 2 ] #for example h=i*Weights #h=[[8 8 8][8 8 8][8 8 8]] All=np.concatenate((All,h),ax
I am using a recurrent neural network to consume time-series events (click stream). My data needs to be formatted such that a each row contains all the events for an id. My data is one-hot encoded, and I have already grouped it by the id. Also I limi
I have a multiprocessing program where one process adds elements to a shared list (multiprocessing.Manager().list()) several other processes consume these elements from that list (and remove them); they run until there is something to process in the
How do you format a float to 2 decimal points with mixed data type? I'm fetching a table and writing rows to csv file. My data is (string, string, float, float, float...) sql = 'select * from testTable' c.execute(sql) columnNames = list(map(lambda x:
I have to split a text file into a specific amount of words per list in list, probably be best to show in example. say the text file looks like this "i am having a good day today" i have to write a function which looks like this ngrams.makeNGram
I have a csv where I need to count the total number for each category: New_Cell[2] Category I need to count 1 [A01] 1 [A01] 0 [A01] 1 [A01] 0 [A02] 1 [A02] 1 [A02] 2 [A02] 1 [A02] I need it to count each occurrence of TRUE for the if-condition so tha
I apologize beforehand if this has already been covered, but I've been unable to find an answer. I want a for loop to produce an output with every other letter having a space before it. Should look something like this: >>>everyOther('banana') b a
I am trying to understand how this works: my_dict = {'a':2,'b':1} min(my_dict, key=my_dict.get) produces b Which is a really cool feature and one I want to understand better. Based on the documentation min(iterable[, key]) Return the smallest item in
When doing: import pandas x = pandas.read_csv('data.csv', parse_dates=True, index_col='DateTime', names=['DateTime', 'X'], header=None, sep=';') with this data.csv file: 1449054136.83;15.31 1449054137.43;16.19 1449054138.04;19.22 1449054138.65;15.12
i have a list object like this value = [<employee 'Mark Twain' as 'Captain'>,<employee 'Huckle' as 'Cowboy'>] now i would like to have the employee and in a seperate variable like emplo[0] and as[0] like emplo[0] = 'Mark Twain' as[0] = 'Captai
I am using Opencv 3.0 with Python 2.7, for an Optical Character Recognition I need to find points of each contours that are found by findContours method. When I do debugging, I can see there are 208 countours found but I am curious about how can I ac
For some reason when I run the code at the end it just displays the message without encrypting or decrypting it im really confused please do not hate on me if this is really obvious I am very new to python and barely know the basics #declare variable
I want to scrape some data from a page which is in a table. So I am only bothered about the data in the table. Earlier I was using Mechanize, but I found sometimes some of the data are missing, especially in the bottom of the table. Googling, I found
I am trying to call a Python script from another. I am using the subprocess-module and calling it like this: subprocess.call(["python","script.py","parameter_name parameter_value"], shell=False) The thing is when I call it th
I was using vim and python perfectly fine till I upgrade to Maverick. Now I have a similar issue as here. When I remove remove canopy path from bash_profile and use default python path , vim works fine, otherwise I am getting the above error. You can
I am creating a new class in UserList, and trying to override the add, append, and extend methods so that duplicate values will not be added to the list by any of these operations. So far I have started with trying to override the append method and w
This question already has an answer here: python list by value not by reference 11 answers I have a list named MyList. I want to copy the list to a new one, then add items to the new one, so I do: MySecondList=MyList for item in MyList: if item==2: M
Is it possible to delete a group (by group name) from a groupby object in pandas? That is, after performing a groupby, delete a resulting group based on its name.Filtering a DataFrame groupwise has been discussed. And a future release of pandas may i
Let's say I have: def recursive(data): for i in data: if condition: recursive(HERE IS THE ISSUE) How do I pass in the data from the current i to the final element in the list?Check out enumerate this will also return the current loop index which you
In a model I usually put a "uuid" field for friendly URI, also a "slug" field. Say I have a model named "SomeModel", by overriding its save() method, I can generate a uuid and a slug when it's being saved: class SomeModel(mod
I have a question regarding strip() in Python. I am trying to strip a semi-colon from a string, I know how to do this when the semi-colon is at the end of the string, but how would I do it if it is not the last element, but say the second to last ele
We're designing a system based on CherryPy that in addition to serving web requests needs to do tasks/jobs in parallel. We want it to be a single process running as a daemon and create threads for all the parallel jobs like scheduled tasks or collect
I must submit two forms at once and I don't want javascript. So I think I can post the form to myself, do my work and then post it on to the third-party payment provider. This is to make the order appear in our datastore. The manual says how to submi
I need to generate all the combinations with length k from a list of length n, and I must do it using recursion. For Example: INPUT: choose_sets([1,2,3,4],3) OUTPUT: [[1,2,3],[1,2,4],[1,3,4],[2,3,4]] INPUT: choose_sets([1,2,3,4],2) OUTPUT: [[1,2],[1,
I've been trying with no success to get my pyOpenSSL client to use TLS/SSL session resume when making several connections sucessively (it's sending http requests) to a Tomcat application server. I'm pretty sure everything is fine on the server end si
params = {'fruit':'orange', 'color':'red', 'size':'5'} How can I turn that into a string: fruit=orange&color=red&size=5 You can do it like this: '&'.join('%s=%s' % (k,v) for k,v in params.items()) If you are building strings for a URL it would
I'm a Python beginner, and I have a utf-8 problem. I have a utf-8 string and I would like to replace all german umlauts with ASCII replacements (in German, u-umlaut 'ΓΌ' may be rewritten as 'ue'). u-umlaut has unicode code point 252, so I tried this:
I am playing around with getting some basic stuff to work in Python before i go into full speed dev mode. Here are the specifics: Python 2.5.4 PyQt4 4.4.3 SqlAlchemy 0.5.2 py2exe 0.6.9 setuptools 0.6c9 pysqlite 2.5.1 setup.py: from distutils.core imp
So far I was familiar with c and c++ only, and I have programmed in these languages only. I have some experience working on some projects in c or c++. Some good projects or applications I've made till now: Duplicate file finder and remover Process mo