Count unique values in a Series or unique row
combinations in a DataFrame. Mirrors
pandas.Series.value_counts() and
pandas.DataFrame.value_counts().
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
Create a Series and count how often each unique value appears. Results are sorted descending by frequency by default.
Pass normalize: true to get relative frequencies that sum to 1
instead of raw counts.
Control sorting: ascending: true for least-frequent first, or
sort: false to preserve insertion order.
By default nulls are excluded (dropna: true). Set
dropna: false to include them in the count.
Count unique row combinations across all columns. Each unique
(city, temp) pair becomes an index label.
Restrict counting to a subset of columns with the subset option.
The result Series is indexed by the unique values (or composite
"v1|v2|…" strings for DataFrames). Use .index.values and
.values to inspect the labels and counts respectively.
// Series
valueCounts(series, {
normalize?: boolean, // default false — return proportions
sort?: boolean, // default true — sort by frequency
ascending?: boolean, // default false — highest count first
dropna?: boolean, // default true — exclude missing values
}): Series<number>
// DataFrame
dataFrameValueCounts(df, {
subset?: readonly string[], // columns to use (default: all)
normalize?: boolean,
sort?: boolean,
ascending?: boolean,
dropna?: boolean,
}): Series<number>