Horje
how to convert categorical data to numerical data in python Code Example
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])
panda categorical data into numerica
sex = train_dataset['Sex'].replace(['female','male'],[0,1])
print(sex)
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)
Source: pbpython.com
convert categorical data type to int in pandas
from sklearn import preprocessing

lab_encoder = preprocessing.LabelEncoder()
df['column'] = lab_encoder.fit_transform(df['column'])
how to convert categorical data to numerical data in python
pd.get_dummies(obj_df, columns=["body_style", "drive_wheels"], prefix=["body", "drive"]).head()
Source: pbpython.com
how to convert categorical data to numerical data in python
obj_df["body_style"] = obj_df["body_style"].astype('category')
obj_df.dtypes
Source: pbpython.com




Python

Related
python enumerate start at 1 Code Example python enumerate start at 1 Code Example
pylab plotting data Code Example pylab plotting data Code Example
convert string to object in python Code Example convert string to object in python Code Example
loop through words in a string python Code Example loop through words in a string python Code Example
new line print python Code Example new line print python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7