python - pass argument to groupby and agg in pandas -
i want use agg after groupby , pass in 2 parameters, param1 , param2. tried following failed. correct way that? thanks.
def myfun(x, param1, param2): #some calculations return result b = a.groupby([a.index, 'time']).agg({'salary': myfun, param1, param2})
use syntax:
param1=1 param2=100 a.groupby([a.index,'time'])['salary'].agg(myfun, param1, param2)
or @ayhan suggests:
a.groupby([a.index,'time']).agg({'salary':lambda x: myfunc(x, param1, param2)})
Comments
Post a Comment