简体   繁体   English

如何将熊猫系列索引日期转换为DatetimeIndex?

[英]How to convert panda series index date into DatetimeIndex?

The following data below is from a pandas series, but I need the date converted to DatetimeIndex like this format: 2020-08-17.以下数据来自熊猫系列,但我需要将日期转换为 DatetimeIndex 格式:2020-08-17。 The index of this series should be a pd.DatetimeIndex.这个系列的索引应该是一个 pd.DatetimeIndex。 What are some ways to convert it as such?有哪些方法可以将其转换为这样的?

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

Just change the index to be as type of datetime:只需将索引更改为日期时间类型:

df.index = pd.to_datetime(df.index)

More generally for a non-index column:更一般地,对于非索引列:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM