Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
About Article
Analyze Data
Archive
Best Practices
Better Outputs
Blog
Code Optimization
Code Quality
Command Line
Daily tips
Dashboard
Data Analysis & Manipulation
Data Engineer
Data Visualization
DataFrame
Delta Lake
DevOps
DuckDB
Environment Management
Feature Engineer
Git
Jupyter Notebook
LLM
LLM
Machine Learning
Machine Learning
Machine Learning & AI
Manage Data
MLOps
Natural Language Processing
NumPy
Pandas
Polars
PySpark
Python Tips
Python Utilities
Python Utilities
Scrape Data
SQL
Testing
Time Series
Tools
Visualization
Visualization & Reporting
Workflow & Automation
Workflow Automation

Enhancing Predictive Models with Workalendar’s Holiday Handling

Table of Contents

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:

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    0
      0
      Your Cart
      Your cart is empty
      Scroll to Top

      Work with Khuyen Tran

      Work with Khuyen Tran