Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import geopandas as gpd
- import pandas as pd
- import numpy as np
- county = gpd.read_file('/home/bera/GIS/data/test/kommun.shp')
- prices = gpd.read_file('/home/bera/GIS/data/test/housing_prices.shp')
- price_column = 'price'
- zip_area_id_column = 'county_id'
- inter = gpd.overlay(county,prices)
- inter['area'] = inter.area
- wm = lambda x: np.average(x, weights=inter.loc[x.index, "area"])
- f = {price_column: {'weighted_mean' : wm} }
- newdf = inter.groupby(zip_area_id_column).agg(f)
- newdf.columns = newdf.columns.droplevel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement