如何为DataFrame中的每一列绘制箱线图? [英] How to plot a boxplot for each column in a DataFrame?

查看:1510
本文介绍了如何为DataFrame中的每一列绘制箱线图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个列的DataFrame df,我想使用matplotlib为每个列创建一个boxplot .

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

df.info()输出如下以供参考

<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

推荐答案

如果要为每列创建一个单独的图,则可以遍历每列并使用plt.figure()为每个图启动一个新图形. /p>

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

如果您只想将所有列放入同一个箱形图,则可以使用df.plot(kind='box')

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

这篇关于如何为DataFrame中的每一列绘制箱线图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆