GeoDataFrame.dissolve(by=None, aggfunc='first', as_index=True, level=None, sort=True, observed=False, dropna=True, **kwargs)[source]#

Dissolve geometries within groupby into single observation. This is accomplished by applying the unary_union method to all geometries within a groupself.

Observations associated with each groupby group will be aggregated using the aggfunc.

bystr or list-like, default None

Column(s) whose values define the groups to be dissolved. If None, the entire GeoDataFrame is considered as a single group. If a list-like object is provided, the values in the list are treated as categorical labels, and polygons will be combined based on the equality of these categorical labels.

aggfuncfunction or string, default “first”

Aggregation function for manipulation of data associated with each group. Passed to pandas groupby.agg method. Accepted combinations are:

  • function

  • string function name

  • list of functions and/or function names, e.g. [np.sum, ‘mean’]

  • dict of axis labels -> functions, function names or list of such.

as_indexboolean, default True

If true, groupby columns become index of result.

levelint or str or sequence of int or sequence of str, default None

If the axis is a MultiIndex (hierarchical), group by a particular level or levels.

Added in version 0.9.0.

sortbool, default True

Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each group. Groupby preserves the order of rows within each group.

Added in version 0.9.0.

observedbool, default False

This only applies if any of the groupers are Categoricals. If True: only show observed values for categorical groupers. If False: show all values for categorical groupers.

Added in version 0.9.0.

dropnabool, default True

If True, and if group keys contain NA values, NA values together with row/column will be dropped. If False, NA values will also be treated as the key in groups.

Added in version 0.9.0.


Keyword arguments to be passed to the pandas DataFrameGroupby.agg method which is used by dissolve. In particular, numeric_only may be supplied, which will be required in pandas 2.0 for certain aggfuncs.

Added in version 0.13.0.


See also


explode multi-part geometries into single geometries


>>> from shapely.geometry import Point
>>> d = {
...     "col1": ["name1", "name2", "name1"],
...     "geometry": [Point(1, 2), Point(2, 1), Point(0, 1)],
... }
>>> gdf = geopandas.GeoDataFrame(d, crs=4326)
>>> gdf
    col1                 geometry
0  name1  POINT (1.00000 2.00000)
1  name2  POINT (2.00000 1.00000)
2  name1  POINT (0.00000 1.00000)
>>> dissolved = gdf.dissolve('col1')
>>> dissolved  
name1  MULTIPOINT (0.00000 1.00000, 1.00000 2.00000)
name2                        POINT (2.00000 1.00000)