How to include end date in pandas date_range method?

前端 未结 7 1736
[愿得一人]
[愿得一人] 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:05

    Include the day when specifying the dates in date_range call

    pd.date_range('2016-01-31', '2016-05-31', freq='M', ).strftime('%Y-%m')
    
    array(['2016-01', '2016-02', '2016-03', '2016-04', '2016-05'], 
          dtype='|S7')
    

提交回复
热议问题