I just want to do the below simple stuff, I have a time-series, label those times in between a range. I've found a post about using dt.xx to filter the time, but that's more complex when we want to mask time like 18:30
and 22:30
, when I use df.ts.dt.hour.gt(18) & (df.ts.dt.minute.eq(30))
, it won't gives me what I wanted.
So, Is there some function like the below or I can achieve some result with another method?
df['tmp'] = np.where( df.ts.dt.time.between('18:30','22:30') , True, False)
format of time series:
Timestamp('2021-10-01 17:30:00')
More data pieces can be obtained from here.
Currently, I'm using some very long and ugly code like:
df["tmp"] = np.where(df.ev_charging.eq(True), df.delivered_wh, 0)
df['p1'] = np.where(df.ts.dt.hour.eq(18) & df.ts.dt.minute.eq(30), 1,0)
df['p2'] = np.where(df.ts.dt.hour.eq(23) & df.ts.dt.minute.eq(30), 1,0)
df['p3'] = np.where(df.ts.dt.hour.eq(4) & df.ts.dt.minute.eq(30), 1,0)
df['p'] = np.where(df.p1.eq(1) | df.p2.eq(1) | df.p3.eq(1), 1, 0)
df = df.drop(['p1','p2','p3'],axis=1)