Skip to content
Advertisement

Python Rank with non numeric columns

I’m trying to find a way to do nested ranking (row number) in python that is equivalent to the following in TSQL: I have a table thank looks like this:

JavaScript

Looking for Python equivalent to:

JavaScript

The output to be:

JavaScript

I’ve tried to use rank() and groupby() but I keep running into a problem of No numeric types to aggregate. Is there a way to rank non numeric columns and give them row numbers

Advertisement

Answer

Use cumcount()

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