w3resource

Pandas DataFrame: nlargest() function

DataFrame - nlargest() function

The nlargest() function is used to get the first n rows ordered by columns in descending order. The columns that are not specified are returned as well, but not used for ordering.

Syntax:

DataFrame.nlargest(self, n, columns, keep='first')

Parameters:

Name Description Type/Default Value Required / Optional
n     Number of rows to return. int Required
columns   Column label(s) to order by. label or list of labels Required
keep   Where there are duplicate values:
  • first : prioritize the first occurrence(s)
  • last : prioritize the last occurrence(s)
  • all : do not drop any duplicates, even it means
    selecting more than n items.
{‘first’, ‘last’, ‘all’}
Default Value: ‘first’
Required

Returns:DataFrame
The first n rows ordered by the given columns in descending order.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - sort_values() function
Next: DataFrame - nsmallest() function



Follow us on Facebook and Twitter for latest update.