1

I have 2 dates: Nov 1,2018 and Jan 1, 2019. I want to generate a monthly date corresponding to the first of every month. I did:

didx=pd.date_range(start='11/01/2018', end='01/01/2019', freq='M',closed=None)

But I got:

2018-11-30
2018-12-31

I want:

2018-11-01
2018-12-01
2019-01-01
Victor
  • 15,091
  • 64
  • 201
  • 364

1 Answers1

2

Doing with freq='MS'

pd.date_range(start='11/01/2018', end='01/01/2019', freq='MS',closed=None)

Out[213]: DatetimeIndex(['2018-11-01', '2018-12-01', '2019-01-01'], dtype='datetime64[ns]', freq='MS')
BENY
  • 258,262
  • 17
  • 121
  • 165
  • The answer is a bit short on details; `MS` means `month start frequency` where the normal `M` means `month end frequency`. See: https://stackoverflow.com/questions/35339139/where-is-the-documentation-on-pandas-freq-tags for an overview of all the `freq` flags. – Bart Oct 08 '19 at 12:23