-1
date['Maturity_date'] = data.apply(lambda data: relativedelta(months=int(data['TRM_LNTH_MO'])) + data['POL_EFF_DT'], axis=1)

Tried this also:

date['Maturity_date'] = date['POL_EFF_DT'] + date['TRM_LNTH_MO'].values.astype("timedelta64[M]")

TypeError: 'type' object does not support item assignment

Tonechas
  • 13,398
  • 16
  • 46
  • 80

2 Answers2

0
import pandas as pd
import datetime

#Convert the date column to date format
date['date_format'] = pd.to_datetime(date['Maturity_date'])

#Add a month column
date['Month'] = date['date_format'].apply(lambda x: x.strftime('%b'))
M PAUL
  • 1,228
  • 2
  • 13
  • 21
0

If you are using Pandas, you may use a resource called: "Frequency Aliases". Something very out of the box:

# For "periods": 1 (is the current date you have) and 2 the result, plus 1, by the frequency of 'M' (month).

import pandas as pd

_new_period = pd.date_range(_existing_date, periods=2, freq='M')

Now you can get exactly the period you want as the second element returned:

# The index for your information is 1. Index 0 is the existing date.

_new_period.strftime('%Y-%m-%d')[1]

# You can format in different ways. Only Year, Month or Day. Whatever.

Consult this link for further information

Bitart
  • 73
  • 2
  • 7