Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot a boxplot for each column in a DataFrame? [duplicate]

I have a DataFrame df of multiple columns and I would like to create a boxplot for each column using matplotlib.

df.info() output of my DataFrame below for reference

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 9568 entries, 0 to 9567
Data columns (total 5 columns):
Ambient Tempreature    9568 non-null float64
Exhaust Vacuum         9568 non-null float64
Ambient Pressure       9568 non-null float64
Relative Humidity      9568 non-null float64
PE                     9568 non-null float64
dtypes: float64(5)
memory usage: 373.8 KB
like image 946
helcode Avatar asked Aug 09 '18 23:08

helcode


1 Answers

If you want to create a separate plot per column, then you can iterate over each column and use plt.figure() to initiate a new figure for each plot.

import matplotlib.pyplot as plt

for column in df:
    plt.figure()
    df.boxplot([column])

If you want to just put all columns into the same boxplot graph then you can just use df.plot(kind='box')

like image 75
helcode Avatar answered Sep 19 '22 20:09

helcode