<jupyter_start><jupyter_text>Holidays or Custom Business Days<jupyter_code>import pandas as pd
df = pd.read_csv("aapl_no_dates.csv")
df.head()
rng = pd.date_range(start="7/1/2017", end="7/21/2017", freq='B') # freq B is not alwyas useful
rng<jupyter_output><empty_output><jupyter_text>Using CustomBusinessDay to generate US holidays calendar frequency<jupyter_code>from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay

us_cal = CustomBusinessDay(calendar=USFederalHolidayCalendar())  #  CReating custombusinessday using USFederalHolidayCalender
rng = pd.date_range(start="7/1/2017",end="8/02/2017", freq=us_cal)
rng
df.set_index(rng,inplace=True)
df.head()<jupyter_output><empty_output><jupyter_text>Own calendar using AbstractHolidayCalendar<jupyter_code># USFederalHolidayCalendar is the only calendar available in pandas
# The link for USFederalHolidayCalendar implementation 
   # https://github.com/pandas-dev/pandas/blob/master/pandas/tseries/holiday.py
# AbstractHolidayCalendar
from pandas.tseries.holiday import AbstractHolidayCalendar, nearest_workday, Holiday
class myCalendar(AbstractHolidayCalendar):  # shift+tab for documentation
    rules = [
        Holiday('My Birth Day', month=10, day=14),#, observance=nearest_workday),
    ]
    
my_bday = CustomBusinessDay(calendar=myCalendar())
pd.date_range('10/1/2020','10/31/2020',freq=my_bday)    #using my birthday as holiday<jupyter_output><empty_output><jupyter_text>CustomBusinessDay (Bangladesh)<jupyter_code>bd_weekdays = "Sun Mon Tue Wed Thu"

b = CustomBusinessDay(weekmask=bd_weekdays)

pd.date_range(start='10/1/2020',periods=20,freq=b)
# Adding custom holidays in existing business days
b = CustomBusinessDay(holidays=['2020-10-14', '2020-10-15'], weekmask=bd_weekdays)

pd.date_range(start="10/1/2020",periods=30,freq=b)<jupyter_output><empty_output>