一般情況
df.groupby('column1')['column2'].sum()
這樣會造成column1成為index
column2聚合后沒有列名
優化
df.groupby('column1',as_index=Flase).agg({'column2'.'sum'})
或者多列分類
df.groupby(['column1','column2'],as_index=Flase).agg({'column3'.'sum'})
這樣就會都有列名
c1 c2 c3
0
1
2
之后再rename c3,重命名一個聚合列名
df.rename({'c3':'c3_sum'})