I have a pandas dataframe as following below:
import pandas as pd
df = pd.DataFrame({'DAY_OF_WEEK': ['Monday', 'Sunday', 'Saturday', 'Monday', 'Tuesday'],
'HOUR': ['21:02:02', '11:22:02', '23:02:02', '09:22:02', '09:02:02'],
'id': [1,2,2,3,1]})
df
I need to applicate a filter for that a new dataframe have only register where HOUR
between 19:00:00 and 07:00:00 or DAY_OF_WEEK
== 'Sunday'. An expected output:
DAY_OF_WEEK | HOUR | ID
Monday |21:02:02 | 1
Saturday |23:02:02 | 2
Monday |09:22:02 | 3
I trying the following:
df2 = df.loc[(pd.to_timedelta(df.HOUR).between('06:00:00','19:00:00') | df['DAY_OF_WEEK'] == 'Sunday')]
calls_night_or_sunday = df[~df2].copy()
but, I have an output where all the lines received NaN
. Can anyone help?