1

I have a dataframe which looks like this (with a lot more rows and columns)-

┌────────┬────────────┬────────────┐
│ email  ┆ col1       ┆ col2       │
│ ---    ┆ ---        ┆ ---        │
│ str    ┆ str        ┆ str        │
╞════════╪════════════╪════════════╡
│ email1 ┆ val_col1_1 ┆ val_col2_1 │
│ email2 ┆ val_col1_2 ┆ val_col2_2 │
│ email3 ┆ val_col1_3 ┆ val_col2_3 │
└────────┴────────────┴────────────┘

How can I efficiently update values in the given columns based on checks done for the email column?

This is basically what I want to do

UPDATE df SET col1="someNewValue" WHERE email="someGivenEmail";

I tried iterating over the dataframe to fetch rows which I then tried to update but I couldn't find a function which gives a mutable reference to a row.

Jmb
  • 18,893
  • 2
  • 28
  • 55
parmesant
  • 73
  • 4
  • 1
    `df.with_columns(pl.when(pl.col('email')=='someGivenEmail').then(pl.lit("newValue")).otherwise(pl.col('col1')).alias('col1'))` – elgreco Jul 06 '23 at 16:02

0 Answers0