探索巴黎行政區(II)
在前一個練習中,我們使用了 GeoDataFrame 客製化的 plot() 方法,產生資料集中幾何物件的簡單視覺化。GeoDataFrame 和 GeoSeries 物件可以視為「具空間意識」的 DataFrame 與 Series。與它們在 pandas 中的對應類型相比,還多了空間專用的方法與屬性。
GeoDataFrame 的 .geometry 屬性會回傳包含幾何物件的欄作為 GeoSeries,不論該欄實際名稱為何(預設情況下也會叫作「geometry」)。
另一個額外的空間功能例子是 area 屬性,可取得多邊形的面積。
已經以 geopandas 名稱匯入 GeoPandas,且行政區資料集已指派為變數 districts。
本練習屬於課程
在 Python 中處理地理空間資料
練習說明
- 使用
type()函式檢查districts是哪一種物件。 - 取用
districts這個 GeoDataFrame 的geometry屬性,並列印此物件的型別。 - 顯示 geometry 的前 5 列。
- 檢視各行政區幾何的面積。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Check what kind of object districts is
print(type(____))
# Check the type of the geometry attribute
print(____)
# Inspect the first rows of the geometry
print(districts.____)
# Inspect the area of the districts
print(districts.____)