Python 如何将panda系列索引日期转换为DatetimeIndex?

Python 如何将panda系列索引日期转换为DatetimeIndex?,python,pandas,Python,Pandas,以下数据来自pandas系列,但我需要将日期转换为DatetimeIndex,格式如下:2020-08-17。此系列的索引应为pd.DatetimeIndex。有哪些方法可以将其转换为这样 8/17/20 14082780.0 8/18/20 14277100.0 8/19/20 14483216.0 8/20/20 14685442.0 8/21/20 14886403.0 Length: 212, dtype: float64 只需将索引更改为datetime

以下数据来自pandas系列,但我需要将日期转换为DatetimeIndex,格式如下:2020-08-17。此系列的索引应为pd.DatetimeIndex。有哪些方法可以将其转换为这样

8/17/20    14082780.0
8/18/20    14277100.0
8/19/20    14483216.0
8/20/20    14685442.0
8/21/20    14886403.0
Length: 212, dtype: float64

只需将索引更改为datetime的类型:

df.index = pd.to_datetime(df.index)
一般而言,对于非索引列:

df['Date']= pd.to_datetime(df['Date'])

谢谢你,诺亚!成功了!我感谢你的帮助。当心。