polars.Expr.top_k#

Expr.top_k(k: int = 5, reverse: bool = False) Expr[source]#

Return the k largest elements.

If ‘reverse=True` the smallest elements will be given.

This has time complexity:

\[\begin{split}O(n + k \\log{}n - \frac{k}{2})\end{split}\]
Parameters:
k

Number of elements to return.

reverse

Return the smallest elements.