Municipality Latitude Longitude Population2011
0 Agia Paraskevi 38.01263 23.82055 59,704 1 Agios Dimitrios 37.93667 23.73320 71,294 2 Alimos 37.91368 23.71506 41,720
search_query = 'Hospital'
categoryId = '4bf58dd8d48988d104941735'
def getNearbyVenues(names, latitudes, longitudes, radius=500):
venues_list=[]
for name, lat, lng in zip(names, latitudes, longitudes):
# create the API request URL
url = 'https://api.foursquare.com/v2/venues/search?client_id={}&client_secret={}&ll={},{}&v={}&query={}&radius={}&limit={}&locale={}&categoryId={}'.format(CLIENT_ID, CLIENT_SECRET, latitudes, longitudes, VERSION, search_query, radius, LIMIT, locale, categoryId)
# make the GET request
results = requests.get(url).json()["response"]
# return only relevant information for each nearby venue
venues_list.append([(
name,
lat,
lng,
v['venues']['name'],
v['venues']['location']['lat'],
v['venues']['location']['lng']) for v in results])
nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])
return(nearby_venues)
`all_venues = getNearbyVenues(names=result['Municipality'],
latitudes=result['Latitude'],
longitudes=result['Longitude']
)` )
你好! 拜托我需要你的帮忙! 我尝试将每个数据框的坐标设置为输入,以获取每个市镇的医院并创建一个新的数据框。
但是似乎我无法正确解析json(空字典...)
答案 0 :(得分:0)
def getNearbyVenues(names, lat1, long1, radius=3000):
venues_list=[]
for name, lat, lng in zip(names, lat1, long1):
# create the API request URL
url1 = 'https://api.foursquare.com/v2/venues/search?client_id={}&client_secret={}&ll={},{}&v={}&query={}&radius={}&limit={}&locale={}&categoryId={}'.format(CLIENT_ID, CLIENT_SECRET, lat, lng, VERSION, search_query, radius, LIMIT, locale, categoryId)
# make the GET request
results = requests.get(url1).json()["response"]["venues"]
# return only relevant information for each nearby venue
venues_list.append([(
name,
lat,
lng,
v['name'],
v['location']['lat'],
v['location']['lng']) for v in results])
nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])
return(nearby_venues)