Код: Выделить всё
import polars as pl
df = pl.from_repr("""
┌─────────┬─────────┬─────────┐
│ Column1 | Column2 | Column3 │
│ --- | --- | --- │
│ str | i64 | str │
╞═════════╪═════════╪═════════╡
│ foo | null | a │
│ null | null | b │
│ bar | 1 | c │
└─────────┴─────────┴─────────┘
""")
Код: Выделить всё
df = df.with_columns(pl.when(pl.col("Column1").is_null()).then(pl.lit("String"))
df = df.with_columns(pl.when(pl.col("Column2").is_null()).then(0))
Код: Выделить всё
shape: (3, 4)
┌─────────┬─────────┬─────────┬─────────┐
│ Column1 ┆ Column2 ┆ Column3 ┆ literal │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ str ┆ i32 │
╞═════════╪═════════╪═════════╪═════════╡
│ foo ┆ null ┆ a ┆ 0 │
│ null ┆ null ┆ b ┆ 0 │
│ bar ┆ 1 ┆ c ┆ null │
└─────────┴─────────┴─────────┴─────────┘
Код: Выделить всё
shape: (3, 3)
┌─────────┬─────────┬─────────┐
│ Column1 ┆ Column2 ┆ Column3 │
│ --- ┆ --- ┆ --- │
│ str ┆ i64 ┆ str │
╞═════════╪═════════╪═════════╡
│ foo ┆ 0 ┆ a │
│ String ┆ 0 ┆ b │
│ bar ┆ 1 ┆ c │
└─────────┴─────────┴─────────┘
Подробнее здесь: https://stackoverflow.com/questions/751 ... -in-python
Мобильная версия