Pandas Rank

DataFrame.rank(axis=0, method='average', numeric_only=None, na_option='keep', ascending=True, pct=False)

method : {‘average’, ‘min’, ‘max’, ‘first’, ‘dense’}
              average: average rank of group
              min: lowest rank in group
              max: highest rank in group
              first: ranks assigned in order they appear in the array
              dense: like ‘min’, but rank always increases by 1 between groups
 #普通排名
df["rank"] = df["vol"].rank(method="min",ascending=False)
#按组别排名
df["rank"] = df["vol"].groupby(df["colx"]).rank(method="min",ascending=False) 

你可能感兴趣的:(Pandas Rank)