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.


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


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’

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


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.