【问题标题】:Discrepancy between Seaborn plotted mean and calculated mean. (Python/Pandas)Seaborn 绘制的平均值和计算的平均值之间的差异。 (蟒蛇/熊猫)
【发布时间】:2018-09-20 12:47:55
【问题描述】:

你好 StackOverflow 的好人!

我已经开始掌握 Python,并且开始对自己知道自己在做什么感到非常自信,直到出现了这个笨蛋:

我正在绘制和比较“类型”=“区域”和“”的数据框的两个子选择。 Seaborn 绘制了这些的箱线图并标记了平均值,但是当我使用 .mean() 计算平均值时,它给出了不同的答案。代码如下:

plotdata = df[df['Type'].isin(['A','B'])]
g = sns.violinplot(x="Type", y="value", data=plotdata, inner="quartile")
plt.ylim(ymin=-4, ymax=4) # This is to zoom on the plot to make the 0 line clearer

This is the resulting plot, note how the means are ~-0.1 and ~1.5

但是当我计算它们时:

print(df_long[df_long['charttype'].isin(['area'])]['error'].mean())
print(df_long[df_long['charttype'].isin(['angle'])]['error'].mean())

返回:

0.014542483333332705
-2.024809368191722

所以我的问题是,为什么这些数字不匹配?

【问题讨论】:

  • 谢谢斯科特,第一次来这里,我找到了答案,但如果我再次询问,我一定会发布数据。谢谢!!

标签: python pandas seaborn


【解决方案1】:

对基本统计的完全误解是问题所在!

箱形图(在 seaborn violin 图内)绘制四分位距和 MEDIAN,而我后来计算了 MEAN。

只需要睡在上面,嘿,一切都变得清晰了。

【讨论】:

    猜你喜欢
    • 2021-11-15
    • 1970-01-01
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 1970-01-01
    • 2014-12-08
    相关资源
    最近更新 更多