根据熊猫中的列表对列进行排序和古怪

时间:2020-07-20 12:48:13

标签: python pandas sorting

你好,我有一个df,例如:

COL1 COL2 
A male
A female
A female
A not determined
B nan 
B male and female 
B male
B female
B female

,我想根据列表的偏好顺序sortgroubpy 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

但这并不是完全一样,因为这里有一个分组信息

0 个答案:

没有答案