I think I came with a lighter solution than the one using pandas
current_month = datetime.today().month
current_year = datetime.today().year
start_year = 2016
#total months between now and the start year
total_months = current_month + (current_year - start_year)*12
months = []
month_count = 1
year_count = start_year
#iterate through the list, when it reaches 13, increment year_count and reset the month_count to 1
for month in range(total_months):
if month_count<13:
months.append(str(year_count) + "-" + str("{0:0=2d}".format(month_count)))
month_count+=1
if month_count == 13:
year_count+=1
month_count=1
results
['2016-01', '2016-02', '2016-03', '2016-04', '2016-05', '2016-06', '2016-07', '2016-08', '2016-09', '2016-10', '2016-11', '2016-12', '2017-01', '2017-02', '2017-03', '2017-04', '2017-05', '2017-06', '2017-07', '2017-08', '2017-09','2017-10', '2017-11', '2017-12', '2018-01', '2018-02', '2018-03', '2018-04', '2018-05', '2018-06']
for some reason, when I replace "if month_count == 13" with "else", it only goes up to 2018-04
I would appreciate some feedback on this solution.