Pandas:如何将int64年份索引转换为日期时间

14

我有一个int64索引,表示年份值,我希望将其视为时间戳索引:

df.index
Int64Index([2001,2002,2003], dtype='int64')

我该如何在pandas中将索引转换为日期时间戳?

1个回答

29
import pandas as pd
df.index = pd.to_datetime(df.index, format='%Y')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接