I would like using the rolling_last_quantile(window_size) instead of using rank() to implemment the quantile of the last element on rolling_window scope.
now i using the rolling_apply to implemment, which like the below:
import polars as pl
df = pl.DataFrame(
{
"A": [1.0, 2.0, 9.0, 2.5, 13.0, 11, 13.5, 4],
}
)
Problem description
I would like using the rolling_last_quantile(window_size) instead of using rank() to implemment the quantile of the last element on rolling_window scope.
now i using the rolling_apply to implemment, which like the below: import polars as pl df = pl.DataFrame( { "A": [1.0, 2.0, 9.0, 2.5, 13.0, 11, 13.5, 4], } )
agg_func = lambda d: ((d.reverse().rank('dense') - pl.lit(1)) / (d.rank('dense').max() - pl.lit(1))) df = df.lazy().with_columns( pl.col('A').rolling_apply(agg_func, 3).alias('B'), ).collect()
print(df)