我有以下数据帧df
Datum HH DayPrecipitation
9377 2016-01-26 18 3
9378 2016-01-26 19 4
9379 2016-01-26 20 11
9380 2016-01-26 21 23
9381 2016-01-26 22 12
我使用
df.pivot_table(index = 'Datum', columns='HH' ,values = 'DayPrecipitation')
这给我留下了一个双栏
HH 18 19 20 21 22
Datum
2016-01-26 3 4 11 23 12
我想使列看起来像这样,并重命名列:
Datum col1 col2 col3 col4 col5 col6
2016-01-26 1 3 4 11 23 12
但是,当我使用reset_index
时,它只添加了另一个索引列,而没有删除multi_索引。
有人知道如何实现上述表格吗?非常感谢您的帮助
您可以删除} 设置新列名,并通过^{} 将索引最后转换为列:
['DayPrecipitation']
中的[]
以避免MultiIndex in columns
,然后通过^{试用
相关问题 更多 >
编程相关推荐