Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculate_age(born, alive, death):
- today = date.today()
- today = datetime.now()
- age_in_years = today.year - born.year - ((today.month, today.day) < (born.month, born.day))
- months = (today.month - born.month - (today.day < born.day)) %12
- age = today - born
- if alive == 'No':
- age_in_years1 = death.year - born.year - ((death.month, death.day) < (born.month, born.day))
- months = (death.month - born.month - (death.day < born.day)) %12
- age = death - born
- return age_in_years1
- else:
- return age_in_years
- df['age'] = df['birthdate'].apply(calculate_age,args = (df.alive, df.death))
- ValueError Traceback (most recent call last)
- <ipython-input-61-bde1cb6c3981> in <module>()
- ----> 1 df['age'] = df['birthdate'].apply(calculate_age,args = (df.alive, df.death))
- ^
- ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Add Comment
Please, Sign In to add comment