布尔过滤器geopandas数据帧在

布尔过滤器geopandas数据帧在,pandas,geopandas,shapely,Pandas,Geopandas,Shapely,我有一个geopandas数据帧,我使用shapely在多点数据集上执行convexhull操作 top_sample_col.within(cvh_base) 这将返回一个布尔值,如何仅将那些赋值为true的赋值给新的gdf?(备选方案A) 我可以使用.set_index(),但是如何通过index=True进行过滤(选项B) 方案A是首选方法 编辑 这确实起到了作用,但它能更精简吗 df['within'] = top_sample_col.within(cvh_base) df = df

我有一个geopandas数据帧,我使用shapely在多点数据集上执行convexhull操作

top_sample_col.within(cvh_base)
这将返回一个布尔值,如何仅将那些赋值为true的赋值给新的gdf?(备选方案A)

我可以使用
.set_index()
,但是如何通过index=True进行过滤(选项B)

方案A是首选方法

编辑

这确实起到了作用,但它能更精简吗

df['within'] = top_sample_col.within(cvh_base)
df = df.loc[df['within'] == True]

可以将布尔数组作为掩码直接传递

df=df.loc[top\u sample\u col.in.(cvh\u base)]