'How to use pandas.merge with some tolerance

I am trying to compare two pandas dataframes and merge the results with some tolerancing of the values. For example, I have two dataframes that have x-, y-position, and frame number. I want to merge these if the frame number is equal and the x- and y-values are within a range of 3.0. Just using pandas.merge requires the x- and y-values to be the exact same. Is there a way to have some tolerance built in to this merging function?



Solution 1:[1]

Try using pd.merge_asof:

df3 = pd.merge_asof(df1, df2, ..., tolerance=3.0)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 richardec