Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reassigning index in pandas DataFrame

I'm fairly sure this is a duplicate, but suppose I have a pandas DataFrame and I've sorted the rows based on the values of some column. Originally the indices were the integers 0, 1, …, n-1 but now they're out of order. How do I reassign these indices to be in the proper order for the new sorted DataFrame?

like image 536
dsaxton Avatar asked Sep 01 '25 17:09

dsaxton


1 Answers

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

like image 123
DeepSpace Avatar answered Sep 04 '25 06:09

DeepSpace



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!