How to Read the World Port Index in Python

On this page

Problem statement

The World Port Index, published by the US National Geospatial-Intelligence Agency, is the standard open list of the world's ports: 3,807 of them, each with its position, country, harbour size and type, depths, tides, the restrictions on entering, and 73 yes-or-no questions about its facilities, services and supplies. It is the reference behind most maps of ports and many shipping studies. Its CSV is 109 columns wide, and three conventions make it misleading if read as it comes: empty cells written as a single space, zeros where a measurement is unknown, and "Unknown" as a third answer to every yes-or-no question. This page reads it and handles each.

Quick answer

Read the CSV, which starts with a byte-order mark, and look at the first rows and the column types:

print(wpi[["World Port Index Number", "Main Port Name", "Country Code", "Harbor Size", "Harbor Type", "Latitude", "Longitude"]].head(3).to_string(index=False))
print(wpi.dtypes.value_counts().to_dict())
 World Port Index Number Main Port Name  Country Code Harbor Size       Harbor Type   Latitude  Longitude
                  7950.0         Maurer United States  Very Small   River (Natural)  40.533333 -74.250000
                 47620.0        Iharana    Madagascar  Very Small Coastal (Natural) -13.350000  50.000000
                 47020.0    Chake Chake      Tanzania       Small Coastal (Natural)  -5.250000  39.766667
{<StringDtype(na_value=nan)>: 92, dtype('float64'): 17}

The rows are in no useful order: Maurer, a very small river port in New Jersey, comes first, then Iharana in Madagascar and Chake Chake in Tanzania. 92 columns are read as text and only 17 as numbers. The World Port Index Number comes back as a float, 7950.0, because pandas reads the whole column as numbers.

World map of the 3,807 ports in the World Port Index by harbour size, very small and small ports along every coast and large ports concentrated in Europe, East Asia and North America. World map of the 3,807 ports in the World Port Index by harbour size, very small and small ports along every coast and large ports concentrated in Europe, East Asia and North America.
The ports of the World Port Index, by harbour size.

Blanks, zeros, flags and ids

1. Blank cells that are a space

print(f"cells holding a single space: {(wpi == ' ').sum().sum():,}; columns with any: {(wpi == ' ').any().sum()}")
print(wpi["Harbor Size"].value_counts(dropna=False).to_dict())
wpi = wpi.replace(r"^\s*$", np.nan, regex=True)
cells holding a single space: 16,106; columns with any: 10
{'Very Small': 2109, 'Small': 1021, 'Medium': 376, 'Large': 174, ' ': 127}

16,106 cells across 10 columns hold a single space instead of being empty, so isna() finds nothing and a value count shows " " as a category: 127 ports have a harbour size of " ". Replacing whitespace-only cells with missing values fixes every column at once.

2. Numbers, and zeros that mean unknown

DEPTHS = [c for c in wpi.columns if c.endswith("(m)")]
print(f"measurement columns: {len(DEPTHS)}")
print((wpi[DEPTHS] == 0).mean().sort_values().round(3).iloc[[0, 1, -2, -1]].to_string())
measurement columns: 13
Anchorage Depth (m)                         0.132
Channel Depth (m)                           0.168
Liquified Natural Gas Terminal Depth (m)    0.994
Offshore Maximum Vessel Beam (m)            0.996

13 columns hold measurements in metres, and a zero in them means "not recorded", not zero metres. 13.2% of anchorage depths and 16.8% of channel depths are 0, and the offshore vessel limits are 0 for 99.6% of ports. Treat 0 as missing before any average, as the zeros page shows.

Horizontal bars of the share of ports with 0 in each of 13 measurement columns, from 13.2% for anchorage depth to 99.6% for offshore maximum vessel beam. Horizontal bars of the share of ports with 0 in each of 13 measurement columns, from 13.2% for anchorage depth to 99.6% for offshore maximum vessel beam.
How often 0 stands for unknown in each measurement column.

3. Yes, No and Unknown

flags = [c for c in wpi.columns if set(wpi[c].dropna().unique()) <= {"Yes", "No", "Unknown"}]
print(f"Yes/No/Unknown columns: {len(flags)}")
print(wpi[flags].apply(lambda s: s.eq("Unknown").mean()).describe().round(3).loc[["min", "50%", "max"]].to_string())
Yes/No/Unknown columns: 73
min    0.000
50%    0.645
max    0.997

73 columns answer yes or no, and every one has "Unknown" as a third value. The median column is 64.5% Unknown, and one is Unknown for 99.7% of ports. Reading these as booleans turns Unknown into No.

4. Ids and points

print(f"index numbers unique: {wpi['World Port Index Number'].is_unique}; duplicated: {wpi['World Port Index Number'].duplicated(keep=False).sum()}")
print(f"UN/LOCODE given: {wpi['UN/LOCODE'].notna().sum():,}; coordinates missing: {wpi.Latitude.isna().sum()}")
ports = gpd.GeoDataFrame(wpi, geometry=gpd.points_from_xy(wpi.Longitude, wpi.Latitude), crs=4326)
print(ports.total_bounds.round(1).tolist())
index numbers unique: False; duplicated: 4
UN/LOCODE given: 3,348; coordinates missing: 0
[-177.4, -77.8, 179.4, 78.9]

The index number is not unique: 4 ports share 2 numbers, a duplicate of Seydisfjordur in Iceland under two spellings and two Nigerian ports. 3,348 ports have a UN/LOCODE, the code used in trade data, and every port has coordinates, from 177.4Β° W to 179.4Β° E and from McMurdo Station at 77.8Β° S to 78.9Β° N in the Arctic.

Ports by country and harbour type

The data used on this page

The US National Geospatial-Intelligence Agency's World Port Index (Pub. 150), the CSV served by its Maritime Safety Information site, downloaded on 28 October 2026 and saved on this site, because NGA revises the index as port information changes. A US government publication, free to use. Depths and lengths are in metres.

from pathlib import Path
import zipfile

import geopandas as gpd
import numpy as np
import pandas as pd
import requests

Path("data").mkdir(exist_ok=True)
# NGA's World Port Index (Pub. 150) as CSV, with Natural Earth's populated places, countries and land. Saved
# 28 October 2026: NGA revises the index as port information changes.
# Live: https://msi.nga.mil/api/publications/download?type=view&key=16920959/SFH00000/UpdatedPub150.csv
ARCHIVE = "nga-world-port-index-2026-10-28.zip"
if not Path(f"data/{ARCHIVE}").exists():
    Path(f"data/{ARCHIVE}").write_bytes(requests.get(f"https://data.spatialworkflow.io/{ARCHIVE}", timeout=600).content)
Z = zipfile.ZipFile(f"data/{ARCHIVE}")
for f in ["ne_10m_populated_places_simple.zip", "ne_110m_admin_0_countries.zip", "ne_50m_land.zip"]:
    Path(f"data/{f}").write_bytes(Z.read(f))
wpi = pd.read_csv(Z.open("UpdatedPub150.csv"), encoding="utf-8-sig")
print(f"World Port Index: {len(wpi):,} ports, {wpi.shape[1]} columns")
World Port Index: 3,807 ports, 109 columns

Example 1: ports by country

print(wpi["Country Code"].value_counts().head(8).to_string())
print(f"countries and territories: {wpi['Country Code'].nunique()}")
Country Code
United States     666
Canada            285
United Kingdom    186
Japan             163
Norway            141
Indonesia         123
Italy             123
Sweden             92
countries and territories: 195

The United States has the most ports in the index, 666, then Canada with 285, the United Kingdom 186, Japan 163 and Norway 141. North American and northern European waters are listed in far more detail than most of Africa and Asia, so a count of ports by country measures the index's coverage as much as the coastline.

Horizontal bars of ports by country for the twelve with the most: United States 666, Canada 285, United Kingdom 186, Japan 163, Norway 141. Horizontal bars of ports by country for the twelve with the most: United States 666, Canada 285, United Kingdom 186, Japan 163, Norway 141.
Ports by country.

Example 2: harbour size and type

print(pd.crosstab(wpi["Harbor Type"], wpi["Harbor Size"])[["Very Small", "Small", "Medium", "Large"]].to_string())
Harbor Size           Very Small  Small  Medium  Large
Harbor Type                                           
Canal or Lake                 26     29      11      6
Coastal (Breakwater)         347    250     124     71
Coastal (Natural)            821    304      93     33
Coastal (Tide Gates)           5     18       9      2
Open Roadstead               497    121      33     12
River (Basins)                32     35      12      8
River (Natural)              362    198      77     29
River (Tide Gates)            13     16      16     10
Typhoon Harbor                 3      1       0      0

By type and size, natural coastal harbours are the most common very small ports, 821, while harbours protected by breakwaters supply the most large ones, 71. Open roadsteads, anchorages off an open coast, are mostly very small. River ports with tide gates are few, but nearly half of them, 16 medium and 10 large, are big ports.