【发布时间】:2021-10-26 18:16:23
【问题描述】:
我正在尝试使用箱线图提取异常值。
# libraries & dataset
import seaborn as sns
import matplotlib.pyplot as plt
# set a grey background (use sns.set_theme() if seaborn version 0.11.0 or above)
sns.set(style="darkgrid")
df = sns.load_dataset('iris')
sns.boxplot(y=df["species"], x=df["sepal_length"])
plt.show()
上图显示了一个异常值。我尝试使用boxplot_stats 提取异常值。但是传单显示一个空数组。
from matplotlib.cbook import boxplot_stats
boxplot_stats(data["sepal_length"])
输出
[{'cihi': 5.966646952167348,
'cilo': 5.633353047832651,
'fliers': array([], dtype=float64),
'iqr': 1.3000000000000007,
'mean': 5.843333333333334,
'med': 5.8,
'q1': 5.1,
'q3': 6.4,
'whishi': 7.9,
'whislo': 4.3}]
有没有办法提取箱线图中显示的异常值?
【问题讨论】:
标签: python pandas matplotlib seaborn boxplot