pandas.core.groupby.SeriesGroupBy.nlargest
- 
SeriesGroupBy.nlargest
- 
Return the largest nelements.Parameters: - 
n : int, default 5
- 
Return this many descending sorted values. 
- 
keep : {‘first’, ‘last’, ‘all’}, default ‘first’
- 
When there are duplicate values that cannot all fit in a Series of nelements:- 
first: take the first occurrences based on the index order
- 
last: take the last occurrences based on the index order
- 
- 
all : keep all occurrences. This can result in a Series of
- size larger than n.
 
- 
 
- 
 Returns: - Series
- 
The nlargest values in the Series, sorted in decreasing order.
 See also - 
Series.nsmallest
- Get the nsmallest elements.
- 
Series.sort_values
- Sort Series by values.
- 
Series.head
- Return the first nrows.
 NotesFaster than .sort_values(ascending=False).head(n)for smallnrelative to the size of theSeriesobject.Examples>>> countries_population = {"Italy": 59000000, "France": 65000000, ... "Malta": 434000, "Maldives": 434000, ... "Brunei": 434000, "Iceland": 337000, ... "Nauru": 11300, "Tuvalu": 11300, ... "Anguilla": 11300, "Monserat": 5200} >>> s = pd.Series(countries_population) >>> s Italy 59000000 France 65000000 Malta 434000 Maldives 434000 Brunei 434000 Iceland 337000 Nauru 11300 Tuvalu 11300 Anguilla 11300 Monserat 5200 dtype: int64The nlargest elements wheren=5by default.>>> s.nlargest() France 65000000 Italy 59000000 Malta 434000 Maldives 434000 Brunei 434000 dtype: int64 The nlargest elements wheren=3. Defaultkeepvalue is ‘first’ so Malta will be kept.>>> s.nlargest(3) France 65000000 Italy 59000000 Malta 434000 dtype: int64 The nlargest elements wheren=3and keeping the last duplicates. Brunei will be kept since it is the last with value 434000 based on the index order.>>> s.nlargest(3, keep='last') France 65000000 Italy 59000000 Brunei 434000 dtype: int64 The nlargest elements wheren=3with all duplicates kept. Note that the returned Series has five elements due to the three duplicates.>>> s.nlargest(3, keep='all') France 65000000 Italy 59000000 Malta 434000 Maldives 434000 Brunei 434000 dtype: int64 
- 
    © 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
    https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.core.groupby.SeriesGroupBy.nlargest.html