Код: Выделить всё
import polars as pl
df = pl.DataFrame({
"Column A": [2, 3, 1, 4, 1, 3, 3, 2, 1, 0],
"Column B": [
"Life", None, None, None, "Death", None,
"Life", None, None, "Death"
]
})
Код: Выделить всё
shape: (10, 2)
┌──────────┬──────────┐
│ Column A ┆ Column B │
│ --- ┆ --- │
│ i64 ┆ str │
╞══════════╪══════════╡
│ 2 ┆ Life │
│ 3 ┆ null │
│ 1 ┆ null │
│ 4 ┆ null │
│ 1 ┆ Death │
│ 3 ┆ null │
│ 3 ┆ Life │
│ 2 ┆ null │
│ 1 ┆ null │
│ 0 ┆ Death │
└──────────┴──────────┘
Конечный результат должен выглядеть следующим образом:
Код: Выделить всё
shape: (10, 3)
┌──────────┬──────────┬──────────┐
│ Column A ┆ Column B ┆ Column C │
│ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ f64 │
╞══════════╪══════════╪══════════╡
│ 2 ┆ Life ┆ 4.0 │
│ 3 ┆ null ┆ null │
│ 1 ┆ null ┆ null │
│ 4 ┆ null ┆ null │
│ 1 ┆ Death ┆ null │
│ 3 ┆ null ┆ null │
│ 3 ┆ Life ┆ 3.0 │
│ 2 ┆ null ┆ null │
│ 1 ┆ null ┆ null │
│ 0 ┆ Death ┆ null │
└──────────┴──────────┴──────────┘
Подробнее здесь: https://stackoverflow.com/questions/780 ... -in-polars
Мобильная версия