ComenzarEmpieza gratis

Set API parameters

Formatting parameters to get the data you need is an integral part of working with APIs. These parameters can be passed to the get() function's params keyword argument as a dictionary.

The Yelp API requires the location parameter be set. It also lets users supply a term to search for. You'll use these parameters to get data about cafes in NYC, then process the result to create a dataframe.

pandas (as pd) and requests have been loaded. The API endpoint is stored in the variable api_url. Authorization data is stored in the dictionary headers.

Este ejercicio forma parte del curso

Streamlined Data Ingestion with pandas

Ver curso

Instrucciones del ejercicio

  • Create a dictionary, parameters, with the term and location parameters set to search for "cafe"s in "NYC".
  • Query the Yelp API (api_url) with requests's get() function and the headers and params keyword arguments set. Save the result as response.
  • Extract the JSON data from response with the appropriate method. Save the result as data.
  • Load the "businesses" values in data to the dataframe cafes and print the head.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Create dictionary to query API for cafes in NYC
parameters = {____,
          	  ____}

# Query the Yelp API with headers and params set
response = ____(____,
                ____,
                ____)

# Extract JSON data from response
data = ____

# Load "businesses" values to a dataframe and print head
cafes = ____(____)
print(cafes.head())
Editar y ejecutar código