Last active
January 12, 2017 15:24
-
-
Save JonasHeylen/6e70c835e46d4292e11d165fd0f22c77 to your computer and use it in GitHub Desktop.
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 pandas.tseries.offsets import Day | |
from pandas.tseries.holiday import AbstractHolidayCalendar, Holiday, Easter, EasterMonday, weekend_to_monday, nearest_workday | |
class BelgianHolidayCalendar(AbstractHolidayCalendar): | |
rules = [ | |
Holiday('Nieuwjaar', month=1, day=1, observance=weekend_to_monday), | |
EasterMonday, | |
Holiday('Dag van de Arbeid', month=5, day=1, observance=nearest_workday), | |
Holiday('O.H. Hemelvaart', month=1, day=1, offset=[Easter(), Day(39)]), | |
Holiday('Pinkstermaandag', month=1, day=1, offset=[Easter(), Day(50)]), | |
Holiday('Nationale feestdag', month=7, day=21, observance=nearest_workday), | |
Holiday('O.L.V. hemelvaart', month=8, day=15, observance=nearest_workday), | |
Holiday('Allerheiligen', month=11, day=1, observance=nearest_workday), | |
Holiday('Wapenstilstand', month=11, day=11, observance=nearest_workday), | |
Holiday('Kerstmis', month=12, day=25, observance=nearest_workday) | |
] |
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
import numpy as np | |
import pandas as pd | |
from pandas.tseries.offsets import CustomBusinessDay | |
from belgian_holiday_calendar import BelgianHolidayCalendar | |
business_days = pd.date_range('20170101', '20171231', freq=CustomBusinessDay(calendar=BelgianHolidayCalendar())) | |
business_days_series = pd.Series(np.ones(len(business_days)), index=business_days) | |
business_days_series.count() | |
business_days_per_month = business_days_series.resample('M').count() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment