Last week, people in Spain and Portugal experienced an 18-hour power outage, causing chaos throughout both countries (https://www.nytimes.com/2025/04/29/world/europe/spain-power-outage-blackout.html?unlocked_article_code=1.FE8.aE9J.wGA5F0_NJ5qt&smid=url-share).
Officials are still trying to determine the cause of the massive blackout, but the reasons seem to include Spain's massive reliance on solar and wind power, which operate differently than traditional power generation, and might thus require different procedures for ramping electric supply up and down (https://slate.com/podcasts/slate-money/2025/05/business-what-the-iberian-power-grid-going-down-means-for-renewable-energy-and-the-us).
Indeed, Spain produces so much energy that it exports it to other countries, including Portugal, France, and Morocco (https://www.yahoo.com/news/spain-portugal-blackouts-actually-happened-112338391.html?guccounter=1).
I couldn't find any good data about blackouts, but I did find that the International Energy Association (IEA, https://www.iea.org/) has published statistics on how much electricity countries are generating, consuming, and exporting. So this week, we'll be comparing countries and years, seeing who is generating, importing, and exporting electricity.
This week's learning goals include cleaning data, working with dates and times, plotting, and pivot tables.
Paid subscribers can download the data file from the end of this post.
Data and five questions
This week's data comes from the IEA's "Monthly electricity statistics" page, at https://www.iea.org/data-and-statistics/data-product/monthly-electricity-statistics#monthly-electricity-statistics . From there, you can download a CSV file containing the data we want.
Here are my five questions for you this week; I'll be back tomorrow with my extended solutions, as well as (for paid subscribers) downloadable notebooks and one-click solutions in Google Colab.
- Import the CSV file into a data frame. Make sure that the
Time
column is treated as adatetime
value. Remove rows in which theCountry
column is from the OECD or IEA. - Create a bar plot showing the 10 countries that had the greatest total net electricity production in 2025.