#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().run_line_magic('matplotlib', 'inline') import geopandas as gpd import pysal as ps import pandas as pd import numpy as np from shapely.geometry import Point # ## Obtain a point dataset # In[2]: pts = gpd.read_file(ps.examples.get_path('columbus.shp')).centroid pts.plot(); # ## Extract XY coords. into columns # In[3]: xys = pd.DataFrame(pts.apply(lambda pt: pd.Series({'X': pt.x, 'Y': pt.y}))) xys.head() # ## Pack XY coords into geometry # In[4]: new_pts = gpd.GeoDataFrame({'geometry': xys.apply(lambda r: Point(r['X'], r['Y']), axis=1) }, crs=pts.crs) new_pts.plot()