Skip to content

narwhals.Series.list

len() -> SeriesT

Return the number of elements in each list.

Null values count towards the total.

Returns:

Type Description
SeriesT

A new series.

Examples:

>>> import pyarrow as pa
>>> import narwhals as nw
>>> s_native = pa.chunked_array([[[1, 2], [3, 4, None], None, []]])
>>> s = nw.from_native(s_native, series_only=True)
>>> s.list.len().to_native()
<pyarrow.lib.ChunkedArray object at ...>
[
  [
    2,
    3,
    null,
    0
  ]
]