import category_encoders as ce # create an object of the OneHotEncoder OHE = ce.OneHotEncoder(cols=['Item_Fat_Content', 'Item_Type', 'Outlet_Identifier', 'Outlet_Size', 'Outlet_Location_Type', 'Outlet_Type'],use_cat_names=True) # encode the categorical variables train_data = OHE.fit_transform(train_data)