I have a dataframe with columns like this. The final df should contain a new column after taking the First_Date column and subtracting the corresponding unit and the corresponding value
df = pd.DataFrame({"First_Date":[pd.to_datetime("2020-01-01")]*5, "Unit":['Years','Months','Days','Years','Days'], "Value":[1,2,2,3,5]})
The output column should have the values:
2019-01-01 2019-11-01 2020-12-29 2017-01-01 2020-12-27
I have tried the timedelta module but the inputs to that is not accepting values from a different column. For example, it does not take
df.apply(lambda x: x['First_Date']- timedelta(x['Unit'] = x['Value'])