How to find the closest match based on 2 keys from one dataframe to another?

前端 未结 2 1981
一向
一向 2020-12-17 00:05

I have 2 dataframes I\'m working with. One has a bunch of locations and coordinates (longitude, latitude). The other is a weather data set with data from weather stations al

2条回答
  •  一个人的身影
    2020-12-17 00:39

    So I appreciate that this is a bit messy, but I used something similar to match genetic data between tables. It relies on the location file longitude and latitude being within 5 of those on the weather file, but these can be changed if need be.

    rows=range(location.shape[0])
    weath_rows = range(weather.shape[0])
    for r in rows:
        lat = location.iloc[r,1]
        max_lat = lat +5
        min_lat = lat -5
        lon = location.iloc[r,2]
        max_lon = lon +5
        min_lon = lon -5
        for w in weath_rows:
            if (min_lat <= weather.iloc[w,2] <= max_lat) and (min_lon <= weather.iloc[w,3] <= max_lon):
                location['Station_Name'] = weather.iloc[w,1]
    

提交回复
热议问题