People using safely managed sanitation services, rural (% of rural population)

Source: worldbank.org, 03.09.2025

Year: 2022

Flag Country Value Value change, % Rank
Andorra Andorra 100 0% 1
United Arab Emirates United Arab Emirates 98.5 0% 4
Austria Austria 99.3 0% 3
Benin Benin 1.78 0% 88
Burkina Faso Burkina Faso 8.64 +4.43% 82
Bangladesh Bangladesh 32.4 +3.75% 59
Bulgaria Bulgaria 61.4 +1.04% 26
Belarus Belarus 48.7 +0.00635% 41
Bhutan Bhutan 57.9 0% 31
Central African Republic Central African Republic 5.71 0% 83
Canada Canada 83.5 0% 15
Switzerland Switzerland 99.6 0% 2
China China 36.7 +3.87% 53
Côte d’Ivoire Côte d’Ivoire 14.1 +2.83% 77
Congo - Kinshasa Congo - Kinshasa 11.2 0% 78
Costa Rica Costa Rica 35.6 +0.574% 54
Cuba Cuba 56 +1.31% 37
Germany Germany 91.4 0% 10
Djibouti Djibouti 20.9 0% 70
Dominican Republic Dominican Republic 47.6 -1.12% 44
Algeria Algeria 56 0% 36
Ecuador Ecuador 61 +1.18% 27
Egypt Egypt 63.1 0% 24
Ethiopia Ethiopia 4.22 0% 86
Fiji Fiji 57.3 -0.284% 34
United Kingdom United Kingdom 93.6 0% 8
Georgia Georgia 39.2 -1.91% 52
Ghana Ghana 18.4 +5.67% 73
Gambia Gambia 22.6 -6.62% 67
Guinea-Bissau Guinea-Bissau 10.7 0% 79
Guyana Guyana 48 -1.16% 43
Honduras Honduras 70.5 +1.63% 21
Hungary Hungary 80.7 0% 17
India India 57.4 +4.99% 33
Ireland Ireland 70.7 -0.103% 20
Iraq Iraq 48 +0.389% 42
Israel Israel 93.8 +0.735% 7
Italy Italy 78.1 0% 18
Kenya Kenya 33 +1.05% 58
Kyrgyzstan Kyrgyzstan 96.5 0% 6
Cambodia Cambodia 34.1 +5.42% 56
Kiribati Kiribati 25.1 +1.66% 65
Laos Laos 59.8 0% 28
Lesotho Lesotho 51 0% 40
Lithuania Lithuania 90.5 +1.31% 11
Luxembourg Luxembourg 88.5 +0.301% 12
Madagascar Madagascar 9.68 +3.81% 81
North Macedonia North Macedonia 18 0% 74
Mali Mali 22.9 +4.89% 66
Myanmar (Burma) Myanmar (Burma) 64.3 0% 23
Montenegro Montenegro 43.1 +1.59% 49
Mongolia Mongolia 56.3 +2.03% 35
Mozambique Mozambique 20.9 +4.31% 71
Malawi Malawi 47.3 +4.97% 45
Niger Niger 5.58 +3.8% 84
Nigeria Nigeria 26.6 +0.77% 64
Netherlands Netherlands 97.5 0% 5
Nepal Nepal 52.2 0% 39
Pakistan Pakistan 40.2 +4.37% 51
Philippines Philippines 68.8 +2.17% 22
North Korea North Korea 1.23 0% 89
Portugal Portugal 86.3 +1.19% 13
Paraguay Paraguay 59 +2% 30
Palestinian Territories Palestinian Territories 54.7 +4.42% 38
Rwanda Rwanda 57.9 0% 32
Senegal Senegal 14.2 +2.5% 76
Sierra Leone Sierra Leone 9.82 +5.07% 80
Somalia Somalia 21.8 0% 69
Serbia Serbia 29.3 -0.164% 63
São Tomé & Príncipe São Tomé & Príncipe 31.5 0% 60
Suriname Suriname 33.9 0% 57
Slovakia Slovakia 75.5 -0.00803% 19
Sweden Sweden 91.8 0% 9
Turks & Caicos Islands Turks & Caicos Islands 43.9 0% 48
Chad Chad 4.22 0% 87
Togo Togo 4.68 0% 85
Thailand Thailand 22.2 0% 68
Tajikistan Tajikistan 59.3 0% 29
Tonga Tonga 35 -0.761% 55
Tunisia Tunisia 62.9 0% 25
Turkey Turkey 81.1 +1.85% 16
Tuvalu Tuvalu 42.1 -1.75% 50
Tanzania Tanzania 19.8 -0.00294% 72
Uganda Uganda 16.2 +0.805% 75
Uzbekistan Uzbekistan 85.9 +0.251% 14
Vietnam Vietnam 45.4 +1.64% 46
Samoa Samoa 44.3 -1.36% 47
Zambia Zambia 30.5 0% 61
Zimbabwe Zimbabwe 30.4 0% 62

                    
# 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.STA.SMSS.RU.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.STA.SMSS.RU.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))