pandas :如何将int64年的索引转换为日期时间 [英] Pandas: how to convert an index of int64 years to datetime

查看:599
本文介绍了 pandas :如何将int64年的索引转换为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个int64索引,它表示要作为时间戳索引的年值:

I have an int64 index representing year values that I want to treat as a timestamp index:

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

如何将索引转换为熊猫的日期时间时间戳?

How do I convert the index to a datetime timestamp in pandas?

推荐答案

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

这篇关于 pandas :如何将int64年的索引转换为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆