Food imports (% of merchandise imports)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Albania Albania 16.6 +3.27% 19
Argentina Argentina 9.08 -14.9% 63
Armenia Armenia 8.38 -17.2% 67
Antigua & Barbuda Antigua & Barbuda 27.7 +2.3% 1
Australia Australia 6.45 +5.31% 79
Azerbaijan Azerbaijan 13.4 -7.85% 33
Belgium Belgium 11.5 +20.3% 47
Burkina Faso Burkina Faso 11.2 -1.63% 50
Bulgaria Bulgaria 13.2 +8.31% 36
Bosnia & Herzegovina Bosnia & Herzegovina 17.4 +6.59% 15
Belize Belize 18.5 -1.14% 13
Bolivia Bolivia 7.51 +5.07% 70
Brazil Brazil 5.71 +6.49% 82
Barbados Barbados 22.7 +2.58% 4
Canada Canada 9.19 +8.58% 61
Switzerland Switzerland 4.73 +11% 85
Chile Chile 12.3 +3.18% 42
China China 8.11 -9.76% 68
Cyprus Cyprus 15.3 +10.6% 26
Czechia Czechia 6.75 +6.24% 76
Germany Germany 9.18 +10.2% 62
Denmark Denmark 14 +3.14% 32
Dominican Republic Dominican Republic 17.2 +0.315% 17
Ecuador Ecuador 12.2 -6.13% 43
Egypt Egypt 20.4 -5.19% 7
Spain Spain 12.5 +1.69% 40
Estonia Estonia 14.2 +13.5% 30
Finland Finland 8.85 +2.79% 65
Fiji Fiji 19 -0.145% 10
United Kingdom United Kingdom 10.4 +4.42% 56
Georgia Georgia 12.4 -0.323% 41
Greece Greece 13.1 +7.45% 37
Grenada Grenada 24.2 +2.14% 2
Guatemala Guatemala 17.4 +2.69% 16
Guyana Guyana 7.48 -25.8% 71
Hong Kong SAR China Hong Kong SAR China 3.32 -6.97% 86
Croatia Croatia 14.3 +2.84% 29
Hungary Hungary 7.23 +5.46% 72
India India 5.06 +7.7% 84
Ireland Ireland 9.41 +10.1% 60
Iceland Iceland 11.5 +2.65% 49
Israel Israel 10.6 +4.63% 54
Italy Italy 11.5 +8.96% 48
Japan Japan 9.52 -1.68% 59
Kyrgyzstan Kyrgyzstan 9.01 -1.71% 64
South Korea South Korea 6.29 -0.723% 80
Sri Lanka Sri Lanka 15.3 -0.401% 25
Lithuania Lithuania 12.7 -0.106% 38
Luxembourg Luxembourg 14.8 +5.88% 28
Latvia Latvia 19.2 +2.75% 9
Macao SAR China Macao SAR China 18.5 +1.51% 14
Moldova Moldova 15.4 +9.21% 23
Maldives Maldives 21.2 +7.36% 5
Mexico Mexico 6.53 +3.29% 78
North Macedonia North Macedonia 11.7 +11.1% 46
Malta Malta 11.9 -12.3% 45
Myanmar (Burma) Myanmar (Burma) 9.74 -19.3% 57
Montenegro Montenegro 23.6 -2.14% 3
Mauritius Mauritius 21.2 -5.73% 6
Malaysia Malaysia 8.5 +1.87% 66
Namibia Namibia 13.2 -0.2% 35
Netherlands Netherlands 13.3 +9.87% 34
Norway Norway 11 +1.79% 52
New Zealand New Zealand 12.5 +10.8% 39
Pakistan Pakistan 14.1 -12.5% 31
Panama Panama 18.7 +14.6% 12
Philippines Philippines 15 +7.91% 27
Poland Poland 9.72 +4.96% 58
Portugal Portugal 15.3 +0.615% 24
Paraguay Paraguay 7.79 +4.37% 69
French Polynesia French Polynesia 15.9 +2.78% 21
Romania Romania 10.7 +1.13% 53
El Salvador El Salvador 20.1 +0.782% 8
Suriname Suriname 15.5 -1.85% 22
Slovakia Slovakia 7.11 +8.54% 74
Slovenia Slovenia 5.35 -14.8% 83
Sweden Sweden 11.2 +2.53% 51
Togo Togo 16.8 -13% 18
Thailand Thailand 6.59 -6.25% 77
Trinidad & Tobago Trinidad & Tobago 16.4 +20.9% 20
Turkey Turkey 6.22 -5.08% 81
Ukraine Ukraine 10.6 -0.274% 55
United States United States 6.93 +2.21% 75
Uzbekistan Uzbekistan 12.1 +5.89% 44
South Africa South Africa 7.17 +13.5% 73
Zimbabwe Zimbabwe 19 +37.2% 11

                    
# 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 = 'TM.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 <- 'TM.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))