Skip to content
3 min read · Tags: excel pivot-table marimo plotting

BW #114: International trade

Get better at: Excel files, pivot tables, plotting, and using Marimo notebooks

BW #114: International trade

International trade has been a major topic in recent weeks, thanks in no small part to Donald Trump's on-again, off-again tariff policies against nearly every country.

Most recently, Trump announced that tariffs will be kept at 10 percent against all countries, still several times higher than what Americans were paying, just until recently, to import goods. This happened after the bond market dropped along with the stock market, a kind of no-confidence vote in US economic policy. Trump also announced tariffs of 145 percent (!) on Chinese goods.

In all of these cases, Trump has said that he's willing to reduce the tariffs further, on condition that affected countries negotiate. We know that some countries are negotiating, but the European Union is planning to respond with its own tariffs, and China has already done so.

With all of the talk about international trade, I thought that it might be interesting to see how much trade various countries do, and with whom. The United Nations runs a data portal known as "Comtrade" (https://comtradeplus.un.org/), which catalogs international trade. You need to register and pay for large data sets, but up to 100,000 records can be downloaded free of charge.

But this week, we have an additional twist: Usually, I develop my solutions using Jupyter, and encourage you to do the same thing. But this time, I'm using Marimo (https://marimo.io/), a new type of notebook that tries to be more modern and Python-centric than traditional Jupyter notebooks.

I've been playing with Marimo for a bit, and have been rather impressed with what I've seen, although it does take a little getting used to if you've been working with Jupyter for a long time. You can check out my YouTube video at https://youtu.be/tLyjRfkyfFg?list=PLbFHh-ZjYFwHbNO7aOe1IXUlHa9ibGQJC to learn more.

Data and six questions

This week's data comes from the UN's Comtrade site. I went to their "TradeFlow" page at https://comtradeplus.un.org/TradeFlow , and entered the following:

I then downloaded the results in Excel format, into a file called TradeData.xlsx. (I tried the CSV-formatted file, but decided to use Excel in the end, partly because there were some weird encoding issues and also it seemed to cut off the data earlier than Excel.) I first needed to register and log in; this allowed me to download the data. Note that free users (like me) can only download 100,000 rows – which means that if your query will result in more than that, you'll only get the first 100,000. In my case, the query returned 78,741 rows and 47 columns, so we were safe.

This week's learning goals include Marimo, pivot tables, sorting, and plotting.

Paid subscribers can download all of the data files from the bottom of this message.

I'll be back tomorrow with my solutions and explanations. Paid subscribers will also be able to download my Marimo (not Jupyter!) notebook.

Meanwhile, here are the six tasks and questions: