Pandas Calculating Age From A Date
I really need help with this one. My previous post was very bad and unclear - I'm sorry - I wish I could delete but hopefully this one will be better. I need to calculate the age
Solution 1:
Convert the dob column from string to a datetime object
df1['dob'] = pd.to_datetime(df1['dob'])
now = datetime.now()
df1['age'] = now - df1['dob']
Solution 2:
Convert string to datetime with format
df1['age'] = now - datetime.strptime(df1['dob'], "%m%d%Y")
Post a Comment for "Pandas Calculating Age From A Date"