Код: Выделить всё
import requests
import pandas as pd
# Set the URL
url = "https://api.eia.gov/v2/electricity/rto/fuel-type-data/data/?frequency=hourly&data[0]=value&facets[respondent][]=ERCO&start=2018-07-01T00&end=2023-04-25T00&sort[0][column]=period&sort[0][direction]=desc&offset=0&length=5000&api_key=7xu8nejTweL67Zzzbsj2K4ngcGgTS828SqpfmSkD"
# Make the API request
response = requests.get(url)
# Extract the data from the response
data = response.json()["series"][0]["data"]
# Convert the data to a pandas dataframe
df = pd.DataFrame(data, columns=["period", "value"])
# Print the dataframe
print(df)
Код: Выделить всё
KeyError Traceback (most recent call last)
Cell In[27], line 11
8 response = requests.get(url)
10 # Extract the data from the response
---> 11 data = response.json()["series"][0]["data"]
13 # Convert the data to a pandas dataframe
14 df = pd.DataFrame(data, columns=["period", "value"])
KeyError: 'series'
Подробнее здесь: https://stackoverflow.com/questions/761 ... ith-python