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

click here

click here


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:




I will be back with more data science algos, keep visiting. Thank You :)

Comments

Popular posts from this blog

Data Analyst Roadmap

Python Data analytics Algorithm