[Python] Python + Polar: Split a column of string into list of list

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new to python polar library, may I ask how could I split a column of string into list of list?

    Minimum example:

    df = pl.DataFrame({'test': "A,B,C,1\nD,E,F,2\nG,H,I,3\nJ,K,L,4"})


    I try the following, somehow I stop after the first split

    df = df.with_columns(pl.col('test').str.split('\n')


    My desired result would be it return a list of list, and also convert the forth position of every sublist into Int64

    [["A","B","C",1], ["D","E","F",2], ["G","H","I",3], ["J","K","L",4]]

    Continue reading...

Compartilhe esta Página