Skip to content

narwhals.Series.map

get

get(key: NonNestedLiteral) -> SeriesT

Return the value for key in each map.

The result is null where the map is null or does not contain key.

Parameters:

Name Type Description Default
key NonNestedLiteral

Key to look up. Its type should match the map's key type.

required

Examples:

>>> import polars as pl
>>> import narwhals as nw
>>> s_native = pl.Series(
...     [{"x": 1, "y": 2}, {"y": 3}, None], dtype=pl.Map(pl.String, pl.Int64)
... )
>>> s = nw.from_native(s_native, series_only=True)
>>> s.map.get("y").to_list()
[2, 3, None]