본문 바로가기

언어 꿀Tip/Python 꿀tip!

07_01_01. pandas groupby

### data aggretation
dat_class2 = dat.groupby(["origin_bizpl_cd", "oper_dt", "line_class_cd", "line_class_nm"], as_index=False)["p_buy_sale_qty","p_buyget_sale_qty"].agg(["sum", "mean"])


dat_class2 = dat.groupby(['yyyymm', 'origin_bizpl_cd']).agg( {"buyget_sale_qty": 'sum', 'buy_sale_qty': ['sum', 'mean']} ) 

 

 

dat_class2.reset_index(drop=False)

 

# 데이터 프레임 index 앞에 숫자 제외하는 것!

dat_class2.reset_index(drop=Ture)