1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to filter empty strings from a list column of Python Polars Dataframe?

Discussão em 'Python' iniciado por Stack, Setembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I have a python polars dataframe as-

    df_pol = pl.DataFrame({'test_names':[['Mallesham','','Bhavik','Jagarini','Jose','Fernando'],
    ['','','','ABC','','XYZ']]})


    I would like to get a count of elements from each list in test_names field not considering the empty values.

    df_pol.with_columns(pl.col('test_names').list.len().alias('tot_names'))


    [​IMG]

    Here it is considering empty strings into count, this is why we can see 6 names in list-2. actually it has only two names.

    required output as:

    [​IMG]

    Continue reading...

Compartilhe esta Página