polars.Series.top_k#

Series.top_k(*, k: int = 5, descending: bool = False) Series[source]#

Return the k largest elements.

If ‘descending=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.

descending

Return the smallest elements.