Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. import geopandas as gpd
  2. import pandas as pd
  3. import numpy as np
  4.  
  5. county = gpd.read_file('/home/bera/GIS/data/test/kommun.shp')
  6. prices = gpd.read_file('/home/bera/GIS/data/test/housing_prices.shp')
  7.  
  8. price_column = 'price'
  9. zip_area_id_column = 'county_id'
  10.  
  11. inter = gpd.overlay(county,prices)
  12. inter['area'] = inter.area
  13.  
  14. wm = lambda x: np.average(x, weights=inter.loc[x.index, "area"])
  15. f = {price_column: {'weighted_mean' : wm} }
  16. newdf = inter.groupby(zip_area_id_column).agg(f)
  17. newdf.columns = newdf.columns.droplevel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement