October 2019
Beginner to intermediate
674 pages
16h 43m
English
The nsmallest and nlargest functions are extremely useful for returning the n smallest and n largest rows after ordering by the desired column.
In the sample sales data, let's find the 3 smallest records by Profit:
sales_data.nsmallest(3, "Profit")
The following will be the output:

The ordering can also be done with respect to multiple columns, as shown here:
sales_data.nlargest(3, ["Quantity", "Profit"])
The following will be the output:

These functions – nsmallest
Read now
Unlock full access