create age groups in pandas

Solutions on MaxInterview for create age groups in pandas by the best coders in the world

showing results for - "create age groups in pandas"
Erica
03 Aug 2016
1X_train_data = pd.DataFrame({'Age':[0,2,4,13,35,-1,54]})
2
3bins= [0,2,4,13,20,110]
4labels = ['Infant','Toddler','Kid','Teen','Adult']
5X_train_data['AgeGroup'] = pd.cut(X_train_data['Age'], bins=bins, labels=labels, right=False)
6print (X_train_data)
7   Age AgeGroup
80    0   Infant
91    2  Toddler
102    4      Kid
113   13     Teen
124   35    Adult
135   -1      NaN
146   54    Adult