简体   繁体   中英

How to plot a boxplot for each column in a DataFrame?

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

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM