过滤数据框检查列中的值是否是某个对象
我有一个问题。我有一个来自 geopandas 的 GeoDataFrame 对象,其中有一列名为“geometry”的列以及来自 shapely.geometry 的多边形和多重多边形。我想过滤数据框,只留下多边形(知道多边形是对象)。
我尝试过:
gdf = gdf[gdf["geometry"] == shapely.geometry.multipolygon.MultiPolygon]
我想如果几何列中的每个值都是此 shapely 的实例,则可能是“验证”的内容。 Geometry.multipolygon.MultiPolygon 对象。
我怎样才能过滤掉这个地理/数据框?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
loc[]
和isinstance()
的组合将过滤为仅多边形。下面是完整的工作示例。a combination of
loc[]
andisinstance()
will filter to just polygons. Full working example below.