How to Plot Value Counts in Pandas Last Updated : 22 Jul, 2024 Comments Improve Suggest changes Like Article Like Report In this article, we'll learn how to plot value counts using provide, which can help us quickly understand the frequency distribution of values in a dataset.Table of ContentConcepts Related to Plotting Value CountsSteps to Plot Value Counts in Pandas1. Install Required Libraries2. Import Required Libraries3. Create or Load a DataFrame4. Calculate Value Counts5. Plot the Value CountsSimple Bar PlotPie ChartValue counts are useful for summarizing categorical data by showing the number of occurrences of each unique value. Plotting these counts can help in visualizing the distribution of data, making it easier to interpret and analyze. Pandas provide convenient methods to calculate and plot these counts directly.Concepts Related to Plotting Value CountsPandas DataFrame: A 2-dimensional labeled data structure with columns of potentially different types.Pandas Series: A one-dimensional labeled array capable of holding any data type.value_counts() Method: A Pandas method that returns a Series containing counts of unique values.Plotting with Matplotlib: Matplotlib is a plotting library that integrates well with Pandas for visualizations.Steps to Plot Value Counts in Pandas1. Install Required LibrariesMake sure you have Pandas and Matplotlib installed. You can install them using pip:pip install pandas matplotlib2. Import Required LibrariesImport Pandas and Matplotlib in your Python script or Jupyter Notebook: Python import pandas as pd import matplotlib.pyplot as plt 3. Create or Load a DataFrameYou can create a DataFrame manually or load data from a file. Here’s an example of creating a DataFrame with categorical data: Python data = {'Category': ['A', 'B', 'A', 'C', 'B', 'A', 'B', 'C', 'C', 'C']} df = pd.DataFrame(data) 4. Calculate Value CountsUse the value_counts() method to get the counts of unique values in a Series: Python # code counts = df['Category'].value_counts() 5. Plot the Value CountsPlot the value counts using Matplotlib: Python counts.plot(kind='bar', color='skyblue') plt.xlabel('Category') plt.ylabel('Count') plt.title('Value Counts of Categories') plt.show() Example 1: Simple Bar Plot Python import pandas as pd import matplotlib.pyplot as plt # Create DataFrame data = {'Category': ['A', 'B', 'A', 'C', 'B', 'A', 'B', 'C', 'C', 'C']} df = pd.DataFrame(data) # Calculate value counts counts = df['Category'].value_counts() # Plot value counts counts.plot(kind='bar', color='skyblue') plt.xlabel('Category') plt.ylabel('Count') plt.title('Value Counts of Categories') plt.show() Output: Example 2: Pie ChartYou can also plot the value counts as a pie chart: Python import pandas as pd import matplotlib.pyplot as plt # Create DataFrame data = {'Category': ['A', 'B', 'A', 'C', 'B', 'A', 'B', 'C', 'C', 'C']} df = pd.DataFrame(data) # Calculate value counts counts = df['Category'].value_counts() # Plot value counts as pie chart counts.plot(kind='pie', autopct='%1.1f%%', colors=['skyblue', 'lightgreen', 'lightcoral']) plt.title('Distribution of Categories') plt.ylabel('') plt.show() Output: ConclusionThe simple technique of plotting value counts in Pandas offers important insights into the distribution of categorical data. These instructions will make it simple for you to see how frequently various values occur in your dataset, which will aid in your comprehension and analysis of the data. Look into more Matplotlib features and Pandas choices for more sophisticated customizations and visualizations. Comment More infoAdvertise with us Next Article How to Plot Value Counts in Pandas P punam6fne Follow Improve Article Tags : Python Python-pandas Practice Tags : python Similar Reads Pandas Index.value_counts()-Python Python is popular for data analysis thanks to its powerful libraries and Pandas is one of the best. It makes working with data simple and efficient. The Index.value_counts() function in Pandas returns the count of each unique value in an Index, sorted in descending order so the most frequent item co 3 min read How to count number of NaN values in Pandas? Let's discuss how to count the number of NaN values in Pandas DataFrame. In Pandas, NaN (Not a Number) values represent missing data in a DataFrame. Counting NaN values of Each Column of Pandas DataFrameTo find the number of missing (NaN) values in each column, use the isnull() function followed by 3 min read Python | Pandas Series.value_counts() Pandas is one of the most widely used library for data handling and analysis. It simplifies many data manipulation tasks especially when working with tabular data. In this article, we'll explore the Series.value_counts() function in Pandas which helps you quickly count the frequency of unique values 2 min read How to Select Column Values to Display in Pandas Groupby Pandas is a powerful Python library used extensively in data analysis and manipulation. One of its most versatile and widely used functions is groupby, which allows users to group data based on specific criteria and perform various operations on these groups. This article will delve into the details 5 min read Count Values in Pandas Dataframe Counting values in Pandas dataframe is important for understanding the distribution of data, checking for missing values or summarizing data. In this article, we will learn various methods to count values in a Pandas DataFrameWe will be using below dataframe to learn about various methods:Pythonimpo 3 min read How to Use Python Pandas to manipulate and analyze data efficientlyPandas is a Python toolbox for working with data collections. It includes functions for analyzing, cleaning, examining, and modifying data. In this article, we will see how we can use Python Pandas with the help of examples.What is Python Pandas?A Python lib 5 min read How to Count Occurrences of Specific Value in Pandas Column? Let's learn how to count occurrences of a specific value in columns within a Pandas DataFrame using .value_counts() method and conditional filtering. Count Occurrences of Specific Values using value_counts()To count occurrences of values in a Pandas DataFrame, use the value_counts() method. This fun 4 min read How to plot Andrews curves using Pandas in Python? Andrews curves are used for visualizing high-dimensional data by mapping each observation onto a function. It preserves means, distance, and variances. It is given by formula: T(n) = x_1/sqrt(2) + x_2 sin(n) + x_3 cos(n) + x_4 sin(2n) + x_5 cos(2n) + ⦠Plotting Andrews curves on a graph can be done 2 min read Pandas - Groupby value counts on the DataFrame Prerequisites: Pandas Pandas can be employed to count the frequency of each value in the data frame separately. Let's see how to Groupby values count on the pandas dataframe. To count Groupby values in the pandas dataframe we are going to use groupby() size() and unstack() method. Functions Used:gro 3 min read Python | Pandas TimedeltaIndex.value_counts() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas TimedeltaIndex.value_counts() function return an object containing counts of un 2 min read Like