본문 바로가기

언어 꿀Tip/Python 꿀tip!

07_01_06. multi columns flatten ex) pd.pivot_table

 

https://stackoverflow.com/questions/39273441/flatten-pandas-pivot-table

Flatten pandas pivot table

This is a follow up of my question. Rather than a pivot table, is it possible to flatten table to look like the following: data = {'year': ['2016', '2016', '2015', '2014', '2013'], 'country':[...

stackoverflow.com

 

 

df_test_01 = pd.pivot_table( df_test , index =['part_datecd'] , columns='good_cls1cd', values=['ntsal_amt','sal_qty'])
# index : 행
# columns : 컬럼으로 들어갈 컬럼명
# value : 값
df_test.columns = list(map("_".join, df_test_01.columns))