I want to filter GeoPandas GeoDataFrame rows by a list containing 4 'matches';
list_of_names = ['BE36_1000_1349', 'BE36_1000_1350', 'BE36_1000_1449', 'BE36_1000_1450']
.
I want to return four complete rows that have the index_tile
column matching the 4 elements in the above list.
print (topo50_df.filter(like=list_of_names))
--------------------------------------------
TypeError: 'in <string>' requires string as left operand, not list
print (topo50_df.query(str(list_of_names)))
--------------------------------------------
KeyError(f"None of [{key}] are in the [{axis_name}]") KeyError: "None of
[Index(['BE36_1000_1349', 'BE36_1000_1350', 'BE36_1000_1449',
'BE36_1000_1450'], dtype='object')] are in the [index]"
import geopandas as gpd
from shapely.geometry import Polygon
imagery_bb_polygon_df = gpd.GeoDataFrame(index=[0], crs=("epsg:2193"), geometry=[Polygon(list_of_points)])
topo50_df = gpd.read_file(topo50_geometry_file)
intersection_matches = topo50_df.overlay(imagery_bb_polygon_df, how='intersection', keep_geom_type=False)
list_of_names = list(intersection_matches.loc[1:4, 'index_tile'])
My GeoDataFrame named topo50_ref
looks like this:
index_tile sheet_code scale tile geometry
210648 BE36_1000_1349 BE36 1000 1349 POLYGON ((1875520.000 5792640.000, 1875040.000...
210649 BE36_1000_1350 BE36 1000 1350 POLYGON ((1876000.000 5792640.000, 1875520.000...
210698 BE36_1000_1449 BE36 1000 1449 POLYGON ((1875520.000 5791920.000, 1875040.000...
210699 BE36_1000_1450 BE36 1000 1450 POLYGON ((1876000.000 5791920.000, 1875520.000...
<class 'geopandas.geodataframe.GeoDataFrame'>