polars.Series.top_k#
- Series.top_k(k: int | IntoExprColumn = 5) Series [source]#
Return the
k
largest elements.This has time complexity:
\[\begin{split}O(n + k \\log{}n - \frac{k}{2})\end{split}\]- Parameters:
- k
Number of elements to return.
See also
Examples
>>> s = pl.Series("a", [2, 5, 1, 4, 3]) >>> s.top_k(3) shape: (3,) Series: 'a' [i64] [ 5 4 3 ]