시작하기무료로 시작하기

공간 조인과 개수 집계

geopandas 코로플레스 플로팅을 준비하기 위해, 건축 허가 데이터를 시의회 선거구와 공간 조인하여 GeoDataFrame을 만듭니다. 그다음 각 선거구에서 발급된 건축 허가 건수를 구할 수 있습니다.

이 연습은 강의의 일부입니다

Python으로 지리공간 데이터 시각화하기

강의 보기

연습 안내

  • permits, council_districts.crs, 그리고 permitsgeometry를 사용해 permits_geo를 생성하세요.
  • permits_geocouncil_districts를 공간 조인하여 각 시의회 선거구 within에 속하는 건축 허가만 얻으세요. 이 결과를 permits_by_district라고 하세요.
  • groupby()size() 메서드를 체이닝하여 각 선거구의 허가 건수를 permit_counts로 계산하세요.
  • permit_counts로부터 counts_df를 생성하고, 인덱스를 재설정한 뒤 열 이름을 districtbldg_permits로 지정하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Create permits_geo
permits_geo = gpd.GeoDataFrame(____, crs = ____.____, geometry = ____.____)

# Spatially join permits_geo and council_districts
permits_by_district = gpd.sjoin(____, ____, ____ = ____)
print(permits_by_district.head(2))

# Count permits in each district
permit_counts = permits_by_district.____(____).____()

# Convert permit_counts to a df with 2 columns: district and bldg_permits
counts_df = ____.to_frame()
counts_df = counts_df.____()
counts_df.____ = ['district', 'bldg_permits']
print(counts_df.head(2))
코드 편집 및 실행