数据帧排序后重置索引

Ahs*_*566 3 dataframe python-3.x pandas

获取这个数据集。

![获取这个数据集。

我按 Cancer_type 列对数据框进行排序,其中包含 [0,1] 值,

df_genes.sort_values(['Cancer_type'], ascending=True)

![在此输入图像描述

然后我重置了索引。

df_genes.reset_index(drop=True,inplace=True)
Run Code Online (Sandbox Code Playgroud)

![在此输入图像描述

重置索引会弄乱 Cancer_type 列。我应该如何重置索引以保持 Cancer_type 列的排序。此链接遵循相同的过程,但我得到不同的结果。

Lui*_*nço 9

那这个呢?

df_genes = df_genes.sort_values(['Cancer_type']).reset_index(drop=True)
Run Code Online (Sandbox Code Playgroud)