Twitter JSON 中的地理数据

在 Python 中分析社交媒体数据

Alex Hanna

Computational Social Scientist

Twitter 文本中的地点

包含地点文本的推文

在 Python 中分析社交媒体数据

用户自定义位置

用户自定义位置

print(tweet['user']['location'])
Bay Area
在 Python 中分析社交媒体数据

place JSON

边界框示意图

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',
 ...}
在 Python 中分析社交媒体数据

计算质心

边界框示意图

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
在 Python 中分析社交媒体数据

coordinates JSON

单一点坐标的地点

print(tweet['coordinates'])
{'type': 'Point', 
'coordinates': [-72.2833, 
                 21.7833]}
在 Python 中分析社交媒体数据

Passons à la pratique !

在 Python 中分析社交媒体数据

Preparing Video For Download...