Assign numerical ranks to values — mirrors
pandas.Series.rank() and
pandas.DataFrame.rank().
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
By default, rankSeries uses method="average"
(tied values share the average of their ranks) and ascending=true
(smallest value gets rank 1).
Five methods mirror pandas: average (default),
min, max, first, and
dense.
Set ascending: false to give rank 1 to the largest value.
Three strategies mirror pandas na_option:
keep (default, NaN in result),
top (nulls get lowest ranks), and
bottom (nulls get highest ranks).
pct: true returns fractional ranks in the range (0, 1].
rankDataFrame ranks each column independently by default.
Set axis: 1 to rank each row's values relative to each other.
Dense rank is useful when you want no gaps — e.g., "1st, 2nd, 2nd, 3rd" instead of "1st, 2nd, 2nd, 4th".
Rank values along an axis. Use rankSeries for a single Series
and rankDataFrame for an entire DataFrame.
// Series
rankSeries(series, {
method?: "average" | "min" | "max" | "first" | "dense",
ascending?: boolean, // default true — smallest gets rank 1
naOption?: "keep" | "top" | "bottom",
pct?: boolean, // default false — return fractional ranks
}): Series<number>
// DataFrame
rankDataFrame(df, {
method?: "average" | "min" | "max" | "first" | "dense",
ascending?: boolean,
naOption?: "keep" | "top" | "bottom",
pct?: boolean,
axis?: 0 | 1, // 0 = rank each column, 1 = rank each row
}): DataFrame