Tutorials References Exercises Videos Menu
Free Website Get Certified Upgrade

Pandas DataFrame nsmallest() Method

❮ DataFrame Reference


Return the 10 rows with the smallest value for "Calories":

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

import pandas as pd

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

newdf = df.nsmallest(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 smallest value for a specified column.


dataframe.nsmallest(n, columns, keep)


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'
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