20 C
London
Monday, July 21, 2025
HomePandas in PythonGeneral Functions in PythonHow to Create Boxplot from Pandas DataFrame

How to Create Boxplot from Pandas DataFrame

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

You can use the following syntax to create boxplots from a pandas DataFrame:

#create boxplot of one column
df.boxplot(column=['col1'])

#create boxplot of multiple columns
df.boxplot(column=['col1', 'col2'])

#create boxplot grouped by one column
df.boxplot(column=['col1'], by='col2') 

The following examples show how to use this syntax in practice with the following DataFrame:

import pandas as pd

#create DataFrame
df = pd.DataFrame({'conference': ['A', 'A', 'A', 'B', 'B', 'B'],
                   'points': [5, 7, 7, 9, 12, 9],
                   'assists': [11, 8, 10, 6, 6, 5],
                   'rebounds': [4, 2, 5, 8, 6, 11],})

#view DataFrame
df

Example 1: Boxplot of One Column

The following code shows how to create a boxplot for one column in a pandas DataFrame:

df.boxplot(column=['points'], grid=False, color='black')

Example 2: Boxplot of Multiple Columns

The following code shows how to create a boxplot for multiple columns in a pandas DataFrame:

df.boxplot(column=['points', 'assists'], grid=False, color='black')

Example 3: Boxplot Grouped by One Column

The following code shows how to create a boxplot grouped by one column in a pandas DataFrame:

df.boxplot(column=['points'], by='conference', grid=False, color='black')

Additional Resources

Pandas: How to Plot Multiple Series
Pandas: How to Plot Multiple Columns on Bar Chart

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories