1

I have a pandas dataframe with a column consisting of dates and the type of the column is datetime64[ns]. I'm trying to get the date of the last day of next month.

For example, I have 2020-11-30 and my code is returning 2020-12-30, but I would like to get 2020-12-31 (since the next month (December) has 31 days). My code is simply adding +1 to the month, but I would also like to get the last day too.

My current code is as follows:

def inc_date(bdx_dt):
    return pd.Timestamp(bdx_dt) + pd.DateOffset(months=1)

my_table['REPORTING_DT_python'] = my_table.apply(lambda row:inc_date(row['BDX_DT']), axis=1)

My current output:

enter image description here

However, I would like to get:

enter image description here

Please help. Thanks in advance.

PKV
  • 167
  • 3
  • 13
  • 2
    Does this answer your question? [Find the end of the month of a Pandas DataFrame Series](https://stackoverflow.com/questions/37354105/find-the-end-of-the-month-of-a-pandas-dataframe-series) – Rustam A. Aug 23 '21 at 23:40
  • 1
    Per the duplicate: `my_table['REPORTING_DT_python'] = my_table['BDX_DT'] + pd.tseries.offsets.MonthEnd(1)` – Henry Ecker Aug 24 '21 at 00:01

0 Answers0