Exercise

Calculating the centroid

The bounding box can range from a city block to a whole state or even country. For simplicity's sake, one way we can deal with handling these data is by translating the bounding box into what's called a centroid, or the center of the bounding box. The calculation of the centroid is straight forward -- we calculate the midpoints of the lines created by the latitude and longitudes.

numpy has been imported as np.

Instructions

100 XP
  • Obtain the first set of coordinates from the place JSON.
  • Calculate the central longitude by adding up the longitude list and dividing by two.
  • Do the same for the latitudes.
  • Apply the calculateCentroid() function to the place column.