How to delete all rows from dataframe between two timestamps inclusive?
my Dataframe looks like :
b a
0 2016-12-02 22:00:00 19.218519
1 2016-12-02 23:00:00 19.171197
2 2016-12-03 00:00:00 19.257836
3 2016-12-03 01:00:00 19.195610
4 2016-12-03 02:00:00 19.176413
For eg : I want to delete all rows from above dataframe whose timestamp falls is in between : "2016-12-02 22:00:00" to "2016-12-03 00:00:00". So, the result will contain only rows 3 and 4.
the type of b column is datetime64 and the type of a is float.
Please suggest.
You can filter those out:
from_ts = '2016-12-02 22:00:00'
to_ts = '2016-12-03 00:00:00'
df = df[(df['b'] < from_ts) | (df['b'] > to_ts)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With