I am trying to create a column in Pandas based off of a conditional statement that calculates time between two events. I was able to work out the day calculation but when plugged into my conditional statement:
def defect_age(df):
if df['Status'] == 'R':
return (pd.to_datetime(df['resolved_on'], errors='coerce')
- pd.to_datetime(df['submitted_on'])) / np.timedelta64(1, 'D')
else:
return 'null'
And then later called by the column:
group_df['Age'] = group_df.apply(defect_age(group_df), axis=0)
I am getting the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I tried to base mine on the question asked HERE... But I am not having much success. Any help is appreciated!