Accessing bounding box
Most tweets which have coordinate-level geographical information attached to them typically come in the form of a bounding box. Bounding boxes are a set of four longitudinal/latitudinal coordinates which denote a particular area in which the user can be located. The bounding box is located in the place value of the Twitter JSON.
The dataset has been loaded for you as a DataFrame in tweets_sotu
.
This exercise is part of the course
Analyzing Social Media Data in Python
Exercise instructions
- Complete the
getBoundingBox()
function by accessing the coordinates value within the bounding box dictionary. - Apply the
getBoundingBox()
function to the appropriate column in thetweets_sotu
DataFrame.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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])