polars.Expr.map.get#

Expr.map.get(key: IntoExpr) → Expr[source]#

Look up key in every map.

Maps that do not hold key yield null, as do null maps. Use contains_key() to tell a missing key apart from a key whose value is null.

engine:In MemoryStreamingDistributed
Parameters:
key

Key to look up. A single value is broadcast over all maps. It is cast to the map’s key type, and a key the cast cannot represent exactly, because it is out of range or would be rounded, is absent.

Returns:
Expr

Expression of the map’s value type.

Examples

>>> df = pl.DataFrame(
...     {
...         "m": pl.Series(
...             [{"a": 1, "b": 2}, {}, None], dtype=pl.Map(pl.String, pl.Int64)
...         ),
...         "k": ["b", "a", "a"],
...     }
... )
>>> df.select(
...     pl.col("m").map.get("a").alias("a"),
...     pl.col("m").map.get(pl.col("k")).alias("by_col"),
... )
shape: (3, 2)
┌──────┬────────┐
│ a    ┆ by_col │
│ ---  ┆ ---    │
│ i64  ┆ i64    │
╞══════╪════════╡
│ 1    ┆ 2      │
│ null ┆ null   │
│ null ┆ null   │
└──────┴────────┘