I am trying to replace values in multiple columns if the value in another column is equal to a specific value. For the df below I want to replace all integers will an empty value if Col A is == ABC
import pandas as pd
df = pd.DataFrame({
'B' : [10,20,30,40,50],
'A' : ['ABC','DEF','XYZ','ABC','DEF'],
'C' : [1,1,1,1,1],
})
Output:
B A C
0 10 ABC 1
1 20 DEF 1
2 30 XYZ 1
3 40 ABC 1
4 50 DEF 1
So I want to replace the integers in Col B,C when A is equal to ABC. I have tried this
mask = df.A != 'ABC'
col = ['B','C']
df = df.loc[mask, col].replace('')
But it only selects the values I want to replace. I'm hoping to produce:
B A C
0 10 ABC 1
1 DEF
2 XYZ
3 40 ABC 1
4 DEF