# get all categorical columns in the dataframe
catCols = [col for col in df1.columns if df1[col].dtype=="O"]
from sklearn.preprocessing import LabelEncoder
lb_make = LabelEncoder()
for item in catCols:
df1[item] = lb_make.fit_transform(df1[item])
from sklearn.preprocessing import LabelEncoder
lb_make = LabelEncoder()
obj_df["make_code"] = lb_make.fit_transform(obj_df["make"])
obj_df[["make", "make_code"]].head(11)
pd.cut(df.Age,bins=[0,2,17,65,99],labels=['Toddler/Baby','Child','Adult','Elderly'])
# where bins is cut off points of bins for the continuous data
# and key things here is that no. of labels is always less than 1
df['Gender'].str[0].str.upper().map({'M':'Male', 'F':'Female'})
pd.get_dummies(obj_df, columns=["body_style", "drive_wheels"], prefix=["body", "drive"]).head()
obj_df["body_style"] = obj_df["body_style"].astype('category')
obj_df.dtypes
## Converting Age to numeric variable
df['Gender']=pd.get_dummies(df['Gender'],drop_first=1)
df.head()