Reputation: 57319
I would like to perform a few aggregations on a groupby object. I would like to do this possibly on different columns and possibly with more than one aggregation per column.
In [1]: from pandas import *
In [2]: df = DataFrame([[1, 'Alice', 100],
[2, 'Bob', -200],
[3, 'Alice', 300],
[4, 'Dennis', 400],
[5, 'Bob', -500]],
columns=['id', 'name', 'amount'])
In [3]: g = df.groupby('name')
In [4]: g.summarize({'num_ids': g.id.nunique(),
'total_amount': g.amount.sum(),
'max_amount': g.amount.max()})
I understand that this is not valid syntax. I hope that it is clear what I'm trying to achieve.
What is the best way to accomplish this with Pandas?
Upvotes: 0
Views: 75