You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [5]: df
Out[5]:
A B C D
0 foo one 0.727964 0.406402
1 bar one 1.653679 0.266521
2 foo two -1.677686 -1.143690
3 bar three -0.591334 -0.594644
4 foo two -0.839865 0.153575
5 bar two -0.857455 -0.054324
6 foo one -0.148167 1.080535
7 foo three 0.118469 0.715423
In [6]: grouped = df.groupby('A')
In [7]: result = grouped.aggregate({'C' : [np.mean, np.std],
...: 'D' : [np.mean, np.std]})
In [8]: result
Out[8]:
C D
mean std mean std
A
bar 0.068297 1.379414 -0.127482 0.435219
foo -0.363857 0.925198 0.242449 0.848860
In [9]: grouped.aggregate({'C' : np.mean, 'D' : [np.mean, np.std]})
Out[9]:
C D
mean mean std
A
bar 0.068297 -0.127482 0.435219
foo -0.363857 0.242449 0.848860
In [10]: paste
result = grouped.aggregate({'C' : np.mean,
'D' : {'foo': np.mean,
'bar': np.std}})
## -- End pasted text --
In [11]: result
Out[11]:
C D
mean foo bar
A
bar 0.068297 -0.127482 0.435219
foo -0.363857 0.242449 0.848860
cc @arthurgerigk
Something of this nature would be nice:
Would also be nice to add some options to agg for what to do with the input dict (by default targets columns)
The text was updated successfully, but these errors were encountered: