使用 pd.Index.map
的最简单解决方案
df.set_index(df.index.map(lambda t: pd.datetime(*t)))
3 months
1987-01-02 1
1987-01-05 2
1987-01-06 3
1987-01-07 4
1987-01-08 5
df.index=pd.to_datetime(pd.DataFrame(df.index.values.tolist(), columns=['year','month','day']))
df
Out[669]:
3 months
1987-01-02 1
1987-01-05 2
1987-01-06 3
1987-01-07 4
1987-01-08 5