1

My primary dataframe df

Id  timestamp
265 2017-05-22 02:57:29
267 2017-05-22 04:35:18
279 2017-05-22 11:08:14
281 2017-05-22 11:39:39
282 2017-05-22 11:40:42
285 2017-05-22 11:52:48
288 2017-05-22 12:00:29

My filter dataframe df2

Id  timestamp
283 2017-05-22 11:46:55
284 2017-05-22 11:51:41
286 2017-05-22 11:58:20

Normally I did

df[(df['timestamp'] >= '2017-05-22 11:46:55') & (df['dt'] =< '2017-05-22 11:58:20')]

But, this is not production friendly, and less reproducible

0

1 Answer 1

1

Use between by min and max datetimes of df2:

df3 = df[df['timestamp'].between(df2['timestamp'].min(), df2['timestamp'].max())]
print (df3)
    Id           timestamp
5  285 2017-05-22 11:52:48
Sign up to request clarification or add additional context in comments.

4 Comments

is between means (>= and <=) or (> and <)
It is inclusive=True by default, so >= and <=.
But if add inclucive=False then get > and <
@NabihBawazir - Super, nice day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.