Tuesday, 27 August 2013

Pandas: replicating SASs proc means by attribute out=agg

Pandas: replicating SASs proc means by attribute out=agg

I have a function foo that operates on a dataframe; specifically two
columns of the dataframe. So something like,
def foo(group):
A = group['A']
B = group['B']
r1 = somethingfancy(A,B) #this is now a float
r2 = somethinggreat(A,B) #this is another float
return {'fancy':r1,'great':r2}
The issue is that I would like to use this function in the following context:
grouped = otherDF[['someAttribute','A','B']].groupby(['someAttribute'])
agg = grouped.apply(foo)
The issue is that agg is now a series of DICT. I would like to cast it as
a dataframe that would essentially look like:
someAttribute, fancy, great
... , ... , ...

No comments:

Post a Comment