LoslegenKostenlos loslegen

Making an API request

Forecasting systems start with a data pipeline that gathers new data from an API or other data source. In this exercise, you'll create the URL link and send a request to the EIA API to retrieve electricity data.

Note that working with EIA API requires creating an API key, so for this exercise's purposes a demo API key was set up for you.

The requests, os, and pandas as pd packages were imported.

Diese Übung ist Teil des Kurses

Designing Forecasting Pipelines for Production

Kurs anzeigen

Anleitung zur Übung

  • Extract the API key from the environment variable, saving it as eia_api_key.
  • Create the full URL path by combining api_url_path and eia_api_key.
  • Make the request using the correct method and passing the full link.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Extract the API key from the environment variable
eia_api_key = os.____('EIA_API_KEY')

# Create the full URL path
api_url = "https://api.eia.gov/v2/"
api_path = "electricity/rto/region-data/"
api_url_path = api_url + api_path + "data/&data[]=value"
full_path = ____ + "?api_key=" + ____

# Make the request
data = requests.____(____).json()

df = pd.DataFrame(data["response"]["data"])
print(df.head())
Code bearbeiten und ausführen