【问题标题】:How to get datetime from a pandas dataframe by row index如何通过行索引从熊猫数据框中获取日期时间
【发布时间】:2022-08-07 12:12:21
【问题描述】:

如何按行索引从以下数据框中获取日期?我正在寻找类似的功能:

get_datetime(dataframe, row_index = 1)

它将日期时间返回为2022-01-11

我已经阅读了Time series / date functionality of Pandas,但是在那里没有看到任何有用的东西。

             open   high    low  close    volume  dividends  stock splits
Date                                                                     
2022-01-06  21.99  22.22  21.59  22.18   1956300          0             0
2022-01-11  22.32  22.93  22.23  22.92   1885700          0             0
2022-01-21  22.40  22.55  22.02  22.13   2265500          0             0
2022-01-26  22.28  22.72  21.79  22.05   2247600          0             0
2022-01-31  22.02  22.92  21.72  22.86   2955500          0             0
2022-02-10  24.73  25.51  24.59  25.29   4069300          0             0
2022-02-15  24.85  25.57  24.56  25.47   5661100          0             0
2022-02-25  24.59  25.07  24.46  24.67   3722400          0             0
2022-03-02  23.20  23.95  23.15  23.82   3268100          0             0
2022-03-07  21.54  21.60  19.51  19.59  10102600          0             0

    标签: python pandas datetime


    【解决方案1】:

    你可以试试

    df.index[1]
    # or
    df.Date[1]
    

    【讨论】:

      猜你喜欢
      • 2021-03-27
      • 2021-05-03
      • 2021-03-19
      • 2016-08-06
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 2019-02-11
      • 2021-03-12
      相关资源
      最近更新 更多