Question
Looking for something like
df.groubpy('key').aggregate(combination(columnA, columnB))
instead of
df['combination'] = combination(columnA, columnB)
df.groupby('key')['combination'].aggregate()
The only requirement is that the combination of columns is calculated after the groupby.
Description
I seems natural, logically wise, for some cases to first groupby and then aggregate.
One example would be different aggregate functions for different combinations of columns that use the same groups.
Looking for
- groupby
- choose combination of columns
- use the corresponding aggregate function
instead of
- create all the necessary columns (for every aggregate function)
- groupby (for every aggregate function)
- apply specific aggregate function
Example
key ColumnA ColumnB
key1 1 1
key2 2 2
key1 3 3
key3 4 4
key2 5 5
#can do
df['combination'] = df.columnA * df.columnB
df.groupby('key').mean()
#looking for
grouped = df.groupby('key')
grouped.mean(columnA * columnB)