How can I encode each categorical unique value to numerical value as I wish?
HeatingQC: Heating quality and condition
Ex Excellent
Gd Good
TA Average/Typical
Fa Fair
Po Poor
I tried to encode this categorical data to numerical. So I used sklearn.processing.LabelEncoder. What I expected was to assign a greater number to Ex and a less number to Po. i.e Ex = 4, Gd = 3, so on.
from sklearn.preprocessing import LabelEncoder
label_encoder = LabelEncoder()
encoded_data = label_encoder.fit_transform(data)
print(data)
print(encoded_data)
output is
Id
1461 TA
1462 TA
1463 Gd
1464 Ex
1465 Ex
Name: HeatingQC, dtype: object
[2 2 1 0 0]
How can I encode ex to 4 and Po to 0?