Skip to content
Advertisement

How to sort a dataframe with the first occurences of each unique element in a column?

Dataframe is

JavaScript

it is

JavaScript

So i’d like to sort this df over the fehmi over the first occurences of the entries and they are grouped together then. The desired is

JavaScript

because we saw trial first in df so we gather its entries together. Then we saw error so they are together and so on.

I attempted with a groupby with its sort is False as it seemed natural but..

JavaScript

I imagine they are almost in the form I need but it is a “groupby object” and cannot get a form I need, but i tried this to get the groups as is

JavaScript

but it gives the original df back!

Advertisement

Answer

factorize + argsort

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement