How to include end date in pandas date_range method?

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

    For the later crowd. You can also try to use the Month-Start frequency.

    >>> pd.date_range('2016-01', '2016-05', freq='MS', format = "%Y-%m" )
    DatetimeIndex(['2016-01-01', '2016-02-01', '2016-03-01', '2016-04-01',
                   '2016-05-01'],
                  dtype='datetime64[ns]', freq='MS')
    

提交回复
热议问题