我需要按月获取以下代码的假期数
代码
import holidays
import calendar
india_holidays = holidays.India ( years=2022 )
#print(india_holidays)
holiday_count_dict = {}
for date, occassion in india_holidays.items ():
date = str ( date )
if date[:7] not in holiday_count_dict:
holiday_count_dict[date[:7]] = 1
else:
val = holiday_count_dict[date[:7]]
holiday_count_dict[date[:7]] = val + 1
print ( "holiday count : ", holiday_count_dict )
print(list(holiday_count_dict.values())[0])
now = datetime.datetime.now ()
cal = calendar.Calendar ()
working_days = len ( [x for x in cal.itermonthdays2 ( now.year, now.month ) if x[0] != 0 and x[1] < 5] ) - (list(holiday_count_dict.values())[0])
请帮助我如何解决它