I'm working on a simulation of work interruptions and I wanted to have a DatetimeIndex that took into account the only normal working hours and considered weekend an holiday time. After quite a bit of digging I found these two little Python gems CustomBusinessDay and CustomBusinessHour.
This is a quick example of how to use them to get a DatetimeIndex with 1 work hour frequency.
The resulting data set shows that USholidays present a real challenge to getting something done around the end of the year. Working on a 6 business day task started on December 22th will be distributed into business days out until Janurary 2 of the following year.
In [ ]:
from datetime import datetime
from pandas.tseries.offsets import CustomBusinessDay, CustomBusinessHour
from pandas.tseries.holiday import USFederalHolidayCalendar
import pandas as pd
#Come up with the US Holiday Calendar
bday_us = CustomBusinessDay(calendar=USFederalHolidayCalendar(), n=6)
#Also use the business hours (9-17) 8hrs per day
bh = CustomBusinessHour(calendar=USFederalHolidayCalendar())
start = datetime(2017, 12, 22, 7,0,0)
#example range
rng = pd.date_range(start=start,
end=start + bday_us,
freq=bh)
rng
In [ ]: