Here is an example dataframe:
X Y Z
1 0 1
0 1 0
1 1 1
Now, here is the rule I've come up with:
- X is left as is
- If Y is equal to 1 set the corresponding value in X to 0
- If Z is equal to 1 set the corresponding value in X and Y to 0
The final dataframe should look like this:
X Y Z
0 0 1
0 1 0
0 0 1
My first thought at a solution is this:
df_null_list = ['X']
for i in ['Y', 'Z']:
df[df[i] == 1][df_null_list] = 0
df_null_list.append(i)
When I do this and sum across the y axis, i'm starting to get values of 2 and 4 which don't make sense. Note, i'm referring to when I ran this on the actual dataset.
Do you have any suggestions for improvements or alternative solutions?