How do update a single cell of Scala Dataframe?

Hi how’s it going?

Here is a sample dataframe:

    var df = Seq(("Bob","Male","20"),("Jenn","Female","25")).toDF("Name","Gender","Age")

Screenshot from 2020-11-09 13-18-02

I want to change the age of the “Bob” row to 30.

    var name_to_change = "Bob"
    var new_age = 30

How would I go about this?

Check out .filter and .withColumn that should get you going in the right direction.

1 Like

I would suggest .withColumn and when(...) otherwise ....

1 Like