I want to dissolve a dataframe grouped by two columns. However, in the documentation of the Dissolve function only one column is provided:

GeoDataFrame.dissolve(by=None, aggfunc='first', as_index=True,
level=None, sort=True, observed=False, dropna=True)

The columns of the dataframe can be thought of like this:

State, Districts, City, Number_Inhabitantes

Instead of the syntax given in the documentation, I would like to do something similar to this, to get the number of Inhabitants per District instead of having the Number of Inhabitantes per city:

GeoDataFrame.dissolve(by= "State"&"Districts",aggfunc={"Number_Inhabitantes": "count"} )

Is there a way to do this?

1 Answer 1


Yes, it is pretty straightforward : the by argument can be a list of column names, even though the doc doesn't mention this. So to obtain "the number of Inhabitants per District", you may use the following :

gdf.dissolve(by=['States', 'Districts'], aggfunc={'Number_Inhabitantes': 'sum'})

N.B.: this will result in a multi-indexed dataframe.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.