按字母顺序排序数据框

时间:2018-02-21 09:46:08

标签: python pandas sorting

birth_data.sort_values(by='name',ascending = True) 
  • 姓名
    1. bruh 96570
    2. gib 95095
    3. mel 115195
    4. nish 112055
    5. raw 88018

我可以对“数字”进行排序,但如果我用“名称”替换它,我会收到错误。

KeyError                                  Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   2441             try:
-> 2442                 return self._engine.get_loc(key)
   2443             except KeyError:

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'name'

During handling of the above exception, another exception occurred:

1 个答案:

答案 0 :(得分:1)

试试:

birth_data.sort_values(by=['name'], ascending = True)

编辑:你确定有一个名为'name'的列吗?