Answers for "categorical to numeric python"

2

convert categorical variable to numeric python

# 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])
Posted by: Guest on December-27-2021

Code answers related to "categorical to numeric python"

Browse Popular Code Answers by Language