Overview:
-
The NumPy class busdaycalendar represents a business calendar. An instance of busdaycalendar holds two pieces of information:
-
What days of a week are working days and what days are non-working days – This information is held by the attribute weekmask.
-
A list of holidays which are exception to the attribute weekmask
-
-
The busdaycalendar is used by other NumPy functions that provides date and time support like is_busday() and busday_count().
Example 1:
This example creates a business calendar with the holidays for a stock exchange specified. It calculates how many trading days are there after deducting the two holidays in January.
# Example Python program that creates a business day # Data courtesy:https://www.nyse.com/markets/hours-calendars startDate = '2025-01-01' trdaingDayCount = numpy.busday_count(startDate, dateEx = '2025-07-29'
|
Output:
Weekly working days mask: |
Example 2:
This example has its week day mask modified for a Doctor who works on an emergency shift in December. The NumPy function busday_count() takes into account both the modified week day mask and the holiday list specified in the busdaycalendar object.
# Example Python program that creates calendar import numpy # Holiday calendar for a Doctor who works on regular shifts # Holiday calendar for a Doctor who works on emergency # Number of working days in December for a Doctor who works workingDaysEmg = numpy.busday_count(startDate, # Check whether Christmas a working day for a Doctor who works on
|
Output:
Number of working days in emergency shift: |