Created
August 19, 2022 18:02
-
-
Save alexkyllo/a4ea9e6252d79a85fe1dfdef06e8bb62 to your computer and use it in GitHub Desktop.
Global holidays table in Python
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
| 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() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run: