如何创建此 Dataframe :
datecreated timestamp value
2022-11-15 1 4000
2022-11-15 2 3900
2022-11-15 3 3850
2022-11-15 4 3810
2022-11-15 5 3790
变成:
datecreated 1 2 3 4 5
0 2022-11-15 4000 3900 3850 3810 3790
我试探着:
df = df.pivot(index='datecreated', columns='timestamp', values='value')
结果为:
timestamp 1 2 3 4 5
datecreated
2022-11-15 4000 3900 3850 3810 3790
重设索引:
timestamp datecreated 1 2 3 ...
0 2022-11-15 4000.0 3900.0 3850.0...
1条答案
按热度按时间sgtfey8w1#
您所看到的只是由于透视而将列的轴名称自动设置为
timestamp
。输出量: