Skip to main content
Open In ColabOpen on GitHub

开放城市数据

Socrata 提供了一个用于城市开放数据的API。

对于像SF犯罪这样的数据集,请转到右上角的API选项卡。

这为您提供了数据集标识符

使用数据集标识符来获取特定城市ID的表格(data.sfgov.org)-

例如,vw6y-z8j6 用于 SF 311 数据

例如,tmnf-yvry 用于 旧金山警察数据

%pip install --upgrade --quiet  sodapy
from langchain_community.document_loaders import OpenCityDataLoader
API Reference:OpenCityDataLoader
dataset = "vw6y-z8j6"  # 311 data
dataset = "tmnf-yvry" # crime data
loader = OpenCityDataLoader(city_id="data.sfgov.org", dataset_id=dataset, limit=2000)
docs = loader.load()
WARNING:root:Requests made without an app_token will be subject to strict throttling limits.
eval(docs[0].page_content)
{'pdid': '4133422003074',
'incidntnum': '041334220',
'incident_code': '03074',
'category': 'ROBBERY',
'descript': 'ROBBERY, BODILY FORCE',
'dayofweek': 'Monday',
'date': '2004-11-22T00:00:00.000',
'time': '17:50',
'pddistrict': 'INGLESIDE',
'resolution': 'NONE',
'address': 'GENEVA AV / SANTOS ST',
'x': '-122.420084075249',
'y': '37.7083109744362',
'location': {'type': 'Point',
'coordinates': [-122.420084075249, 37.7083109744362]},
':@computed_region_26cr_cadq': '9',
':@computed_region_rxqg_mtj9': '8',
':@computed_region_bh8s_q3mv': '309'}

这个页面有帮助吗?