且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将Pandas Multi-Index转换为Pandas时间戳

更新时间:2023-02-03 14:34:13

在熊猫中来回转换数据变得非常麻烦,就像您所经历的那样. 对于大熊猫和索引,我的一般建议是永远不要只设置索引,而要先复制它.请确保您有一列包含索引的列,因为pandas不允许对索引进行所有操作,并且强烈设置和重置索引可能会导致列消失.

Converting data back and forth in pandas gets messy very fast, as you seem to have experienced. My recommendation in general concerning pandas and indexing, is to never just set the index, but to copy it first. Make sure you have a column which contains the index, since pandas does not allow all operations on the index, and intense setting and resetting of the index can cause columns to dissapear.

TLDR; 不要将索引转换回来.保留一份副本.

TLDR; Don't convert the index back. Keep a copy.