Мой фрейм данных:
Код: Выделить всё
import polars as pl
df = (pl.DataFrame({"Products": ["cell_foo","cell_fooFlex","cell_fooPro"]}))
Код: Выделить всё
mapping= {
"cell_foo" : "cell",
"cell_fooFlex" : "cell",
"cell_fooPro": "cell"
}
(df.with_columns(pl.col("Products").str.replace_many(mapping ).alias("Replaced")))
Код: Выделить всё
shape: (3, 2)
┌──────────────┬──────────┐
│ Products ┆ Replaced │
│ --- ┆ --- │
│ str ┆ str │
╞══════════════╪══════════╡
│ cell_foo ┆ cell │
│ cell_fooFlex ┆ cellFlex │
│ cell_fooPro ┆ cellPro │
└──────────────┴──────────┘
Код: Выделить всё
shape: (3, 2)
┌──────────────┬──────────┐
│ Products ┆ Replaced │
│ --- ┆ --- │
│ str ┆ str │
╞══════════════╪══════════╡
│ cell_foo ┆ cell │
│ cell_fooFlex ┆ cell │
│ cell_fooPro ┆ cell │
└──────────────┴──────────┘
Подробнее здесь: https://stackoverflow.com/questions/796 ... -in-polars
Мобильная версия