Search code examples
pythonpython-polarsrust-polars

Is there a Polars expressions API way to get the number of elements in a list in a cell?


Is there a Polars expressions API way to get the length of a list in a cell? For example, if column "fruits" has a row with ["apple", "banana"], I'd like to create a column n_fruits which has value 2 for that row.

I tried .len() and .count(), but those both count the number of rows in the column.


Solution

  • Use the .list namespace so it's .list.len()