Suppose I have the following dataframe
df = pl.DataFrame({'x':[[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]]})
To get the nth percentile, I can do the following:
list_quantile_30 = pl.element().quantile(0.3)
df.select(pl.col('x').arr.eval(list_quantile_30))
But I can't figure out how to get the index corresponding to the percentile? Here is how I would do it using numpy:
import numpy as np
series = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
np.searchsorted(series, np.percentile(series, 30))
Is there a way to do this in a Polars way without using apply?