Skip to main content
`Ctrl`+`K`

# pandas.api.typing.Expanding.rank

Expanding.rank(method='average', ascending=True, pct=False, numeric_only=False)

  Calculate the expanding rank.

  Each value is ranked relative to all prior observations, with configurable tie-breaking and optional percentile normalization.

  Parameters:
    method{‘average’, ‘min’, ‘max’}, default ‘average’

      How to rank the group of records that have the same value (i.e. ties):

      - average: average rank of the group

      - min: lowest rank in the group

      - max: highest rank in the group

    ascending bool, default True

      Whether or not the elements should be ranked in ascending order.

    pct bool, default False

      Whether or not to display the returned rankings in percentile form.

    numeric_only bool, default False

      Include only float, int, boolean columns.

  Returns:
    Series or DataFrame

      Return type is the same as the original object with `np.float64` dtype.

  See also

  `Series.expanding`

    Calling expanding with Series data.

  `DataFrame.expanding`

    Calling expanding with DataFrames.

  `Series.rank`

    Aggregating rank for Series.

  `DataFrame.rank`

    Aggregating rank for DataFrame.

  Examples

      >>> s = pd.Series([1, 4, 2, 3, 5, 3])
      >>> s.expanding().rank()
      0    1.0
      1    2.0
      2    2.0
      3    3.0
      4    5.0
      5    3.5
      dtype: float64

      >>> s.expanding().rank(method="max")
      0    1.0
      1    2.0
      2    2.0
      3    3.0
      4    5.0
      5    4.0
      dtype: float64

      >>> s.expanding().rank(method="min")
      0    1.0
      1    2.0
      2    2.0
      3    3.0
      4    5.0
      5    3.0
      dtype: float64