-
Series.nlargest(*args, **kwargs)
[source] -
Return the largest
n
elements.Parameters: n : int
Return this many descending sorted values
keep : {?first?, ?last?, False}, default ?first?
Where there are duplicate values: -
first
: take the first occurrence. -last
: take the last occurrence.take_last : deprecated
Returns: top_n : Series
The n largest values in the Series, in sorted order
See also
Notes
Faster than
.sort_values(ascending=False).head(n)
for smalln
relative to the size of theSeries
object.Examples
1234>>>
import
pandas as pd
>>>
import
numpy as np
>>> s
=
pd.Series(np.random.randn(
1e6
))
>>> s.nlargest(
10
)
# only sorts up to the N requested
Series.nlargest()

2025-01-10 15:47:30
Please login to continue.