--- id: segregation version: "2.5.5" license: BSD 3-Clause license_treatment: permissive maintenance: active --- # segregation — Analytics for spatial and non-spatial segregation in Python. License: permissive · Maintenance: active · Downloads: 150.7K/mo ## What it is and what it does Segregation is a PySAL package for quantifying and analyzing patterns of urban segregation using demographic data. It implements a large suite of segregation indices—ranging from classic measures like dissimilarity and isolation to modern spatial variants—and wraps them as classes that accept a pandas or geopandas DataFrame, a group-of-interest column, and a total-population column to produce point estimates. Beyond calculation, the package provides statistical inference (testing whether estimates are significant or comparing two estimates) and decomposition (breaking differences into spatial-structure and demographic-structure components). The package is built on a stack of geospatial and scientific Python libraries: geopandas for geometry handling, scikit-learn and scipy for statistical methods, numba for numerical acceleration, and joblib for parallelization. It targets researchers and practitioners analyzing residential patterns, income distribution, or other demographic segregation in urban areas. Spatial indices can use PySAL weights matrices, Euclidean distances, or topological relationships, giving users fine control over how distance and adjacency are defined. Use it for: - Calculate dissimilarity or isolation indices to measure how evenly a demographic group is distributed across neighborhoods. - Compare segregation levels between two cities or time periods using inference tests to determine statistical significance. - Decompose changes in segregation into components driven by shifts in spatial structure versus demographic composition. - Compute local segregation indices to identify neighborhoods with high or low segregation relative to the city overall. - Analyze segregation using multiscalar definitions or distance-decay models to understand patterns at different geographic scales. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Calculates over 40 segregation indices—both aspatial and spatial—to measure patterns of urban segregation, and tests their statistical significance and decomposes differences into spatial and demographic components. Yes. The package is actively maintained, has no known vulnerabilities, and fills a specialized but well-defined niche in spatial demographic analysis. Low install friction and a permissive license make adoption straightforward. Install it if you need to compute segregation indices or test segregation hypotheses; skip it if your work does not involve demographic or residential segregation measurement. ## Install pip install segregation uv add segregation poetry add segregation ## Installing segregation Before you install: Low friction installation with a pure-Python wheel. Active maintenance—last commit 2026-08-07, released 2026-06-18. Requires Python 3.12 or later. Pulls in 13 runtime dependencies including geopandas, scikit-learn, and scipy, which may add setup time in constrained environments. License in practice: BSD 3-Clause permissive license allows commercial and private use with minimal restrictions; you must retain the license and copyright notice. Quickstart: pip install segregation from segregation.aspatial import Dissim import pandas as pd df = pd.DataFrame({"group_pop": ["values"], "total_pop": ["values"]}) index = Dissim(df, "group_pop", "total_pop") print(index.statistic) Requires Python 3.12 or later. For spatial indices, input must be a geopandas.GeoDataFrame with a geometry column. Verify before relying: - Whether all 40+ segregation measures are equally well-maintained and documented. - Performance characteristics when working with large datasets or many spatial weights matrices. - Whether the package supports integration with external spatial network objects beyond PySAL weights. ## Package facts - License: BSD 3-Clause (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 150.7K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags segregation indices calculation, urban segregation analysis, spatial segregation measures, demographic segregation metrics, dissimilarity index computation, segregation inference testing, spatial demographics analysis, spatial-analysis, demographics, segregation-indices [View on SkillFed](https://skillfed.io/packages/segregation) · [View on PyPI](https://pypi.org/project/segregation/)