Yelp API: Return the Business Type

35 Views Asked by At

I have a list of businesses and business id. I can currently return categories but what I really want is the higher level / root category. I want to tell if the business is a restaurant, car wash, hair salon, etc. Currently categories returns something like this:

['Sushi Bars', 'Japanese', 'Seafood'].

I don't need it at this level -- I just need to know the type of business. Is there an API to return this information?

Here is my current code:

import requests
import pandas as pd

yelp_df = pd.read_excel("yelp_html.xlsx").head(10)
headers = {"Authorization": "Bearer "}

yelp_api_responses = []


for url in yelp_df['Business URL']:
    business_id = url.split('/')[-1]
    
    business_url = f"https://api.yelp.com/v3/businesses/{business_id}"
    
    response = requests.get(url=business_url, headers=headers)
    
    if response.status_code == 200:
        business_info = response.json()
        categories = [category['title'] for category in business_info.get('categories', [])]
    else:
        categories = []    

    yelp_api_responses.append(categories)

yelp_df['Categories'] = yelp_api_responses
yelp_df.to_excel("yelp_with_categories.xlsx", index=False)

I have a list of businesses and their URL in yelp_html.xlsx that I can parse to get the business id. When I pass the business id to the API, I see categories in the response, but it does not tell me if the business type is a restaurant, car wash, etc.

0

There are 0 best solutions below