import pandas as pd
df = pd.DataFrame({
'name':['john','mary','paul','john','mary'],
'num_children':[0,4,5,28,28],
'num_pets':[0,1,2,28,28]
})
df.replace({'name':{'john':'works','mary':'works'}})
I want to do the equivalent of the above code, replace all values in the 'name' column that are not "paul" with "works". The example only has three possible values so it's not too bad, but is there an easier way to do it for a column with much more possible values?
Thanks in advance!