floss
floss

Reputation: 2773

How to remove specific time-range data using Pandas

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?

How do I do this?

Upvotes: 0

Views: 455

Answers (1)

BENY
BENY

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

Related Questions