I have StartDate and ExitDate two columns in my dataframe
I wish to create a third column Tenure by finding Difference between ExitDate and StartDate.
The below code gives error
‘ufunc ‘isnat’ is only defined for np.datetime64 and np.timedelta64.’
Although the datatypes are
def calculateTenure(row):
print(row.StartDate, row.ExitDate, row.ExitDateTemp)
if np.isnat(row.ExitDate):
print('in here')
ExitDate = pd.datetime.now()
return (row.ExitDate.year - row.StartDate.year)
df['Tenure'] = df.apply(lambda row:calculateTenure(row), axis=1)
The main motive is to check if ExitDate is NaT so that current date can be used for calculation instead.