gpt4 book ai didi

python-3.x - 排序数据框后重置索引

转载 作者:行者123 更新时间:2023-12-05 09:15:00 24 4
gpt4 key购买 nike

获取此数据集。

![Take this dataset.

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

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

![enter image description here

然后我重置索引。

df_genes.reset_index(drop=True,inplace=True)

![enter image description here

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

最佳答案

这个呢?

df_genes = df_genes.sort_values(['Cancer_type']).reset_index(drop=True)

关于python-3.x - 排序数据框后重置索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53332116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com