How to Create Boxplot from Pandas DataFrame?
Last Updated : 17 Mar, 2025
A box plot (or whisker plot) is a statistical graph that shows the minimum, first quartile (Q1), median, third quartile (Q3) and maximum values of a dataset. It helps analyze data spread, skewness and outliers and is widely used in data visualization. In this article you'll learn how to create box plots using Pandas, detect outliers and explore different methods to generate them in Python.
Using .plot() function
We can create a box plot on each column of a Pandas DataFrame by following the below syntax-
DataFrame_Name['column_name'].plot(kind='box', title='title_of_plot')
Finding Quartiles in Pandas
Before creating a boxplot you can calculate quartiles using the quantile() function.
Python import pandas as pd data = pd.Series([1, 2, 3, 4, 5, 6]) print(data.quantile([0.25, 0.5, 0.75]))
Output:

Example 1: Boxplot without an Outlier
Consider the below data to create a DataFrame and to plot a box plot on it. Let’s create it and generate a boxplot for the "Marks" column.
Python import pandas as pd import matplotlib.pyplot as plt data = pd.DataFrame({'Name': ['Akhil', 'Nikhil', 'Satyam', 'Sravan', 'Pavan'], 'Marks': [77, 95, 89, 78, 64], 'Credits': [8, 10, 9, 8, 7]}) data['Marks'].plot(kind='box', title='Marks of Students') plt.show()
Output:

Example 2: Boxplot with an Outlier
If a dataset contains outliers they will be marked separately in the boxplot. Like in below example the minimum mark of the student is 10 which is very small and far from other marks (data points). So it is indicated as o at the bottom which represents an outlier. If any of the data points in the data is much larger or smaller compared to other values then the following plot will be generated.
Python import pandas as pd import matplotlib.pyplot as plt data = pd.DataFrame({'Name': ['Akhil', 'Nikhil', 'Satyam', 'Sravan', 'Pavan'], 'Marks': [77, 95, 89, 78, 10], 'Credits': [8, 10, 9, 8, 0]}) data['Marks'].plot(kind='box', title='Marks of students') plt.show()
Output:

Using pandas.DataFrame.boxplot() function
Pandas also provides the boxplot() function to create a boxplot directly. We use pandas.DataFrame.boxplot to draw the box plot for respective columns in a DataFrame. Here we plotted the boxplot using the boxplot method instead of using the plot method and specifying its kind. As we did not specify the grid argument as a parameter in the boxplot method, it will consider the default value i.e. True.
Python import pandas as pd data = pd.DataFrame({'Name': ['Akhil', 'Nikhil', 'Satyam', 'Sravan', 'Pavan'], 'Marks': [77, 95, 89, 78, 64], 'Credits': [8, 10, 9, 8, 7]}) data.boxplot(column='Marks')
Output:

Similar Reads
How to Create a Histogram from Pandas DataFrame? A histogram is a graph that displays the frequency of values in a metric variable's intervals. These intervals are referred to as "bins," and they are all the same width. We can create a histogram from the panda's data frame using the df.hist() function. Syntax: DataFrame.hist(column=None, by=None,
2 min read
Create empty dataframe in Pandas The Pandas Dataframe is a structure that has data in the 2D format and labels with it. DataFrames are widely used in data science, machine learning, and other such places. DataFrames are the same as SQL tables or Excel sheets but these are faster in use.Empty DataFrame could be created with the help
1 min read
How To Compare Two Dataframes with Pandas compare? A DataFrame is a 2D structure composed of rows and columns, and where data is stored into a tubular form. It is mutable in terms of size, and heterogeneous tabular data. Arithmetic operations can also be performed on both row and column labels. To know more about the creation of Pandas DataFrame. He
5 min read
How to Plot Multiple Series from a Pandas DataFrame? In this article, we will discuss how to plot multiple series from a dataframe in pandas. Series is the range of the data  that include integer points we cab plot in pandas dataframe by using plot() function Syntax: matplotlib.pyplot(dataframe['column_name']) We can place n number of series and we ha
2 min read
How to Create Horizontal Boxplots in R? In this article, we will discuss how to create horizontal boxplots in the R programming language. Method 1: Create Horizontal boxplot in base R In this method to create the horizontal bar plot, the user simply needs to call the boxplot() function which is a base function of the R language, then the
3 min read