def _nearest_neighbor(df1, df2):
"""
For a DataFrame of xy coordinates find the nearest xy
coordinates in a subsequent DataFrame
Parameters
----------
df1 : pandas.DataFrame
DataFrame of records to return as the nearest record to records in df2
df2 : pandas.DataFrame
DataFrame of records with xy coordinates for which to find the
nearest record in df1 for
Returns
-------
df1.index.values[indexes] : pandas.Series
index of records in df1 that are nearest to the coordinates in df2
"""
kdt = KDTree(df1.as_matrix())
indexes = kdt.query(df2.as_matrix(), k=1, return_distance=False)
return df1.index.values[indexes]
评论列表
文章目录