Return the n largest or smallest values — mirrors
pandas.Series.nlargest(), Series.nsmallest(),
DataFrame.nlargest(), and DataFrame.nsmallest().
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
nlargestSeries(s, n) returns a new Series containing the n
largest values, sorted in descending order. NaN / null values are always excluded.
nsmallestSeries(s, n) returns the n smallest values sorted
in ascending order.
keep parameterWhen there are ties at the selection boundary, keep controls which
ones survive: first (default),
last, or
all (may return more than n rows).
The result preserves the original labels, not a reset 0-based index.
Missing values are silently excluded from both the selection and the result.
nlargestDataFrame(df, n, { columns }) returns the n rows with
the largest values in the given column(s), sorted descending. Multiple columns
provide a lexicographic tie-breaker.
nsmallestDataFrame(df, n, { columns }) returns the rows with the
smallest values, sorted ascending.
Behavior when n exceeds the series length, n is zero, all values are NaN, or values are strings.
Both Series and DataFrame variants accept an options object for tie-breaking and column selection.
// Series
nlargestSeries(series, n, {
keep?: "first" | "last" | "all", // default "first"
}): Series
nsmallestSeries(series, n, {
keep?: "first" | "last" | "all", // default "first"
}): Series
// DataFrame
nlargestDataFrame(df, n, {
columns: string | string[], // column(s) to sort by
keep?: "first" | "last" | "all",
}): DataFrame
nsmallestDataFrame(df, n, {
columns: string | string[],
keep?: "first" | "last" | "all",
}): DataFrame