枢轴数据框并获取两个值列
我有一个数据集,看起来像这样:
地区 | 国家 | 产品 | 组类别产品 | productfamily | reality | 其他信息 |
---|---|---|---|---|---|---|
dk | 欧洲 | x | y | z | 1/2 | x |
de | 欧洲 | x1 y1 | z1 | z1 z1 | 1/12 | -US |
Americas | X | Y | Z | 6 | /9- | 我 |
想拥有一个像这样的枢轴
Region
Europe Americas
DK DE US
Value Other info Value Other info Value Other info
ProductGroup Category ProductFamily
C Y Z 1/2 X 6/9 -
X1 Y1 Z1 1/12 -
我已经尝试过
x = df_out.pivot(index=['MATKL','ProductGroup','Category','ProductFamily'],
columns=['Region','Country'], values = ['value','Eother info'])
它几乎可以完成工作,但是它为我带来了两个块,然后所有地区,国家,然后是其他信息,以获取其他信息。
I have a dataset there look like this:
Region | Country | ProductGroup | Category | ProductFamily | value | other info |
---|---|---|---|---|---|---|
DK | Europe | X | y | Z | 1/2 | X |
DE | Europe | X1 | y1 | Z1 | 1/12 | - |
US | Americas | X | y | Z | 6/9 | - |
I Would like to have a pivot like this
Region
Europe Americas
DK DE US
Value Other info Value Other info Value Other info
ProductGroup Category ProductFamily
C Y Z 1/2 X 6/9 -
X1 Y1 Z1 1/12 -
I have tried this
x = df_out.pivot(index=['MATKL','ProductGroup','Category','ProductFamily'],
columns=['Region','Country'], values = ['value','Eother info'])
It does nearly the job, but it give me two blocks on for value and then all region, countries and then the same for Other info.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 > 带有 a>:
Use
DataFrame.reorder_levels
withDataFrame.sort_index
:尝试以下操作:
Try this: