CARTOframes

A Python package for integrating CARTO maps, analysis, and data services into data science workflows.

What is CARTOframes?

CARTOframes is a Python package for integrating CARTO maps, analysis, and data services into data science workflows.

Python data analysis workflows often rely on the pandas and jupyter notebook de facto standards. 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. To understand the fundamentals of CARTOframes, read the guides. To view the source code, browse the open-source repository in GitHub and contribute. Otherwise, read the full reference API, or find different support options.

Guides

Quick reference guides for learning how to use CARTOframes features.

Reference

Browse the interactive API documentation to search for specific CARTOframes methods, arguments, and sample code that can be used to build your applications.

Check Full Reference API
1
2
3
4
5
6
7
8
9
10
from cartoframes.auth import Credentials, set_default_credentials
from cartoframes.data.observatory import Enrichment

set_default_credentials('creds.json')
enrichment = Enrichment()

enriched_dataset_cdf = enrichment.enrich_points(
    bikeshare_df,
    variables=['no_cars_d19dfd10']
)

Examples

Play with real examples and learn by doing.

Create a Dataset from a CSV file

This example illustrates how to create a Dataset from a CSV file using pandas

In [1]:
import pandas

remote_file_path = 'http://data.sfgov.org/resource/wg3w-h783.csv'

df = pandas.read_csv(remote_file_path)

# Clean latitude and longitude values that are NaN
df = df[df.longitude == df.longitude]
df = df[df.latitude == df.latitude]

df.head()
Out[1]:
incident_datetime incident_date incident_time incident_year incident_day_of_week report_datetime row_id incident_id incident_number cad_number ... point :@computed_region_6qbp_sg9q :@computed_region_qgnn_b9vv :@computed_region_26cr_cadq :@computed_region_ajp5_b2md :@computed_region_nqbw_i6c3 :@computed_region_2dwj_jsy4 :@computed_region_h4ep_8xdi :@computed_region_y6ts_4iup :@computed_region_jg9y_a9du
2 2019-10-04T14:25:00.000 2019-10-04T00:00:00.000 14:25 2019 Friday 2019-10-04T16:13:00.000 85442603474 854426 190746203 192772728.0 ... POINT (-122.51129492624534 37.77507596005672) 8.0 8.0 4.0 29.0 NaN NaN NaN NaN NaN
3 2019-10-03T19:30:00.000 2019-10-03T00:00:00.000 19:30 2019 Thursday 2019-10-03T23:25:00.000 85419706244 854197 190744514 192764437.0 ... POINT (-122.42746205880601 37.76877049785351) 28.0 3.0 5.0 5.0 5.0 NaN NaN NaN NaN
4 2019-10-04T16:53:00.000 2019-10-04T00:00:00.000 16:53 2019 Friday 2019-10-04T16:53:00.000 85446351040 854463 190746532 192772932.0 ... POINT (-122.5030864538133 37.781176766186576) 6.0 8.0 4.0 29.0 NaN NaN NaN NaN NaN
5 2019-10-02T14:10:00.000 2019-10-02T00:00:00.000 14:10 2019 Wednesday 2019-10-02T22:59:00.000 85425706224 854257 196208142 NaN ... POINT (-122.410497554147 37.80696290988273) 99.0 6.0 3.0 23.0 NaN NaN NaN NaN NaN
6 2019-10-03T23:30:00.000 2019-10-03T00:00:00.000 23:30 2019 Thursday 2019-10-03T23:31:00.000 85422712030 854227 190744586 192764446.0 ... POINT (-122.417715898404 37.807978726080414) 99.0 6.0 3.0 23.0 NaN NaN NaN NaN NaN

5 rows × 35 columns

In [2]:
from cartoframes.data import Dataset

ds = Dataset(df)
In [3]:
from cartoframes.viz import Map, Layer

Map(Layer(ds))
Out[3]: