modin.pandas.DataFrameGroupBy.rank¶

DataFrameGroupBy.rank(method: str = 'average', ascending: bool = True, na_option: str = 'keep', pct: bool = False, *args, **kwargs)[source]¶

Provide the rank of values within each group.

Parameters:
  • method ({"average", "min", "max", "first", "dense"}) – How to rank the group of records that have the same value (i.e. break ties): - average: average rank of the group - min: lowest rank in the group - max: highest rank in the group - first: ranks assigned in order they appear in the array - dense: like ‘min’, but rank always increases by 1 between groups.

  • ascending (bool) – Whether the elements should be ranked in ascending order.

  • na_option ({"keep", "top", "bottom"}) – How to rank NaN values: - keep: assign NaN rank to NaN values - top: assign the lowest rank to NaN values - bottom: assign the highest rank to NaN values

  • pct (bool) – Whether to display the returned rankings in percentile form.

  • axis ({{0 or 'index', 1 or 'columns'}}, default None) –

    The axis to use. 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise. If axis is not provided, grouper’s axis is used.

    Snowpark pandas does not currently support axis=1, since it is deprecated in pandas.

    Deprecated since version 2.1.0: For axis=1, operate on the underlying object instead. Otherwise, the axis keyword is not necessary.

Return type:

Series or DataFrame with ranking of values within each group

Examples

>>> df = pd.DataFrame({"group": ["a", "a", "a", "b", "b", "b", "b"], "value": [2, 4, 2, 3, 5, 1, 2]})
>>> df
  group  value
0     a      2
1     a      4
2     a      2
3     b      3
4     b      5
5     b      1
6     b      2
>>> df = df.groupby("group").rank(method='min')
>>> df
   value
0      1
1      3
2      1
3      3
4      4
5      1
6      2
Copy