Python · imports & African reporter codes
All 54 African UN numeric codes; reusable across every step below.
1# Install the official wrapper once2# pip install comtradeapicall34import comtradeapicall5import pandas as pd6import os7import time8from datetime import datetime910today = datetime.now().strftime('%d%b%Y')1112def output_to_excel(df, filename):13 path = f'./{filename}_{today}.xlsx'14 df.to_excel(path, index=False)15 print(f"Saved: {path}")1617# ── Reporter list: all 54 African UN numeric codes ───────────────────────────18reporter_iso3 = {19 12: "Algeria", 24: "Angola", 204: "Benin", 72: "Botswana",20 854: "Burkina Faso", 108: "Burundi", 132: "Cape Verde", 120: "Cameroon",21 140: "CAR", 148: "Chad", 174: "Comoros", 178: "Congo",22 384: "Côte d'Ivoire", 262: "Djibouti", 818: "Egypt", 232: "Eritrea",23 231: "Ethiopia", 226: "Eq. Guinea", 266: "Gabon", 270: "Gambia",24 288: "Ghana", 324: "Guinea", 624: "Guinea-Bissau", 404: "Kenya",25 426: "Lesotho", 430: "Liberia", 434: "Libya", 450: "Madagascar",26 454: "Malawi", 466: "Mali", 478: "Mauritania", 480: "Mauritius",27 508: "Mozambique", 504: "Morocco", 516: "Namibia", 562: "Niger",28 566: "Nigeria", 646: "Rwanda", 678: "São Tomé", 686: "Senegal",29 690: "Seychelles", 694: "Sierra Leone", 706: "Somalia",30 710: "South Africa", 728: "South Sudan", 729: "Sudan",31 748: "Eswatini", 834: "Tanzania", 768: "Togo", 788: "Tunisia",32 800: "Uganda", 894: "Zambia", 716: "Zimbabwe",33}34reporters = list(reporter_iso3.keys())