Skip to content
Advertisement

Turn cell into False based another row/column Pandas

I have the following table of boolean values:

JavaScript
index val1 val2 val3 val4 val5 val6
1 True False True True True False
2 False True True False True False
3 False False False True False True
4 True True True False False True

I also have the following dictionary:

JavaScript

How do I change the table so for every key column in dict, if that row has a True value, the value columns turn to False?

index val1 val2 val3 val4 val5 val6
1 True False False True False False
2 False True True False True False
3 False False False True False False
4 True False False False False True

For example, since val1 is True at index 1, val2 and val3 turned to False

I’m doing something like this:

JavaScript

but I get the following error:

JavaScript

Advertisement

Answer

You can’t use if with Series, which is only meant for scalar boolean check. Use conditional update with boolean indexing instead:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement