Код: Выделить всё
import polars as pl
df = pl.DataFrame(
{
"ID": ["1", "1", "1", "1", "1"],
"column": ["foo", "foo", "bar", "ham", "egg"],
"table": ["A", "A", "C", "D", "E"],
"value_a": ["tree", tree, None, "bean", None,],
"value_b": ["Lorem", "Ipsum", "Dal", "Curry", "Dish",],
"mandatory": ["M", "M", "M", "CM", "M"]
}
)
print(df)
Код: Выделить всё
shape: (5, 6)
┌─────┬────────┬───────┬─────────┬─────────┬───────────┐
│ ID ┆ column ┆ table ┆ value_a ┆ value_b ┆ mandatory │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ str ┆ str │
╞═════╪════════╪═══════╪═════════╪═════════╪═══════════╡
│ 1 ┆ foo ┆ A ┆ tree ┆ Lorem ┆ M │
│ 1 ┆ foo ┆ B ┆ tree ┆ Ipsum ┆ M │
│ 1 ┆ bar ┆ C ┆ null ┆ Dal ┆ M │
│ 1 ┆ ham ┆ D ┆ bean ┆ Curry ┆ M │
│ 1 ┆ egg ┆ E ┆ null ┆ Dish ┆ M │
└─────┴────────┴───────┴─────────┴─────────┴───────────┘
Код: Выделить всё
shape: (2, 8)
┌───────┬─────┬────────┬───────┬─────────┬─────────┬───────────┬─────────────────────────┐
│ index ┆ ID ┆ column ┆ table ┆ value_a ┆ value_b ┆ mandatory ┆ warning │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ str ┆ str ┆ str ┆ str ┆ str ┆ str │
╞═══════╪═════╪════════╪═══════╪═════════╪═════════╪═══════════╪═════════════════════════╡
│ 0 ┆ 1 ┆ foo ┆ A ┆ tree ┆ Lorem ┆ M ┆ Row value is not unique │
│ 1 ┆ 1 ┆ foo ┆ A ┆ tree ┆ Ipsum ┆ M ┆ Row value is not unique │
└───────┴─────┴────────┴───────┴─────────┴─────────┴───────────┴─────────────────────────┘
Код: Выделить всё
report = (df.with_row_count("index")
.filter(pl.any(pl.col("*").is_null()) & pl.col("mandatory").eq("M"))
.with_columns(pl.lit("Missing value detected").alias("warning"))
)
Подробнее здесь: https://stackoverflow.com/questions/756 ... -in-polars
Мобильная версия