python - Select specific regions of .shp file using Geopandas -
i have .shp file contains limits of oceans , seas. but, instead of plotting of them, i'm interested in 6. geopandas creates similar dataframe (let's call "df"), pandas. possible create new dataframe ("df1") have selected areas of "df"?
from mpl_toolkits.basemap import basemap import numpy np import matplotlib.pyplot plt import geopandas gp tes = gp.read_file(r'your\path\world_seas_iho_v1\world_seas.shp') tes1 = tes[(tes.name == "north pacific ocean"), (tes.name == "south pacific ocean")] tes1.plot() plt.show() plt.ion()
when run this, "tes1" gets error:
"series objects mutable, cannot hashed."
any idea?
thanks!
(tes.name == "north pacific ocean"), (tes.name == "south pacific ocean")
tuple
of boolean series. can't pass indexer. want use bitwise or |
combine boolean series , use result slice dataframe.
from mpl_toolkits.basemap import basemap import numpy np import matplotlib.pyplot plt import geopandas gp tes = gp.read_file(r'your\path\world_seas_iho_v1\world_seas.shp') tes1 = tes[(tes.name == "north pacific ocean") | (tes.name == "south pacific ocean")] tes1.plot() plt.show() plt.ion()
or use isin
tes = gp.read_file(r'your\path\world_seas_iho_v1\world_seas.shp') tes1 = tes[tes.name.isin(['north pacific ocean', 'south pacific ocean'])] tes1.plot() plt.show() plt.ion()
wiki
Comments
Post a Comment