Given a dataframe, I'd like to be able to aggregate the top 10% of a group, something like:
ans = (df
.groupby("groupId")
.agg(pl.col('myValue')
.sort_by(pl.col('order'))
.first(0.1).mean()
.alias('mean_of_top_decile')
)
)
The code above does not work because .first
does not take any parameters, and certainly not a float to represent percentages.
Is there any way to do this in polars?