I want to handle non-aligned or missing values (NaN, Inf, -Inf) as 1s or 0s.
df1 = pd.DataFrame({"x":[1, 2, 3, 4, 5],
"y":[3, 4, 5, 6, 7]},
index=['a', 'b', 'c', 'd', 'e'])
df2 = pd.DataFrame({"y":[1, NaN, 3, 4, 5],
"z":[3, 4, 5, 6, 7]},
index=['b', 'c', 'd', 'e', 'f'])
Above code leads to the following
df1 * df2
x y z
a NaN NaN NaN
b NaN 4.0 NaN
c NaN NaN NaN
d NaN 18.0 NaN
e NaN 28.0 NaN
f NaN NaN NaN
I want to ignore NaN, and also handle non-aligned values like 1s in left or right DF or both.
eg.
Case 1: Replace the missing or inconsistent value with df1by 1
df1 * df2
x y z
a 1 3 NaN
b 2 4.0 NaN
c 3 5 NaN
d 4 18.0 NaN
e 5 28.0 NaN
f NaN NaN NaN
Case 2: replace the missing or inconsistent value with df2by 1
df1 * df2
x y z
a NaN NaN NaN
b NaN 4.0 3
c NaN NaN 4
d NaN 18.0 5
e NaN 28.0 6
f NaN 5 7
Case 3: Replace any missing or inconsistent value with 1 if another DF has a value.
df1 * df2
x y z
a 1 3 NaN
b 2 4.0 3
c 3 5 4
d 4 18.0 5
e 5 28.0 6
f NaN 5 7
In the case of addison, I want to treat missing or missing aligned values as 0s.