More Than a Feeling — it’s a Rating

Photo by Lance Anderson on Unsplash
import pandas as pd
import numpy as np
import requests
import json
#from yelp.client import Client
import matplotlib.pyplot as plt
url = 'https://api.yelp.com/v3'
response = requests.get(url)
# check the status code
response.status_code
MY_API_KEY = "insert_your_key_here"term = 'bagels'
location = 'Boston'
SEARCH_LIMIT = 50
url = 'https://api.yelp.com/v3/businesses/search'headers = {
'Authorization': 'Bearer {}'.format(MY_API_KEY),
}
url_params = {
'term': term.replace(' ', '+'),
'location': location.replace(' ', '+'),
'limit': SEARCH_LIMIT
}
response_bagels = requests.get(url, headers=headers, params=url_params)
print(response_bagels)
bagels = json.loads(response_bagels.text)
print(type(bagels)) #spoiler - jsons are dictionaries
for key in bagels.keys():
print(key)
#making the bagels dictionary a dataframe
bagels_df = pd.DataFrame.from_dict(bagels['businesses'])
bagels_df.columns
df = bagels_df.loc[:,['name', 'rating', 'review_count', 'price', 'location']]
df = df.sort_values('rating', ascending = False)
fig, ax = plt.subplots(figsize = (15,7.5))
x = df['name'][:25]
y = df['rating'][:25]
ax.set_xlabel('Name', fontsize = 17)
ax.set_ylabel('Rating', fontsize = 17)
ax.set_title('Bagel Places Boston', fontsize = 24)
plt.xticks(rotation=80, fontsize = 15)
ax.bar(x,y, color = 'dodgerblue')
plt.savefig('../data/Bagels_namerating')
Photo by Katarzyna Grabowska on Unsplash | Charles River

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store