简体   繁体   English

Select 行基于 Pandas Dataframe 中 Python 中的日期(日期不是列)

[英]Select rows based on date in a Pandas' Dataframe in Python (date is not a column)

I have got a dataframe like:我有一个 dataframe 像:

*nothing*            open          high
2020-01-12            122            59
2020-01-13            113            52
2020-02-14            144            64
2020-03-15            135            64

How can I only select rows from 2020-01-13 to 2020-02-14 using a filter?如何使用过滤器仅从 2020 年 1 月 13 日到 2020 年 2 月 14 日的 select 行? I'm aware there are more questions like these but this dataframe doesn't have a name for the date column (eg the date is the index).我知道还有更多这样的问题,但是这个 dataframe 没有日期列的名称(例如,日期是索引)。

Thank you!谢谢!

You can filter the index using loc :您可以使用loc过滤索引:

df.loc[(df.index >= '2020-01-13') & (df.index <= '2020-02-14')]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM