I have a Pandas Series like:
0 bar
1 foo
2 bar
3 bar
4 bar
5 foo
I would like to map this Series to another Series based on a numpy array specifying the order, [bar, foo]
. Then the result should be:
0 0
1 1
2 0
3 0
4 0
5 1
How can I do that?
Background: I have a sklearn learner which maps categorical target internally to learner.classes_
numpy array with order of original classes. I am trying to implement some additional methods and I would need to map their input (the input Series above) using those classes_
, each class to its index, because this is what is then internally used in the learner.