Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 更改数据帧中的行顺序_Python_Pandas_Sorting_Jupyter Notebook - Fatal编程技术网

Python 更改数据帧中的行顺序

Python 更改数据帧中的行顺序,python,pandas,sorting,jupyter-notebook,Python,Pandas,Sorting,Jupyter Notebook,我在python3的pandas中有以下数据框: +------------------------------+ | total_sum | percent_of_total | +--------------+------------------------------+ | Group | | | +--------------+----------------

我在
python3
pandas
中有以下数据框:

               +------------------------------+
               | 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','bastom+')
,但我得到了以下错误<代码>类型错误:不可损坏的类型:“列表”。看起来熊猫会按字母顺序对这些索引进行排序。如何对行重新排序?

根据注释:


尝试使用
.reindex

.reindex(['11-', 'Just 12', 'Some College', 'Bachelor+'])

文档中有更多详细信息。

您是否尝试过使用
.reindex(['11-'、'Just 12'、'Some College'、'badom+')
。医生有更多的细节。你就是那个男人!!这确实返回了我所需要的。@SSC如果您能将您的评论复制到答案部分,那就太好了