我正在尝试使用API将大数据导入python。但我无法获得整个数据。该请求仅允许检索前1000行。
r = requests.get("https://data.cityofchicago.org/resource/6zsd-86xi.json")
json=r.json()
df=pd.DataFrame(json)
df.drop(df.columns[[0,1,2,3,4,5,6,7]], axis=1, inplace=True) #dropping some columns
df.shape
输出
(1000,22)
该网站包含近600万个数据点。然而,只有1000个被检索。我该如何解决这个问题?分块正确吗?有人可以帮我提供代码吗?
感谢。
答案 0 :(得分:1)
您需要对结果进行分页以获取整个数据集。大多数API将限制单个请求中返回的结果数量。根据{{3}},您需要将$limit
和$offset
参数添加到请求网址。
例如,对于结果的第一页,您将从 -
https://data.cityofchicago.org/resource/6zsd-86xi.json?$limit=1000&$offset=0
然后,对于下一页,您只需增加偏移量 -
https://data.cityofchicago.org/resource/6zsd-86xi.json?$limit=1000&$offset=1000
继续递增,直到您拥有整个数据集。