If I have enum class:
from enum import Enum
class Colors(Enum):
RED = 1
ORANGE = 2
GREEN = 3
And if I have a dataframe whose one column is color (it can be in lowercase to):
>>> import pandas as pd
>>> df = pd.DataFrame({'X':['A', 'B', 'C', 'A'], 'color' : ['GREEN', 'RED', 'ORANGE', 'ORANGE']})
>>> df
X color
0 A GREEN
1 B RED
2 C ORANGE
3 A ORANGE
How to make color column as categorical type respecting Color class values, and sort the dataframe by "color" and "X" (ascending)?
For example, the dataframe above should be sorted as:
X, color
--------
B, RED
A, ORANGE
C, ORANGE
A, GREEN