I have two Polars Series that contain lists as objects, something like:
series1 = pl.Series(["[1.2, 3.4]", "[5.6, 7.8]", "[9.1, 2.3]"])
series2 = pl.Series(["[1.0, 3.0]", "[5.0, 7.0]", "[9.0, 2.0]"])
I need to operate with both of them, so I'm doing:
def parse_list(string_rep):
return ast.literal_eval(string_rep)
parsed_series1 = series1.map_elements(parse_list)
parsed_series2 = series2.map_elements(parse_list)
However, my original series are very big, and the operation above is taking around 30min to run. In my case, it isn't acceptable.
I was thinking in to cast the Series instead, something like:
series1.cast(pl.List)
but I'm getting a Series where all the elements are null:
Any help is highly appreciated.
Polars version: 0.20.9

As mentioned, in this case the strings you're working are valid JSON.
Meaning you can use
.str.json_decode()