How can I have the comparison between two pandas dataframe rows considering an acceptable deviation instead of a 100% match?
For example:
Acceptable deviation: 10
column1 | column2 | Result
100 | 110 | True
0 | 20 | False
0 | 9 | True
I wasn’t able to find any references to built-in functions or similar scenarios.
>Solution :
Use:
df['Result'] = abs(df['column1'] - df['column2']) <= 10
print(df)
# Output:
column1 column2 Result
0 100 110 True
1 0 20 False
2 0 9 True
Alternative, chained methods:
df['Result'] = df['column1'].sub(df['column2']).abs().le(10)