I have a DataFrame like below
df = pd.DataFrame({
'A' : [x,x,x,x,x],
'B' : [1,2,1,1,2]
})
I would like to replace x by y where df['B'] == 2 I know there are lots of ways but what is the shortest code to accomplish this? I believe np.where is one way but can it change value (or overwrite variable) based on values in another column?