The following table represents a heat matrix that highlights the total amount of electricity, in terawatt-hours (TWh), produced by each source within the US48 power grid during 2023.
To create the heat matrix from the raw dataset, which typically comes in a long format, we need to apply several steps that will be covered in this tutorial.
Before we begin, let’s understand the dataset we are working with.
Data
The US power grid produces electricity from various sources, such as natural gas, solar, and petroleum, every hour. The amount of electricity produced by each source is recorded in each row of the dataset.
The data is provided by the US Energy Information Administration (EIA). Check out this tutorial to learn how to retrieve the data from the EIA API.
import pandas as pd
df = pd.read_csv('data.csv')
Questions
- How can we transform a DataFrame from long to wide format?
- Which function summarizes data into categories?
- How do we visualize data trends through a heat matrix?