w3resource

Pandas: Holidays between two dates using the US federal holiday calendar


30. Generate Holidays using US Federal Calendar

Write a Pandas program to generate holidays between two dates using the US federal holiday calendar.

Sample Solution:

Python Code :

import pandas as pd
from pandas.tseries.holiday import *
sdt = datetime(2021, 1, 1)
edt = datetime(2030, 12, 31)
print("Holidays between 2021-01-01 and 2030-12-31 using the US federal holiday calendar.")
cal = USFederalHolidayCalendar()
for dt in cal.holidays(start=sdt, end=edt): 
    print (dt)

Sample Output:

Holidays between 2021-01-01 and 2030-12-31 using the US federal holiday calendar.
2021-01-01 00:00:00
2021-01-18 00:00:00
2021-02-15 00:00:00
2021-05-31 00:00:00
2021-07-05 00:00:00
2021-09-06 00:00:00
2021-10-11 00:00:00
2021-11-11 00:00:00
2021-11-25 00:00:00
2021-12-24 00:00:00
2021-12-31 00:00:00
2022-01-17 00:00:00
2022-02-21 00:00:00
2022-05-30 00:00:00
2022-07-04 00:00:00
2022-09-05 00:00:00
2022-10-10 00:00:00
2022-11-11 00:00:00
2022-11-24 00:00:00
2022-12-26 00:00:00
2023-01-02 00:00:00
2023-01-16 00:00:00
2023-02-20 00:00:00
2023-05-29 00:00:00
2023-07-04 00:00:00
2023-09-04 00:00:00
2023-10-09 00:00:00
2023-11-10 00:00:00
2023-11-23 00:00:00
2023-12-25 00:00:00
2024-01-01 00:00:00
2024-01-15 00:00:00
2024-02-19 00:00:00
2024-05-27 00:00:00
2024-07-04 00:00:00
2024-09-02 00:00:00
2024-10-14 00:00:00
2024-11-11 00:00:00
2024-11-28 00:00:00
2024-12-25 00:00:00
2025-01-01 00:00:00
2025-01-20 00:00:00
2025-02-17 00:00:00
2025-05-26 00:00:00
2025-07-04 00:00:00
2025-09-01 00:00:00
2025-10-13 00:00:00
2025-11-11 00:00:00
2025-11-27 00:00:00
2025-12-25 00:00:00
2026-01-01 00:00:00
2026-01-19 00:00:00
2026-02-16 00:00:00
2026-05-25 00:00:00
2026-07-03 00:00:00
2026-09-07 00:00:00
2026-10-12 00:00:00
2026-11-11 00:00:00
2026-11-26 00:00:00
2026-12-25 00:00:00
2027-01-01 00:00:00
2027-01-18 00:00:00
2027-02-15 00:00:00
2027-05-31 00:00:00
2027-07-05 00:00:00
2027-09-06 00:00:00
2027-10-11 00:00:00
2027-11-11 00:00:00
2027-11-25 00:00:00
2027-12-24 00:00:00
2027-12-31 00:00:00
2028-01-17 00:00:00
2028-02-21 00:00:00
2028-05-29 00:00:00
2028-07-04 00:00:00
2028-09-04 00:00:00
2028-10-09 00:00:00
2028-11-10 00:00:00
2028-11-23 00:00:00
2028-12-25 00:00:00
2029-01-01 00:00:00
2029-01-15 00:00:00
2029-02-19 00:00:00
2029-05-28 00:00:00
2029-07-04 00:00:00
2029-09-03 00:00:00
2029-10-08 00:00:00
2029-11-12 00:00:00
2029-11-22 00:00:00
2029-12-25 00:00:00
2030-01-01 00:00:00
2030-01-21 00:00:00
2030-02-18 00:00:00
2030-05-27 00:00:00
2030-07-04 00:00:00
2030-09-02 00:00:00
2030-10-14 00:00:00
2030-11-11 00:00:00
2030-11-28 00:00:00
2030-12-25 00:00:00

For more Practice: Solve these Related Problems:

  • Write a Pandas program to generate a list of US federal holidays between two dates and then flag any that fall on weekends.
  • Write a Pandas program to create a holiday calendar using US federal holidays and then merge it with a time-series for visualization.
  • Write a Pandas program to generate holidays for a specified date range and then compute the monthly holiday count.
  • Write a Pandas program to create a DataFrame of US federal holidays and then cross-verify the holiday names and dates with a standard list.

Go to:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program create a series with a PeriodIndex which represents all the calendar month periods in 2029 and 2031. Also print the values for all periods in 2030.
Next: Write a Pandas program to create a monthly time period and display the list of names in the current local scope.

Python Code Editor:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.