diff --git a/cartoframes/__version__.py b/cartoframes/__version__.py
index d2cd642a7..f3fad9939 100644
--- a/cartoframes/__version__.py
+++ b/cartoframes/__version__.py
@@ -1 +1 @@
-__version__ = '0.2.4b4'
+__version__ = '0.3.0b5'
diff --git a/cartoframes/context.py b/cartoframes/context.py
index 71f55d1fe..405b7f45b 100644
--- a/cartoframes/context.py
+++ b/cartoframes/context.py
@@ -58,22 +58,18 @@
class CartoContext(object):
"""CartoContext class for authentication with CARTO and high-level operations
such as reading tables from CARTO into dataframes, writing dataframes to
- CARTO tables, and creating custom maps from dataframes and CARTO tables.
- Future methods interact with CARTO's services like
- `Data Observatory Bases: CartoContext class for authentication with CARTO and high-level operations
such as reading tables from CARTO into dataframes, writing dataframes to
-CARTO tables, and creating custom maps from dataframes and CARTO tables.
-Future methods interact with CARTO’s services like
-Data Observatory, and routing,
-geocoding, and isolines.object
Manages connections with CARTO for data and map operations. Modeled after SparkContext.
-Example
-Create a CartoContext object:
-import cartoframes
-cc = cartoframes.CartoContext(BASEURL, APIKEY)
-
Credentials
instancecreds
¶cartoframes.Credentials – Credentials
instance
Example
+Create a CartoContext object:
+import cartoframes
+cc = cartoframes.CartoContext(BASEURL, APIKEY)
+
data_augment
(table_name, metadata)¶Interactive maps are rendered in an
-iframe
, while static maps are rendered in img
tags.
Interactive maps are +rendered as HTML in an iframe, while static maps are returned as +matplotlib Axes objects or IPython Image.
IPython.display.HTML
+IPython.display.HTML or matplotlib Axes
DataFrame representation of query supplied. Pandas data types are inferred from PostgreSQL data types. -In the case of PostgreSQL date types, the data type ‘object’ is -used.
+In the case of PostgreSQL date types, dates are attempted to be +converted, but on failure a data type ‘object’ is used.pandas.DataFrame
@@ -388,22 +397,19 @@read
(table_name, limit=None, index='cartodb_id', decode_geom=False)¶Read tables from CARTO into pandas DataFrames.
-Example
-import cartoframes
-cc = cartoframes.CartoContext(BASEURL, APIKEY)
-df = cc.read('acadia_biodiversity')
-
Read a table from CARTO into a pandas DataFrames.
Parameters: |
|
---|
Example
+import cartoframes
+cc = cartoframes.CartoContext(BASEURL, APIKEY)
+df = cc.read('acadia_biodiversity')
+
write
(df, table_name, temp_dir='/tmp', overwrite=False, lnglat=None, encode_geom=False, geom_col=None, **kwargs)¶write
(df, table_name, temp_dir='/Users/peschbacher/Library/Caches/cartoframes', overwrite=False, lnglat=None, encode_geom=False, geom_col=None, **kwargs)¶
Write a DataFrame to a CARTO table.
Example
Write a pandas DataFrame to CARTO.
@@ -444,8 +456,15 @@ guessing to create a geometry from the country column. This uses a CARTO Import API param content_guessing parameter.url = 'https://en.wikipedia.org/wiki/List_of_countries_by_life_expectancy'
+# retrieve first HTML table from that page
df = pd.read_html(url, header=0)[0]
-cc.write(df, 'life_expectancy', content_guessing=True)
+# send to carto, let it guess polygons based on the 'country'
+# column. Also set privacy to 'public'
+cc.write(df, 'life_expectancy',
+ content_guessing=True,
+ privacy='public')
+cc.map(layers=Layer('life_expectancy',
+ color='both_sexes_life_expectancy'))
Note
+DataFrame indexes are changed to ordinary columns. CARTO creates +an index called cartodb_id for every table that runs from 1 to +the length of the DataFrame.
+Layer classes for map creation. See examples in layer.Layer and layer.QueryLayer -for example usage.
+for example usage for data layers. See layer.BaseMap for +basemap layers.cartoframes.layer.
AbstractLayer
¶cartoframes.layer.
Layer
(table_name, source=None, overwrite=False, time=None, color=None, size=None, tooltip=None, legend=None)¶
Bases: cartoframes.layer.QueryLayer
A cartoframes Data Layer based on a specific table in user’s CARTO -database. This layer class is useful for visualizing individual datasets -with CartoContext.map().
+database. This layer class is used for visualizing individual datasets +with CartoContext.map()’slayers
+keyword argument.
Example
import cartoframes
from cartoframes import QueryLayer, styling
@@ -127,24 +131,38 @@
'scheme': styling.prism(10)})])
Parameters: See QueryLayer
for a full list of arguments.
Parameters: |
|
+
---|
cartoframes.layer.
QueryLayer
(query, time=None, color=None, size=None, tooltip=None, legend=None)¶Bases: cartoframes.layer.AbstractLayer
cartoframes Data Layer based on an arbitrary query to the user’s CARTO +
cartoframes data layer based on an arbitrary query to the user’s CARTO database. This layer class is useful for offloading processing to the cloud to do some of the following:
SELECT * FROM table LIMIT
+1000
)Used in the layers keyword in CartoContext.map().
Example
@@ -186,62 +204,77 @@Style to apply to layer.
-If time is a dict
, the following keys are options:
Time-based style to apply to layer.
+If time is a str
, it must be the name of a column which
+has a data type of datetime or float.
If time is a dict
, the following keys are options:
avg
, sum
, or another PostgreSQL aggregate
-functions
+avg
,
+sum
, or another PostgreSQL aggregate functions
with a numeric output. Defaults to count
.True
) or not (False
, default)If time is a str
, then it must be a column name available in
-the query that is of type numeric or datetime.
Color style to apply to map.
-If color is a dict
, the following keys are options, with
+
Color style to apply to map. For +example, this can be used to change the color of all geometries +in this layer, or to create a graduated color or choropleth map.
+If color is a str
, there are two options:
If color is a dict
, the following keys are options, with
values described:
quantiles
, equal
,
-headtails
, or jenks
. Defaults to quantiles
.If you wish to define a custom scheme outside of CartoColors, it +is recommended to use the styling.custom +utility function.
+Size style to apply to point data.
-If size is a dict
, the follow keys are options, with values
-described as:
Size style to apply to point data.
+If size is an int
, all points are sized by this value.
If size is a str
, this value is interpreted as a column,
+and the points are sized by the value in this column. The
+classification method defaults to quantiles, with a min size of
+5, and a max size of 5. Use the dict
input to override these
+values.
If size is a dict
, the follow keys are options, with
+values described as:
quantiles
, equal
,
-headtails
, or jenks
. Defaults to quantiles
.BinMethod
(excluding category).cartoframes.styling.
BinMethod
¶Bases: object
Data classification methods used for the styling of data on maps.
+quantiles
¶str – Quantiles classification for quantitative data
+jenks
¶str – Jenks classification for quantitative data
+headtails
¶str – Head/Tails classification for quantitative data
+equal
¶str – Equal Interval classification for quantitative data
+category
= 'category'equal
= 'equal'¶equal
= 'equal'headtails
= 'headtails'¶headtails
= 'headtails'jenks
= 'jenks'¶jenks
= 'jenks'quantiles
= 'quantiles'¶quantiles
= 'quantiles'cartoframes.styling.
custom
(colors, bins=None, bin_method='quantiles')¶Get custom scheme
+Create a custom scheme.
+Parameters: |
|
+
---|
CartoColor Safe qualitative scheme
cartoframes.styling.
scheme
(name, bins, bin_method)¶Return a custom scheme based on CartoColors.
+Parameters: |
|
+
---|
Warning
+Input types are particularly sensitive in this function, and little
+feedback is given for errors. name
and bin_method
arguments
+are case-sensitive.
cartoframes.styling.
sunset
(bins, bin_method='quantiles')¶context.
CartoContext
(base_url=None, api_key=None, creds=None, session=None, verbose=0)¶
CartoContext class for authentication with CARTO and high-level operations such as reading tables from CARTO into dataframes, writing dataframes to -CARTO tables, and creating custom maps from dataframes and CARTO tables. -Future methods interact with CARTO’s services like -Data Observatory, and routing, -geocoding, and isolines.
+CARTO tables, creating custom maps from dataframes and CARTO tables, and +augmenting data using CARTO’s Data Observatory. Future methods will interact with +CARTO’s services like routing, geocoding, and isolines, PostGIS backend for spatial +processing, and much more.Manages connections with CARTO for data and map operations. Modeled after SparkContext.
-Example
-Create a CartoContext object:
-import cartoframes
-cc = cartoframes.CartoContext(BASEURL, APIKEY)
-
Credentials
instancecreds
¶cartoframes.Credentials – Credentials
instance
Return type: |
|
---|---|
Return type: |
data_augment
(table_name, metadata)¶Augment an existing CARTO table with Data Observatory measures. See the full Data -Observatory catalog for all available -measures. The result of this operation is:
-Note
-This method alters table_name in the user’s CARTO database by -adding additional columns. To avoid this, create a copy of the -table first and use the new copy instead.
-Example
-Add new measures to a CARTO table and pass it to a pandas -DataFrame. Using the “Median Household Income in the past 12 -months” measure from the Data Observatory Catalog.
+Create a CartoContext object:
import cartoframes
cc = cartoframes.CartoContext(BASEURL, APIKEY)
-median_income = [{'numer_id': 'us.census.acs.B19013001',
- 'geom_id': 'us.census.tiger.block_group',
- 'numer_timespan': '2011 - 2015'}]
-df = cc.data_augment('transaction_events',
- median_income)
+
write
(df, table_name, temp_dir=SYSTEM_TMP_PATH, overwrite=False, lnglat=None, encode_geom=False, geom_col=None, **kwargs)¶Write a DataFrame to a CARTO table.
+Example
+Write a pandas DataFrame to CARTO.
+cc.write(df, 'brooklyn_poverty', overwrite=True)
+
Scrape an HTML table from Wikipedia and send to CARTO with content +guessing to create a geometry from the country column. This uses +a CARTO Import API param content_guessing parameter.
+url = 'https://en.wikipedia.org/wiki/List_of_countries_by_life_expectancy'
+# retrieve first HTML table from that page
+df = pd.read_html(url, header=0)[0]
+# send to carto, let it guess polygons based on the 'country'
+# column. Also set privacy to 'public'
+cc.write(df, 'life_expectancy',
+ content_guessing=True,
+ privacy='public')
+cc.map(layers=Layer('life_expectancy',
+ color='both_sexes_life_expectancy'))
Parameters: |
|
---|---|
Returns: | A DataFrame representation of table_name which -has new columns for each measure in metadata. + |
Returns: | If lnglat flag is set and the
+DataFrame has more than 100,000 rows, a |
Return type: | pandas.DataFrame + |
Return type: |
|
Note
+DataFrame indexes are changed to ordinary columns. CARTO creates +an index called cartodb_id for every table that runs from 1 to +the length of the DataFrame.
+data_boundaries
(df=None, table_name=None)¶Not currently implemented
-data_discovery
(keywords=None, regex=None, time=None, boundary=None)¶Not currently implemented
+read
(table_name, limit=None, index='cartodb_id', decode_geom=False)¶Read a table from CARTO into a pandas DataFrames.
+Parameters: |
|
+
---|---|
Returns: | DataFrame representation of table_name from +CARTO. + |
+
Return type: | pandas.DataFrame + |
+
Example
+import cartoframes
+cc = cartoframes.CartoContext(BASEURL, APIKEY)
+df = cc.read('acadia_biodiversity')
+
query
(query, table_name=None, decode_geom=False)¶Pull the result from an arbitrary SQL query from a CARTO account +into a pandas DataFrame. Can also be used to perform database +operations (creating/dropping tables, adding columns, updates, etc.).
+Parameters: |
|
+
---|---|
Returns: | DataFrame representation of query supplied. +Pandas data types are inferred from PostgreSQL data types. +In the case of PostgreSQL date types, dates are attempted to be +converted, but on failure a data type ‘object’ is used. + |
+
Return type: | pandas.DataFrame + |
+
map
(layers=None, interactive=True, zoom=None, lat=None, lng=None, size=(800, 400), ax=None)¶Interactive maps are rendered in an
-iframe
, while static maps are rendered in img
tags.
Interactive maps are +rendered as HTML in an iframe, while static maps are returned as +matplotlib Axes objects or IPython Image.
IPython.display.HTML
+IPython.display.HTML or matplotlib Axes
query
(query, table_name=None, decode_geom=False)¶Pull the result from an arbitrary SQL query from a CARTO account -into a pandas DataFrame. Can also be used to perform database -operations (creating/dropping tables, adding columns, updates, etc.).
-Parameters: |
|
-
---|---|
Returns: | DataFrame representation of query supplied. -Pandas data types are inferred from PostgreSQL data types. -In the case of PostgreSQL date types, the data type ‘object’ is -used. - |
-
Return type: | pandas.DataFrame - |
-
read
(table_name, limit=None, index='cartodb_id', decode_geom=False)¶Read tables from CARTO into pandas DataFrames.
-Example
-import cartoframes
-cc = cartoframes.CartoContext(BASEURL, APIKEY)
-df = cc.read('acadia_biodiversity')
-
Parameters: |
|
-
---|---|
Returns: | DataFrame representation of table_name from -CARTO. - |
-
Return type: | pandas.DataFrame - |
-
sync
(dataframe, table_name)¶Depending on the size of the DataFrame or CARTO table, perform -granular operations on a DataFrame to only update the changed cells -instead of a bulk upload. If on the large side, perform granular -operations, if on the smaller side use Import API.
+data_augment
(table_name, metadata)¶Augment an existing CARTO table with Data Observatory measures. See the full Data +Observatory catalog for all available +measures. The result of this operation is:
+Note
-Not yet implemented.
+This method alters table_name in the user’s CARTO database by +adding additional columns. To avoid this, create a copy of the +table first and use the new copy instead.
write
(df, table_name, temp_dir='/tmp', overwrite=False, lnglat=None, encode_geom=False, geom_col=None, **kwargs)¶Write a DataFrame to a CARTO table.
Example
-Write a pandas DataFrame to CARTO.
-cc.write(df, 'brooklyn_poverty', overwrite=True)
-
Scrape an HTML table from Wikipedia and send to CARTO with content -guessing to create a geometry from the country column. This uses -a CARTO Import API param content_guessing parameter.
-url = 'https://en.wikipedia.org/wiki/List_of_countries_by_life_expectancy'
-df = pd.read_html(url, header=0)[0]
-cc.write(df, 'life_expectancy', content_guessing=True)
+Add new measures to a CARTO table and pass it to a pandas
+DataFrame. Using the “Median Household Income in the past 12
+months” measure from the Data Observatory Catalog.
+import cartoframes
+cc = cartoframes.CartoContext(BASEURL, APIKEY)
+median_income = [{'numer_id': 'us.census.acs.B19013001',
+ 'geom_id': 'us.census.tiger.block_group',
+ 'numer_timespan': '2011 - 2015'}]
+df = cc.data_augment('transaction_events',
+ median_income)
Parameters: |
|
||||||
---|---|---|---|---|---|---|---|
Returns: | If lnglat flag is set and the
-DataFrame has more than 100,000 rows, a | ||||||
Returns: | A DataFrame representation of table_name which +has new columns for each measure in metadata. |
||||||
Return type: |
| ||||||
Return type: | pandas.DataFrame |
Parameters: |
|
+
---|
layer.
QueryLayer
(query, time=None, color=None, size=None, tooltip=None, legend=None)¶cartoframes Data Layer based on an arbitrary query to the user’s CARTO +
cartoframes data layer based on an arbitrary query to the user’s CARTO database. This layer class is useful for offloading processing to the cloud to do some of the following:
SELECT * FROM table LIMIT
+1000
)Used in the layers keyword in CartoContext.map().
Example
@@ -682,62 +698,77 @@Style to apply to layer.
-If time is a dict
, the following keys are options:
Time-based style to apply to layer.
+If time is a str
, it must be the name of a column which
+has a data type of datetime or float.
If time is a dict
, the following keys are options:
avg
, sum
, or another PostgreSQL aggregate
-functions
+avg
,
+sum
, or another PostgreSQL aggregate functions
with a numeric output. Defaults to count
.True
) or not (False
, default)If time is a str
, then it must be a column name available in
-the query that is of type numeric or datetime.
Color style to apply to map.
-If color is a dict
, the following keys are options, with
+
Color style to apply to map. For +example, this can be used to change the color of all geometries +in this layer, or to create a graduated color or choropleth map.
+If color is a str
, there are two options:
If color is a dict
, the following keys are options, with
values described:
quantiles
, equal
,
-headtails
, or jenks
. Defaults to quantiles
.If you wish to define a custom scheme outside of CartoColors, it +is recommended to use the styling.custom +utility function.
+Size style to apply to point data.
-If size is a dict
, the follow keys are options, with values
-described as:
Size style to apply to point data.
+If size is an int
, all points are sized by this value.
If size is a str
, this value is interpreted as a column,
+and the points are sized by the value in this column. The
+classification method defaults to quantiles, with a min size of
+5, and a max size of 5. Use the dict
input to override these
+values.
If size is a dict
, the follow keys are options, with
+values described as:
quantiles
, equal
,
-headtails
, or jenks
. Defaults to quantiles
.BinMethod
(excluding category).styling.
BinMethod
¶Data classification methods used for the styling of data on maps.
+quantiles
¶str – Quantiles classification for quantitative data
+jenks
¶str – Jenks classification for quantitative data
+headtails
¶str – Head/Tails classification for quantitative data
+equal
¶str – Equal Interval classification for quantitative data
+category
¶str – Category classification for qualitative data
+styling.
antique
(bins, bin_method='category')¶styling.
custom
(colors, bins=None, bin_method='quantiles')¶Get custom scheme
+Create a custom scheme.
+Parameters: |
|
+
---|
styling.
scheme
(name, bins, bin_method)¶Return a custom scheme based on CartoColors.
+Parameters: |
|
+
---|
Warning
+Input types are particularly sensitive in this function, and little
+feedback is given for errors. name
and bin_method
arguments
+are case-sensitive.
styling.
sunset
(bins, bin_method='quantiles')¶Example
-Poll for a job’s status if you’ve caught the BatchJobStatus
+
Poll for a job’s status if you’ve caught the BatchJobStatus
instance.
import time
job = cc.write(df, 'new_table',
@@ -981,7 +1090,7 @@ BatchJobStatustime.sleep(5)
Create a BatchJobStatus
instance if you have a job_id output
+
Create a BatchJobStatus
instance if you have a job_id output
from a cc.write operation.
>>> from cartoframes import CartoContext, BatchJobStatus
>>> cc = CartoContext(username='...', api_key='...')
@@ -1272,6 +1381,14 @@ Indices and tablesModule Index
Version: | 0.3.0b5 | +
---|