본문 바로가기

언어 꿀Tip/Python 꿀tip!

07_01_12. aggregation column level down & 컬럼명 변경

 

## 컬럼명 level down
df_01_ag = df_01.groupby(["origin_bizpl_cd" , "goods_cd", "bizpl_goods_cd"] ).agg({"bg_purch_qty" : ["sum","mean"]})

# agg column level down
df_01_ag = df_01_ag.droplevel(0, axis= 1).reset_index()



## aggregation 컬럼명 변경
df_01_ag = df_01.groupby(["origin_bizpl_cd" , "goods_cd", "bizpl_goods_cd"] ).agg({"bg_purch_qty": [("sum", "sum"), ("mean", "mean"), ("max", "max")], "bg_purch_qty_yn":[("count", "sum")]})
df_01_ag = df_01_ag.droplevel(0, axis= 1).reset_index()