I have a DataFrame
that resulted from spatially joining a digital elevation map with a square grid map.
This unexpectedly resulted in duplicate rows where two rows will have the same "geometry"
but a different "Elevation"
value.
How do I get the median of "Elevation"
for each unique "geometry"
? I'm new to GeoPandas, so I tried the traditional methods of aggregating a DataFrame
, but found that "geometry"
cannot be operated with the groupby()
function.
mrkna_grid.groupby("geometry")['Elevation'].median()
I have also tried using the dissolve()
function, but I don't think I'm doing it correctly because the number of rows were reduced to just seventy (70) as opposed to the original two thousand (2000) before the spatial join.
mrkna_grid.dissolve(by="Elevation", aggfunc="median")
"geometry"
and the median of all its"Elevation"
associated with said"geometry"