Tìm số lượng từ một phép nối không gian
Bạn sẽ sử dụng bộ dữ liệu giấy phép xây dựng được cấp ở Nashville trong năm 2017. DataFrame này, tên là permits, đã được nạp sẵn cho bạn, cùng với GeoDataFrame council_districts.
Bài tập này là một phần của khóa học
Trực quan hóa dữ liệu không gian địa lý bằng Python
Hướng dẫn bài tập
- Tạo cột
geometrytrongpermitstừlatvàlng. - Tạo
permits_geo, một GeoDataFrame, sử dụngpermits, hệ tọa độ (crs) từcouncil_districts, vàgeometrytừpermits. - Dùng phép nối không gian để tìm các giấy phép được cấp
withintừng khu vực hội đồng. In 2 hàng đầu tiên. - Tạo
permit_countsđể hiển thị số giấy phép trong mỗi khu vực, dùnggroupby()và.size(). Inpermit_counts.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
import geopandas as gpd
# Create a geometry column in permits from lat and lng
permits[____] = gpd.points_from_xy(____.____ , ____.____)
# Build a GeoDataFrame: permits_geo
permits_geo = gpd.GeoDataFrame(____, crs = ____.crs, geometry = ____.geometry)
# Spatial join of permits_geo and council_districts
permits_by_district = gpd.____(permits_geo, council_districts, predicate = ____)
print(permits_by_district.head(2))
# Create permit_counts
permit_counts = permits_by_district.groupby([____]).____()
print(permit_counts)