I was doing an exercise from Automating GIS Processes courses and one of the tasks required me to join a YKR grid cell data set with two data sets of travel times to two shopping centres from every other place in the Helsinki metropolitan area.
Here's the head of the YKR grid cell data set:
# YKR grid cell data set
import geopandas as gpd
grid = gpd.read_file(DATA_DIRECTORY / "YKR_grid_EPSG3067.gpkg")
grid.head()
Here's the travel time data set for shopping centre 1(Itis) (I removed the unnecessary column & replace -1 values with NaN):
shopping_centres_itis = shopping_centres_itis[["from_id","to_id","pt_r_t","car_r_t"]]
shopping_centres_itis = shopping_centres_itis.rename(columns = {'pt_r_t' : 'pt_r_t_Itis', 'car_r_t' : 'car_r_t_Itis'})
shopping_centres_itis['pt_r_t_Itis'] = shopping_centres_itis['pt_r_t_Itis'].replace({-1: numpy.nan})
shopping_centres_itis['car_r_t_Itis'] = shopping_centres_itis['car_r_t_Itis'].replace({-1: numpy.nan})
shopping_centres_itis.head()
Here's the data set for shopping complex 2 (Myyrmanni)
shopping_centres_myyrmanni = shopping_centres_myyrmanni[["from_id","to_id","pt_r_t","car_r_t"]]
shopping_centres_myyrmanni = shopping_centres_myyrmanni.rename(columns = {'pt_r_t' : 'pt_r_t_Myyrmanni', 'car_r_t' : 'car_r_t_Myyrmanni'})
shopping_centres_myyrmanni['pt_r_t_Myyrmanni'] = shopping_centres_myyrmanni['pt_r_t_Myyrmanni'].replace({-1: numpy.nan})
shopping_centres_myyrmanni['car_r_t_Myyrmanni'] = shopping_centres_myyrmanni['car_r_t_Myyrmanni'].replace({-1: numpy.nan})
shopping_centres_myyrmanni.head()
The question is what is the configuration to join the 2 travel time data frames to the YKR grid GeoDataFrame? Should I rename "from_id" column from the travel time data frames to YKR_ID? I tried .sjoin but failed because the travel time data frames weren't GeoDataFrame. Meanwhile, I got KeyError when doing .join