Created
February 12, 2025 12:02
-
-
Save tommylees112/9e8b4652959c75ae7ae1a5262e550752 to your computer and use it in GitHub Desktop.
Get holidays from the holidays python package for various geographies and years
This file contains hidden or 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 typing import Optional | |
import numpy as np | |
import pandas as pd | |
import holidays | |
def get_holidays( | |
years: Optional[list[int]] = None, | |
holiday: Optional[holidays.CountryHoliday] = None, | |
) -> pd.DataFrame: | |
if holiday is None: | |
holiday = holidays.GB | |
if years is None: | |
years = np.arange(2012, 2025) | |
return ( | |
pd.DataFrame(holiday(years=years), index=[0]) | |
.T.reset_index(names="date") | |
.rename(columns={0: "type"}) | |
) | |
if __name__ == "__main__": | |
print(get_holidays()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment