An experimental Python pandas interface for using CARTO
Project description
A Python package for integrating CARTO maps and services into data science workflows.
Python data analysis workflows often rely on the de facto standards pandas and Jupyter notebooks. Integrating CARTO into this workflow saves data scientists time and energy by not having to export datasets as files or retain multiple copies of the data. Instead, CARTOFrames give the ability to communicate reproducible analysis while providing the ability to gain from CARTO’s services like hosted, dynamic or static maps and Data Observatory augmentation.
Complete documentation: https://cartodb.github.io/cartoframes/
Install Instructions
cartoframes relies on pandas and the CARTO Python SDK). To install cartoframes on your machine, do the following:
$ pip install cartoframes
Once you’ve done this, cartoframes will be installed. See the example usage section below for using cartoframes in a Jupyter notebook. User must have a CARTO API key for writing DataFrames to an account or reading from private tables.
Note: Eventually cartoframes will be fully installable from pip.
Example usage
Data workflow
Get table from CARTO, make changes in pandas, sync updates with CARTO:
import cartoframes
# `base_url`s are of the form `http://{username}.carto.com/` for most users
cc = cartoframes.CartoContext(base_url='https://eschbacher.carto.com/',
api_key=APIKEY)
# read a table from your CARTO account to a DataFrame
df = cc.read('brooklyn_poverty_census_tracts')
# do fancy pandas operations (add/drop columns, change values, etc.)
df['poverty_per_pop'] = df['poverty_count'] / df['total_population']
# updates CARTO table with all changes from this session
cc.write(df, 'brooklyn_poverty_census_tracts', overwrite=True)
Write an existing pandas DataFrame to CARTO.
import pandas as pd
import cartoframes
df = pd.read_csv('acadia_biodiversity.csv')
cc = cartoframes.CartoContext(base_url=BASEURL,
api_key=APIKEY)
cc.write(df, 'acadia_biodiversity')
Map workflow
The following will embed a CARTO map in a Jupyter notebook, allowing for custom styling of the maps driven by Turbo Carto and CartoColors. See the CartoColor wiki for a full list of available color schemes.
from cartoframes import Layer, BaseMap, styling
cc = cartoframes.CartoContext(base_url=BASEURL,
api_key=APIKEY)
cc.map(layers=[BaseMap('light'),
Layer('acadia_biodiversity',
color={'column': 'simpson_index',
'scheme': styling.tealRose(5)}),
Layer('peregrine_falcon_nest_sites',
size='num_eggs',
color={'column': 'bird_id',
'scheme': styling.vivid(10))],
interactive=True)
Augment from Data Observatory
Note: This is a provisional function, so the signature may change.
Interact with CARTO’s Data Observatory:
import cartoframes
cc = cartoframes.CartoContext(BASEURL, APIKEY)
# total pop, high school diploma (normalized), median income, poverty status (normalized)
# See Data Observatory catalog for codes: https://cartodb.github.io/bigmetadata/index.html
data_obs_measures = [{'numer_id': 'us.census.acs.B01003001'},
{'numer_id': 'us.census.acs.B15003017',
'normalization': 'predenominated'},
{'numer_id': 'us.census.acs.B19013001'},
{'numer_id': 'us.census.acs.B17001002',
'normalization': 'predenominated'},]
df = cc.data_augment('transactions', data_obs_measures)
df.head()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for cartoframes-0.2.1b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a6dc928be9ca75a04f4bd0c2b0fb8a97e09d29a5b38fdd3e80c68af4d36f297 |
|
MD5 | bc91cbe2d658aac4ae42d484e3d89ef4 |
|
BLAKE2b-256 | 6ae81f4d5790ab4f3f70fa0109acfe027d04a4136aad7237c02ce8c8a1087a78 |
Hashes for cartoframes-0.2.1b1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96b85f8b70a44ca7c4b5963f08d60ed349f54ae2832217a0ccaf806d1b4a04ed |
|
MD5 | f28f14eb43a1177424ce48dab41833be |
|
BLAKE2b-256 | a46bcbe2c4102c3b9c6d36eafcd42e31a6b78018c0e0a1f1b2e4a89d416749d3 |