Answers for "To convert categorical data to numerical"

CSS
2

how to convert contionous data into categorical data in python

pd.cut(df.Age,bins=[0,2,17,65,99],labels=['Toddler/Baby','Child','Adult','Elderly'])
# where bins is cut off points of bins for the continuous data 
# and key things here is that no. of labels is always less than 1
Posted by: Guest on May-26-2021
0

how to convert categorical data to numerical data in python

obj_df["body_style"] = obj_df["body_style"].astype('category')
obj_df.dtypes
Posted by: Guest on May-26-2021
0

To convert categorical data to numerical

cat_cols = ['Item_Identifier', 'Item_Fat_Content', 'Item_Type', 'Outlet_Identifier', 
         'Outlet_Size', 'Outlet_Location_Type', 'Outlet_Type', 'Item_Type_Combined']
enc = LabelEncoder()

for col in cat_cols:
    train[col] = train[col].astype('str')
    test[col] = test[col].astype('str')
    train[col] = enc.fit_transform(train[col])
    test[col] = enc.transform(test[col])
Posted by: Guest on May-24-2021

Code answers related to "To convert categorical data to numerical"

Browse Popular Code Answers by Language