polars.Series.list.to_map#

Series.list.to_map() → Series[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 Series.map.entries().

Examples

>>> s = pl.Series([[{"key": "a", "value": 1}, {"key": "b", "value": 2}]])
>>> s.list.to_map()
shape: (1,)
Series: '' [map[str, i64]]
[
        {"a": 1, "b": 2}
]