polars.Expr.list.to_map#

Expr.list.to_map() → Expr[source]#

Convert the List of Struct entries to a Map.

The input must be a List of Struct with exactly two fields named key and value. Keys must not be null; duplicate keys within a row are resolved by keeping the first position and the last value.

The inverse of Expr.map.entries().

engine:In MemoryStreamingDistributed

Examples

>>> df = pl.DataFrame(
...     {"m": [[{"key": "a", "value": 1}, {"key": "b", "value": 2}]]}
... )
>>> df.select(pl.col("m").list.to_map())
shape: (1, 1)
┌──────────────────┐
│ m                │
│ ---              │
│ map[str, i64]    │
╞══════════════════╡
│ {"a": 1, "b": 2} │
└──────────────────┘