Reputation: 16375
I first try to replace all the values that have "LOSE" with 0.
df.mask(df == 'LOSE', 0,inplace=True)
This works fine. I want to replace multiple values with 1.
df.mask(df in ['WIN','FREE','PENALTY','DRAW'],1, inplace=True)
This does not work:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Any ideas how to express replacing multiple values in a data-frame.
Upvotes: 0
Views: 931
Reputation: 323226
You should use isin
df.mask(df.isin(['WIN','FREE','PENALTY','DRAW']),1, inplace=True)
Upvotes: 4