0

I have a dataframe df like this:

Student_id         Subject           Performance_level
10010              mathematics        Satisfactory 
10011              Physics            Poor
10012              Chemistry          Neutral
10013              Physics            Poor
10014              History            Neutral

I want to use label encoding the column Performance_level with Poor as 1 and Neutral as 2 and Satisfied as 3(i.e, order or ranking is important) By default label encoding sorts according to Alphabetic order and assign corresponding Numerical value. How to customize this to the specific values like Poor as 1 and Neutral as 2 and Satisfied as 3.

Student_id         Subject           Performance_level   Performance_level_encoded
10010              mathematics        Satisfactory               3
10011              Physics            Poor                       1
10012              Chemistry          Neutral                    2
10013              Physics            Poor                       1
10014              History            Neutral                    2
Ranyk
  • 255
  • 1
  • 8
  • I think you need dictionary and then use `map` – jezrael Jan 28 '21 at 08:14
  • But whether `mapping` be considered as ordinal encoding, whether ML model will recognize the order for those categorical feature? – Ranyk Jan 28 '21 at 08:46
  • Ya, not sure if possible in label encoding, [link](https://stackoverflow.com/questions/38749305/labelencoder-order-of-fit-for-a-pandas-df?noredirect=1&lq=1) – jezrael Jan 28 '21 at 08:48

0 Answers0