Created
May 6, 2021 06:35
-
-
Save lmeulen/cd9c3c27614c43e18abb83cb3d0fadd6 to your computer and use it in GitHub Desktop.
traveltime_traveltime_per_pc4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pc = gpd.read_file(os.path.join('PC_4-shp','PC4.shp')) | |
df = pd.read_csv(OUTPUT) | |
gdf = gpd.GeoDataFrame(df, | |
geometry=gpd.points_from_xy(df.EndLon, df.EndLat)) | |
[['geometry', 'DurationMin']] | |
def get_avg_traveltime(pc4): | |
v = gdf[gdf.within(pc4['geometry'] )].mean(skipna=True) | |
if math.isnan(v): | |
return np.NaN | |
else: | |
return int(v[0]) | |
pc['Traveltime'] = pc.apply(lambda x: get_avg_traveltime(x), axis=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment