I have three dataframes of the same dimensions. I would like to find common occurrences (1s and -1s) in at least 2 out of the 3 dataframes. I want an output dataframe of the same dimensions in which the elements are in at least two dataframes.
I have written the following example for everyone to understand the problem. In the example I want to find in which positions there is a 1 or a -1 in at least two dataframes.
import pandas as pd
A= {'a': [0, '.', 0, -1],'b': [0, '.', 1, 0], 'c':[1,'.', 0, 1] }
A = pd.DataFrame(data=A)
a b c
0 0 0 1
1 . . .
2 0 1 0
3 -1 0 1
B= {'a': [0, '.', 0, -1],'b': [1, '.', 1, 0], 'c':[1,'.', 0, -1] }
B = pd.DataFrame(data=B)
B
a b c
0 0 1 1
1 . . .
2 0 1 0
3 -1 0 -1
C = {'a': [0, '.', 0, 0],'b': [1, '.', 1, 0], 'c':[0,'.', 0, 0] }
C = pd.DataFrame(data=C)
C
a b c
0 0 1 0
1 . . .
2 0 1 0
3 0 0 0
The desired output would be:
a b c
0 0 1 1
1 . . .
2 0 1 0
3 -1 0 0
So if there is more than one 1 or more than one -1 the result in the output dataframe is 1 or -1 respectively. If there is just one 1 or -1 the result in the output dataframe is 0.
I have kept the dots as they are in the original dataframe but they are insignificant for the problem as they are the same in all three dataframes, always.
I have tried few things but none of them worked.
I would appreciate any help.
Thanks a lot!