如何使用后缀列旋转数据框?
我有一个带有以下结构的熊猫数据框架:
Frame P_1_x P_1_y P_2_x P_2_y ... P_N_x P_N_y
0 1 9 6 2 4 3
我想将其转换为:
x y
P_1 1 9
P_2 6 2
.
.
.
P_N 4 3
有没有有效的方法与熊猫一起做?
我尝试使用pandas.wide_to_long()函数和多索引,但我无法使其在我的情况下起作用。
I have a pandas dataframe with the following structure:
Frame P_1_x P_1_y P_2_x P_2_y ... P_N_x P_N_y
0 1 9 6 2 4 3
And I would like to transform it to:
x y
P_1 1 9
P_2 6 2
.
.
.
P_N 4 3
Is there any efficient way to do it with pandas?
I tried to use the pandas.wide_to_long() function and multi indexing but I couldn't make it work in my case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
围绕
_
拆分列,然后使用展开
参数以转换为多索引,然后堆叠多索引列以重新设计:Split the columns around
_
and useexpand
parameter to convert to multiindex, then stack the multiindex columns to reshape: