Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset index after sorting data frame

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.

like image 577
Ahsaan-566 Avatar asked Mar 19 '26 18:03

Ahsaan-566


1 Answers

What about this?

df_genes = df_genes.sort_values(['Cancer_type']).reset_index(drop=True)
like image 174
Luiz Picanço Avatar answered Mar 21 '26 18:03

Luiz Picanço



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!