define aggfunc for each values column in pandas pivot table

后端 未结 3 901
广开言路
广开言路 2021-01-31 10:11

Was trying to generate a pivot table with multiple \"values\" columns. I know I can use aggfunc to aggregate values the way I want to, but what if I don\'t want to sum or avg bo

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 10:57

    You can apply a specific function to a specific column by passing in a dict.

    pd.pivot_table(df, values=['D','E'], rows=['B'], aggfunc={'D':np.sum, 'E':np.mean})
    

提交回复
热议问题