w3resource

Pandas Series: nlargest() function

Get the largest n elements in Pandas

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

Syntax:

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

Parameters:

Name Description Type/Default Value Required / Optional
n Return this many descending sorted values. int
Default Value: 5
Required
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’
Required

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

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts