【发布时间】:2020-04-03 05:29:32
【问题描述】:
获取此数据集。
我按包含 [0,1] 值的 Cancer_type 列对数据框进行排序,
df_genes.sort_values(['Cancer_type'], ascending=True)
然后我重置索引。
df_genes.reset_index(drop=True,inplace=True)
重置索引会弄乱 Cancer_type 列。 我应该如何重置索引以保持 Cancer_type 列的排序。 这个link 遵循相同的程序,但我得到了不同的结果。
【问题讨论】:
-
df_genes.sort_values(['Cancer_type'], ascending=True).reset_index(drop=True,inplace=True)是您需要做的。或者更确切地说保存您的排序 df 然后重置索引 -
成功了,谢谢!
标签: python-3.x pandas dataframe