開始使用免費開始

距離社區中心的藝術品距離

現在你已經有中心點與藝術品位置,且單位已換成可用來計算公尺距離,是時候執行距離計算了。

本練習屬於課程

在 Python 視覺化地理空間資料

檢視課程

練習說明

  • 匯入可協助漂亮列印的套件。
  • 走訪 art_dist_meters 建立字典 art_distances,以 title 為鍵,並以從 centerdistance() 為值。將 center 作為 GeoSeries.distance()other 參數傳入。
  • 使用 pprintpprint 方法來漂亮列印 art_distances

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import package for pretty printing
import ____

# Build a dictionary of titles and distances for Urban Residents art
art_distances = {}
for row in ____.iterrows():
    vals = row[1]
    key = vals['title']
    ctr = vals[____]
    art_distances[key] = vals['geometry'].distance(____)

# Pretty print the art_distances
____.____(art_distances)
編輯並執行程式碼