【问题标题】:How to remove the 'seconds' of Pandas dataframe index?如何删除 Pandas 数据帧索引的“秒”?
【发布时间】:2015-04-24 05:23:21
【问题描述】:

给定一个具有如下时间序列的数据框:

                      Close
2015-02-20 14:00:00  1200.1
2015-02-20 14:10:00  1199.8
2015-02-21 14:00:00  1199.3
2015-02-21 14:10:00  1199.0
2015-02-22 14:00:00  1198.4
2015-02-22 14:10:00  1199.7

我怎样才能摆脱索引的“秒”,使其看起来像这样:

                   Close
2015-02-20 14:00  1200.1
2015-02-20 14:10  1199.8
2015-02-21 14:00  1199.3
2015-02-21 14:10  1199.0
2015-02-22 14:00  1198.4
2015-02-22 14:10  1199.7

谢谢

【问题讨论】:

    标签: python pandas time-series dataframe


    【解决方案1】:

    您可以像这样使用mapstrftime

    df.index =df.index.map(lambda t: t.strftime('%Y-%m-%d %H:%M'))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-01
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      相关资源
      最近更新 更多