Python 将多索引转换为列
我有一个类似的数据帧:Python 将多索引转换为列,python,pandas,Python,Pandas,我有一个类似的数据帧: action_type value 0 0 link_click 1 1 mobile_app_install 5 2 video_view 181 3 omni_view_content 2 1 0 post_reaction 32 1 link_click 124
action_type value
0 0 link_click 1
1 mobile_app_install 5
2 video_view 181
3 omni_view_content 2
1 0 post_reaction 32
1 link_click 124
2 mobile_app_install 190
3 video_view 6162
4 omni_custom 2420
5 omni_activate_app 4525
2 0 comment 1
1 link_click 53
2 post_reaction 23
3 video_view 2246
4 mobile_app_install 87
5 omni_view_content 24
6 post_engagement 2323
7 page_engagement 2323
我想换位,以便:
看起来您可以尝试:
(df.set_index('action_type', append=True)
.reset_index(level=1, drop=True)['value']
.unstack('action_type')
)
究竟是什么问题?请提供,请参阅。此外,除非绝对必要,否则请不要以图像形式共享信息。看:,.Ty你太棒了:)