1pd.cut(df.Age,bins=[0,2,17,65,99],labels=['Toddler/Baby','Child','Adult','Elderly'])
2# where bins is cut off points of bins for the continuous data
3# and key things here is that no. of labels is always less than 1
1obj_df["body_style"] = obj_df["body_style"].astype('category')
2obj_df.dtypes
3
1cat_cols = ['Item_Identifier', 'Item_Fat_Content', 'Item_Type', 'Outlet_Identifier', 'Outlet_Size', 'Outlet_Location_Type', 'Outlet_Type', 'Item_Type_Combined']
2enc = LabelEncoder()
3
4for col in cat_cols:
5 train[col] = train[col].astype('str')
6 test[col] = test[col].astype('str')
7 train[col] = enc.fit_transform(train[col])
8 test[col] = enc.transform(test[col])
9