Pandas: Represent value_counts as Percentage


Introduction to Frequency Analysis with Pandas

In the realm of data analysis, understanding the distribution and frequency of values within a dataset is a fundamental task. The pandas library in Python provides powerful tools to achieve this efficiently. One such indispensable function is value_counts(), which allows data scientists and analysts to quickly summarize the occurrences of unique values within a Series, typically a column of a DataFrame.

While raw counts are often informative, representing these counts as percentages can offer a clearer perspective on the proportional distribution of categories. Percentages normalize the data, making it easier to compare distributions across different datasets or columns, regardless of their absolute sizes. This transformation is particularly useful for reporting, visualization, and understanding the relative importance of each category.

This article will guide you through various methods to represent the output of value_counts() as percentages in pandas, covering different formatting requirements. We will explore techniques to display percentages as decimals, formatted with explicit percent symbols, and even alongside their original counts for a comprehensive view.

Understanding the value_counts() Function

The value_counts() method is a core pandas Series function that returns a new Series containing counts of unique values. By default, it returns the absolute frequencies in descending order, making it straightforward to identify the most common elements. However, its true power for proportional analysis emerges with the use of the normalize parameter.

When the normalize parameter is set to True, the function computes the relative frequencies of the unique values, meaning each count is divided by the sum of all counts. This transforms the output from absolute numbers to proportions, where the sum of all values will be 1.0. These proportions are the foundation for generating percentage representations.

Below, we will demonstrate three distinct methods to harness value_counts() for percentage calculations, each catering to different presentation needs.

df.my_col.value_counts(normalize=True)
df.my_col.value_counts(normalize=True).mul(100).round(1).astype(str) + '%'
counts = df.my_col.value_counts()
percs = df.my_col.value_counts(normalize=True)
pd.concat([counts,percs], axis=1, keys=['count', 'percentage'])

Setting Up Our Example DataFrame

To illustrate these methods practically, we will use a simple pandas DataFrame. This DataFrame, named df, contains two columns: ‘team’ and ‘points’. Our goal will be to analyze the distribution of teams using the ‘team’ column.

The following code snippet demonstrates how to create this sample DataFrame. It’s a small, manageable dataset that perfectly showcases the functionalities of value_counts() and its percentage representations.

import pandas as pd

#create DataFrame
df = pd.DataFrame({'team': ['A', 'A', 'B', 'B', 'B', 'B', 'B', 'C'],
                   'points': [15, 12, 18, 20, 22, 28, 35, 40]})

#view DataFrame
print(df)

  team  points
0    A      15
1    A      12
2    B      18
3    B      20
4    B      22
5    B      28
6    B      35
7    C      40

As you can observe from the output, we have 8 entries in total, with various occurrences for teams ‘A’, ‘B’, and ‘C’. This DataFrame will serve as our foundation for the subsequent examples.

Method 1: Displaying Percentages as Decimals

The most direct way to obtain percentages using value_counts() is by leveraging its normalize=True parameter. When this parameter is activated, the function calculates the frequency of each unique value and then divides it by the total number of non-null values in the Series. The result is a Series where each value represents the proportion of its occurrence, ranging from 0 to 1.

This decimal representation is often preferred for internal calculations, statistical modeling, or when further arithmetic operations are needed, as it maintains numerical precision. Below is the code demonstrating this method applied to our ‘team’ column, followed by its output.

#count occurrence of each value in 'team' column as percentage of total
df.team.value_counts(normalize=True)

B    0.625
A    0.250
C    0.125
Name: team, dtype: float64

From the generated output, we can deduce the following:

  • The value B accounts for 0.625 (or 62.5%) of the entries in the team column.
  • The value A accounts for 0.250 (or 25%) of the entries in the team column.
  • The value C accounts for 0.125 (or 12.5%) of the entries in the team column.

It is important to note that the output data type (float64) indicates that these are floating-point numbers, suitable for numerical computations.

Method 2: Formatting Percentages with Symbols

While decimal representations are numerically robust, they are not always the most user-friendly format for presentations or reports. Often, displaying percentages with an explicit percent symbol (e.g., “62.5%”) enhances readability for a broader audience. This method involves a series of chained operations to transform the normalized counts into formatted strings.

First, we apply normalize=True as before to get the proportions. Then, we multiply these proportions by 100 using the .mul() method to convert them into a percentage scale. To control the precision, we use .round(1) to round the numbers to one decimal place. Finally, we convert the numbers to strings using .astype(str), which allows us to concatenate the percent symbol ‘%’ directly to each string.

#count occurrence of each value in 'team' column as percentage of total
df.team.value_counts(normalize=True).mul(100).round(1).astype(str) + '%'

B    62.5%
A    25.0%
C    12.5%
Name: team, dtype: object

As evident from the output, the percentages are now presented as strings, each appended with a percent symbol. Notice the dtype: object, which signifies that the Series now holds string values rather than numeric ones. This format is ideal for direct display in tables or reports where human readability is paramount and further numerical calculations are not immediately required on these specific values.

Method 3: Combining Counts and Percentages

In certain analytical scenarios, it is beneficial to view both the absolute counts and their corresponding percentages simultaneously. This provides a complete picture, showing not only the proportion of each category but also the underlying volume. To achieve this, we can compute the raw counts and normalized percentages separately and then combine them into a single, cohesive DataFrame.

First, we obtain the absolute counts using value_counts() without the normalize parameter. Simultaneously, we calculate the percentages (as decimals) by setting normalize=True. These two Series are then concatenated side-by-side using pd.concat(). The axis=1 argument ensures column-wise concatenation, while keys=[‘count’, ‘percentage’] assigns meaningful column names to the resulting DataFrame.

#count occurrence of each value in 'team' column
counts = df.team.value_counts()

#count occurrence of each value in 'team' column as percentage of total 
percs = df.team.value_counts(normalize=True)

#concatenate results into one DataFrame
pd.concat([counts,percs], axis=1, keys=['count', 'percentage'])

        count	percentage
B	5	0.625
A	2	0.250
C	1	0.125

The resulting DataFrame provides two columns: count, showing the absolute frequency of each unique team, and percentage, displaying its proportional representation. This combined view is incredibly valuable for detailed data exploration, allowing analysts to quickly grasp both the magnitude and the relative significance of each category within the dataset.

Conclusion

The ability to represent frequency counts as percentages is a powerful feature in pandas, significantly enhancing the interpretability of data distributions. Whether you need precise decimal proportions for further numerical analysis, human-readable percentages with symbols for reports, or a combined view of counts and percentages for comprehensive insights, pandas offers flexible and efficient methods to achieve these.

By mastering the value_counts() function and its interaction with parameters like normalize, along with other pandas Series and DataFrame operations, you can effectively summarize and present categorical data in a clear, concise, and informative manner. These techniques are fundamental for anyone working with data analysis and reporting in Python.

Additional Resources

For those looking to deepen their pandas expertise, the following tutorials explain how to perform other common tasks and explore additional functionalities:

Cite this article

Mohammed looti (2026). Pandas: Represent value_counts as Percentage. PSYCHOLOGICAL STATISTICS. Retrieved from https://statistics.arabpsychology.com/pandas-represent-value_counts-as-percentage/

Mohammed looti. "Pandas: Represent value_counts as Percentage." PSYCHOLOGICAL STATISTICS, 12 Apr. 2026, https://statistics.arabpsychology.com/pandas-represent-value_counts-as-percentage/.

Mohammed looti. "Pandas: Represent value_counts as Percentage." PSYCHOLOGICAL STATISTICS, 2026. https://statistics.arabpsychology.com/pandas-represent-value_counts-as-percentage/.

Mohammed looti (2026) 'Pandas: Represent value_counts as Percentage', PSYCHOLOGICAL STATISTICS. Available at: https://statistics.arabpsychology.com/pandas-represent-value_counts-as-percentage/.

[1] Mohammed looti, "Pandas: Represent value_counts as Percentage," PSYCHOLOGICAL STATISTICS, vol. X, no. Y, ص Z-Z, April, 2026.

Mohammed looti. Pandas: Represent value_counts as Percentage. PSYCHOLOGICAL STATISTICS. 2026;vol(issue):pages.

Download Post (.PDF)
Scroll to Top