首页 > 解决方案 > Why sort_index removes time portion of datetime columns?

问题描述

I have a dataframe with a datetimeIndex: enter image description here

but when I try to sort this dataframe using sort_index() the time portion of all datetime columns (including the index) is removed. Why? How can I prevent it?
here's the code to sort:

data_date_index.sort_index(inplace=True)

and here's my dataframe after running the above line of code: enter image description here

标签: pythonpandasdatetime

解决方案


这很奇怪,但是当我data_date_index.head()在另一个单元格中运行时,它工作得很好(时间部分没有被删除)


推荐阅读