From pd.date_range('2016-01', '2016-05', freq='M', ).strftime('%Y-%m')
, the last month is 2016-04
, but I was expecting it to be 2016-05
. It seems to me this function is behaving like the range
method, where the end parameter is not included in the returning array.
Is there a way to get the end month included in the returning array, without processing the string for the end month?
I dont think so. You need to add the (n+1) boundary
Either way, you have to manually add some information. I believe adding just one more month is not a lot of work.
Include the day when specifying the dates in
date_range
callA way to do it without messing with figuring out month ends yourself.
You can use
.union
to add the next logical value after initializing thedate_range
. It should work as written for any frequency:Alternatively, you can use
period_range
instead ofdate_range
. Depending on what you intend to do, this might not be the right thing to use, but it satisfies your question:In either case, the resulting output is as expected:
For the later crowd. You can also try to use the Month-Start frequency.