为什么 pandas 的 sort_valiues 方法对汉字内容的列排序失败?

import pandas as pd

dff = pd.DataFrame({
    'col1': ['啊', '八', '卡', '丫', '哇', '扒'],
    'col2': [2, 1, 9, 8, 7, 4],
    'col3': [0, 1, 9, 4, 2, 3],
})

print(dff)
dff.sort_values(by='col1', inplace=True)
print('-'*20)
print(dff)

如上面的代码,输出结果如下:

  col1  col2  col3
0    啊     2     0
1    八     1     1
2    卡     9     9
3    丫     8     4
4    哇     7     2
5    扒     4     3
--------------------
  col1  col2  col3
3    丫     8     4
1    八     1     1
2    卡     9     9
4    哇     7     2
0    啊     2     0
5    扒     4     3

 

明显第二列没有排序成功。

为什么?

print([x.encode('unicode_escape').decode('gbk') for x in dff.col1])

得到:

['\\u554a', '\\u516b', '\\u5361', '\\u4e2b', '\\u54c7', '\\u6252']

应该是按汉字在unicode中的编码顺序从低到高排列的

你按第一列的值排序,那同一行的值不也就跟着换顺序了吗