【问题标题】:Pandas: how to convert an index of int64 years to datetimePandas:如何将 int64 年的索引转换为日期时间
【发布时间】:2015-01-23 19:34:33
【问题描述】:

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

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

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

【问题讨论】:

    标签: pandas


    【解决方案1】:
    import pandas as pd
    df.index = pd.to_datetime(df.index, format='%Y')
    

    【讨论】:

      猜你喜欢
      • 2016-10-01
      • 2018-05-11
      • 2018-10-30
      • 1970-01-01
      • 2020-01-16
      • 1970-01-01
      • 2017-07-11
      相关资源
      最近更新 更多