2024-10-04 03:27:34 发布
网友
我有一个熊猫数据帧,我想重塑它。在
Country 1991 1992 1993 Deutschland 1 2 3 Griechenland 4 7 0
如何生成如下所示的新数据帧:
使用melt(然后按国家和年份对值进行排序并重置索引):
melt
(df.melt('Country', var_name='Year', value_name='Value') .sort_values(['Country', 'Year']) .reset_index(drop=True))
输出:
使用
melt
(然后按国家和年份对值进行排序并重置索引):输出:
^{pr2}$相关问题 更多 >
编程相关推荐