How to change row's values of a column matching pattern in Julia?

There are two easy ways to do what you want.

df = DataFrame(group=["foo", "notfoo", "foo"], data = 1:3)

Using replace

replace!(df.group, "foo" => "bar")
group data
String Int64
1 bar 1
2 notfoo 2
3 bar 3

Or by indexing as you do in your example

df[df.group .== "foo","group"] .= "bar"

Both of these will do the change inplace.

1 Like