First, it is good to check if there is a method specifically for Brazil in this module. To check the methods of this and any other module, use the function builtin dir()
. So we have:
from pandas.tseries import holiday
print(dir(holiday))
returning:
['AbstractHolidayCalendar', 'DateOffset', 'Day', 'Easter', 'EasterMonday', 'FR', 'GoodFriday', 'Holiday', 'HolidayCalendarFactory', 'HolidayCalendarMetaClass', 'List', 'MO', 'PerformanceWarning', 'SA', 'SU', 'Series', 'TH', 'TU', 'Timestamp', 'USColumbusDay', 'USFederalHolidayCalendar', 'USLaborDay', 'USMartinLutherKingJr', 'USMemorialDay', 'USPresidentsDay', 'USThanksgivingDay', 'WE', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'after_nearest_workday', 'before_nearest_workday', 'date_range', 'datetime', 'get_calendar', 'holiday_calendars', 'nearest_workday', 'next_monday', 'next_monday_or_tuesday', 'next_workday', 'np', 'previous_friday', 'previous_workday', 'register', 'sunday_to_monday', 'timedelta', 'warnings', 'weekend_to_monday']
I mean, it really seems to have data in this module just for the US. The second option is to check if there is another module that does the same thing with data from other countries. In fact, there is a module just for this that can be found in this link. Doing the same test for this new package, we have:
import holidays
print(dir(holidays))
returning:
['APR', 'AR', 'AT', 'AU', 'AUG', 'AW', 'Argentina', 'Aruba', 'Australia', 'Austria', 'BE', 'BG', 'BR', 'BY', 'Belarus', 'Belgium', 'Brazil', 'Bulgaria', 'CA', 'CH', 'CL', 'CO', 'CZ', 'Canada', 'Chile', 'Colombia', 'CountryHoliday', 'Croatia', 'Czech', 'Czechia', 'DE', 'DEC', 'DK', 'DO', 'Denmark', 'DominicanRepublic', 'ECB', 'EE', 'EG', 'ES', 'Egypt', 'England', 'Estonia', 'EuropeanCentralBank', 'FEB', 'FI', 'FRA', 'FRI', 'Finland', 'France', 'GB', 'GR', 'Germany', 'Greece', 'HK', 'HND', 'HR', 'HU', 'HolidayBase', 'Honduras', 'HongKong', 'Hungary', 'IE', 'IL', 'IND', 'IS', 'ISR', 'IT', 'Iceland', 'India', 'Ireland', 'IsleOfMan', 'Israel', 'Italy', 'JAN', 'JP', 'JUL', 'JUN', 'Japan', 'KE', 'Kenya', 'LT', 'LU', 'Lithuania', 'Luxembourg', 'MAR', 'MAY', 'MON', 'MX', 'Mexico', 'NG', 'NI', 'NL', 'NO', 'NOV', 'NZ', 'Netherlands', 'NewZealand', 'Nicaragua', 'Nigeria', 'NorthernIreland', 'Norway', 'OCT', 'PE', 'PL', 'PT', 'PTE', 'PY', 'Paraguay', 'Peru', 'Poland', 'Polish', 'Portugal', 'PortugalExt', 'RS', 'RU', 'Russia', 'SAT', 'SE', 'SEP', 'SG', 'SI', 'SK', 'SUN', 'Scotland', 'Serbia', 'Singapore', 'Slovak', 'Slovakia', 'Slovenia', 'SouthAfrica', 'Spain', 'Sweden', 'Switzerland', 'TAR', 'THU', 'TUE', 'UA', 'UK', 'US', 'Ukraine', 'UnitedKingdom', 'UnitedStates', 'WED', 'WEEKEND', 'Wales', 'ZA', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'argentina', 'aruba', 'australia', 'austria', 'belarus', 'belgium', 'brazil', 'bulgaria', 'canada', 'chile', 'colombia', 'constants', 'countries', 'createHolidaySum', 'croatia', 'czechia', 'denmark', 'dominican_republic', 'egypt', 'estonia', 'european_central_bank', 'finland', 'france', 'germany', 'greece', 'holiday_base', 'honduras', 'hongkong', 'hungary', 'iceland', 'india', 'ireland', 'israel', 'italy', 'japan', 'kenya', 'list_supported_countries', 'lithuania', 'luxembourg', 'mexico', 'netherlands', 'new_zealand', 'nicaragua', 'nigeria', 'norway', 'paraguay', 'peru', 'poland', 'portugal', 'russia', 'serbia', 'singapore', 'slovakia', 'slovenia', 'south_africa', 'spain', 'sweden', 'switzerland', 'ukraine', 'united_kingdom', 'united_states', 'utils']
Now just rewrite the code with the new module:
import holidays
feriados= holidays.Brazil()
for feriado in feriados['2020-01-01': '2020-12-31'] :
print(feriado)
returning:
2020-01-01
2020-02-25
2020-02-26
2020-04-10
2020-04-12
2020-04-21
2020-05-01
2020-06-11
2020-09-07
2020-10-12
2020-11-02
2020-11-15
2020-12-25
Forgot to add Link.
– Neto Costa
Truth @Netocosta I will add now. Thank you
– Lucas