Using the following test data:
df2 = pd.DataFrame(np.random.randn(12, 3), columns=['A', 'B', 'C'])
thresh = .3
df2['matches'] = np.where(df2.A - df2.B < thresh,1,0)
I created the df2['matches'] column showing a value of 1 when df2.A - df2.B < thresh.
A B C matches
0 0.501554 -0.589855 -0.751568 0
1 -0.295198 0.512442 0.466915 1
2 0.074863 0.343388 -1.700998 1
3 0.115432 -0.507847 -0.825545 0
4 1.013837 -0.007333 -0.292192 0
5 -0.930738 1.235501 -0.652071 1
6 -1.026615 1.389294 0.035041 1
7 0.969147 -0.397276 1.272235 0
8 0.120461 -0.634686 -1.123046 0
9 0.956896 -0.345948 -0.620748 0
10 -0.552476 1.376459 0.447807 1
11 0.882275 0.490049 0.713033 0
However, I actually would like to compare all three columns and if the values are within thresh it will return a number corresponding with the amount of matches in df2['matches].
So for example if Col A = 1, B = 2 and C = 1.5 and thresh was .5 the function would return 3 in the ['matches'] column.
Is there a function that already does something similar or can anyone help with this?