'Pandas equivalent to dense rank

I am trying to copy a dense rank SQL statement in pandas. The SQL statement looks as follows:

            ,DENSE_RANK() OVER(PARTITION BY [Team],[Season] ORDER BY [Team], 
       [Season],CAST([characteristic].[value] AS INT) DESC)  AS ROW#

The python code I have tried so far, ranks only over one column, instead of two.

    df['Rank'] = df1.Team.rank(method='dense').astype(int)

Does anyone have a better solution?



Solution 1:[1]

IIUC use:

df[['Rank1', 'Rank2']] = df1[['Team','Season']].rank(method='dense').astype(int)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jezrael