Answers for "convert categorical data to numeric"

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
1

panda categorical data into numerica

sex = train_dataset['Sex'].replace(['female','male'],[0,1])
print(sex)
Posted by: Guest on March-04-2021
1

how to convert categorical data to numerical data in python

pd.get_dummies(obj_df, columns=["body_style", "drive_wheels"], prefix=["body", "drive"]).head()
Posted by: Guest on May-26-2021

Code answers related to "convert categorical data to numeric"

Browse Popular Code Answers by Language