เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การสร้าง GeoDataFrame และตรวจสอบ geometry

มาดูกันว่า service district ต่างๆ ในเมืองแนชวิลล์อยู่ที่ไหนบ้าง โดยได้เก็บ path ของไฟล์ shapefile ไว้ในตัวแปร shapefile_path แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การแสดงผลข้อมูลเชิงภูมิศาสตร์ด้วย Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Import geopandas โดยใช้ alias ทั่วไปว่า gpd
  • อ่านไฟล์ shapefile ของ service district ด้วย geopandas แล้วดู 5 แถวแรกโดยใช้เมธอด head()
  • แสดงค่าใน geometry field ของแถวแรก (ชื่อแถวคือ '0') เพื่อดูข้อมูลที่อยู่ในฟิลด์นั้น โดยส่ง service_district.loc[0, 'geometry'] เข้าไปในฟังก์ชัน print()

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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, '____'])
แก้ไขและรันโค้ด