import pandas as pd
from datetime import date
# import
import holidays
# use the code of Peru(PE) in 2022
pe_holidays = holidays.PE(years = 2022)
sorted_holidays = sorted(pe_holidays)
# We verify the holidays of Peru
for date in sorted_holidays:
print(date, pe_holidays[date])
# create array of tuples (date, name_holiday)
arr = [(date, pe_holidays[date]) for date in pe_holidays]
# create our dataframe
df_holidays_pe = pd.DataFrame(arr, columns = ['date', 'name_holiday'])
# change column 'date' to datetime type
df_holidays_pe['date'] = pd.to_datetime(df_holidays_pe['date'])
# select only the name of the day
df_holidays_pe['date'] = df_holidays_pe['date'].dt.day_name()
# change the name of the column 'date'
df_holidays_pe.rename(columns = {'date': 'day_name'}, inplace = True)
df_holidays_pe
# group by data = name_of_day
df_holidays_pe = df_holidays_pe.groupby('day_name').count().sort_values(by = 'name_holiday', ascending = False)
# rename the column name
df_holidays_pe.rename(columns = {'name_holiday': 'count_holidays'}, inplace = True)
df_holidays_pe