如果cols
列表中所有值的排序规则都是唯一的,请set_index
与结合使用unstack
:
cols = ['Country name','Country Code','Year','Series Name']
df = education_level.set_index(cols)['Value'].unstack()
如果没有,请使用pivot_table
聚合函数-例如mean
:
df1 = df.pivot_table(index=['Country name','Country Code','Year'],
columns='Series Name',
values='Value',
aggfunc='mean')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句