简体   繁体   English

如何 select 行基于范围日期列 pandas python

[英]How to select rows based on range date column pandas python

I want to create new data frame that select rows that has range date from df['Date'] column between 2020-01-01 to 2020-03-31 in pandas python from below data frame.我想在 pandas Z23EEEB7947BDD75BDDZ36 中的 pandas Z23EEEB4947BDD25BDDZFC6 中创建新的数据框,该行的日期范围为 df['Date'] 列之间的 df['Date'] 列。 Anyone can help me?任何人都可以帮助我吗?

  Date        Name      Status
0 2020-01-01  Ali       Closed
1 2020-01-05  Sara      Closed
2 2020-02-15  Tyra      Approve
3 2020-03-19  Alia      Reject
4 2020-03-29  Aiman     Closed
5 2020-05-01  Alice     Closed
6 2020-07-12  Danish    Closed

You can use boolean indexing to select rows based on a condition.您可以根据条件使用boolean 索引到 select 行。

mask = (df['Date'] >= '2020-01-01') & (df['Date'] <= '2020-03-31')
q1_df = df[mask]

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

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