Pandas: 如何将int64年的索引转换为datetime

Pandas: how to convert an index of int64 years to datetime

我有一个代表年份值的 int64 索引,我想将其视为时间戳索引:

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

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

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