Answers for "how to change value of categorical variable in python"

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
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
0

how to change value of categorical variable in python

df['Gender'].str[0].str.upper().map({'M':'Male', 'F':'Female'})
Posted by: Guest on September-06-2021

Code answers related to "how to change value of categorical variable in python"

Python Answers by Framework

Browse Popular Code Answers by Language