'filter dataframe checking if values in a column are certain object
I have a question. I have a GeoDataFrame object from geopandas with a column named "geometry" and polygons and multipolygons from shapely.geometry. I want to filter the dataframe and only leaving out the multipolygons (knowing that multipolygons are object).
I tried:
gdf = gdf[gdf["geometry"] == shapely.geometry.multipolygon.MultiPolygon]
I guess it could be something along the lines of "validate" if every value in the geometry column, is instance of this shapely.geometry.multipolygon.MultiPolygon object.
How could I filter out this Geo/DataFrame?
Solution 1:[1]
gdf = gdf.loc[gdf["geometry"].apply(lambda x: type(x) == shapely.geometry.multipolygon.MultiPolygon]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mohammad Ayoub |
