I have two dataframes (with unequal rows, but the same columns) such as the following.
DataFrame A:
dummy | probability
-------------------
0 | .1
-------------------
0 | .2
DataFrame B:
dummy | probability
-------------------
1 | .05
-------------------
1 | .2
What I would like to do is implement a vectorized conditional check for pairwise elements.
My actual dataset has a few hundred thousand elements. So if I check element wise, using a double for loop would require at least 100000^2 iterations which I do not want at all.
I believe there is probably a way to do this using numpy and pandas that I am currently unaware of.
pseudocode should look something like this:
def vectorized_counts():
A = 0
B = 0
tie = 0
if element in dfA second column > element in dfB second column:
A += 1
elif element in dfA second column < element in dfB second column:
B += 1
else:
tie += 1
return list(A,B,tie)
For my test example above, we have:
A
.1 > .05
.2 > .05
B
.1 < .2
tie
.2 = .2
Hence:
A = 2
B = 1
tie = 1
What way can I go about this? It is simple enough to compare one element of a dataframe with the corresponding element of another dataframe. What is confusing me is how to compare every element of a dataframe with every element of another dataframe.