Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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])
 
PREVIOUS NEXT
Tagged: #convert #categorical #variable #numeric #python
ADD COMMENT
Topic
Name
3+5 =