End-to-end data pipeline and Streamlit application for analyzing U.S. electricity demand, fuel mix, grid stress, and wholesale power prices using:
- EIA (Energy Information Administration) demand and generation data
- GridStatus ISO-level price data for CAISO, NYISO, and ERCOT
- Google BigQuery for storage, querying, and app performance
- Streamlit for interactive visualization
This project builds a full-stack data workflow:
APIs โ Data Cleaning & Validation โ BigQuery โ Interactive Streamlit Dashboard
The application allows users to:
- Explore electricity demand by fuel type
- Compare demand across regions and balancing authorities
- Identify high- and low-demand anomaly periods as a proxy for grid stress
- Analyze how fuel mix changes during anomalous demand periods
- Compare wholesale electricity prices with demand for selected ISOs
flowchart LR
A[EIA API<br/>Daily Fuel + Region Data] --> B[ETL Script<br/>load_daily_eia_to_bigquery.py]
C[GridStatus<br/>Hourly ISO Price Data] --> D[ETL Script<br/>load_gridstatus_hourly_prices_to_bigquery.py]
B --> E[BigQuery<br/>daily_fuel_main]
B --> F[BigQuery<br/>daily_region_main]
D --> G[BigQuery<br/>hourly_pricing_main]
E --> H[Streamlit App<br/>main_page.py]
F --> H
G --> H
H --> I[Fuel Type Demand<br/>app.py]
H --> J[Regional Demand<br/>region.py]
H --> K[Grid Stress Analysis<br/>grid_stress.py]
H --> L[Price-Demand Analysis<br/>price_demand.py]
H --> M[Proposal & Reflections<br/>proposal.py]
The EIA pipeline pulls recent electricity data from the EIA Open Data API and loads it into BigQuery.
Source: EIA Open Data API, electricity/rto datasets
Tables:
daily_fuel_maindaily_region_main
Loader:
python load_daily_eia_to_bigquery.pyStrategy:
- Uses a rolling 90-day window
- Cleans and normalizes API output
- Converts EIA column names into BigQuery-friendly snake case
- Replaces the destination table with each refresh
- Verifies each load using row counts, date ranges, and latest load timestamps
To load the regional demand table instead of the default fuel table:
EIA_DATA_SOURCE=region python load_daily_eia_to_bigquery.pyThe price pipeline uses the gridstatus Python package to collect hourly wholesale electricity price data.
Source: GridStatus
ISOs covered:
- CAISO
- NYISO
- ERCOT
Table:
hourly_pricing_main
Loader:
python load_gridstatus_hourly_prices_to_bigquery.pyStrategy:
- Uses a rolling 7-day price window
- Pulls hourly LMP data
- Keeps selected trading hubs / zones to keep the table manageable
- Standardizes price fields across ISOs
- Stores:
- LMP
- energy component
- congestion component
- loss component
- market
- location
- interval timestamps
- ISO name
All app-facing data is served from BigQuery rather than directly from APIs.
project: sipa-adv-c-purple-flamingo
dataset: eia_data
Expected tables:
daily_fuel_main
daily_region_main
hourly_pricing_main
The app uses a shared BigQuery utility layer to:
- Read Streamlit secrets
- Create authenticated BigQuery clients
- Apply default project, dataset, and table names
- Push date filtering into SQL queries
- Read fuel, region, and price data into pandas dataframes
Run the app with:
streamlit run main_page.pyThe app contains five pages:
Shows electricity demand by fuel type.
Features:
- Line or stacked area charts
- Top-N fuel type filtering
- Unit toggle between MWh and GWh
- Optional Eastern timezone filtering
- Data served from BigQuery
Shows electricity demand by balancing authority / region.
Features:
- Regional demand trends
- Top-N region filtering
- Regional anomaly detection
- Day-over-day demand changes
- Cross-region demand snapshot for a selected date
Provides a focused grid stress page using demand anomalies.
Features:
- Z-score anomaly detection
- High-demand and low-demand anomaly labels
- Day-over-day percentage changes
- Fuel mix comparison on anomaly days vs. normal days
- Largest fuel mix shift analysis
Combines GridStatus price data with EIA regional demand data.
Features:
- ISO-level daily price and demand metrics
- Mean or median LMP aggregation
- Dual-axis price and demand time series
- Price-demand scatterplots
- Correlation metrics by ISO
Supported ISOs:
- CAISO
- NYISO
- ERCOT
Documents project evolution, methodological decisions, and feedback from the teaching team.
Grid stress is operationalized as unusually high or low total demand.
The app:
- Aggregates demand by day
- Calculates day-over-day changes
- Computes z-scores
- Flags high- and low-demand anomalies based on a user-selected threshold
Conceptually:
z = (daily demand - mean demand) / standard deviation
High-demand anomalies are days above the positive threshold. Low-demand anomalies are days below the negative threshold.
For anomaly periods, the app compares average fuel mix shares on anomalous days against normal days.
This helps answer:
- Which fuel types increase during high-demand periods?
- Which fuel types decline during low-demand periods?
- How does generation composition change under stress?
The price-demand page links:
- EIA regional demand data
- GridStatus hourly ISO prices
The app aggregates hourly prices to the daily level, maps EIA respondent codes to ISO names, and compares price and demand over matching dates.
.
โโโ app.py
โโโ region.py
โโโ grid_stress.py
โโโ price_demand.py
โโโ proposal.py
โโโ main_page.py
โโโ eia_api.py
โโโ data_utils.py
โโโ schemas.py
โโโ bigquery_utils.py
โโโ load_daily_eia_to_bigquery.py
โโโ load_gridstatus_hourly_prices_to_bigquery.py
โโโ LAB_10.md
โโโ tests/
โโโ requirements.txt
โโโ pyproject.toml
โโโ README.md
โโโ workflows/
git clone https://github.com/advanced-computing/purple-flamingo.git
cd purple-flamingopython -m venv .venv
source .venv/bin/activateOn Windows:
.venv\Scripts\activatepip install -r requirements.txtKey dependencies include:
streamlitpandasplotlypandera[pandas]google-cloud-bigquerypandas-gbqgridstatuspytestruff
Create a local secrets file:
.streamlit/secrets.toml
Example:
EIA_API_KEY = "your_eia_api_key_here"
[gcp_service_account]
type = "service_account"
project_id = "sipa-adv-c-purple-flamingo"
private_key_id = "..."
private_key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
client_email = "streamlit@sipa-adv-c-purple-flamingo.iam.gserviceaccount.com"
client_id = "..."
token_uri = "https://oauth2.googleapis.com/token"
[bigquery]
project_id = "sipa-adv-c-purple-flamingo"
dataset_id = "eia_data"
fuel_table_id = "daily_fuel_main"
region_table_id = "daily_region_main"
pricing_table_id = "hourly_pricing_main"Do not commit .streamlit/secrets.toml.
If running loaders locally, authenticate with Google Cloud:
gcloud auth application-default loginThen export your EIA API key:
export EIA_API_KEY="your_eia_api_key_here"python load_daily_eia_to_bigquery.pyEIA_DATA_SOURCE=region python load_daily_eia_to_bigquery.pypython load_gridstatus_hourly_prices_to_bigquery.pystreamlit run main_page.pyThe app will read from BigQuery using the configuration in Streamlit secrets.
Run the test suite:
pytestOr, for quieter output:
pytest -qRun Ruff:
ruff check .The repoโs Ruff configuration is stored in pyproject.toml.
To keep the app responsive:
- App pages read from BigQuery rather than directly from the EIA API
- Date filters are pushed into SQL
- BigQuery clients are cached with
st.cache_resource - Query outputs are cached with
st.cache_data - EIA tables use a rolling 90-day snapshot
- Price data uses a shorter rolling price window
- Pages include timing captions for performance checks
See lab_10.md for notes on BigQuery loading and performance decisions.
Check:
- Date range
- EIA API key
- Whether the relevant BigQuery table has been loaded
Check:
.streamlit/secrets.toml- Google Cloud application-default credentials
- Project ID and dataset name
- Service account permissions
Check that both tables are populated for overlapping dates:
daily_region_mainhourly_pricing_main
The price page requires overlapping dates between ISO price data and EIA regional demand data.
Some ISO endpoints may fail or be unavailable depending on market, date range, or upstream data availability. The price loader is designed to continue loading other ISOs when one fails.
Validation warnings usually indicate missing fields, null values, or unexpected API output. The app attempts to continue with cleaned rows when possible.
Potential next steps:
- Add NOAA weather data for event-based analysis
- Expand ISO coverage to PJM, MISO, SPP, or ISO-NE
- Add explicit data freshness indicators in the app
- Add event-based case studies for heat waves, winter storms, or price spikes
- Aileen Yang
- Aria Kovalovich
- Chengpu Deng
This project evolved from an initial exploratory dashboard into a more complete data system for examining electricity demand, grid stress, fuel mix, and wholesale power prices.
The central question is:
How does the electricity system behave under stress, and how do prices respond?
The final application combines policy-relevant energy data, reproducible data engineering, statistical anomaly detection, and interactive visualization.