Geographical data in Twitter JSON

Analyzing Social Media Data in Python

Alex Hanna

Computational Social Scientist

Locations in Twitter text

Tweet with location text

Analyzing Social Media Data in Python

User-defined location

User-defined location

print(tweet['user']['location'])
Bay Area
Analyzing Social Media Data in Python

place JSON

Bounding box illustration

print(tweet['place'])
{'attributes': {},
 'bounding_box': {'coordinates': 
  [[[-80.47611, 37.185195],
    [-80.47611, 37.273387],
    [-80.381618, 37.273387],
    [-80.381618, 37.185195]]],
  'type': 'Polygon'},
 'country': 'United States',
 'country_code': 'US',
 'full_name': 'Blacksburg, VA',
 'name': 'Blacksburg',
 'place_type': 'city',
 ...}
Analyzing Social Media Data in Python

Calculating the centroid

Bounding box illustration

coordinates = [
    [-80.47611, 37.185195],
    [-80.47611, 37.273387],
    [-80.381618, 37.273387],
    [-80.381618, 37.185195]]

longs = np.unique( [x[0] for x 
    in coordinates] )
lats  = np.unique( [x[1] for x 
    in coordinates] )

central_long = np.sum(longs) / 2
central_lat  = np.sum(lats) / 2
Analyzing Social Media Data in Python

coordinates JSON

Single coordinate place

print(tweet['coordinates'])
{'type': 'Point', 
'coordinates': [-72.2833, 
                 21.7833]}
Analyzing Social Media Data in Python

Let's practice!

Analyzing Social Media Data in Python

Preparing Video For Download...