【问题标题】:Formatting datetime stamp格式化日期时间戳
【发布时间】:2018-06-15 09:09:39
【问题描述】:

我有一个索引为 DateTime 标记的数据框。我想通过格式化索引来改变它。我必须使用 strftime 来申请,但是当我以前喜欢这个时它不起作用。

df.index = df.index.map(strftime('%Y-%m-%d'))
Error: 'strftime' is not defined

但是当我这样做时它工作得很好:

df1.index[0].strftime('%Y-%m-%d')

我想申请我所有的索引。请给点建议?

【问题讨论】:

    标签: python pandas dataframe timestamp


    【解决方案1】:

    你很亲密,需要strftime:

    df.index = df.index.strftime('%Y-%m-%d')
    

    【讨论】:

      猜你喜欢
      • 2020-03-21
      • 1970-01-01
      • 2021-04-14
      • 2015-08-09
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      • 2016-02-13
      • 2012-01-03
      相关资源
      最近更新 更多