Before we begin, remember that I'm offering two new hands-on agentic coding workshops later this month:
- On Thursday, April 23rd, you'll learn about OpenCode, the open-source tool that works with a variety of models, free and commercial, and
- On Monday, April 27th, you'll learn advanced techniques in Claude Code – MCP servers, skills, and multiple agents.
You can learn more about these workshops with a recording from yesterday's info session at https://youtu.be/y1FXHpyFsRM?si=P5169N6g2qD5kADB. Full info, and signup links, are at https://lernerpython.com/code-with-claude/.
And now, this week's questions:
As of this writing, Iran and the United States are playing a game of economic chicken. And as they wait for something to change, the world's economy is starting to buckle.
As a result, energy prices have skyrocketed around the world (https://www.nytimes.com/2026/04/22/business/iran-war-oil-hoarding.html?unlocked_article_code=1.c1A.3QDh.fYueF0YAuuyE&smid=url-share). Just yesterday, Germany's Lufthansa airline announced that it's cancelling 20,000 flights to save on jet fuel (https://www.msn.com/en-us/travel/news/deutsche-lufthansa-to-cancel-20000-short-haul-flights-to-save-jet-fuel/ar-AA21pvF2).
But what exactly is the price of oil? There are two main prices, and we'll compare them this week.
First, we'll look at the "spot" oil prices, meaning how much you would have to pay to get a barrel of oil (i.e., 42 gallons or 159 liters) right now. If you're an airline, and you need jet fuel, then you can't really say that you'll wait a few weeks for prices to go down. But there are at least two different measurements for spot prices, and we'll see how they have changed over time.
Next, we'll look at oil futures. Maybe you don't need the oil right away. Maybe you'll need it in July, and want to buy "oil futures," indicating how much you believe it'll cost to receive a barrel of oil several months down the road. If you're worried that the price of oil will rise, you might buy such futures, much as you might buy an airline ticket for a trip in several months. You lock in the current price, ensuring that even if prices go up, you'll have the original, cheaper price.
For more about oil prices and purchasing, check out NPR's Planet Money podcast from about 10 years ago, when they bought some oil: https://www.npr.org/sections/money/2016/08/26/491342091/planet-money-buys-oil
Paid subscribers, both to Bamboo Weekly and to my LernerPython+data membership program (https://LernerPython.com) get all of the questions and answers, as well as downloadable data files, downloadable versions of my notebooks, one-click access to my notebooks, and invitations to monthly office hours.
Learning goals for this week include joins, dates and times, APIs, grouping, and plotting with Plotly.
Data and six questions
This week's data will come from two different sources:
- Spot oil prices will come from FRED (https://fred.stlouisfed.org/), from the St. Louis Federal Reserve.
- Prices for oil futures based on fixed dates (in this case, July 2026) will come from Yahoo Finance.
By looking at oil prices in two different ways, we'll better understand how they change, and what the difference between spot and future prices might mean.
Here are my six questions for this week. I'll be back tomorrow with solutions and explanations:
- Use the
fedfredpackage from PyPI to download the daily spot oil prices from FRED for both West Texas Intermediate (WTI) and Brent. These are known as theDCOILWTICOandDCOILBRENTEUdata sets. Only keep rows for which there's data on both prices. Put them into a single Pandas data frame. Are prices currently at an all-time high? (If not, then when were they?) - Calculate, for the entire data set, the mean price for each two-month period. Where do the most recent two-month period's prices rank across historical oil prices? (Are they the highest, second highest, third highest, etc.)