Similar to posts in R on this topic, we can use Python’s Pandas library to replace Categorical data with numeric values.

Mall_Customers['Gender'].replace(0, 'Female',inplace=True)
Mall_Customers['Gender'].replace(1, 'Male',inplace=True)

While the replacement syntax is backwards, IMO, this one liner works pretty good and you get to set the numeric value of your choice. However, you have to supply a value for each category in the column. There’s no auto indexing (as far as I know) in Pandas.

#

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *

Archives
Categories