본문 바로가기
파이썬. 데이터분석/Pandas

Pandas : pivot 다중 aggfunc (sum,count 같이)

by 한국수달보호협회장 2022. 9. 28.

 

배송주기_피벗 = pd.pivot_table(배송주기, index=['코드','고객사명'], values = ['고객그룹','배송일수'], aggfunc={'고객그룹':'count','배송일수':'sum'})

 

이렇게 하면 매장수는 count, 배송일수는 sum

 

 

출처 : https://stackoverflow.com/questions/20119414/define-aggfunc-for-each-values-column-in-pandas-pivot-table

 

define aggfunc for each values column in pandas pivot table

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 both columns but instead ...

stackoverflow.com