获取数据框 pandas 中日期时间的索引

Posted

技术标签:

【中文标题】获取数据框 pandas 中日期时间的索引【英文标题】:Get the index of a datatime in a dataframe 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。 【参考方案1】:

您可以尝试以下方法

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

【讨论】:

以上是关于获取数据框 pandas 中日期时间的索引的主要内容,如果未能解决你的问题,请参考以下文章