Spec-Zone.ru › Polars

polars.count

polars.count(
    *columns: str,
) → Expr

Return the number of non-null values in the column.

This function is syntactic sugar for col(columns).count().

Calling this function without any arguments returns the number of rows in the context. This way of using the function is deprecated. Please use len() instead.

Parameters:
*columns

One or more column names.

Returns:
Expr

Expression of data type UInt32.

See also

Expr.count

Examples

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2, None],
...         "b": [3, None, None],
...         "c": ["foo", "bar", "foo"],
...     }
... )
>>> df.select(pl.count("a"))
shape: (1, 1)
┌─────┐
│ a   │
│ --- │
│ u32 │
╞═════╡
│ 2   │
└─────┘

Return the number of non-null values in multiple columns.

>>> df.select(pl.count("b", "c"))
shape: (1, 2)
┌─────┬─────┐
│ b   ┆ c   │
│ --- ┆ --- │
│ u32 ┆ u32 │
╞═════╪═════╡
│ 1   ┆ 3   │
└─────┴─────┘

Return the number of rows in a context. This way of using the function is deprecated. Please use len() instead.

>>> df.select(pl.count())  
shape: (1, 1)
┌───────┐
│ count │
│ ---   │
│ u32   │
╞═══════╡
│ 3     │
└───────┘

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

Spec-Zone.ru

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