I have this dataframe
import polars as pl
df = pl.from_repr("""
┌─────┬───────┐
│ one ┆ two │
│ --- ┆ --- │
│ str ┆ str │
╞═════╪═══════╡
│ a ┆ hola │
│ b ┆ world │
└─────┴───────┘
""")
And I want to change hola for hello:
shape: (2, 2)
┌─────┬───────┐
│ one ┆ two │
│ --- ┆ --- │
│ str ┆ str │
╞═════╪═══════╡
│ a ┆ hello │ # <-
│ b ┆ world │
└─────┴───────┘
How can I change the values of a row based on a condition in another column?
For instance, with PostgreSQL I could do this:
UPDATE my_table SET two = 'hello' WHERE one = 'a';
Or in Spark
my_table.withColumn("two", when(col("one") == "a", "hello"))
I've tried using with_columns(pl.when(pl.col("one") == "a").then("hello")) but that changes the column "one".
EDIT: I could create a SQL instance and plot my way through via SQL but there must be way to achieve this via the Python API.