I have dissolved polygons with geopandas. However, the head of attribute table became values of this table.
How can I fix this trouble?
See:
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communitySimple dissolve by GeoDataFrame field (Aggregation with dissolve)
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
continents = world.dissolve('continent')
continents.head(3)
But if we use as_index=False
from Pandas DataFrame.groupby
continents2 = world.dissolve('continent', as_index=False)
continents2.head(3)
Examine the GeoPandas test_dissolve.py script
It is a problem of indexing in DataFrame.groupby
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
continents = world.dissolve('continent')
type(continents)
<class 'geopandas.geodataframe.GeoDataFrame'>
continents.index
Index([u'Africa', u'Antarctica', u'Asia', u'Europe', u'North America',
u'Oceania', u'Seven seas (open ocean)', u'South America'],
dtype='object', name=u'continent')
continents is a GeoDataFrame with a hierarchical index
With
continents2 = world.dissolve('continent', as_index=False)
You eliminate the hierarchical index and you have the columns again