Generate list of months between interval

I found a very succinct way to do this with Pandas, sharing in case it helps anybody:


UPDATE: I’ve got it down to a one-liner with the help of this post 🙂

pd.date_range('2014-10-10','2016-01-07', 
              freq='MS').strftime("%b-%y").tolist()

OLD ANSWER:

daterange = pd.date_range('2014-10-10','2016-01-07' , freq='1M') 
daterange = daterange.union([daterange[-1] + 1])  
daterange = [d.strftime('%b-%y') for d in daterange]

The second line prevents the last date from getting clipped off the list.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)