dtoolkit.geoaccessor.geoseries.xy#
- dtoolkit.geoaccessor.geoseries.xy(s: GeoSeries, /, reverse: bool = False, frame: bool = True, drop: bool = True, name: Hashable | tuple[Hashable, Hashable] = ('x', 'y')) Series | DataFrame | GeoDataFrame [source]#
Return the x and y location of Point geometries in a GeoSeries.
- Parameters:
- reversebool, default False
If True, return (y, x) instead.
- framebool, default True
If True, return a DataFrame.
Changed in version 0.0.20: The default value of
frame
is set to True.- dropbool, default True
If True, only return the new generated coordinates.
- nameHashable or a tuple of Hashable, default (‘x’, ‘y’)
If
frame=True
, the column names of the returned DataFrame, else the name of the returned Series.
- Returns:
- Series, DataFrame, or GeoDataFrame
If
drop=False
, return a GeoDataFrame.If
drop=True
andframe=True
, return a DataFrame with x and y two columns.If
drop=True
andframe=False
, return a Series with tuple of coordinate.
Examples
>>> import dtoolkit.geoaccessor >>> import geopandas as gpd >>> from shapely import Point >>> s = gpd.GeoSeries([Point(0, 1), Point(0, 2), Point(0, 3)]) >>> s 0 POINT (0.00000 1.00000) 1 POINT (0.00000 2.00000) 2 POINT (0.00000 3.00000) dtype: geometry
Get the x and y coordinates of each point as a tuple.
>>> s.xy(frame=False, name=None) 0 (0.0, 1.0) 1 (0.0, 2.0) 2 (0.0, 3.0) dtype: object
Set
reverse=True
to return (y, x).>>> s.xy(reverse=True, frame=False, name=None) 0 (1.0, 0.0) 1 (2.0, 0.0) 2 (3.0, 0.0) dtype: object
Set
frame=True
to return a DataFrame with x and y columns.>>> s.xy() x y 0 0.0 1.0 1 0.0 2.0 2 0.0 3.0
Keep the geometry column.
>>> s.xy(drop=False) x y geometry 0 0.0 1.0 POINT (0.00000 1.00000) 1 0.0 2.0 POINT (0.00000 2.00000) 2 0.0 3.0 POINT (0.00000 3.00000)