Pandas Get Date Timestamp Which Belong To Businesshours Or Businessdays
Find out all the Businesshours and BusinessDays from the given list. I followed couple of docs about pandas offsets, but could not figure it out. followed stackoverflow as well, he
Solution 1:
I suppose, you are looking for something like:
bh = pd.offsets.BusinessHour() # avoid not necessary imports
y.apply(pd.Timestamp).apply(bh.rollforward)
The result is:
02020-02-11 13:44:5312020-02-12 13:44:5322020-02-11 09:00:0032020-02-03 09:00:00Name:hours,dtype:datetime64[ns]
So:
- two first hours have not been changed (they are within business hours).
- third (2020-02-11 8:44:53) has been advanced to 9:00 (start of the business day).
- fourth (2020-02-02 13:44:53 on Sunday) has been advanced to the next day (Monday) at 9:00.
Or, if you want only to check whether particulat date / hour is within business hours, run:
y.apply(pd.Timestamp).apply(bh.onOffset)
The resutl is:
0True1True2False3FalseName:hours,dtype:bool
meaning that two last date / hours are outside business hours.
Post a Comment for "Pandas Get Date Timestamp Which Belong To Businesshours Or Businessdays"