Created
June 21, 2018 19:56
-
-
Save messiest/c9abb837a02ea4bec53ced79950e75ac to your computer and use it in GitHub Desktop.
Pandas calendar for US Bank Holidays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from pandas.tseries.offsets import DateOffset, WeekOfMonth | |
from pandas.tseries.holiday import sunday_to_monday, AbstractHolidayCalendar, \ | |
Holiday, USMemorialDay, USLaborDay, USColumbusDay, USThanksgivingDay | |
class BankCalendar(AbstractHolidayCalendar): | |
rules = [ | |
Holiday("New Year's Day", month=1, day=1, observance=sunday_to_monday), | |
Holiday("Martin Luther King Jr.'s Birthday", month=1, day=1, offset=WeekOfMonth(week=3, weekday=1)), | |
Holiday("Washington's Birthday", month=2, day=1, offset=WeekOfMonth(week=3, weekday=1)), | |
USMemorialDay, | |
Holiday("Independence Day", month=7, day=4, observance=sunday_to_monday), | |
USLaborDay, | |
USColumbusDay, | |
Holiday("Veteran's Day", month=11, day=11, observance=sunday_to_monday), | |
USThanksgivingDay, | |
Holiday("Christmas Day", month=12, day=25, observance=sunday_to_monday), | |
] | |
if __name__ == "__main__": | |
bank_cal = BankCalendar() | |
print(bank_cal.holidays(datetime(2018, 1, 1), datetime(2019, 1, 1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment