More Than a Feeling — it’s a Rating


’Tis the season for adventure, specifically a ladies trip. A time to make somewhat post pandemic memories. My friends are all vaccinated so we’ve decided to visit our friend in Boston.

“She said I think I’ll go to Boston” -Augustana

Conveniently the weekend I’m traveling to Boston with the girls, happens to be the same week my brother is moving to Boston. As a result, I took the liberty of doing some Yelp research on the best spots in Boston.

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

To get some data from yelp

url = ''
response = requests.get(url)

Check the status code

# check the status code

Insert your API key to pull in the first 50 bagel places in Boston

MY_API_KEY = "insert_your_key_here"term = 'bagels'
location = 'Boston'
url = ''headers = {
'Authorization': 'Bearer {}'.format(MY_API_KEY),
url_params = {
'term': term.replace(' ', '+'),
'location': location.replace(' ', '+'),
response_bagels = requests.get(url, headers=headers, params=url_params)

Check response


Turn the text into a JSON file

bagels = json.loads(response_bagels.text)
print(type(bagels)) #spoiler - jsons are dictionaries

Use the following code to find the keys in the JSON dictionary

for key in bagels.keys():

Using the values of the business key to create a dataframe

#making the bagels dictionary a dataframe
bagels_df = pd.DataFrame.from_dict(bagels['businesses'])

Find out the columns


Reduce amount of columns

df = bagels_df.loc[:,['name', 'rating', 'review_count', 'price', 'location']]

Sort the dataframe from highest rated bagels to lowest rated bagels

df = df.sort_values('rating', ascending = False)

Make graph

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),y, color = 'dodgerblue')

And repeat the process with other terms. Instead of the string bagel we can use the string coffee.

Photo by Katarzyna Grabowska on Unsplash | Charles River

Aspiring Data Scientist

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