polars.Expr.list.to_map#
- Expr.list.to_map() Expr[source]#
Convert the
ListofStructentries to aMap.The input must be a
ListofStructwith exactly two fields namedkeyandvalue. 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().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} │ └──────────────────┘