Skip to content

Instantly share code, notes, and snippets.

@tommylees112
Created February 12, 2025 12:02
Show Gist options
  • Save tommylees112/9e8b4652959c75ae7ae1a5262e550752 to your computer and use it in GitHub Desktop.
Save tommylees112/9e8b4652959c75ae7ae1a5262e550752 to your computer and use it in GitHub Desktop.
Get holidays from the holidays python package for various geographies and years
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