0

Say I have two pandas dataframes, both containing x and y coordinates (floats). I want to join the dataframes on the two columns, i.e. where df1['x']==df2['x'] && df1['y']==df2['y'] within some tolerance to get a result like so:

df1=  x  ,  y  ,  tag1 
     1.2   1.3    'ab'

df2=  x  ,  y  ,  tag2 
     1.1   1.2    'cd'

becomes

df_result=  x  ,  y  ,  tag1 , tag2
           1.2   1.3    'ab'   'cd'

In the example the tolerance would be 0.1.

Is this possible with pandas while specifying some tolerance to account for float problems?

Of course, I could iterate, but usually, that is wrong when using pandas.

  • `df1.merge(df2,on = ['x','y'],how ='inner')` – ansev Jan 22 '20 at 10:22
  • @ansev so we can't specify/use a tolerance? Or does that happen automatically? – Ruben Kruepper Jan 22 '20 at 10:24
  • 2
    Yes we can use: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.merge_asof.html , I am not sure if it is duplicates, so I am going to upvote to reopen, please edit your question showing an example of the tolerance that you want to use – ansev Jan 22 '20 at 10:30
  • @ansev as_of only works on one column. This question asks for multiple columns. – rocksNwaves Oct 21 '21 at 14:40

0 Answers0