首页 > 解决方案 > 我们怎样才能得到一个情节箱线图背后的不同统计数据?

问题描述

我想获得一个情节箱线图背后的确切统计数据。

这似乎让我非常接近,但我错过了第一季度和第三季度。

stats = df.groupby(['Market'])['Revenue'].describe()
stats

Q1 和 Q3 似乎与我看到的不同。

import plotly.express as px
fig = px.box(df, x="Market", y="Revenue", color="Market")
fig.update_traces(quartilemethod="exclusive")
fig.update_layout(showlegend=False)
fig.show()

它与“排他性”或“包容性”论点有关,但我不知道有什么区别。此外,默认值df.groupby(['Market'])['Revenue'].describe()似乎与“包容性”参数相匹配。

Q1:“独家”和“包容”有什么区别?

Q2:是否df.groupby(['Market'])['Revenue'].describe()有“排他性”论点?

标签: pythonpython-3.xdataframeplotly

解决方案


第一季度

我没有在plotly文档中找到描述,但可以公平地假设解释与 Percentile 没有太大区别:

在统计学中,百分位数(或百分位数)是一个分数,在其频率分布中,给定百分比的分数低于该分数(不包括定义),或者是给定百分比低于或低于该分数的分数(包括定义)。例如,第 50 个百分位数(中位数)是低于(不包括)或等于或低于(包括)分布中 50% 的分数的分数。

您可以在 plotly 文档中仔细查看四分位算法之间的差异下的差异的直观表示:

在此处输入图像描述

第二季度

不,df.describe()似乎没有exclusive论据:

关于模块 pandas.core.generic 中描述的方法的帮助:

describe(percentiles=None, include=None, exclude=None, datetime_is_numeric=False) -> ~FrameOrSeries pandas.core.frame.DataFrame 实例的方法

如您所见,它确实具有includeexclude。但他们做的事情与您正在寻找的事情截然不同:

include : 'all',dtypes 的列表或 None (默认),可选 要包含在结果中的数据类型的白名单。忽略为Series。以下是选项:

    - 'all' : All columns of the input will be included in the output.
    - A list-like of dtypes : Limits the results to the
      provided data types.
      To limit the result to numeric types submit
      ``numpy.number``. To limit it instead to object columns submit
      the ``numpy.object`` data type. Strings
      can also be used in the style of
      ``select_dtypes`` (e.g. ``df.describe(include=['O'])``). To
      select pandas categorical columns, use ``'category'``
    - None (default) : The result will include all numeric columns.
exclude : list-like of dtypes or None (default), optional,
    A black list of data types to omit from the result. Ignored
    for ``Series``. Here are the options:

    - A list-like of dtypes : Excludes the provided data types
      from the result. To exclude numeric types submit
      ``numpy.number``. To exclude object columns submit the data
      type ``numpy.object``. Strings can also be used in the style of
      ``select_dtypes`` (e.g. ``df.describe(include=['O'])``). To
      exclude pandas categorical columns, use ``'category'``
    - None (default) : The result will exclude nothing.

推荐阅读