Concevoir des pipelines de prévision pour la production
Rami Krispin
Senior Manager, Data Science and Engineering





import requests
import pandas as pd
import os
import requests
import pandas as pd
import os
api_url = "https://api.eia.gov/v2/"
api_path = "electricity/rto/region-data/"
import requests
import pandas as pd
import os
api_url = "https://api.eia.gov/v2/"
api_path = "electricity/rto/region-data/"
get_request = api_url + api_path + "data/&data[]=value"
print(get_request)
https://api.eia.gov/v2/electricity/rto/region-data/data/&data[]=value
eia_api_key = os.getenv('EIA_API_KEY')get_request = get_request + "?api_key=" + eia_api_key
eia_api_key is personal and must be sourced from the EIA websitedata = requests.get(get_request).json()
df = pd.DataFrame(data['response']['data'])
data = requests.get(get_request).json()
df = pd.DataFrame(data['response']['data'])
print(df.head())
period respondent respondent-name value
0 2022-04-06T07 AVA Avista Corporation 462894.0
1 2024-04-06T07 AZPS Arizona Public Service Company 463663.0
2 2024-04-07T07 BANC Balancing Authority of Northern California 464916.0
3 2024-04-07T07 BPAT Bonneville Power Administration 459376.0
4 2024-04-07T07 CAL California 441989.0

Data input format for statsforecast and mlforecast packages:
unique_id - the series IDds - the series timestampy - the series valuesdf = pd.read_csv("data/data.csv")
ts = df[["period", "value"]]
ts["period"] = pd.to_datetime(ts["period"])
ts = ts.sort_values("period")
Data input format:
unique_id - the series IDds - the series timestampy - the series valuests = ts[["period", "value"]]
ts["period"] = pd.to_datetime(ts["period"])
ts = ts.sort_values("period")
ts = ts.rename(columns = {"period": "ds", "value": "y"})
ts["unique_id"] = 1
print(ts.head())
ds y unique_id
0 2022-04-06 23:00:00 462894.0 1
1 2022-04-07 00:00:00 463663.0 1
2 2022-04-07 01:00:00 464916.0 1
3 2022-04-07 02:00:00 459376.0 1
4 2022-04-07 03:00:00 441989.0 1
Concevoir des pipelines de prévision pour la production