在多邊形內彙總點資料
既然你已經把 art 和 neighborhoods 做了空間連接,你就可以對資料進行分組、彙總與排序,找出哪個鄰里有最多的公共藝術。你可以計算作品標題的數量,來看每個鄰里各有多少件作品。
本練習屬於課程
在 Python 視覺化地理空間資料
練習說明
- 從
neighborhood_art只取出name和title,然後依每個鄰里的名稱(name)分組。將結果存成neighborhood_art_grouped。 - 對
neighborhood_art_grouped進行彙總,查看每個多邊形內有多少件作品。使用.agg('count')來取得各鄰里的作品數量,並用.sort_values()排序,by設為title、ascending設為False。列印結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Get name and title from neighborhood_art and group by name
neighborhood_art_grouped = neighborhood_art[['name', 'title']].groupby(____)
# Aggregate the grouped data and count the artworks within each polygon
print(____.agg('count').sort_values(by = ____, ascending = False))