What is the advantage of converting a series like
>>> df
Color
0 Red
1 Blue
2 Green
3 Red
To a multiple series like the below?
>>> pd.get_dummies(df)
Color_Blue Color_Green Color_Red
0 0 0 1
1 1 0 0
2 0 1 0
3 0 0 1
One could as well have a hot encoded values for the Color Column as below?
>>> labels=list(set(df.Color))
>>> pd.DataFrame(df.Color.map({x:labels.index(x) for x in labels}).rename('Color_Code'))
Color_Code
0 1
1 2
2 0
3 1
I know syntactically pd.get_dummies
looks much simpler, but somehow I want to lean towards a lesser number of features than more number of features...