I am in a process of making a fbprophet sales forecasting model. I am going to pass a list of holidays to model, and I was using a for loop to get sundays and the national holiday dates between 2 given years, and then append these values to an empty list 'ee'.
I am able to get all the sundays in the list but not the national holidays, there might be something wrong with the 2nd for loop. Can somebody help me? I'm trying to get a list of Sundays and dates - 26th Jan, 15th Aug, 2nd Oct between 2 years
Here is the code:
from datetime import date, timedelta
set =[]
def allsundays(year1,year2):
d = date(year1, 1, 1) # January 1st
d += timedelta(days = 6 - d.weekday()) # First Sunday
while d.year <= year2:
yield d
d += timedelta(days = 7)
def nat_hol(year1,year2):
j=0
r= date(year1 +j,1,26)
i= date(year1 +j,8,15)
o= date(year1 +j,10,2)
while (r.year <= year2 and i.year <= year2 and o.year <= year2):
yield (r,i,o)
j=j+1
for ee in nat_hol(2016,2021):
set.append(ee.strftime("%Y-%m-%d"))
set
This is the output:
['2016-01-03',
'2016-01-10',
'2016-01-17',
'2016-01-24',
'2016-01-31',
'2016-02-07',
'2016-02-14',
'2016-02-21',
'2016-02-28',
'2016-03-06',
'2016-03-13',
'2016-03-20',
'2016-03-27',
'2016-04-03',
'2016-04-10',