Quantcast
Viewing all articles
Browse latest Browse all 14069

How to get an index of max value element from a list column in python polars?

I have a data frame:

pl.DataFrame({'no_of_docs':[[9,4,2],                            [3,9,1,10],                            [10,3,2,1],                            [10,30],                            [1,2,3,6,4,5]]})

Here the column: no_of_docs is a list[int] type one: i would like to add a new column with the max value index from each list?

Another case:

pl.DataFrame({'no_of_docs':[['9','4','2'],                            ['3','9','1','10'],                            ['10','3','2','1'],                            ['10','30'],                            ['1','2','3','6','4','5']]})

Here no_of_docs is a type of list[str] and how to convert it to int and get an index of max value.

Expected output:

Image may be NSFW.
Clik here to view.
enter image description here


Viewing all articles
Browse latest Browse all 14069

Trending Articles