Home > Net >  Pandas: show only rows that were valid on a specific date
Pandas: show only rows that were valid on a specific date

Time:11-30

I'm trying to find rows in a dataframe that were valid on a specific date

Dataframe:

idx start   end
0   2019-08-23  2019-12-31
1   2018-01-01  2018-07-05
2   2020-04-01  2020-11-27
3   2018-03-24  2018-06-18

find values that were valid on 2018-05-16

Result:

idx start   end
1   2018-01-01  2018-07-05
3   2018-03-24  2018-06-18

How can I filter out all other entries?

CodePudding user response:

offset = (df['wished_date'] > start_date) & (df['wished_date'] <= end_date)
df = df.loc[offset]
df
  • Related