Polars add elements to list
00:32 31 Dec 2025

Suppose I have the following polars DataFrame:

df = pl.DataFrame({"a": [["A111", "A110"], ["Z254"], ["B897", "C768", "D456"]]})

Now, at each list element, I want to add an element formed by the first character of that list element followed by 3 zeros.

This is the expected result:

df = pl.DataFrame({"a": [["A111", "A000", "A110", "A000"], ["Z254", "Z000"], ["B897", "B000", "C768", "C000", "D456", "D000"]]})

How can I do that?

Reading the documentation of the list namespace I cannot find anything to add an element

python-polars polars