I want to create a list (or array or whathever) of a given number of dates at monthly intervals.
Basically what I want is this
>>>some_function(start_date=date(2005, 5, 14), periods=4, freq='M')
['2005-05-14', '2005-06-14', '2005-07-14', '2005-08-14']
and if the day of the startmonth is close to end of the month I want this
>>>some_function(start_date=date(2007, 12, 31), periods=4, freq='M')
['2007-12-31', '2008-01-31', '2008-02-29', '2008-03-31']
I am aware of the pandas date_range function, however it produces this
pd.date_range(date(2005, 5, 14), periods=4, freq='M')
Out[1]: DatetimeIndex(['2005-05-31', '2005-06-30', '2005-07-31', '2005-08-31'],
dtype='datetime64[ns]', freq='M')
i.e. it sets the month end as the day. Which is not what I want.
Obviously, this could be produced iterating over the number of periods, but this creates a hassle when the day of the startmonth is close to the last day of the month.
Does anybody know of a function producing this or is the method outlined above the only way?