People using safely managed drinking water services, urban (% of urban population)

Source: worldbank.org, 03.09.2025

Year: 2022

Flag Country Value Value change, % Rank
Afghanistan Afghanistan 36.4 +0.0946% 75
Australia Australia 99.5 -0.0207% 5
Azerbaijan Azerbaijan 92.3 0% 20
Bangladesh Bangladesh 54.2 +0.0459% 62
Brazil Brazil 88.9 +0.549% 24
Bhutan Bhutan 58.9 +3.48% 55
Botswana Botswana 72.9 0% 44
Central African Republic Central African Republic 11.3 0% 87
Chile Chile 99.4 0% 7
China China 97.9 +0.193% 10
Côte d’Ivoire Côte d’Ivoire 58.8 -0.157% 56
Congo - Kinshasa Congo - Kinshasa 24.2 +0.504% 82
Colombia Colombia 81.2 -0.0611% 33
Costa Rica Costa Rica 80.4 0% 35
Czechia Czechia 98 0% 9
Germany Germany 100 0% 2
Dominican Republic Dominican Republic 46.9 -0.0162% 67
Algeria Algeria 73.1 0% 43
Ecuador Ecuador 74.7 0% 42
Spain Spain 99.8 0% 4
Ethiopia Ethiopia 38.6 +0.365% 74
Fiji Fiji 52.5 +0.0139% 63
France France 100 +0.0679% 1
Georgia Georgia 88 +0.0384% 27
Ghana Ghana 62.6 +0.257% 52
Gibraltar Gibraltar 100 0% 1
Gambia Gambia 67.8 +0.144% 48
Guinea-Bissau Guinea-Bissau 36.3 0% 76
Guatemala Guatemala 65.5 +0.116% 49
Hong Kong SAR China Hong Kong SAR China 100 0% 1
Honduras Honduras 78.4 +0.0703% 37
Croatia Croatia 96.6 0% 16
Hungary Hungary 100 0% 1
Indonesia Indonesia 34.6 +0.422% 78
Iran Iran 96.2 +0.0297% 17
Iraq Iraq 64.6 0% 50
Israel Israel 99.5 -0.0151% 6
Kyrgyzstan Kyrgyzstan 91.8 0% 21
Cambodia Cambodia 57.5 +1.27% 57
Kiribati Kiribati 20.4 +0.823% 84
Kuwait Kuwait 100 0% 1
Laos Laos 27 0% 80
Sri Lanka Sri Lanka 83 -2.63% 30
Lesotho Lesotho 72.6 +0.16% 45
Lithuania Lithuania 99.3 0% 8
Luxembourg Luxembourg 99.8 0% 3
Macao SAR China Macao SAR China 100 0% 1
Saint Martin (French part) Saint Martin (French part) 96.6 0% 15
Morocco Morocco 90.3 0% 22
Monaco Monaco 100 0% 1
Madagascar Madagascar 41.3 +2.83% 71
North Macedonia North Macedonia 84.6 0% 29
Myanmar (Burma) Myanmar (Burma) 72.4 0% 46
Montenegro Montenegro 87.3 0% 28
Mongolia Mongolia 51.3 +1.9% 65
Malawi Malawi 52.4 +1.42% 64
Nigeria Nigeria 35.7 +0.731% 77
Nepal Nepal 23.2 0% 83
Pakistan Pakistan 56.8 +1.04% 58
Peru Peru 59.8 +0.265% 54
Philippines Philippines 61.9 +0.157% 53
Palau Palau 97.7 +1.3% 11
North Korea North Korea 77 0% 40
Portugal Portugal 97.1 -0.00543% 14
Paraguay Paraguay 72.2 0% 47
Palestinian Territories Palestinian Territories 81.5 +0.345% 32
Romania Romania 95 0% 18
Rwanda Rwanda 54.6 +0.563% 61
Senegal Senegal 41.3 +0.263% 72
Singapore Singapore 100 0% 1
Sierra Leone Sierra Leone 12.2 +0.56% 86
El Salvador El Salvador 78.6 -0.201% 36
Serbia Serbia 81.5 0% 31
São Tomé & Príncipe São Tomé & Príncipe 40.3 0% 73
Suriname Suriname 63.4 0% 51
Eswatini Eswatini 77.5 +0.435% 38
Turks & Caicos Islands Turks & Caicos Islands 46.5 0% 68
Chad Chad 17.6 0% 85
Togo Togo 33.9 +0.222% 79
Turkmenistan Turkmenistan 97.1 0% 13
Tonga Tonga 50.8 +0.0877% 66
Tunisia Tunisia 77.4 +0.0418% 39
Tuvalu Tuvalu 10.5 +0.02% 88
Tanzania Tanzania 25.5 +1.05% 81
Uganda Uganda 45.1 +3.13% 70
Ukraine Ukraine 88.3 -0.0348% 26
Uruguay Uruguay 94.6 0% 19
United States United States 97.6 +0.0906% 12
Uzbekistan Uzbekistan 88.8 +0.0785% 25
Vietnam Vietnam 75.8 +0.139% 41
Vanuatu Vanuatu 56.3 +0.129% 59
Samoa Samoa 90.2 0% 23
South Africa South Africa 80.5 -0.675% 34
Zambia Zambia 45.5 0% 69
Zimbabwe Zimbabwe 55.5 0% 60

                    
# 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 = 'SH.H2O.SMDW.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 <- 'SH.H2O.SMDW.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))