存取邊界框
大多數具有座標層級地理資訊的推文,通常會以邊界框(bounding box)的形式出現。邊界框由 4 個經緯度座標組成,用來標示使用者可能所在的特定區域。這個邊界框位在 Twitter JSON 的 place 欄位中。
資料集已為你載入為 tweets_sotu 的 DataFrame。
本練習屬於課程
使用 Python 分析社群媒體資料
練習說明
- 完成
getBoundingBox()函式,從邊界框字典中存取coordinates的值。 - 將
getBoundingBox()函式套用到tweets_sotuDataFrame 中合適的欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
def getBoundingBox(place):
""" Returns the bounding box coordinates."""
return place[____][____]
# Apply the function which gets bounding box coordinates
bounding_boxes = tweets_sotu[____].apply(getBoundingBox)
# Print out the first bounding box coordinates
print(bounding_boxes.values[0])