momepy.gini¶
-
momepy.gini(y, graph, q=
None)[source]¶ Calculates the Gini index of values within neighbours defined in
graph. Usesinequality.gini.Giniunder the hood. Requires ‘inequality’ package.Notes
The index of
ymust match the index along which thegraphis built.- Parameters:¶
- y : Series¶
A DataFrame or Series containing the values to be analysed.
- graph : libpysal.graph.Graph¶
A spatial weights matrix for the data.
- q : tuple, list, optional (default (0,100)))¶
A two-element sequence containing floats between 0 and 100 (inclusive) that are the percentiles over which to compute the range. The order of the elements is not important.
- Returns:¶
A Series containing resulting values.
- Return type:¶
Series
Examples
>>> from libpysal import graph >>> path = momepy.datasets.get_path("bubenec") >>> buildings = geopandas.read_file(path, layer="buildings") >>> buildings.head() uID geometry 0 1 POLYGON ((1603599.221 6464369.816, 1603602.984... 1 2 POLYGON ((1603042.88 6464261.498, 1603038.961 ... 2 3 POLYGON ((1603044.65 6464178.035, 1603049.192 ... 3 4 POLYGON ((1603036.557 6464141.467, 1603036.969... 4 5 POLYGON ((1603082.387 6464142.022, 1603081.574...Define spatial graph:
>>> knn5 = graph.Graph.build_knn(buildings.centroid, k=5) >>> knn5 <Graph of 144 nodes and 720 nonzero edges (1 component, 0 isolates) indexed by [0, 1, 2, 3, 4, ...]>Gini index of building area within 5 nearest neighbors:
>>> momepy.gini(buildings.area, knn5) focal 0 0.228493 1 0.102110 2 0.605867 3 0.085589 4 0.080435 ... 139 0.525724 140 0.156737 141 0.239009 142 0.259808 143 0.204820 Length: 144, dtype: float64To eliminate the effect of outliers, you can take into account only values within a specified percentile range (
q).>>> momepy.gini(buildings.area, knn5, q=(25, 75)) focal 0 0.073817 1 0.001264 2 0.077521 3 0.000321 4 0.001264 ... 139 0.505618 140 0.055096 141 0.130501 142 0.025522 143 0.110987 Length: 144, dtype: float64