访问边界框
大多数带有坐标级地理信息的推文通常以边界框(bounding box)的形式提供。边界框由四个经度/纬度坐标组成,用于表示用户可能所在的特定区域。该边界框位于 Twitter JSON 的 place 字段中。
数据集已为您加载为 DataFrame,名称为 tweets_sotu。
本练习是课程的一部分
在 Python 中分析社交媒体数据
练习说明
- 通过访问边界框字典中的 coordinates 值,完善
getBoundingBox()函数。 - 将
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])