I have a csv file which has 25 columns some are numeric and some are categorical and some are like names of actors, directors. I want use regression models on this data. In order to do so I have to convert the categorical columns string types to numeric values using LabelBinarizer from scikit package. How can I use LabelBinarize on this dataframe which has multiple categorical data?
Essentially I want to binarize the labels and add them to the dataframe.
In the below code, I have retrieved the list of the columns I want to binarize not able to figure out how to add the new column back to the df?
categorylist = ['color', 'language', 'country', 'content_rating']
for col in categorylist:
tempdf = label_binarizer.fit_transform(df[col])
In the next step, I want add the tempdf
to df
and drop the original column df[col].