python - 我们怎样才能得到一个情节箱线图背后的不同统计数据?
问题描述
我想获得一个情节箱线图背后的确切统计数据。
这似乎让我非常接近,但我错过了第一季度和第三季度。
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()
有“排他性”论点?
解决方案
第一季度
我没有在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 实例的方法
如您所见,它确实具有include
和exclude
。但他们做的事情与您正在寻找的事情截然不同:
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.
推荐阅读
- mysql - 每当 id 更改时,如何将用户定义的变量值设置为零?
- javafx - 填充组合框 FXML
- php - 所有页面都显示 404 Not Found Nginx 但主页工作正常
- swift - 在 Swift 中导入钠的问题
- c - 在 Linux 内核中使用 workqueue 或 kthread 执行 ELF
- php - 我有一个登录 php 文件给我这个错误“mysqli_stmt_close() 期望参数 1 是 mysqli_stmt,布尔值”
- python - 无法解释python中打印语句的输出
- linux - 如何创建能够让我查看、修改和附加它创建的文本文件的 Shell 脚本
- html - 为什么 _POST 不从 HTML 表单中收集数据?
- r - 通过矢量化加速 R 中的三重嵌套 For 循环