I have a Pandas dataframe that has a column owner_type that reads first, second, third etc. I am trying to first replace these categorical variable with numeric values 1, 2, 3 and then cast to a float before applying a linear regression model on the dataframe. When I use replace to do this, I get all empty values returned.
My end goal : Convert categorical variable of owner_type into a numeric value.
Code I used.
cardata['Owner_Type'] = cardata['Owner_Type'].str.replace(r'[\xa0]',"")
cardata['Owner_Type'] = cardata['Owner_Type'].replace(['First'], '1', inplace = True)
cardata['Owner_Type'] = cardata['Owner_Type'].replace(['Second'], '2', inplace = True)
cardata['Owner_Type'] = cardata['Owner_Type'].replace(['Third'], '3', inplace = True)
cardata['Owner_Type'] = cardata['Owner_Type'].replace(['Fourth'], '4', inplace = True)
cardata['Owner_Type'] = cardata['Owner_Type'].replace(['Fourth & Above'], '5', inplace = True)
cardata['Owner_Type'].value_counts()
Output of above code is
Series([], Name: Owner_Type, dtype: int64
What I was expecting for output : [1, 2, 3, 4, 5]
Please help.