I have a pandas data frame that looks something like:
import pandas as pd
import numpy as np
d={'original tenor':[10,10,10,10,10,10,10,10,10,10,10],\
'residual tenor':[5,4,3,2,1,10,9,8,7,6,5],\
'date':(['01/01/2018','02/01/2018','03/01/2018','04/01/2018','05/01/2018','06/01/2018','07/01/2018','08/01/2018','09/01/2018','10/01/2018','11/01/2018'])\
}
df=pd.DataFrame(data=d)
df['date'] = pd.to_datetime(df['date'],format='%d/%m/%Y')
df
The residual tenor reduces based on the date. When residual tenor goes to 1, the next residual tenor is then the original tenor. I am trying to get a formula to populate the residual tenor given the original tenor and residual tenor. So, given the following data frame, I would expect the NaN to be replaced by 5
d={'original tenor':[10,10],\
'residual tenor':[5,np.nan],\
'date':(['01/01/2018','11/01/2018'])\
}
df=pd.DataFrame(data=d)
df['date'] = pd.to_datetime(df['date'],format='%d/%m/%Y')
df