【发布时间】:2022-01-24 02:58:57
【问题描述】:
我有一个这样的 cvs 格式的数据文件:
StudentID Math Physics Chemistry History
001 80 90 95 98
002 99 85 90 70
003 77 80 95 90
我想要的格式是这样的:
StudentID Math Score
001 Math 80
001 Physics 90
001 Chemistry 95
001 History 98
002 Math 99
002 Physics 85
002 Chemistry 90
002 History 70
003 Math 77
003 Physics 80
003 Chemistry 95
003 History 90
如何在 Pandas 中进行这种格式转换?提前致谢。
【问题讨论】:
-
你试过
df.melt(id_vars='StudentID')吗? -
嘿@JonClements,感谢您的意见。我已经对这个问题发布了相同的答案。
标签: python pandas dataframe format data-conversion