Maintaining the geostructure when indexing a geodataframe

797 views Asked by At

I'm having a bit of trouble extracting a single point from a GeoDataFrame in pandas/geopandas.

In fact if I use a single index (using iloc or ix) the function returns a pd.Series file, and I therefore lose all the attributes and methods. This is what I'm talking about:

>>> type(OMS)
<class 'geopandas.geodataframe.GeoDataFrame'>
>>> type(OMS.iloc[2:3])
<class 'geopandas.geodataframe.GeoDataFrame'>
>>> type(OMS.iloc[2])
<class 'pandas.core.series.Series'>

Is there a way to efficiently extract one geometry without changing data structure/type?

In particular I need to apply the buffer method (that exists in both GeoDataFrame and GeoSeries classes) on that extracted point.

Thanks!

1

There are 1 answers

2
Scott Boston On BEST ANSWER

Use double brackets:

OMS.iloc[[2]]