Pandas Map function to provide labels to categorical/text labels

PHOTO EMBED

Mon Sep 05 2022 09:44:22 GMT+0000 (UTC)

Saved by @DataSynapse82 #python #pandas #label #mapping

#Add the new column which gives a unique number to each of these labels 

df['label_num'] = df['label'].map({
    'Household' : 0, 
    'Books': 1, 
    'Electronics': 2, 
    'Clothing & Accessories': 3
})

#checking the results 
df.head(5)
content_copyCOPY

Code to map unique numbers to categorical features.