Python Label Encoding (Categorical Data into numeric)
Label Encoding refers to converting the labels into a numeric form so as to convert them into the machine-readable form. Machine learning algorithms can then decide in a better way how those labels must be operated. It is an important pre-processing step for the structured dataset in supervised learning
import pandas
Consider this dataset-
df = {'Customer_rating' : ['Poor', 'Good', 'Very good' , 'Excellent']}
df1 = pd.DataFrame(df)
df1
output:
customer_rating_encode = {'Poor' :1, 'Good':2, 'Very Good':3, 'Excellent':4}
df1['Customer_rating'] = df1.Customer_rating.map(customer_rating_encode)
df1
Output:
Comments
Post a Comment
If You have any doubt please let me know