I have a a Polars Dataframe:
import polars as pl
pl.Config(fmt_table_cell_list_len=8, fmt_str_lengths=80)
df = 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 not considering the empty strings.
df.with_columns(pl.col('test_names').list.len().alias('tot_names'))
┌─────────────────────────────────────────────────────────────┬───────────┐
│ test_names ┆ tot_names │
│ --- ┆ --- │
│ list[str] ┆ u32 │
╞═════════════════════════════════════════════════════════════╪═══════════╡
│ ["Mallesham", "", "Bhavik", "Jagarini", "Jose", "Fernando"] ┆ 6 │
│ ["", "", "", "ABC", "", "XYZ"] ┆ 6 │
└─────────────────────────────────────────────────────────────┴───────────┘
Here it is including empty strings in the count, but I would like to filter them out and get:
┌─────────────────────────────────────────────────────────────┬───────────┐
│ test_names ┆ tot_names │
│ --- ┆ --- │
│ list[str] ┆ u32 │
╞═════════════════════════════════════════════════════════════╪═══════════╡
│ ["Mallesham", "", "Bhavik", "Jagarini", "Jose", "Fernando"] ┆ 5 │
│ ["", "", "", "ABC", "", "XYZ"] ┆ 2 │
└─────────────────────────────────────────────────────────────┴───────────┘