Skip to content

Instantly share code, notes, and snippets.

@alexkyllo
Created August 19, 2022 18:02
Show Gist options
  • Select an option

  • Save alexkyllo/a4ea9e6252d79a85fe1dfdef06e8bb62 to your computer and use it in GitHub Desktop.

Select an option

Save alexkyllo/a4ea9e6252d79a85fe1dfdef06e8bb62 to your computer and use it in GitHub Desktop.
Global holidays table in Python
import pandas as pd
from holidays import country_holidays, list_supported_countries
def main():
"""Get a global holidays table."""
years = 2022, 2023, 2024
all_holidays = {
ct: country_holidays(ct, years=years) for ct in list_supported_countries().keys()
}
df = pd.DataFrame.from_dict(all_holidays).melt(ignore_index=False).dropna()
df.index = pd.to_datetime(df.index)
df.index.name = "Date"
df.columns = ["Country", "Holiday"]
df = df.sort_values(["Date", "Country"], ascending=[True, True])
df.to_csv("global_holidays_2022_2024.csv")
if __name__ == "__main__":
main()
@alexkyllo
Copy link
Author

To run:

pip install holidays pandas
python make_holiday_table.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment