Function len

  • Return the number of elements in the column. This is similar to COUNT(*) in SQL.

    Returns pl.Expr

    Expr - Expression of data type :class:UInt32.

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

    Generate an index column by using len in conjunction with :func:intRange.

    >>> df.select(
    ... pl.intRange(pl.len(), dtype=pl.UInt32).alias("index"),
    ... pl.all(),
    ... )
    shape: (3, 4)
    ┌───────┬──────┬──────┬─────┐
    indexabc
    │ --- ┆ --- ┆ --- ┆ --- │
    u32i64i64str
    ╞═══════╪══════╪══════╪═════╡
    013foo
    12nullbar
    2nullnullfoo
    └───────┴──────┴──────┴─────┘