I want to assign df2's "ID" for rows in df1 that have the same latitude and longitude as a row in df2, or close enough according to `max_lat_offset` and `max_lon_offset`.

This for loop version does what I want, but is slow with large datasets:

```
for df1_index, df1_row in df1.iterrows():
    for df2_index, df2_row in df_2.iterrows():
        if abs(df2_row['latitude'] - df1_row['lat']) < max_lat_offset and abs(df2_row['longitude'] - df1_row['lon']) < max_lon_offset:
            df1.at[df1_index,'id'] = df2_row['ID']

```

Is it possible to use a clever pandas/numpy trick to work this out? I have tried using `np.where`

```
df1['id'] = np.where(abs(df2.latitude - df1.lat) < max_lat_offset and abs(df2.longitude - df1.lon) < max_lon_offset, df2['ID'], None)

```

But I get `ValueError: The truth value of a Series is ambiguous`.

Pandas experts, what's the optimal way to do this?

**Update - here is what the data in the df's look like:**

df1:

```
lat lon id
0   53.045913   -1.410764   NaN
1   57.148783   -6.211683   NaN
2   51.421184   0.824588    NaN
3   51.504658   -0.104954   NaN
4   51.464968   -0.073252   NaN

```

df2:

```
latitude    longitude   ID
0   51.387471   -3.406610   1
1   55.735807   -4.888574   2
2   53.716417   -1.281885   3
3   52.448628   0.725273    4
4   52.230195   -0.881341   5

```

The expected output is df1, modified so that `id` has the df2 `ID` value of a row with sufficiently close latitude and longitude.