Pandas Series: nlargest() function

Get the largest n elements in Pandas

The nlargest() function is used to get the largest n elements.


Series.nlargest(self, n=5, keep='first')
Pandas Series nlargest image


Name Description Type/Default Value Required / Optional
n Return this many descending sorted values. int
Default Value: 5
keep When there are duplicate values that cannot all fit in a Series of n elements:
  • first : return the first n occurrences in order of appearance.
  • last : return the last n occurrences in reverse order of appearance.
  • all : keep all occurrences. This can result in a Series of size larger than n.
{‘first’, ‘last’, ‘all’}
Default Value: ‘first’

Returns: Series
The n largest values in the Series, sorted in decreasing order.


Download the Pandas Series Notebooks from here.

Previous: Minimum values in Pandas requested axis
Next: Get the smallest n elements in Pandas