Answers for "convert categorical column to numeric pandas"

2

convert column to numeric pandas

# convert all columns of DataFrame
df = df.apply(pd.to_numeric) # convert all columns of DataFrame

# convert just columns "a" and "b"
df[["a", "b"]] = df[["a", "b"]].apply(pd.to_numeric)
Posted by: Guest on May-09-2020
0

panda categorical data into numerica

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

transform categorical variables python

from sklearn.preprocessing import LabelEncoder

lb_make = LabelEncoder()
obj_df["make_code"] = lb_make.fit_transform(obj_df["make"])
obj_df[["make", "make_code"]].head(11)
Posted by: Guest on May-20-2020

Code answers related to "convert categorical column to numeric pandas"

Python Answers by Framework

Browse Popular Code Answers by Language