How to sort unique values of column?

Screen Link:

I hope I am posting this good. I still do not understand how to link a question with the project…

The thing should be easy, but I cannot find a code to get unique values of a column sorted. Either I get unique values, or I get them sorted. I am getting crazy trying to find out that.

For example, I have a column with this values: [1, 2, 5, 3, 2, 1]. I would like to get the result: [5,3,2,1]

We have this for unique values, but they are not sorted:

Or this to sort values, but then we have all of them:

I can get values sorted by the number of appearences with:

But again, this is not what I want.


Hi @ncirauqu,

You should do this:

sorted_unique = sorted(dete_resignations['institute_service'].unique())

Or, if you need a list in descending order:

sorted_reverse_unique = sorted(dete_resignations['institute_service'].unique(), reverse=True)

That’s it. Thanks so much!!!

1 Like