I have several dataframes which have a score value. I need to find if any combinations of summed score values exceed a threshold.
import pandas as pd
df1 = pd.DataFrame([
{'Node': 'A', 'Score': 1},
{'Node': 'B', 'Score': 2},
{'Node': 'C', 'Score': 3},
])
df2 = pd.DataFrame([
{'Node': 'D', 'Score': 4},
{'Node': 'E', 'Score': 5},
{'Node': 'F', 'Score': 6},
])
df3 = pd.DataFrame([
{'Node': 'G', 'Score': 7},
{'Node': 'H', 'Score': 8},
{'Node': 'I', 'Score': 9},
])
I need to check if A Score + D Score > threshold, A Score + E Score > threshold, ..., C Score + F Score > threshold.
This will get the number of combinations which exceed the threshold between two dataframes. Is there an efficient way to extend this to find the number of times the threshold has been exceeded for all dataframes and combinations greater than 2 dataframes?
threshold = 10
s1 = df1['Score']
s2 = df2['Score']
s1.apply(lambda x: (x + s2) > threshold).values.sum()
The output should be True if the threshold was exceeded in any combination of dataframes.