Код: Выделить всё
import pandas as pd
df = pd.DataFrame({'a': [1,2,3], 'b':[[1,2,3], [2], [5,0]]})
a b
0 1 [1, 2, 3]
1 2 [2]
2 3 [5, 0]
df.assign(c=df['b'].str.len())
a b c
0 1 [1, 2, 3] 3
1 2 [2] 1
2 3 [5, 0] 2
Код: Выделить всё
import polars as pl
dfp = pl.DataFrame({'a': [1,2,3], 'b':[[1,2,3], [2], [5,0]]})
dfp.with_columns(pl.col('b').map_elements(lambda x: len(x)).alias('c'))
Лучше как это сделать в Polars?
Подробнее здесь: https://stackoverflow.com/questions/747 ... ist-column