Population in the largest city (% of urban population)

Source: worldbank.org, 01.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Afghanistan Afghanistan 40.7 -1.06% 36
Angola Angola 36.8 -0.116% 46
Albania Albania 29.8 +1.5% 72
United Arab Emirates United Arab Emirates 31.9 -2.48% 67
Argentina Argentina 36.9 +0.352% 44
Armenia Armenia 56.6 -2.33% 15
Australia Australia 22.5 -0.681% 106
Austria Austria 36.3 -0.227% 49
Azerbaijan Azerbaijan 41.6 +0.0942% 33
Burundi Burundi 60 +0.567% 12
Belgium Belgium 18.3 -0.312% 123
Benin Benin 17.9 +1.25% 125
Burkina Faso Burkina Faso 43 +0.513% 29
Bangladesh Bangladesh 33.4 +0.0125% 57
Bulgaria Bulgaria 25.9 -0.446% 93
Bahrain Bahrain 50.8 +1.59% 19
Bosnia & Herzegovina Bosnia & Herzegovina 21.6 +0.165% 108
Belarus Belarus 27.9 +0.364% 81
Bolivia Bolivia 22.1 -0.339% 107
Brazil Brazil 12.2 +0.158% 139
Central African Republic Central African Republic 41.9 -1.72% 32
Canada Canada 19 -2.15% 116
Switzerland Switzerland 21.5 -0.971% 109
Chile Chile 39.9 +0.0311% 37
China China 3.23 +0.854% 151
Côte d’Ivoire Côte d’Ivoire 34.2 -0.24% 55
Cameroon Cameroon 26.8 +0.173% 86
Congo - Kinshasa Congo - Kinshasa 32.4 -0.222% 63
Congo - Brazzaville Congo - Brazzaville 61.8 +0.193% 11
Colombia Colombia 26.7 -0.138% 87
Costa Rica Costa Rica 34.7 +0.257% 54
Cuba Cuba 25.2 +0.36% 95
Czechia Czechia 16.3 -0.0682% 130
Germany Germany 5.5 +0.383% 150
Djibouti Djibouti 66.1 -0.213% 9
Denmark Denmark 26.3 +0.0841% 91
Dominican Republic Dominican Republic 36.9 +0.274% 43
Algeria Algeria 8.32 -0.315% 144
Ecuador Ecuador 27.1 +0.379% 85
Egypt Egypt 44.9 -0.132% 28
Eritrea Eritrea 71.6 +0.24% 5
Spain Spain 17 -0.778% 126
Estonia Estonia 47.5 +0.00306% 25
Ethiopia Ethiopia 18.3 -0.381% 124
Finland Finland 27.8 -0.392% 82
France France 20.1 -0.0539% 113
Gabon Gabon 38.1 -0.844% 40
United Kingdom United Kingdom 16.6 -0.321% 129
Georgia Georgia 48.3 +0.62% 23
Ghana Ghana 18.9 +0.618% 117
Guinea Guinea 38.3 -0.368% 38
Gambia Gambia 27.6 -0.424% 83
Guinea-Bissau Guinea-Bissau 68 +0.143% 7
Equatorial Guinea Equatorial Guinea 34.8 +1.01% 52
Greece Greece 37.5 -0.219% 41
Guatemala Guatemala 32.1 -0.31% 66
Hong Kong SAR China Hong Kong SAR China 100 0% 1
Honduras Honduras 24.4 -0.0902% 97
Croatia Croatia 30 -0.794% 71
Haiti Haiti 43 -0.108% 30
Hungary Hungary 25.4 +0.012% 94
Indonesia Indonesia 6.81 -0.237% 147
India India 6.32 +0.331% 149
Ireland Ireland 36.9 -0.687% 45
Iran Iran 13.5 -0.405% 137
Iraq Iraq 23.9 +0.206% 100
Israel Israel 48.5 +0.316% 21
Italy Italy 10.2 -0.0525% 143
Jamaica Jamaica 36.6 -0.127% 47
Jordan Jordan 21.1 -0.278% 110
Japan Japan 32.5 +0.124% 62
Kazakhstan Kazakhstan 16.8 -0.245% 128
Kenya Kenya 32.7 +0.243% 61
Kyrgyzstan Kyrgyzstan 40.9 -0.644% 35
Cambodia Cambodia 51.2 +0.0573% 18
South Korea South Korea 23.7 +0.0421% 101
Kuwait Kuwait 67.4 -0.769% 8
Laos Laos 24.4 -0.795% 98
Lebanon Lebanon 46.2 -1.52% 27
Liberia Liberia 57.2 +0.256% 14
Libya Libya 19.7 -0.623% 114
Sri Lanka Sri Lanka 15 +0.635% 133
Lithuania Lithuania 27.2 -0.877% 84
Latvia Latvia 48.3 +0.14% 22
Macao SAR China Macao SAR China 100 0% 1
Morocco Morocco 15.8 -0.303% 131
Moldova Moldova 46.6 +1.9% 26
Madagascar Madagascar 30.7 +0.37% 70
Mexico Mexico 21 -0.203% 111
North Macedonia North Macedonia 57.4 +2.14% 13
Mali Mali 26.6 -0.486% 89
Myanmar (Burma) Myanmar (Burma) 32.3 -0.0261% 64
Mongolia Mongolia 69.6 +0.0884% 6
Mozambique Mozambique 14.1 -1.06% 136
Mauritania Mauritania 51.4 -0.236% 17
Malawi Malawi 33.1 +0.0516% 59
Malaysia Malaysia 31.3 +0.39% 68
Namibia Namibia 29.2 -0.416% 76
Niger Niger 32.1 -0.294% 65
Nigeria Nigeria 12.9 +0.184% 138
Nicaragua Nicaragua 26.6 -0.709% 88
Netherlands Netherlands 7.03 -0.285% 146
Norway Norway 23.4 +0.0269% 103
Nepal Nepal 24.5 +1.23% 96
New Zealand New Zealand 36.4 -0.724% 48
Oman Oman 35.7 -3.55% 50
Pakistan Pakistan 18.3 +0.0037% 121
Panama Panama 63.9 +0.142% 10
Peru Peru 42 +0.028% 31
Philippines Philippines 26.5 +0.357% 90
Papua New Guinea Papua New Guinea 28.6 -0.369% 80
Poland Poland 8.16 +0.284% 145
Puerto Rico Puerto Rico 81.2 -0.137% 2
North Korea North Korea 18.9 +0.0292% 118
Portugal Portugal 41.2 -1.44% 34
Paraguay Paraguay 81.1 -0.124% 3
Palestinian Territories Palestinian Territories 19.4 +0.104% 115
Qatar Qatar 28.7 -5.06% 79
Romania Romania 16.9 -0.927% 127
Russia Russia 11.7 +0.167% 141
Rwanda Rwanda 50 -0.00548% 20
Saudi Arabia Saudi Arabia 26 -3.06% 92
Sudan Sudan 35.3 +1.15% 51
Senegal Senegal 38.2 -0.143% 39
Singapore Singapore 100 0% 1
Sierra Leone Sierra Leone 34.8 -0.307% 53
El Salvador El Salvador 23.3 -0.593% 104
Somalia Somalia 29.6 -0.364% 74
Serbia Serbia 37.3 +0.276% 42
South Sudan South Sudan 18.6 -1.36% 120
Slovakia Slovakia 15.1 +0.162% 132
Sweden Sweden 18.3 +0.563% 122
Syria Syria 18.8 -1.74% 119
Chad Chad 33 -2.35% 60
Togo Togo 47.6 -0.484% 24
Thailand Thailand 28.9 +0.198% 77
Tajikistan Tajikistan 33.5 -0.345% 56
Turkmenistan Turkmenistan 22.6 -0.598% 105
Trinidad & Tobago Trinidad & Tobago 74.5 -0.169% 4
Tunisia Tunisia 28.9 +0.312% 78
Turkey Turkey 24.1 +0.473% 99
Tanzania Tanzania 31.2 +0.038% 69
Uganda Uganda 29.6 +0.15% 73
Ukraine Ukraine 11.4 -0.491% 142
Uruguay Uruguay 54.9 +0.352% 16
United States United States 6.7 -0.724% 148
Uzbekistan Uzbekistan 14.3 -0.99% 134
Venezuela Venezuela 11.9 +0.212% 140
Vietnam Vietnam 23.6 +0.187% 102
Yemen Yemen 20.7 -1.14% 112
South Africa South Africa 14.3 +0.0747% 135
Zambia Zambia 33.2 +0.343% 58
Zimbabwe Zimbabwe 29.5 -0.671% 75

                    
# 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 = 'EN.URB.LCTY.UR.ZS'

# 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 <- 'EN.URB.LCTY.UR.ZS'

# 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))