Get n-smallest values from a particular column in Pandas DataFrame
nsmallest() function returns the top n rows with the smallest values in the specified column(s).
Syntax:
DataFrame.nsmallest(n, columns, keep='first')
Parameters:
- n: Number of rows to return.
- columns: Column label(s) to order by.
- keep: Decides what to do if there are duplicate values:
'first' (default): keeps the first occurrence.
'last': keeps the last occurrence.
'all': keeps all occurrences.
To download the dataset used in this article, click here
Loading the Dataset
import pandas as pd
df = pd.read_csv(r'enter the path to dataset here')
df.head(10)

Explanation:
- pd.read_csv(): loads the dataset as a pandas dataframe
- df.head(10): prints the top 10 rows of the dataframe.
Example 1: Find the 5 Youngest Players (Smallest Ages)
df.nsmallest(5, ['Age'])
Output

Example 2: Find the 10 Lightest Players (Smallest Weights)
df.nsmallest(10, ['Weight'])
Output

Example 3: Getting the 5 smallest Rows by Age and Weight Together
df.nsmallest(5, ['Age', 'Weight'])
Output
