Food exports (% of merchandise exports)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Albania Albania 13.4 +11.6% 47
Argentina Argentina 48.9 -7.2% 13
Armenia Armenia 9.58 -27.2% 63
Antigua & Barbuda Antigua & Barbuda 84.7 +6.49% 3
Australia Australia 12.1 +3.78% 51
Azerbaijan Azerbaijan 4.14 +45.9% 77
Belgium Belgium 13 +9.04% 48
Burkina Faso Burkina Faso 7.09 -16.9% 69
Bulgaria Bulgaria 15.2 -13% 41
Bosnia & Herzegovina Bosnia & Herzegovina 7.06 +13.4% 70
Belize Belize 95.7 +0.518% 1
Bolivia Bolivia 22.2 -6.89% 29
Brazil Brazil 40.4 -4.11% 18
Barbados Barbados 43.5 -5.66% 17
Canada Canada 13.5 -0.0761% 46
Switzerland Switzerland 2.51 -2.18% 81
Chile Chile 22.9 +3.29% 26
China China 2.43 -1.2% 82
Cyprus Cyprus 22.5 +5.75% 28
Czechia Czechia 5.44 +2.83% 75
Germany Germany 6.28 +5.12% 74
Denmark Denmark 17.7 +3.62% 36
Dominican Republic Dominican Republic 25 +8.12% 23
Ecuador Ecuador 53.7 +5.99% 11
Egypt Egypt 21.9 +9.42% 30
Spain Spain 18.6 +8% 34
Estonia Estonia 13.6 +16.6% 45
Finland Finland 3.07 +11.2% 80
Fiji Fiji 64.3 -6.14% 8
United Kingdom United Kingdom 6.82 +4.16% 71
Georgia Georgia 45.7 +16.6% 15
Greece Greece 21.7 +7.37% 31
Grenada Grenada 69.1 +12% 6
Guatemala Guatemala 47.5 -2.33% 14
Guyana Guyana 1.99 -59.3% 83
Hong Kong SAR China Hong Kong SAR China 1.55 +0.203% 85
Croatia Croatia 15.2 -4.9% 40
Hungary Hungary 9 +5.23% 65
India India 11.1 +1.04% 54
Ireland Ireland 7.93 -6.36% 68
Iceland Iceland 44 -1.52% 16
Israel Israel 3.81 -3.04% 78
Italy Italy 11 +8.68% 55
Japan Japan 1.15 -1.61% 86
Kyrgyzstan Kyrgyzstan 10.1 -7.37% 60
South Korea South Korea 1.63 -1.1% 84
Sri Lanka Sri Lanka 27.3 +6.03% 22
Lithuania Lithuania 19 +2.36% 33
Luxembourg Luxembourg 11.8 +8.09% 52
Latvia Latvia 22.5 +1.73% 27
Macao SAR China Macao SAR China 17.8 -38.2% 35
Moldova Moldova 56.1 -2.19% 10
Maldives Maldives 94.4 -2.27% 2
Mexico Mexico 8.51 +1.74% 66
North Macedonia North Macedonia 10.6 +18.9% 56
Malta Malta 9.66 -4.29% 62
Myanmar (Burma) Myanmar (Burma) 36.7 +28.9% 19
Montenegro Montenegro 16.8 +22.8% 37
Mauritius Mauritius 50.9 +3.36% 12
Malaysia Malaysia 10.2 +7.1% 58
Namibia Namibia 28 +16.4% 21
Netherlands Netherlands 16.3 +8.45% 38
Norway Norway 10.2 +4.68% 59
New Zealand New Zealand 67.1 +1.98% 7
Pakistan Pakistan 24.4 +11.2% 24
Panama Panama 73.6 +323% 4
Philippines Philippines 10.4 +23.7% 57
Poland Poland 14.9 +3.43% 42
Portugal Portugal 14.4 +6.23% 44
Paraguay Paraguay 69.5 -1.34% 5
French Polynesia French Polynesia 15.8 +54.9% 39
Romania Romania 11.5 -11.5% 53
El Salvador El Salvador 22.9 +6.13% 25
Suriname Suriname 6.37 +82.4% 73
Slovakia Slovakia 4.66 +2.87% 76
Slovenia Slovenia 3.68 -3.25% 79
Sweden Sweden 6.71 -1.07% 72
Togo Togo 30.8 -3.69% 20
Thailand Thailand 14.7 -2.24% 43
Trinidad & Tobago Trinidad & Tobago 8.2 +21.3% 67
Turkey Turkey 12.3 +2.68% 49
Ukraine Ukraine 59.1 -2.1% 9
United States United States 9.45 -1.01% 64
Uzbekistan Uzbekistan 9.69 +11% 61
South Africa South Africa 12.2 +4.44% 50
Zimbabwe Zimbabwe 21.6 +6.35% 32

                    
# Install missing packages
import sys
import subprocess

def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])

# Required packages
for package in ['wbdata', 'country_converter']:
try:
__import__(package)
except ImportError:
install(package)

# Import libraries
import wbdata
import country_converter as coco
from datetime import datetime

# Define World Bank indicator code
dataset_code = 'TX.VAL.FOOD.ZS.UN'

# Download data from World Bank API
data = wbdata.get_dataframe({dataset_code: 'value'},
date=(datetime(1960, 1, 1), datetime.today()),
parse_dates=True,
keep_levels=True).reset_index()

# Extract year
data['year'] = data['date'].dt.year

# Convert country names to ISO codes using country_converter
cc = coco.CountryConverter()
data['iso2c'] = cc.convert(names=data['country'], to='ISO2', not_found=None)
data['iso3c'] = cc.convert(names=data['country'], to='ISO3', not_found=None)

# Filter out rows where ISO codes could not be matched — likely not real countries
data = data[data['iso2c'].notna() & data['iso3c'].notna()]

# Sort for calculation
data = data.sort_values(['iso3c', 'year'])

# Calculate YoY absolute and percent change
data['value_change'] = data.groupby('iso3c')['value'].diff()
data['value_change_percent'] = data.groupby('iso3c')['value'].pct_change() * 100

# Calculate ranks (higher GDP per capita = better rank)
data['rank'] = data.groupby('year')['value'].rank(ascending=False, method='dense')

# Calculate rank change from previous year
data['rank_change'] = data.groupby('iso3c')['rank'].diff()

# Select desired columns
final_df = data[['country', 'iso2c', 'iso3c', 'year', 'value',
'value_change', 'value_change_percent', 'rank', 'rank_change']].copy()

# Optional: Add labels as metadata (could be useful for export or UI)
column_labels = {
'country': 'Country name',
'iso2c': 'ISO 2-letter country code',
'iso3c': 'ISO 3-letter country code',
'year': 'Year',
'value': 'GDP per capita (current US$)',
'value_change': 'Year-over-Year change in value',
'value_change_percent': 'Year-over-Year percent change in value',
'rank': 'Country rank by GDP per capita (higher = richer)',
'rank_change': 'Change in rank from previous year'
}

# Display first few rows
print(final_df.head(10))

# Optional: Save to CSV
#final_df.to_csv("gdp_per_capita_cleaned.csv", index=False)
                    
                
                    
# Check and install required packages
required_packages <- c("WDI", "countrycode", "dplyr")

for (pkg in required_packages) {
  if (!requireNamespace(pkg, quietly = TRUE)) {
    install.packages(pkg)
  }
}

# Load the necessary libraries
library(WDI)
library(dplyr)
library(countrycode)

# Define the dataset code (World Bank indicator code)
dataset_code <- 'TX.VAL.FOOD.ZS.UN'

# Download data using WDI package
dat <- WDI(indicator = dataset_code)

# Filter only countries using 'is_country' from countrycode
# This uses iso2c to identify whether the entry is a recognized country
dat <- dat %>%
  filter(countrycode(iso2c, origin = 'iso2c', destination = 'country.name', warn = FALSE) %in%
           countrycode::codelist$country.name.en)

# Ensure dataset is ordered by country and year
dat <- dat %>%
  arrange(iso3c, year)

# Rename the dataset_code column to "value" for easier manipulation
dat <- dat %>%
  rename(value = !!dataset_code)

# Calculate year-over-year (YoY) change and percentage change
dat <- dat %>%
  group_by(iso3c) %>%
  mutate(
    value_change = value - lag(value),                              # Absolute change from previous year
    value_change_percent = 100 * (value - lag(value)) / lag(value) # Percent change from previous year
  ) %>%
  ungroup()

# Calculate rank by year (higher value => higher rank)
dat <- dat %>%
  group_by(year) %>%
  mutate(rank = dense_rank(desc(value))) %>% # Rank countries by descending value
  ungroup()

# Calculate rank change (positive = moved up, negative = moved down)
dat <- dat %>%
  group_by(iso3c) %>%
  mutate(rank_change = rank - lag(rank)) %>% # Change in rank compared to previous year
  ungroup()

# Select and reorder final columns
final_data <- dat %>%
  select(
    country,
    iso2c,
    iso3c,
    year,
    value,
    value_change,
    value_change_percent,
    rank,
    rank_change
  )

# Add labels (variable descriptions)
attr(final_data$country, "label") <- "Country name"
attr(final_data$iso2c, "label") <- "ISO 2-letter country code"
attr(final_data$iso3c, "label") <- "ISO 3-letter country code"
attr(final_data$year, "label") <- "Year"
attr(final_data$value, "label") <- "GDP per capita (current US$)"
attr(final_data$value_change, "label") <- "Year-over-Year change in value"
attr(final_data$value_change_percent, "label") <- "Year-over-Year percent change in value"
attr(final_data$rank, "label") <- "Country rank by GDP per capita (higher = richer)"
attr(final_data$rank_change, "label") <- "Change in rank from previous year"

# Print the first few rows of the final dataset
print(head(final_data, 10))