So I have a dataframe that has the date of birth written as a string '2012-07-06T21:00:00.000Z'
(example).
I want to calculate the users' age from that. Note that this is a string and I think I need it to be datetime to be able to calculate it.
Thank you much
my code (Python):
def calculate_age(born):
born = datetime.strptime(born, "%Y-%m-%d'T'%H:%M:%S.%f%Z").date()
today = date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
df['age'] = df['birth_date'].apply(calculate_age)