Difference between set_index. and sort_index

Hello, Could someone explain me the difference between set_index and sort_index ?

In my opinion, it seems they have the same result. But surely there’s a difference that I can’t understand.

Thanks for your help

Best,

Carlos

Compare documentation:

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.set_index.html

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sort_index.html

1 Like

Thanks, I think I’ve realized the difference now.

Best

You can check the API for sort_values and sort_index at the Pandas documentation for details on the parameters. sort_values() : You use this to sort the Pandas DataFrame by one or more columns. sort_index() : You use this to sort the Pandas DataFrame by the row index.

Thanks, I think I’ve realized the difference now...

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.