1

I have a DataFrame with a column named BOD:

0       1958-04-14
1       1954-02-28
2       1955-04-01
3       1955-08-28
4       1955-09-06 

Name: BOD, Length: 10768, dtype: datetime64[ns]

And I need to create a new column ('age') calculating the age of each row. I had some problems with formats and couldnt do it.

  • What have you tried so far? Post [mre] of your code. Also check [how to ask homework questions](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) – buran Mar 11 '21 at 19:42
  • What is your expected output? (also can be really annoying if you need to require calendar year subtraction, such that someone born March 12th 1921 is still considered 99) – ALollz Mar 11 '21 at 19:43
  • What format did you want your age to be in? Years? Days? – piRSquared Mar 11 '21 at 19:43
  • 1
    `df.assign(age=pd.Timestamp('now') - df.BOD)` – piRSquared Mar 11 '21 at 19:43
  • @piRSquared has worked! The only problem is that gaves me the age in days. How can I change it to just years? Thanks! – Agustín Jornet Mar 11 '21 at 20:00
  • 1
    Follow the link to the duped question. Your answer is there. – piRSquared Mar 11 '21 at 20:03

0 Answers0