It has been an, um, exciting time for those of us living in Israel. On Saturday morning, air-raid sirens went off, telling us to enter a local bomb shelter or thick-walled safe room. It was at that moment that US and Israeli planes started to attack Iran's government and military, and it was assumed that Iran would retaliate by bombing Israeli cities — which it did.
Since Saturday morning, we have spent many hours of each day in our safe room, where we turn on the news and wait for our domestic-safety app to tell us when we can leave. Sadly, a number of people have been killed and injured, typically while outside of a shelter. We had about eight air-raid sirens on Wednesday, with some missiles fired from Iran and others fired from Iran's Hezbollah militia in Lebanon.
I want to stress that my family and I are safe. That said, it's a tense time here, for sure, and being awakened in the middle of the night with air-raid sirens and booming sounds is obviously quite disturbing.
I'm in touch with a friend of mine from the Python community who lives in Iran. He and his friends are delighted by these attacks, and are hoping that it will help to replace their current government with one that is more open and liberal. It'll take some time to see just how this all plays out.
The situation is complex, and now includes a number of Iran's neighbors, such as the United Arab Emirates, Bahrain, Saudi Arabia, and Qatar. Iran has been attacking them with missiles and drones in an attempt to widen and prolong the war. They have also started to threaten that they will attack any ships passing through the Strait of Hormuz. This is a narrow waterway that passes next to Iran, but also next to the oil-exporting countries of the Persian Gulf.
As the New York Times reported on Tuesday (New York Times story: https://www.nytimes.com/interactive/2026/03/03/business/iran-war-oil-gas-strait-of-hormuz.html?unlocked_article_code=1.QlA.8gcD.xn74_tuE5sXN&smid=url-share), a huge proportion of the world's oil passes through the Strait of Hormuz. Cutting off this supply of oil would be quite bad for a number of countries.
How much oil goes through the Strait of Hormuz? What countries export through there? What countries would be hurt most if ships were stopped from traveling through there?
This week, we'll answer these questions using data, mostly from the EIA, the Energy Information Administration (https://eia.gov), part of the US government.
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 working with JSON, cleaning data, multi-indexes, plotting with Plotly, and pivot tables.
Data and five questions
This week's data comes from the EIA. To get the data file you'll need, go to https://www.eia.gov/international/data/world/petroleum-and-other-liquids/annual-crude-and-lease-condensate-exports. Click on country/region. Click on "data options". On the right, choose "Crude oil including lease condensate" in the first group, under "production", to get production information along with the export data. Then click on "view data". Finally, download the JSON file.
Note that Persian Gulf countries are considered to be Saudi Arabia, Bahrain, Iraq, Iran, Qatar, Kuwait, and the United Arab Emirates (UAE). You'll need that to answer some of the questions.
Here are my five tasks and questions for the week; I'll be back tomorrow with my solutions and explanations:
- Turn the JSON file from the EIA into a Pandas data frame. The data frame should have four columns from the JSON file –
iso(the 3-letter country code),activityid(a string, with'production'replacing 1 and'export'replacing 4),year(an integer, a 4-digit year) andvalue(a float). The last two of these will be taken from thedatacolumn in the JSON file, expanded such that you'll have one row in the data frame for eachdate-valuepair in a given row. Replace both'--'andNAwithnp.nanvalues. Set the two-level multi-index to beisoandyear. Remove the'WORL'values, representing the entire world. - Create a line plot showing, for each year in the data set, the number of thousands of barrels of oil exported by each Persian Gulf country. The x axis should contain years, the y axis should show the value, and there should be a line for each of the seven countries. How much oil does Iran export, relative to the other countries?