convert birth date column to age pandas

Solutions on MaxInterview for convert birth date column to age pandas by the best coders in the world

showing results for - "convert birth date column to age pandas"
Greta
26 Jan 2017
1(pd.to_datetime('today').year-pd.to_datetime('1956-07-01').year)
2
3Out[83]: 61
Davide
20 Jul 2016
1import datetime as DT
2import io
3import numpy as np
4import pandas as pd
5
6pd.options.mode.chained_assignment = 'warn'
7
8content = '''     ssno        lname         fname    pos_title             ser  gender  dob 
90    23456789    PLILEY     JODY        BUDG ANAL             0560  F      031871 
101    987654321   NOEL       HEATHER     PRTG SRVCS SPECLST    1654  F      120852
112    234567891   SONJU      LAURIE      SUPVY CONTR SPECLST   1102  F      010999
123    345678912   MANNING    CYNTHIA     SOC SCNTST            0101  F      081692
134    456789123   NAUERTZ    ELIZABETH   OFF AUTOMATION ASST   0326  F      031387'''
14
15df = pd.read_csv(io.StringIO(content), sep='\s{2,}')
16df['dob'] = df['dob'].apply('{:06}'.format)
17
18now = pd.Timestamp('now')
19df['dob'] = pd.to_datetime(df['dob'], format='%m%d%y')    # 1
20df['dob'] = df['dob'].where(df['dob'] < now, df['dob'] -  np.timedelta64(100, 'Y'))   # 2
21df['age'] = (now - df['dob']).astype('<m8[Y]')    # 3
22print(df)
queries leading to this page
how to get age in dataframehow to get age from birth date in python dataframepandas getting age from datafind age pandascalculate age from given date of birth in pandaspandas dataframe find age from date of birthhow to calculate lifespan in pandasage dataframe in pandasfind age from date of birth and today python pandasconvert date to age python dataframe columnhow to format age in pandaspandas getting age from datecalculate age given date of birth in pandas from a dataset of year born in a columncalculate age from date of birth in dataset in python pandascalculate age pandasget age from dob column pythonpandas convert date of birth to ageage from pandas dataframecalculate age given date of birth in pandas calculating age from date of birth in pandascalculate age from date of birth column in pandascalculating age today pandasconvert dob to age in pandas column containing null valuesconvert birth date to age pandaspython 2 columns work out ageconvert birth date column to age pandaschange date of birth to age pandasconvert dob to age in pandas column containingget age from date of birth pandashow to calculate age from date of birth in pandashow to convert age in days to age in years dataframedataframe datetime to ageget age from now pandaspandas date to agepandas calculate age from date of birthcreate age from date of birth pandaspython calculate pandas age from date of birthto datetime pandascalculate age given date of birth in pandas dataframeget age from birth date pandasconvert pandas series datetime to agecalculate age from date of birth python pandaspython dataframe calculate age from date columncalculate age column birthday pandasdate to age in pandascalculate age from date of birth in pandascalculate age python pandashow to calculate age from given date column in pthin dataframefind age from birth column pandasconvert birth date to age in pandasget age a dataframe pythonhow to calculate age from date of birth pandasdataframe to calculate dob pythoncalculate age based on date of birth pandasfind age from date of birth in pandaspandas age calculation give date of birthcalculate age from date of birth column pandasdataframe date to agecalculate age from date of birth pandaspandas age in completed yearsage from birthdate in pandasbirthdate to age conversion in pandascalculate age based on date of birth and death pandas dataframehow to get age from date of birth in python pandasconvert birth date column to age pandas