Is there any Polars-based optimization that can be applied to the apply-lambda methodology in this post Remove substring from column based on another column ?
In the polars dataframe below, how could we remove the “_sub
” substrings based on the value of sub
?
import polars as pl
pl.DataFrame(
{"origin": ["id1_COUNTRY", "id2_NAME"],
"sub": ["COUNTRY", "NAME"]}
)
shape: (2, 2)
┌─────────────┬─────────┐
│ origin ┆ sub │
│ --- ┆ --- │
│ str ┆ str │
╞═════════════╪═════════╡
│ id1_COUNTRY ┆ COUNTRY │
│ id2_NAME ┆ NAME │
└─────────────┴─────────┘