I have a df
with two columns: date and offset(integer value). I want to subtract the number of months (based on the column value) from the date and get the month-end date. I've tried:
df['NewDate'] = df['Date'] - relativedelta(months=df['Offset'])
and:
df['NewDate'] = df.apply(lambda x: x['Date']-pd.offsets.MonthEnd(months=x['Offset']), axis=1)
but couldn't get either to work (the second runs very slow due to df.apply anyways).
Orig df
Date Offset
12/31/17 0
12/31/17 1
12/31/17 2
12/31/17 3
New df
Date Offset NewDate
12/31/17 0 12/31/17
12/31/17 1 1/31/18
12/31/17 2 2/28/18
12/31/17 3 3/31/18