Skip to content
Advertisement

How to groupby 2 columns but order descending by count()

i have a dataframe and want to group 2 columns, which is working fine.

JavaScript
JavaScript

Now the grouped dataframe is sorted by the CustomerID values. But i want to sort it by the count(). So that i have the Sektor then the CustomerIDs but the CustomerIds that occure the most should be at the top. So descending.

Expected Output should be:

JavaScript

How do i do that?

Advertisement

Answer

Use:

JavaScript

If need 10 rows in ouput:

JavaScript

If need 10 rows (if exist) per groups by Sektor:

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