Spec-Zone.ru › Polars

polars.Expr.item

Expr.item(
    *,
    allow_empty: bool = False,
) → Expr

Get the single value.

engine:In MemoryStreamingDistributed

This raises an error if there is not exactly one value.

Parameters:
allow_empty

Allow having no values to return null.

See also

Expr.get()

Get a single value by index.

Examples

>>> df = pl.DataFrame({"a": [1]})
>>> df.select(pl.col("a").item())
shape: (1, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 1   │
└─────┘
>>> df = pl.DataFrame({"a": [1, 2, 3]})
>>> df.select(pl.col("a").item())
Traceback (most recent call last):
...
polars.exceptions.ComputeError: aggregation 'item' expected a single value, got 3 values
...
>>> df.head(0).select(pl.col("a").item(allow_empty=True))
shape: (1, 1)
┌──────┐
│ a    │
│ ---  │
│ i64  │
╞══════╡
│ null │
└──────┘

© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.item.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API