Pandas: convert date in month to the 1st day of next month

You can use pd.offsets.MonthBegin()

In [261]: d = pd.to_datetime(['2011-09-30', '2012-02-28'])

In [262]: d
Out[262]: DatetimeIndex(['2011-09-30', '2012-02-28'], dtype="datetime64[ns]", freq=None)

In [263]: d + pd.offsets.MonthBegin(1)
Out[263]: DatetimeIndex(['2011-10-01', '2012-03-01'], dtype="datetime64[ns]", freq=None)

You’ll find a lot of examples in the official Pandas docs

Leave a Comment