How to use pandas.DataFrame.boxplot() function In Python Pandas

We can also use pandas.DataFrame.boxplot to draw the box plot for respective columns in a DataFrame.

Syntax

DataFrameName.boxplot(column=’column_name’,grid=True/False)

grid indicates grid lines in a graph. It is an optional parameter, if not specified it will be considered as true.

Example:

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.

Python3




# import necessary packages
import pandas as pd
  
# create a dataframe
data = pd.DataFrame({'Name': ['Akhil', 'Nikhil', 'Satyam', 'Sravan', 'Pavan'],
                     'Marks': [77, 95, 89, 78, 64],
                     'Credits': [8, 10, 9, 8, 7]})
  
# box plot for marks column
data.boxplot(column='Marks')


Output:

 



How to Create Boxplot from Pandas DataFrame?

Box plot is also called a Whisker plot which provides a summary of a set of data that includes minimum, first-quartile, median, third quartile, and maximum value. This Box plot is present in the matplotlib library. In the Box plot graph, the x-axis represents the data we are going to plot and the y-axis represents frequency. 

Similar Reads

Method 1: Using DataFrame_Name[‘column_name’].plot() function

We can create a box plot on each column of a Pandas DataFrame by following the below syntax-...

Method 2: Using pandas.DataFrame.boxplot() function

...