我在pandas
的{{1}}中有以下数据框:
python3
我想改变包括索引在内的行的顺序......
+------------------------------+
| total_sum | percent_of_total |
+--------------+------------------------------+
| Group | | |
+--------------+------------------------------+
| 11- | 99435 | 0.255880 |
+--------------+-----------+------------------+
| Bachelor+ | 64900 | 0.167010 |
+--------------+-----------+------------------+
| Just 12 | 162483 | 0.418124 |
+--------------+-----------+------------------+
| Some College | 61782 | 0.158986 |
+---------------------------------------------+
我尝试使用 +------------------------------+
| total_sum | percent_of_total |
+--------------+------------------------------+
| Group | | |
+--------------+------------------------------+
| 11- | 99435 | 0.255880 |
+--------------+-----------+------------------+
| Just 12 | 162483 | 0.418124 |
+--------------+-----------+------------------+
| Some College | 61782 | 0.158986 |
+--------------+-----------+------------------+
| Bachelor+ | 64900 | 0.167010 |
+--------------+-----------+------------------+
并收到以下错误... .sort_index(['11-', 'Just 12', 'Some College', 'Bachelor+'])
。所以看起来像pandas按字母顺序对这些索引进行排序。如何重新排序行?