In this week's homework, you're going to apply your knowledge about APIs to connect to a publicly available one through the EIA. Did you know that Texas is the biggest generator of wind electricity in the country? It's three times higher than the second biggest wind generating state (Iowa). You're going to use the new version of the EIA API (V2) to call this wind generation data so your Python script uses the updated data when the latest wind generation hourly data is available. A few hints to help you figure this out: You'll need to first sign up for an EIA account, then request an API key of your own to use. Set up the API via a tool like Swagger Inspector first to make sure you're using the right API query input parameters. Take a close look at the EIA API documentation, especially the examples of how to set it up. Here is an example of the script, I just don't have the whole script.
A few hints to help you figure this out: You'll need to first sign up for an EIA account, then request an API key of your own to use. Set up the API via a tool like Swagger Inspector first to make sure you're using the right API query input parameters. Take a close look at the EIA API documentation, especially the examples of how to set it up.
import pandas as pd
import requests
eia_url = 'https://api.eia.gov/v2/electricity/rto/fuel-type-data/data/?frequency=hourly&data[0]=value&facets[r]=ERCOT&facets[fuel_type]=wind'
# By using the API dashboard to create the URL link to focus on ERCOT area and wind as fuel type. Also added my eia_r
eia_r = requests.get(eia_url)
# Set a new variable eia_r by using eia_url response
response_eia = eia_r.json()
# Chained with json format
df_eia = pd.DataFrame(response_eia["response"]["data"])
# Defined df_eia as a dataframe from response_eia, and df_eia.head() to show the table from the cell locked from "response_eia["response"]["data"]"
df_eia.head()
# From this df_eia, use head() to show the table from the cell locked from "response_eia["response"]["data"]"
df_eia.head()
# Respondent-name ERCOT Electric Reliability Council of Texas, Inc.
# Respondent-name ERCOT Electric Reliability Council of Texas, Inc.
# Respondent-name ERCOT Electric Reliability Council of Texas, Inc.
# Respondent-name ERCOT Electric Reliability Council of Texas, Inc.
# Respondent-name ERCOT Electric Reliability Council of Texas, Inc.
# Period Respondent
# 0 2023-07-17T05
# 1 2023-07-17T04
# 2 2023-07-17T03
# 3 2023-07-17T02
# 4 2023-07-17T01
# Fuel-type WND
# Fuel-type WND
# Fuel-type WND
# Fuel-type WND
# Fuel-type WND
# Type-name value
# Type-name value
# Type-name value
# Type-name value
# Type-name value
# Value Wind 15957 megawatthours
# Value Wind 13482 megawatthours
# Value Wind 10194 megawatthours
# Value Wind 8097 megawatthours
# Value Wind 7089 megawatthours
# Value-units Wind