So I have a dataframe with date of birth(dob) and Inclusion Date (Ref) and since I work on an insurance company it is pretty important to know what age the person is on each month.
I tried creating a method like this
def relativeAge(dob,ref):
ref = pd.to_datetime(ref)
dob= pd.to_datetime(dob)
for ind in dob:
return ref.dt.year - dob.dt.year - ((ref.dt.month,ref.dt.day)< (dob.dt.month,dob.dt.day))
So I could call it like this
df['age'] = relativeAge(df['dob'], df['ref'])
From what I got, I have to put this '.dt' in front of the atribute I am trying to get, otherwise I get this error:
AttributeError: 'Series' object has no attribute 'year'
Then, I got this:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
So I tried to put . item() after each condition, using lambda... but no cigar.
I am still learning how to properly iterate through columns and rows in pandas, I believe that's why I am getting stuck on this problem. Any ideas? Do I need to iterate when calling the function?
Thanks!