Reputation: 2773
My dataset df
looks like this:
time Open
2017-01-01 00:00:00 5.2475
2017-01-01 01:00:00 5.2180
2017-01-01 02:00:00 5.2128
...., ....
2017-12-31 23:00:00 5.7388
This is an hourly
dataset.
I want to remove any data between 10 PM Friday
to 10 AM Sunday
What did I do?
I am able to remove the entire day like this:
df = df[df['time'].dt.dayofweek != 5] # Removes Saturday
Friday
and Sunday
aswell.How do I do this?
Upvotes: 0
Views: 455
Reputation: 323376
You can just write your conditions one by one
s1=df['time'].dt.dayofweek == 5
s2=(df['time'].dt.dayofweek == 4)&(df.time.dt.hour>20)
s3=(df['time'].dt.dayofweek == 6)&(df.time.dt.hour<10)
df=df[~(s1|s2|s3)]
Upvotes: 2