I have the following dataframe
import pandas as pd
data = {
"a": [0, 1, 0,1],
"b": [0,0,1,1]
}
#load data into a DataFrame object:
df = pd.DataFrame(data)
The expected output is df2
data = {
"a": [1, 0.75, 0.25,1],
"b": [1,0.25,0.75,1]
}
#load data into a DataFrame object:
df2 = pd.DataFrame(data)
When both a and b are same, the output dataframe should have 1. If a =0 and b=1 then output dataframe should be 0.25 and 0.75. If a =1 and b=0 then output dataframe should be 0.75 and 0.25. How to do this without for loop? Thanks in advance.