pandas 如何防止在熊猫的箱线图中绘制异常值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28725763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:59:04  来源:igfitidea点击:

How to prevent from plotting outlier in boxplot in pandas

pythonpandas

提问by Hello lad

I have a DataFrame(called result_df) and want to plot one column with boxplot.

我有一个 DataFrame(称为result_df)并想用箱线图绘制一列。

But certain outliers spoiled the visualization. How could I prevent from ploting outliers?

但是某些异常值破坏了可视化。我怎样才能防止绘制异常值?

Code I used:

我使用的代码:

fig, ax = pl.subplots()
fig.set_size_inches(18.5,10.5)
result_df.boxplot(ax=ax)
pl.show()

回答by ljetibo

Important: I haven't paid enough attention, apparently that happens a lot, and I missed that it's pandasspecific. However from questions I saw it's basically matplotlib for graphing in the background so this could still work. Sorry I failed to be more careful.

重要提示:我没有给予足够的关注,显然这种情况经常发生,我错过了它的pandas具体性。然而,从问题中我看到它基本上是用于在后台绘图的 matplotlib,所以这仍然可以工作。抱歉,我没能更加小心。

Luckily for you there is such a thing. In the manualunder results: dicttitle torwards the bottom of the page it states:

对你来说幸运的是有这样的事情。在页面底部标题下的手册results: dict中,它指出:

fliers: points representing data that extend beyond the whiskers (outliers).

传单:表示超出胡须(异常值)的数据的点。

Setting showfliers=Falsewill hopefully help you.

设置showfliers=False希望对您有所帮助。

I do have to mention though, that I find it really really strange they shortened outliers to fliers. If that doesn't help manualoffers a second solution:

不过我不得不提一下,我发现他们将异常值缩短为传单真的很奇怪。如果这没有帮助,手册提供了第二种解决方案:

sym : str or None, default = None

The default symbol for flier points. Enter an empty string (‘') if you don't want to show fliers. If None, then the fliers default to ‘b+' If you want more control use the flierprops kwarg.

sym : str 或 None,默认 = None

传单点的默认符号。如果您不想显示传单,请输入一个空字符串 ('')。如果没有,则传单默认为 'b+' 如果您想要更多控制,请使用 flierprops kwarg。