Guest User

Untitled

a guest
Jun 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. def calculate_age(born, alive, death):
  2. today = date.today()
  3. today = datetime.now()
  4. age_in_years = today.year - born.year - ((today.month, today.day) < (born.month, born.day))
  5. months = (today.month - born.month - (today.day < born.day)) %12
  6. age = today - born
  7. if alive == 'No':
  8. age_in_years1 = death.year - born.year - ((death.month, death.day) < (born.month, born.day))
  9. months = (death.month - born.month - (death.day < born.day)) %12
  10. age = death - born
  11. return age_in_years1
  12. else:
  13. return age_in_years
  14.  
  15. df['age'] = df['birthdate'].apply(calculate_age,args = (df.alive, df.death))
  16.  
  17. ValueError Traceback (most recent call last)
  18. <ipython-input-61-bde1cb6c3981> in <module>()
  19. ----> 1 df['age'] = df['birthdate'].apply(calculate_age,args = (df.alive, df.death))
  20. ^
  21. 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