If you are thinking about pivot tables in Excel, you can add additional columns and go from sum to average or minimum. Is it possible to get multiple values ββin pivotin Pandas?
Here is a working example (taken from pandas documentation):
import pandas as pd
import numpy as np
df = pd.DataFrame({'A' : ['one', 'one', 'two', 'three'] * 6,
....: 'B' : ['A', 'B', 'C'] * 8,
....: 'C' : ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 4,
....: 'D' : np.random.randn(24),
....: 'E' : np.random.randn(24),
....: 'F' : np.random.randn(24)})
Here is an example:
pd.pivot_table(df, values=['D', 'E'], rows=['B'], aggfunc=np.mean)
What returns:
D E
B
A -0.083449 -0.242955
B 0.826492 -0.058596
C 0.124266 -0.197583
Can I use an np.sumexample pivothere?
source
share