def __call__(self, fields, geo_for, geo_in=None, cache=NopCache()):
"""Special method to make API object invocable.
Arguments:
* fields: list of variables to return.
* geo_* fields must be given as dictionaries, eg:
`{'county': '*'}`
* cache: cache in which to store results. Not cached by default.
"""
params = {
'get': ','.join(fields),
'key': self.key,
'for': self._geo2str(geo_for),
}
if geo_in:
params['in'] = self._geo2str(geo_in)
j = fetchjson(self.endpoint, cache, self.session, params=params)
ret = pd.DataFrame(data=j[1:], columns=j[0])
for field in fields:
if self.variables[field].get('predicateType') == 'int':
ret[field] = pd.to_numeric(ret[field])
return ret
评论列表
文章目录