Tạo GeoDataFrame và khám phá geometry
Hãy xem các quận dịch vụ (service districts) ở Nashville nằm ở đâu. Đường dẫn tới shapefile của quận dịch vụ đã được lưu trong biến shapefile_path.
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
- Import
geopandasvới bí danh thường dùng làgpd. - Đọc shapefile của quận dịch vụ bằng
geopandasvà xem 5 hàng đầu tiên bằng phương thứchead(). - In trường geometry ở hàng đầu tiên (tên hàng là '0') để xem dữ liệu trong trường đó. Bạn sẽ truyền
service_district.loc[0, 'geometry']vào hàmprint()để thực hiện việc này.
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
import ____ as ____
# Read in the services district shapefile and look at the first few rows.
service_district = gpd.____(shapefile_path)
print(service_district.____())
# Print the contents of the service districts geometry in the first row
print(service_district.loc[0, '____'])