【问题标题】:Get the index of a datatime in a dataframe pandas获取数据框 pandas 中日期时间的索引
【发布时间】:2021-08-14 10:17:14
【问题描述】:

for row in data['column_name']: if row.date() < datetime.today().date(): print(row,????)

我无法获取数据框中特定列的数据时间索引。我使用了这段代码,我想用该行返回该行的索引。谁能帮帮我?

【问题讨论】:

  • 使用loc,不要重复——例如df.loc[df['datetime'].dt.date < pd.Timestamp('now').date()]。如需详细解答,请提供minimal reproducible example

标签: python pandas dataframe datetime indexing


【解决方案1】:

您可以尝试以下方法

df.index[df['column_name'].dt.date < pd.Timestamp('now').date()].tolist()

【讨论】:

    猜你喜欢
    • 2017-08-28
    • 2020-06-04
    • 2019-03-16
    • 2018-07-31
    • 1970-01-01
    • 2012-12-01
    • 2015-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多