I have this sample:
import pandas as pd
import numpy as np
dic = {'name':
['j','c','q','j','c','q','j','c','q'],
'foo or bar':['foo','bar','bar','bar','foo','foo','bar','foo','foo'],
'amount':[10,20,30, 20,30,40, 200,300,400]}
x = pd.DataFrame(dic)
x
pd.pivot_table(x,
values='amount',
index='name',
columns='foo or bar',
aggfunc=[np.mean, np.sum])
It returns this:
I'd like to just have the highlighted columns. Why can I not specify tuples in the aggfunc argument like this?
pd.pivot_table(x,
values='amount',
index='name',
columns='foo or bar',
aggfunc=[(np.mean, 'bar'), (np.sum, 'foo')])
Is using .ix like here (define aggfunc for each values column in pandas pivot table) the only option?
