Reputation: 439
Probably a quick and easy task for most of the people here. Though, for me starter in python in gave some problems. Lets say we have:
DATA.
g=pd.DataFrame({'AGGRESSION':[0,1,0,0,1], 'DECEPTIVENESS':[0,1,0,0,0]},index= [1,2,3,4,5])
QUESTION AND DESIRED RESULT. I would like to iterate through rows check for rows where aggresiveness and deceptivness both equal to 1, leave 1 only for deceptivness in the relevant row.
g['AGRESSION']=[0,0,0,0,1]
g['DECEPTIVENESS']=[0,1,0,0,0]
Upvotes: 0
Views: 44
Reputation: 214957
You can use Series.where
:
g['AGGRESSION'] = g['AGGRESSION'].where(~((g['AGGRESSION'] == 1) & (g['DECEPTIVENESS'] == 1)), 0)
or Simply:
g['AGGRESSION'][(g['AGGRESSION'] == 1) & (g['DECEPTIVENESS'] == 1)] = 0
Upvotes: 2