Enhancing Predictive Models with Workalendar’s Holiday Handling

Incorporating holiday and working day information into predictive models can enhance accuracy, but it’s challenging due to regional variations in holiday schedules.

Workalendar simplifies this process by handling working days, holidays, and business calendars for various countries and regions.

Here are some examples:

Get US holidays in 2024:

    from datetime import date 
    from workalendar.usa import UnitedStates
    
    US_cal = UnitedStates()
    US_cal.holidays(2024)
    [(datetime.date(2024, 1, 1), 'New year'),
     (datetime.date(2024, 1, 15), 'Birthday of Martin Luther King, Jr.'),
     (datetime.date(2024, 2, 19), "Washington's Birthday"),
     (datetime.date(2024, 5, 27), 'Memorial Day'),
     (datetime.date(2024, 7, 4), 'Independence Day'),
     (datetime.date(2024, 9, 2), 'Labor Day'),
     (datetime.date(2024, 10, 14), 'Columbus Day'),
     (datetime.date(2024, 11, 11), 'Veterans Day'),
     (datetime.date(2024, 11, 28), 'Thanksgiving Day'),
     (datetime.date(2024, 12, 25), 'Christmas Day')]

    Check if a date is a working day:

    US_cal.is_working_day(date(2024, 9, 15)) # Sunday
    False
    US_cal.is_working_day(date(2024, 9, 2)) # Labor Day
    False

    Calculate the number of working days between two dates, excluding weekends and holidays:

    # Calculate working days between 2024/1/19 and 2024/5/15
    US_cal.get_working_days_delta(date(2024, 1, 19), date(2024, 5, 15))
    82

    Get Japan holidays in 2024:

    from workalendar.asia import Japan
    
    # Get holidays in Japan
    JA_cal = Japan()
    JA_cal.holidays(2024)
    [(datetime.date(2024, 1, 1), 'New year'),
     (datetime.date(2024, 1, 8), 'Coming of Age Day'),
     (datetime.date(2024, 2, 11), 'Foundation Day'),
     (datetime.date(2024, 2, 23), "The Emperor's Birthday"),
     (datetime.date(2024, 3, 20), 'Vernal Equinox Day'),
     (datetime.date(2024, 4, 29), 'Showa Day'),
     (datetime.date(2024, 5, 3), 'Constitution Memorial Day'),
     (datetime.date(2024, 5, 4), 'Greenery Day'),
     (datetime.date(2024, 5, 5), "Children's Day"),
     (datetime.date(2024, 7, 15), 'Marine Day'),
     (datetime.date(2024, 8, 11), 'Mountain Day'),
     (datetime.date(2024, 9, 16), 'Respect-for-the-Aged Day'),
     (datetime.date(2024, 9, 22), 'Autumnal Equinox Day'),
     (datetime.date(2024, 10, 14), 'Sports Day'),
     (datetime.date(2024, 11, 3), 'Culture Day'),
     (datetime.date(2024, 11, 23), 'Labour Thanksgiving Day')]

    Link to Workalendar.

    Next Step

    If you liked this blog post, you might also like:

    Related Posts

    Scroll to Top

    Work with Khuyen Tran

    Work with Khuyen Tran