简体   繁体   中英

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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