Pandas convert categorical into numeric code example
Example 1: pandas categorical to numeric
dataset["sex"] = dataset["sex"].astype('category').cat.codes
Example 2: panda categorical data into numerica
sex = train_dataset['Sex'].replace(['female','male'],[0,1])
print(sex)
Example 3: pandas categorical to numeric
dataset['Origin'] = dataset['Origin'].map({1: 'USA', 2: 'Europe', 3: 'Japan'})
Example 4: how to convert categorical data to numerical data in python
obj_df["body_style"] = obj_df["body_style"].astype('category')
obj_df.dtypes