pandas.core.window.rolling.Rolling.rank — pandas 2.2.3 documentation (original) (raw)

Rolling.rank(method='average', ascending=True, pct=False, numeric_only=False)[source]#

Calculate the rolling rank.

Added in version 1.4.0.

Parameters:

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

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

ascendingbool, default True

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

pctbool, default False

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

numeric_onlybool, default False

Include only float, int, boolean columns.

Added in version 1.5.0.

Returns:

Series or DataFrame

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

Examples

s = pd.Series([1, 4, 2, 3, 5, 3]) s.rolling(3).rank() 0 NaN 1 NaN 2 2.0 3 2.0 4 3.0 5 1.5 dtype: float64

s.rolling(3).rank(method="max") 0 NaN 1 NaN 2 2.0 3 2.0 4 3.0 5 2.0 dtype: float64

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