Loading CSV with geometry

To ensure that a table (address data from OpenAddresses in this case) with latitude and longitude columns is imported as a geospatial dataset, we have to use the Shapely library's Point class. Each Point geometry is generated from the LON and LAT fields of the address dataset which has been imported:

import geopandas as gdpimport cartoframesimport pandas as pdfrom shapely.geometry import PointAPIKEY = "{API KEY}"cc = cartoframes.CartoContext(base_url='https://{username}.carto.com/',                              api_key=APIKEY)address_df = pd.read_csv(r'data/city_of_juneau.csv')geometry = [Point(xy) for xy in zip(address_df.LON, address_df.LAT)]address_df = address_df.drop(['LON', 'LAT'], axis=1)crs = {'init': 'epsg:4326'}geo_df = gdp.GeoDataFrame(address_df, ...

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.