ENH: Total (that is: sum or "margins") for value_counts()
Author: kandilphiCreated Sep 17, 2026Updated Sep 17, 2026
LabelsEnhancementNeeds Triage
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
The function "pd.crosstab" shows the count values for all the combinations. As an add-on you can choose "dropna" and "margins". The function "value_counts" does almost the same for a single series, but does not offer to show the total amount ("margins").
Feature Description
Add a new feature called "margin" (or "total") to value_counts, which –in addition– returns the total of all listed value counts (much like "margins" for the pd.crosstab function.
Alternative Solutions
"margins" in pd.crosstab
or
print(df.colA.shape[0]) df.colA.value_counts()
Additional Context
Thanks & much obliged !
Source: pandas-dev/pandas