python
Why am I getting “IndentationError: expected an indented block”?
if len(trashed_files) == 0 : print "No files trashed from current dir ('%s')" % os.path.realpath(os.curdir) else : index=raw_input("What file to restore [0..%d]: " % (len(trashed_files)-1)) if index == "*" : for tfile in trashed_files : try: tfile.restore() except IOError, e: import sys print >> sys.stderr, str(e) sys.exit(1) elif index == "" : print "Exiting" else … Read more
How to one-hot-encode from a pandas column containing a list?
I would like to break down a pandas column consisting of a list of elements into as many columns as there are unique elements i.e. one-hot-encode them (with value 1 representing a given element existing in a row and 0 in the case of absence).
What’s the function like sum() but for multiplication? product()?
Python’s sum() function returns the sum of numbers in an iterable.
Performance of Pandas apply vs np.vectorize to create new column from existing columns
I am using Pandas dataframes and want to create a new column as a function of existing columns. I have not seen a good discussion of the speed difference between df.apply() and np.vectorize(), so I thought I would ask here.
Check if something is (not) in a list in Python
I have a list of tuples in Python, and I have a conditional where I want to take the branch ONLY if the tuple is not in the list (if it is in the list, then I don’t want to take the if branch)
What’s the difference between dist-packages and site-packages?
I’m a bit miffed by the python package installation process. Specifically, what’s the difference between packages installed in the dist-packages directory and the site-packages directory?
Python’s most efficient way to choose longest string in list?
I have a list of variable length and am trying to find a way to test if the list item currently being evaluated is the longest string contained in the list. And I am using Python 2.6.1
How to convert string to datetime format in pandas python?
I have a column I_DATE of type string(object) in a dataframe called train as show below.
Sharing a result queue among several processes
The documentation for the multiprocessing module shows how to pass a queue to a process started with multiprocessing.Process. But how can I share a queue with asynchronous worker processes started with apply_async? I don’t need dynamic joining or anything else, just a way for the workers to (repeatedly) report their results back to base.