Pandas panel = collection of tables/data frames aligned by index and column

Pandas panel provides a nice way to collect related data frames together while maintaining correspondence between the index and column values: import pandas as pd, pylab#Full dimensions of a slice of our panelindex = [‘1′,’2′,’3′,’4’] #major_indexcolumns = [‘a’,’b’,’c’] #minor_indexdf = pd.DataFrame(pylab.randn(4,3),columns=columns,index=index) #A full slice of the paneldf2 = pd.DataFrame(pylab.randn(3,2),columns=[‘a’,’c’],index=[‘1′,’3′,’4’]) #A partial slicedf3 = pd.DataFrame(pylab.randn(2,2),columns=[‘a’,’b’],index=[‘2′,’4’]) #Another… Read More Pandas panel = collection of tables/data frames aligned by index and column

Python: Multiprocessing: xlrd workbook can’t be passed as argument

import multiprocessing as mp, xlrddef myfun(b): print b.sheet_names()b=xlrd.open_workbook(‘../../Notes/sessions_and_neurons.xlsx’)p = mp.Pool(4)p.map(myfun, [b,b,b,b]) Exception in thread Thread-2:Traceback (most recent call last): File “/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/threading.py”, line 551, in __bootstrap_inner self.run() File “/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/threading.py”, line 504, in run self.__target(*self.__args, **self.__kwargs) File “/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/multiprocessing/pool.py”, line 319, in _handle_tasks put(task)PicklingError: Can’t pickle : attribute lookup __builtin__.instancemethod failed

Python: Multiprocessing: passing multiple arguments to a function

Write a wrapper function to unpack the arguments before calling the real function. Lambda won’t work, for some strange un-Pythonic reason. import multiprocessing as mpdef myfun(a,b): print a + bdef mf_wrap(args): return myfun(*args)p = mp.Pool(4)fl = [(a,b) for a in range(3) for b in range(2)]#mf_wrap = lambda args: myfun(*args) -> this sucker, though more pythonic… Read More Python: Multiprocessing: passing multiple arguments to a function

Calculating confidence intervals: straight Python is as good as scipy.stats.scoreatpercentile

UPDATE:I would say the most efficient AND readable way of working out confidence intervals from bootstraps is: numpy.percentile(r,[2.5,50,97.5],axis=1) Where r is a n x b array where n are different runs (e.g different data sets) and b are the individual bootstraps within a run. This code returns the 95% CIs as three numpy arrays. Confidence… Read More Calculating confidence intervals: straight Python is as good as scipy.stats.scoreatpercentile

Three coding fonts

Coding fonts should: Look good at small sizes, (10-11 pt) – you can see more code in your window Have good distinction between characters, especially (O,0), (i,l), (l,1)(`,’) – your programs have enough bugs already Three fonts that I have tried out and that work for me are, in order Anonymous Pro – Looks good… Read More Three coding fonts

D5100: More notes

Video It took me a little bit to get warmed up to the concept, but now I definitely see the potential for using DSLRs for movie making. Camcorders (in the price range I would consider) are fitted with single lenses (probably a superzoom) with average optical quality. Their smaller sensor size means a much noisier… Read More D5100: More notes