I have two Pandas DataFrames containing "lat"
and "long"
coordinates. I'd like to do a spatial join and merge columns from one DataFrame
into another.
import pandas as pd
df1 = pd.DataFrame(data={
'name': ['post', 'sutter', 'oak'],
'Lat': [37.788151, 37.789551, 37.815730],
'Long': [-122.407570, -122.408302, -122.288810]
})
df2 = pd.DataFrame(data={
'id': [0, 1, 2],
'col1': ['xx','yy','zz'],
'Lat': [37.787994, 37.789575, 37.813122],
'Long': [-122.407419, -122.408312, -122.288810]
})
When a match is found based on the "lat"
, "long"
coordinates, the join
/ output would look like this:
name Lat Long col1
post 37.788151 -122.407570 xx
sutter 37.789551 -122.408302 NaN
oak 37.815730 -122.288810 NaN
Open to ideas on how to implement this solution? Spatial joins or maybe using reverse geocoding
API to get addresses from "Lat"
"Long"
and then join on them?
points_from_xy
. create buffer for points (any one geodataframe) and sjoinLat
,Long
and join on address.