你好,我有一个df,例如:
COL1 COL2
A male
A female
A female
A not determined
B nan
B male and female
B male
B female
B female
,我想根据列表的偏好顺序sort
和groubpy
COL2
,例如:
list_preference_order=['female','male and female','male',not determined,nan']
并获取:
COL1 COL2
A female
A female
A male
A not determined
B female
B female
B male and female
B male
B nan
我知道这里有一个类似的问题:Sort and groubpy columns depending on a list inPandas
但这并不是完全一样,因为这里有一个分组信息