-1

I need to put the name of the airport from df1 that matches with the lat and lng in df2

I tried using join and groupby but it work

df1:

 name     code     lat     lng
 temp0      a1      3.2    121.9
 temp1      a2      4.9    151.6
 temp2      b1      6.7    125.3

df2:

 city       lat      lng     admin  nearest_airport_lat  nearest_airport_lng
 city 1     4.7     132.6    admin1     4.9                  151.6
 city 2     5.1     142.9    admin1     6.7                  125.3
 city 3     2.2     110.4    admin1     3.2                  121.9

expected output:

  city      lat      lng    admin   nearest_airport_lat nearest_airport_lng   airport
 city 1     4.7     132.6   admin1          4.9                  151.6        temp1

1 Answers1

2

use merge

pd.merge(df1, df2, on=['lat', 'lng'], how= "inner")
Zaynul Abadin Tuhin
  • 28,879
  • 5
  • 20
  • 49