For example, I have two dataframes like:
dataframe1 would be
A B C D E
values1 0.25 0.33 0.12 0.22 0.08
values2 0.20 0.50 0.89 0.65 0.75
and dataframe2 would be
A B C D E
boolean1 True False True False True
boolean2 False False True True True
and want a result with one dataframe:
A B C D E
1 0.25 0 0.12 0 0.08
2 0 0 0.89 0.65 0.78
So if it is True in dataframe2 just bring the value from the dataframe1 and if it is False then replace with 0. How can I do this?
>Solution :
You can use
df1 = df1.where(df2.values, 0)
# or
df1 = df1.mask(~df2.values, 0)
print(df1)
A B C D E
values1 0.25 0.0 0.12 0.00 0.08
values2 0.00 0.0 0.89 0.65 0.75