applying functions to groups in pandas dataframe,df.groupby('type').apply(foo)