esda: Exploratory Spatial Data Analysis in PySAL

raw JSON →
2.9.0 verified Mon Apr 27 auth: no python

esda is a Python library implementing methods for exploratory spatial data analysis, part of the PySAL family. It provides global and local spatial autocorrelation statistics (Moran's I, Geary's C, Getis-Ord G, etc.), spatial correlograms, and shape-based measures. Current version is 2.9.0, requires Python >=3.11. Releases follow a monthly-to-quarterly cadence, with active maintenance.

pip install esda
error ModuleNotFoundError: No module named 'esda.moran'
cause Trying to import Moran_Local from the wrong submodule.
fix
Use from esda import Moran_Local instead of from esda.moran import Moran_Local.
error ValueError: The weights matrix is not row-standardized.
cause Moran class expects row-standardized weights by default.
fix
Use w.transform = 'R' before passing to Moran, or create weights with row-standardization (e.g., libpysal.weights.KNN(..., transform='R')).
error AttributeError: 'Moran' object has no attribute 'I'
cause The object was not created correctly; perhaps `y` is not numeric or `w` is invalid.
fix
Ensure y is a 1D numeric array and w is a properly initialized libpysal weights object.
breaking In esda>=2.5, shapely>=2 is required and pygeos is no longer supported. Upgrade shapely or pin shapely<2.
fix pip install shapely>=2 or ensure you have a compatible version.
gotcha Moran_Local (Local Moran's I) uses a randomization-based p-value by default. For analytical p-values, set `permutations=0` when constructing the object.
fix moran_local = Moran_Local(y, w, permutations=0)
gotcha The `spatial_lag` function is not a separate function; use `libpysal.weights.lag_spatial(w, y)` instead.
fix import libpysal; lag = libpysal.weights.lag_spatial(w, y)
deprecated The `assuncao_rate` function is deprecated since version 2.5. Please use `esda.rate_smoothing.assuncao_rate` instead.
fix from esda.rate_smoothing import assuncao_rate
gotcha When using `Moran_Local.plot()` or `Moran_Local.scatterplot()`, ensure matplotlib is installed. These are available since v2.7.
fix pip install matplotlib
pip install esda[all]

Compute Global Moran's I with a K-nearest neighbors weight matrix.

import libpysal
from esda import Moran
import numpy as np

# Generate random data and a spatial weights matrix
np.random.seed(123)
y = np.random.random(100)
w = libpysal.weights.KNN(k=5, ids=np.arange(100))

# Compute Global Moran's I
mi = Moran(y, w)
print(f"Moran's I: {mi.I:.3f}, p-value: {mi.p_sim:.3f}")
# Output: Moran's I: -0.022, p-value: 0.632