各行政區的樹木密度地圖(2)
現在我們已經取得各行政區的樹木數量,可以繪製一張以樹木密度著色的行政區地圖。
為此,你需要先把前一步計算出的各行政區樹木數量(trees_by_district)合併回行政區資料集。我們會使用 pd.merge() 函式,根據共同欄位把兩個 DataFrame 做連接。
由於各行政區的面積不同,視覺化樹木密度(樹木數量相對於面積)會是更公平的比較方式。
行政區資料集已預先載入為 districts,上一題的最終結果(每個行政區的樹木數量 DataFrame)可用作 trees_by_district。GeoPandas 已以 geopandas 匯入,Pandas 以 pd 匯入。
本練習屬於課程
在 Python 中處理地理空間資料
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print the first rows of the result of the previous exercise
print(trees_by_district.head())
# Merge the 'districts' and 'trees_by_district' dataframes
districts_trees = pd.merge(____)
# Inspect the result
print(districts_trees.head())