Loading a CSV dataset

To load a dataset into the account using CARTOframes, we will use the pandas library again, which is installed with the Jupyter modules. Pandas allow us to read data from a CSV (and other file formats), loading it into a Pandas dataframe (a special data object that allows for a multitude of data-manipulation methods, as well as producing output). Then, using CartoContext, the dataframe is written (as a table) to the account:

import pandas as pdAPIKEY = "{YOUR API KEY}"cc = cartoframes.CartoContext(base_url='https://{username}.carto.com/', api_key=APIKEY)df = pd.read_csv(r'Path\to\sacramento.csv')cc.write(df, 'sacramento_addresses')

This will write the CSV table, imported as a dataframe, into the CARTO account DATASETS ...

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.