Let's create a tiny dataframe to see how how we can convert DoB to Age
DoBdata = pd.DataFrame({'name': ['John', 'Chris'], 'DoB' : ['1980-12-01', '1985-04-05']})
import datetime
DoBdata['Age'] = DoBdata['DoB'].apply(lambda x : datetime.datetime.today().year - datetime.datetime.strptime(x, '%Y-%m-%d').year)
DoBdata
Coming back to our original adult data, Let's say we want to bin people into 3 categories as per their age - Young, Middle, Old.
We will be using cut method of pandas as below.
bins = [0, 40, 60, 100]
groups = ['Young-Age', 'Mid-Age', 'Old-Age']
adult_data['age-group'] = pd.cut(adult_data['age'], bins, labels=groups)
adult_data.head(5)