How to include end date in pandas date_range method?

前端 未结 7 1735
[愿得一人]
[愿得一人] 2021-01-02 02:42

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

7条回答
  •  醉酒成梦
    2021-01-02 03:27

    I dont think so. You need to add the (n+1) boundary

       pd.date_range('2016-01', '2016-06', freq='M' ).strftime('%Y-%m')
    

    The start and end dates are strictly inclusive. So it will not generate any dates outside of those dates if specified. http://pandas.pydata.org/pandas-docs/stable/timeseries.html

    Either way, you have to manually add some information. I believe adding just one more month is not a lot of work.

提交回复
热议问题