dtoolkit.geoaccessor.geoseries.xy#
- dtoolkit.geoaccessor.geoseries.xy(s: GeoSeries, /, reverse: bool = False, frame: bool = True, drop: bool = True, name: Union[Hashable, tuple[Hashable, Hashable]] = ('x', 'y')) Union[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
frameis 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.- xstr, default ‘x’
Name of the x column if frame=True.
Deprecated since version 0.0.20: Please use ‘name’ instead.
- ystr, default ‘y’
Name of the y column if frame=True.
Deprecated since version 0.0.20: Please use ‘name’ instead.
- Returns
- Series, DataFrame, or GeoDataFrame
If
drop=Fasle, return a GeoDataFrame.If
drop=Trueandframe=True, return a DataFrame with x and y two columns.If
drop=Trueandframe=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=Trueto 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=Trueto 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)