polars.Expr.hist#

Expr.hist(
bins: IntoExpr | None = None,
*,
bin_count: int | None = None,
include_category: bool = False,
include_breakpoint: bool = False,
) Expr[source]#

将值分入桶中并计算它们的出现次数。

警告

此功能被视为不稳定。它可能会在任何时候更改,而不被视为破坏性更改。

Parameters:
bins

需要进行的离散化处理。 如果未给出,我们将根据数据确定边界。

bin_count

如果没有提供bins,这将用于确定bins的距离

include_breakpoint

包含一个指示上断点的列。

include_category

包含一个显示区间为类别的列。

Returns:
DataFrame

示例

>>> df = pl.DataFrame({"a": [1, 3, 8, 8, 2, 1, 3]})
>>> df.select(pl.col("a").hist(bins=[1, 2, 3]))
shape: (2, 1)
┌─────┐
│ a   │
│ --- │
│ u32 │
╞═════╡
│ 1   │
│ 2   │
└─────┘
>>> df.select(
...     pl.col("a").hist(
...         bins=[1, 2, 3], include_breakpoint=True, include_category=True
...     )
... )
shape: (2, 1)
┌──────────────────────┐
│ a                    │
│ ---                  │
│ struct[3]            │
╞══════════════════════╡
│ {2.0,"(1.0, 2.0]",1} │
│ {3.0,"(2.0, 3.0]",2} │
└──────────────────────┘