Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Pandas DataFrame nlargest() Method

❮ DataFrame Reference


Example

Return the 10 rows with the largest value for "Colories":

In this example we use a .csv file called data.csv

import pandas as pd

df = pd.read_csv('data.csv')

newdf = df.nlargest(10, "Calories")
Try it Yourself »

Definition and Usage

The nlargest() method returns a specified number of rows, starting at the top after sorting the DataFrame by the highest value for a specified column.


Syntax

dataframe.nlargest(n, columns, keep)

Parameters

The keep parameter is a keyword argument.

Parameter Value Description
n   Required, a Number, specifying the number of rows to return
columns   Optional, A String (column label), or a list of column labels, specifying the column(s) to order by
keep 'all'
'first'
'last'
Optional, default 'last', specifying what to do with duplicate rows.

Return Value

A DataFrame with Boolean values.

This method does not change the original DataFrame.


❮ DataFrame Reference