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

--

--

--

Aspiring Data Scientist

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Past vs Present vs Future At GIGIH 2021

Performing Analysis Of Meteorological Data

Celebrating A Year With Hamoye

Deep Prognosis: Predicting Mortality in the ICU

Multi faceted data exploration in the browser using Leaflet and amCharts

A Not so Short Introduction to the Rust Programming Language

Sentiment Analysis — Everything You Need To Know

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
Raizel Bernstein

Raizel Bernstein

Aspiring Data Scientist

More from Medium

Does the Seasons Impact the Citi Bike Usage in New York?

Is the Hudson Valley winning against Omicron?

Cyclistic: An analysis of the relationship between casual and member bike users

Seasons of Covid (in Charts)