Reset index after sorting data frame

Viewed 10102

Take this dataset.

![Take this dataset.

I sorted the data frame by Cancer_type column which contains [0,1] values,

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

![enter image description here

Then I reset the index.

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

![enter image description here

Resetting index messes up the Cancer_type column. How should I reset the index keeping the Cancer_type column sorted. This link follows same procedure but I'm getting different results.

1 Answers

What about this?

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