Skip to content

Instantly share code, notes, and snippets.

@gbarreiro
Last active September 22, 2020 09:31
Show Gist options
  • Save gbarreiro/a7e94cc7332bda25ec182370d462b7af to your computer and use it in GitHub Desktop.
Save gbarreiro/a7e94cc7332bda25ec182370d462b7af to your computer and use it in GitHub Desktop.
Best cuisines: get the number of restaurants for each cuisine on each city
restaurants = pd.DataFrame(columns=['City', 'Cuisine', 'Number of restaurants']) # define the DataFrame where the results will be stored
for city in cities:
for cuisine_name, category_id in cuisines.items():
# For each city, retrieve the top restaurants from Foursquare for each cuisine...
query = requests.get("{url}&near={city}&categoryId={category_id}".format(url=URL, city=city, category_id=category_id))
if query.status_code == 200:
number = query.json()
restaurants = restaurants.append({
'City': city,
'Cuisine': cuisine_name,
'Number of restaurants': number
}, ignore_index=True)
restaurants # print the results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment