polars.Expr.rolling_rank_by
-
Compute a rolling rank based on another column.
Warning
This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.
Given a
bycolumn<t_0, t_1, ..., t_n>, thenclosed="right"(the default) means the windows will be:- (t_0 - window_size, t_0]
- (t_1 - window_size, t_1]
- …
- (t_n - window_size, t_n]
- Parameters:
-
- by
-
Should be
DateTime,Date,UInt64,UInt32,Int64, orInt32data type (note that the integral ones require using'i'inwindow size). - window_size
-
The length of the window. Can be a dynamic temporal size indicated by a timedelta or the following string language:
- 1ns (1 nanosecond)
- 1us (1 microsecond)
- 1ms (1 millisecond)
- 1s (1 second)
- 1m (1 minute)
- 1h (1 hour)
- 1d (1 calendar day)
- 1w (1 calendar week)
- 1mo (1 calendar month)
- 1q (1 calendar quarter)
- 1y (1 calendar year)
- 1i (1 index count)
By “calendar day”, we mean the corresponding time on the next day (which may not be 24 hours, due to daylight savings - in cases of ambiguity, we follow RFC-5545 and preserve the DST fold of the original datetime). Similarly for “calendar week”, “calendar month”, “calendar quarter”, and “calendar year”.
-
method{‘average’, ‘min’, ‘max’, ‘dense’, ‘random’} -
The method used to assign ranks to tied elements. The following methods are available (default is ‘average’):
- ‘average’ : The average of the ranks that would have been assigned to all the tied values is assigned to each value.
- ‘min’ : The minimum of the ranks that would have been assigned to all the tied values is assigned to each value. (This is also referred to as “competition” ranking.)
- ‘max’ : The maximum of the ranks that would have been assigned to all the tied values is assigned to each value.
- ‘dense’ : Like ‘min’, but the rank of the next highest element is assigned the rank immediately after those assigned to the tied elements.
- ‘random’ : Choose a random rank for each value in a tie.
- seed
-
Random seed used when
method='random'. If set to None (default), a random seed is generated for each rolling rank operation. - min_samples
-
The number of values in the window that should be non-null before computing a result.
-
closed{‘left’, ‘right’, ‘both’, ‘none’} -
Define which sides of the temporal interval are closed (inclusive), defaults to
'right'.
- Returns:
-
- Expr
-
An Expr of data
Float64ifmethodis"average"or, the index size (seeget_index_type()) otherwise.
Expr.rolling_rank_by(
by: IntoExpr,
window_size: timedelta | str_,
method: RankMethod = 'average',
*,
seed: int | None = None,
min_samples: int = 1,
closed: ClosedInterval = 'right',
) → Expr
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.rolling_rank_by.html