Let's create a tiny dataframe to see how how we can convert DoB to Age

In [27]:
DoBdata = pd.DataFrame({'name': ['John', 'Chris'], 'DoB' : ['1980-12-01', '1985-04-05']})
In [28]:
import datetime
DoBdata['Age'] = DoBdata['DoB'].apply(lambda x : datetime.datetime.today().year - datetime.datetime.strptime(x, '%Y-%m-%d').year)
In [29]:
DoBdata
Out[29]:
DoB name Age
0 1980-12-01 John 38
1 1985-04-05 Chris 33

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.

In [30]:
bins = [0, 40, 60, 100]
groups = ['Young-Age', 'Mid-Age', 'Old-Age']
In [31]:
adult_data['age-group'] = pd.cut(adult_data['age'], bins, labels=groups)
In [32]:
adult_data.head(5)
Out[32]:
age workclass fnlwgt education education-num marital-status occupation relationship race sex capital-gain capital-loss hours-per-week native-country salary age-group
0 39 State-gov 77516 Bachelors 13 Never-married Adm-clerical Not-in-family White Male 2174 0 40 United-States <=50K Young-Age
1 50 Self-emp-not-inc 83311 Bachelors 13 Married-civ-spouse Exec-managerial Husband White Male 0 0 13 United-States <=50K Mid-Age
2 38 Private 215646 HS-grad 9 Divorced Handlers-cleaners Not-in-family White Male 0 0 40 United-States <=50K Young-Age
3 53 Private 234721 11th 7 Married-civ-spouse Handlers-cleaners Husband Black Male 0 0 40 United-States <=50K Mid-Age
4 28 Private 338409 Bachelors 13 Married-civ-spouse Prof-specialty Wife Black Female 0 0 40 Cuba <=50K Young-Age