Python ProgrammingPython Programming

Box plot represent pandas data

Simple box plot

plt.boxplot() is the method to plot a boxplot. The green line in each box represents the median value of the column by default.

import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame([[10, 20, 30, 40], [7, 14, 21, 28], [15, 15, 8, 12],
                   [15, 14, 1, 8], [7, 1, 1, 8], [5, 4, 9, 2]],
                  columns=['Apple', 'Orange', 'Banana', 'Pear'],
                  index=['Basket1', 'Basket2', 'Basket3', 'Basket4',
                         'Basket5', 'Basket6'])

df.boxplot(['Apple', 'Orange', 'Banana', 'Pear'])
plt.show()

The following is the output that will be obtained:


Box plot represent pandas data