Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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_Sorting_Pandas_Dataframe_Multi Index - Fatal编程技术网

Python 按多索引的一级对数据帧进行排序

Python 按多索引的一级对数据帧进行排序,python,sorting,pandas,dataframe,multi-index,Python,Sorting,Pandas,Dataframe,Multi Index,我有一个多索引数据帧,需要由一个索引器进行排序。以下是数据片段: gene VIM treatment dose time TGFb 0.1 2 -0.158406 1 2 0.039158 10 2 -0.052608 0.1 24 0.157153 1 24 0.20

我有一个多索引数据帧,需要由一个索引器进行排序。以下是数据片段:

gene                      VIM  
treatment dose time            
TGFb      0.1  2    -0.158406  
          1    2     0.039158  
          10   2    -0.052608  
          0.1  24    0.157153  
          1    24    0.206030  
          10   24    0.132580  
          0.1  48   -0.144209  
          1    48   -0.093910  
          10   48   -0.166819  
          0.1  6     0.097548  
          1    6     0.026664  
          10   6    -0.008032  

我希望对数据进行排序,以便时间索引按升序排列。我的第一个想法是使用pandas.sort_值,但这似乎对索引不起作用。有人知道这样做的方法吗?谢谢

使用
排序索引
指定
级别

df.sort_index(level=2)

所有收益率:

df.sort_index(level=-1)
df.sort_index(level='time')