Pie plots in Pandas

Pandas is a popular Python-based data analysis toolkit that can be imported using

import pandas as pd

It presents a diverse range of utilities from parsing multiple file-formats to converting an entire data table into a NumPy matrix array. This property makes pandas a trusted ally in data science and machine learning.

Pandas can help with the creation of multiple types of data analysis graphs. One such example is the pie plota sector plot showing the contribution of each variable.

A pie chart is used to help someone understand the composition of something. If there is categorical data, then a pie chart will have each slice represent a different category to make it easier to understand the data.

The default implementation of pie plot is:

DataFrame.plot.pie( **kwargs)

Parameters

  • y: int or string - The columns label or position that needs to be plotted. If not provided, subplots=True must be added.

  • **kwargs: tuple (rows, columns) - All other plotting keyword arguments to be passed to DataFrame.plot().

Code

The following code shows how a pie plot can be added in Python. You can change the parameters to see how the output varies.

main.py
dataset.csv
#import library
import pandas as pd
#add csv file to dataframe
df = pd.read_csv('dataset.csv')
print(df)
#create pie plot
pieplot = df.plot.pie(y= "Maths", figsize = (5,5), legend = False)

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved