1

I have a problem to define a date range using python code. how can I generate a monthly date range like '2000-01-01', '2000-02-01',....'2011-12-01' using python code.

dates = pd.date_range(start='2000-01-01', end='2001-12-01',freq='M')

got output:

DatetimeIndex(['2000-01-31', '2000-02-29', '2000-03-31', '2000-04-30',
           '2000-05-31', '2000-06-30', '2000-07-31', '2000-08-31',
           '2000-09-30', '2000-10-31', '2000-11-30', '2000-12-31',
           '2001-01-31', '2001-02-28', '2001-03-31', '2001-04-30',
           '2001-05-31', '2001-06-30', '2001-07-31', '2001-08-31',
           '2001-09-30', '2001-10-31', '2001-11-30'],
          dtype='datetime64[ns]', freq='M')

But I want output should be

DatetimeIndex(['2000-01-01', '2000-02-01', '2000-03-01', '2000-04-01',
           ... '2001-11-01'],
          dtype='datetime64[ns]', freq='M')
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161

1 Answers1

0

you can test this:

dates = pd.date_range(start='2000-01-01', end='2001-12-01',freq='MS')

with MS for Month Start