{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Read data from a CARTO SQL Query\n", "\n", "This example illustrates how to read data from a CARTO table using a SQL Query.\n", "\n", "> Use this when you need to see or modify the data locally. If you only need to visualize the data, just use the query directly in the Layer: `Layer('SELECT * FROM dataset_name')`\n", "\n", "_Note: You'll need [CARTO Account](https://carto.com/signup) credentials to reproduce this example._" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from cartoframes.auth import set_default_credentials\n", "\n", "set_default_credentials('cartoframes')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
cartodb_idthe_geomfield_1nameaddressrevenue
01POINT (-73.95901 40.67109)0Franklin Ave & Eastern Pkwy341 Eastern Pkwy,Brooklyn, NY 112381321040.772
12POINT (-73.96122 40.57796)1607 Brighton Beach Ave607 Brighton Beach Avenue,Brooklyn, NY 112351268080.418
23POINT (-73.98976 40.61912)265th St & 18th Ave6423 18th Avenue,Brooklyn, NY 112041248133.699
\n", "
" ], "text/plain": [ " cartodb_id the_geom field_1 \\\n", "0 1 POINT (-73.95901 40.67109) 0 \n", "1 2 POINT (-73.96122 40.57796) 1 \n", "2 3 POINT (-73.98976 40.61912) 2 \n", "\n", " name address \\\n", "0 Franklin Ave & Eastern Pkwy 341 Eastern Pkwy,Brooklyn, NY 11238 \n", "1 607 Brighton Beach Ave 607 Brighton Beach Avenue,Brooklyn, NY 11235 \n", "2 65th St & 18th Ave 6423 18th Avenue,Brooklyn, NY 11204 \n", "\n", " revenue \n", "0 1321040.772 \n", "1 1268080.418 \n", "2 1248133.699 " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes import read_carto\n", "\n", "gdf = read_carto(\"SELECT * FROM starbucks_brooklyn WHERE revenue > 1200000\")\n", "gdf.head()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", " None\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", " Static map image\n", " \n", " \n", "
\n", "
\n", "
\n", " \n", " \n", "
\n", "
\n", "
\n", "\n", " \n", "\n", "
\n", "
\n", " :\n", "
\n", " \n", " \n", "
\n", "
\n", "\n", "
\n", " StackTrace\n", "
    \n", "
    \n", "
    \n", "\n", "\n", "\n", "\n", "\n", "\">\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes.viz import Layer\n", "\n", "Layer(gdf)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 2 }