Код: Выделить всё
df = pl.DataFrame({"values": [[[1]], [[2, 3], [5,6]]]})
df.with_columns(
sum=pl.concat_list(pl.col("values")).list.eval(
pl.element().list.sum()))
shape: (2, 2)
┌──────────────────┬───────────┐
│ values ┆ sum │
│ --- ┆ --- │
│ list[list[i64]] ┆ list[i64] │
╞══════════════════╪═══════════╡
│ [[1]] ┆ [1] │
│ [[2, 3], [5, 6]] ┆ [5, 11] │
└──────────────────┴───────────┘
Код: Выделить всё
df.with_columns(
sum=pl.concat_list(pl.col("values")).list.eval(
pl.reduce(lambda e1, e2: e1*e2,pl.element())))
shape: (2, 2)
┌──────────────────┬──────────────────┐
│ values ┆ sum │
│ --- ┆ --- │
│ list[list[i64]] ┆ list[list[i64]] │
╞══════════════════╪══════════════════╡
│ [[1]] ┆ [[1]] │
│ [[2, 3], [5, 6]] ┆ [[2, 3], [5, 6]] │
└──────────────────┴──────────────────┘
Подробнее здесь: https://stackoverflow.com/questions/793 ... st-product
Мобильная версия