{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Enrich Polygons from a Dataset\n", "\n", "This example illustrates how to enrich polygons that are in a dataset with variables from CARTO's Data Observatory.\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('creds.json')" ] }, { "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", "
OBJECTIDFULLTRACTIDTRACTIDgeometry
0151013102901102901POLYGON ((-77.09099 38.84516, -77.08957 38.844...
1251013103000103000POLYGON ((-77.08558 38.82992, -77.08625 38.828...
2351013102902102902POLYGON ((-77.09520 38.84499, -77.09442 38.844...
\n", "
" ], "text/plain": [ " OBJECTID FULLTRACTID TRACTID \\\n", "0 1 51013102901 102901 \n", "1 2 51013103000 103000 \n", "2 3 51013102902 102902 \n", "\n", " geometry \n", "0 POLYGON ((-77.09099 38.84516, -77.08957 38.844... \n", "1 POLYGON ((-77.08558 38.82992, -77.08625 38.828... \n", "2 POLYGON ((-77.09520 38.84499, -77.09442 38.844... " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from geopandas import read_file\n", "\n", "census_track = 'http://libs.cartocdn.com/cartoframes/files/census_track.geojson'\n", "census_track_gdf = read_file(census_track)\n", "census_track_gdf.head(3)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "You can find more entities with the Global country filter. To apply that filter run:\n", "\tCatalog().country('glo')\n" ] }, { "data": { "text/plain": [ "[,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ]" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes.data.observatory import Catalog\n", "\n", "Catalog().country('usa').category('demographics').geographies" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "You can find more entities with the Global country filter. To apply that filter run:\n", "\tCatalog().country('glo')\n" ] }, { "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", " \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", " \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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
slugnamedescriptioncategory_idcountry_iddata_source_idprovider_idgeography_namegeography_descriptiontemporal_aggregationtime_coverageupdate_frequencyis_public_datalangversioncategory_nameprovider_namegeography_idid
0acs_sociodemogr_858c104eSociodemographics - United States of America (...The American Community Survey (ACS) is an ongo...demographicsusasociodemographicsusa_acsCensus Tract - United States of America (2015)Shoreline clipped TIGER/Line boundaries. More ...5yrs[2008-01-01, 2013-01-01)NoneTrueeng20082012DemographicsAmerican Community Surveycarto-do-public-data.carto.geography_usa_censu...carto-do-public-data.usa_acs.demographics_soci...
1acs_sociodemogr_6bf5c7f4Sociodemographics - United States of America (...The American Community Survey (ACS) is an ongo...demographicsusasociodemographicsusa_acsCensus Tract - United States of America (2015)Shoreline clipped TIGER/Line boundaries. More ...5yrsNoneNoneTrueeng20142018DemographicsAmerican Community Surveycarto-do-public-data.carto.geography_usa_censu...carto-do-public-data.usa_acs.demographics_soci...
2acs_sociodemogr_dda43439Sociodemographics - United States of America (...The American Community Survey (ACS) is an ongo...demographicsusasociodemographicsusa_acsCensus Tract - United States of America (2015)Shoreline clipped TIGER/Line boundaries. More ...5yrs[2011-01-01, 2016-01-01)NoneTrueeng20112015DemographicsAmerican Community Surveycarto-do-public-data.carto.geography_usa_censu...carto-do-public-data.usa_acs.demographics_soci...
3acs_sociodemogr_97c32d1fSociodemographics - United States of America (...The American Community Survey (ACS) is an ongo...demographicsusasociodemographicsusa_acsCensus Tract - United States of America (2015)Shoreline clipped TIGER/Line boundaries. More ...5yrs[2010-01-01, 2015-01-01)NoneTrueeng20102014DemographicsAmerican Community Surveycarto-do-public-data.carto.geography_usa_censu...carto-do-public-data.usa_acs.demographics_soci...
4acs_sociodemogr_d4b2cf03Sociodemographics - United States of America (...The American Community Survey (ACS) is an ongo...demographicsusasociodemographicsusa_acsCensus Tract - United States of America (2015)Shoreline clipped TIGER/Line boundaries. More ...5yrs[2006-01-01, 2011-01-01)NoneTrueeng20062010DemographicsAmerican Community Surveycarto-do-public-data.carto.geography_usa_censu...carto-do-public-data.usa_acs.demographics_soci...
5acs_sociodemogr_496a0675Sociodemographics - United States of America (...The American Community Survey (ACS) is an ongo...demographicsusasociodemographicsusa_acsCensus Tract - United States of America (2015)Shoreline clipped TIGER/Line boundaries. More ...5yrs[2013-01-01, 2018-01-01)NoneTrueeng20132017DemographicsAmerican Community Surveycarto-do-public-data.carto.geography_usa_censu...carto-do-public-data.usa_acs.demographics_soci...
6acs_sociodemogr_9ed5d625Sociodemographics - United States of America (...The American Community Survey (ACS) is an ongo...demographicsusasociodemographicsusa_acsCensus Tract - United States of America (2015)Shoreline clipped TIGER/Line boundaries. More ...5yrs[2007-01-01, 2012-01-01)NoneTrueeng20072011DemographicsAmerican Community Surveycarto-do-public-data.carto.geography_usa_censu...carto-do-public-data.usa_acs.demographics_soci...
7acs_sociodemogr_cfeb0968Sociodemographics - United States of America (...The American Community Survey (ACS) is an ongo...demographicsusasociodemographicsusa_acsCensus Tract - United States of America (2015)Shoreline clipped TIGER/Line boundaries. More ...5yrs[2009-01-01, 2014-01-01)NoneTrueeng20092013DemographicsAmerican Community Surveycarto-do-public-data.carto.geography_usa_censu...carto-do-public-data.usa_acs.demographics_soci...
8acs_sociodemogr_30d1f53Sociodemographics - United States of America (...The American Community Survey (ACS) is an ongo...demographicsusasociodemographicsusa_acsCensus Tract - United States of America (2015)Shoreline clipped TIGER/Line boundaries. More ...5yrs[2012-01-01, 2017-01-01)NoneTrueeng20122016DemographicsAmerican Community Surveycarto-do-public-data.carto.geography_usa_censu...carto-do-public-data.usa_acs.demographics_soci...
\n", "
" ], "text/plain": [ " slug \\\n", "0 acs_sociodemogr_858c104e \n", "1 acs_sociodemogr_6bf5c7f4 \n", "2 acs_sociodemogr_dda43439 \n", "3 acs_sociodemogr_97c32d1f \n", "4 acs_sociodemogr_d4b2cf03 \n", "5 acs_sociodemogr_496a0675 \n", "6 acs_sociodemogr_9ed5d625 \n", "7 acs_sociodemogr_cfeb0968 \n", "8 acs_sociodemogr_30d1f53 \n", "\n", " name \\\n", "0 Sociodemographics - United States of America (... \n", "1 Sociodemographics - United States of America (... \n", "2 Sociodemographics - United States of America (... \n", "3 Sociodemographics - United States of America (... \n", "4 Sociodemographics - United States of America (... \n", "5 Sociodemographics - United States of America (... \n", "6 Sociodemographics - United States of America (... \n", "7 Sociodemographics - United States of America (... \n", "8 Sociodemographics - United States of America (... \n", "\n", " description category_id country_id \\\n", "0 The American Community Survey (ACS) is an ongo... demographics usa \n", "1 The American Community Survey (ACS) is an ongo... demographics usa \n", "2 The American Community Survey (ACS) is an ongo... demographics usa \n", "3 The American Community Survey (ACS) is an ongo... demographics usa \n", "4 The American Community Survey (ACS) is an ongo... demographics usa \n", "5 The American Community Survey (ACS) is an ongo... demographics usa \n", "6 The American Community Survey (ACS) is an ongo... demographics usa \n", "7 The American Community Survey (ACS) is an ongo... demographics usa \n", "8 The American Community Survey (ACS) is an ongo... demographics usa \n", "\n", " data_source_id provider_id \\\n", "0 sociodemographics usa_acs \n", "1 sociodemographics usa_acs \n", "2 sociodemographics usa_acs \n", "3 sociodemographics usa_acs \n", "4 sociodemographics usa_acs \n", "5 sociodemographics usa_acs \n", "6 sociodemographics usa_acs \n", "7 sociodemographics usa_acs \n", "8 sociodemographics usa_acs \n", "\n", " geography_name \\\n", "0 Census Tract - United States of America (2015) \n", "1 Census Tract - United States of America (2015) \n", "2 Census Tract - United States of America (2015) \n", "3 Census Tract - United States of America (2015) \n", "4 Census Tract - United States of America (2015) \n", "5 Census Tract - United States of America (2015) \n", "6 Census Tract - United States of America (2015) \n", "7 Census Tract - United States of America (2015) \n", "8 Census Tract - United States of America (2015) \n", "\n", " geography_description temporal_aggregation \\\n", "0 Shoreline clipped TIGER/Line boundaries. More ... 5yrs \n", "1 Shoreline clipped TIGER/Line boundaries. More ... 5yrs \n", "2 Shoreline clipped TIGER/Line boundaries. More ... 5yrs \n", "3 Shoreline clipped TIGER/Line boundaries. More ... 5yrs \n", "4 Shoreline clipped TIGER/Line boundaries. More ... 5yrs \n", "5 Shoreline clipped TIGER/Line boundaries. More ... 5yrs \n", "6 Shoreline clipped TIGER/Line boundaries. More ... 5yrs \n", "7 Shoreline clipped TIGER/Line boundaries. More ... 5yrs \n", "8 Shoreline clipped TIGER/Line boundaries. More ... 5yrs \n", "\n", " time_coverage update_frequency is_public_data lang version \\\n", "0 [2008-01-01, 2013-01-01) None True eng 20082012 \n", "1 None None True eng 20142018 \n", "2 [2011-01-01, 2016-01-01) None True eng 20112015 \n", "3 [2010-01-01, 2015-01-01) None True eng 20102014 \n", "4 [2006-01-01, 2011-01-01) None True eng 20062010 \n", "5 [2013-01-01, 2018-01-01) None True eng 20132017 \n", "6 [2007-01-01, 2012-01-01) None True eng 20072011 \n", "7 [2009-01-01, 2014-01-01) None True eng 20092013 \n", "8 [2012-01-01, 2017-01-01) None True eng 20122016 \n", "\n", " category_name provider_name \\\n", "0 Demographics American Community Survey \n", "1 Demographics American Community Survey \n", "2 Demographics American Community Survey \n", "3 Demographics American Community Survey \n", "4 Demographics American Community Survey \n", "5 Demographics American Community Survey \n", "6 Demographics American Community Survey \n", "7 Demographics American Community Survey \n", "8 Demographics American Community Survey \n", "\n", " geography_id \\\n", "0 carto-do-public-data.carto.geography_usa_censu... \n", "1 carto-do-public-data.carto.geography_usa_censu... \n", "2 carto-do-public-data.carto.geography_usa_censu... \n", "3 carto-do-public-data.carto.geography_usa_censu... \n", "4 carto-do-public-data.carto.geography_usa_censu... \n", "5 carto-do-public-data.carto.geography_usa_censu... \n", "6 carto-do-public-data.carto.geography_usa_censu... \n", "7 carto-do-public-data.carto.geography_usa_censu... \n", "8 carto-do-public-data.carto.geography_usa_censu... \n", "\n", " id \n", "0 carto-do-public-data.usa_acs.demographics_soci... \n", "1 carto-do-public-data.usa_acs.demographics_soci... \n", "2 carto-do-public-data.usa_acs.demographics_soci... \n", "3 carto-do-public-data.usa_acs.demographics_soci... \n", "4 carto-do-public-data.usa_acs.demographics_soci... \n", "5 carto-do-public-data.usa_acs.demographics_soci... \n", "6 carto-do-public-data.usa_acs.demographics_soci... \n", "7 carto-do-public-data.usa_acs.demographics_soci... \n", "8 carto-do-public-data.usa_acs.demographics_soci... " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "datasets = Catalog().country('usa').category('demographics').geography('cdb_censustract_af861cba').datasets\n", "datasets.to_dataframe()" ] }, { "cell_type": "code", "execution_count": 5, "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", " \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", " \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", " \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", " \n", " \n", " \n", "
slugnamedescriptiondb_typeagg_methodcolumn_namevariable_group_iddataset_idid
79median_income_57be5af4Median IncomeMedian Household Income in the past 12 Months....FLOATAVGmedian_incomeNonecarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
165no_car_2207f034no_carWorkers age 16 and over with no vehicle. All p...FLOATSUMno_carcarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
166no_cars_3a983c4eno_carsCar-free households. The number of households ...FLOATSUMno_carscarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
167one_car_13b3a60bone_carOne car households. The number of households w...FLOATSUMone_carcarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
168two_cars_fec37223two_carsTwo car households. The number of households w...FLOATSUMtwo_carscarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
169three_cars_32e541e7three_carsThree car households. The number of households...FLOATSUMthree_carscarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
170four_more_cars_297e8a8afour_more_carsFour car households. The number of households ...FLOATSUMfour_more_carscarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
174commuters_by_ca_120481e3commuters_by_car_truck_vanCommuters by Car, Truck, or Van. The number of...FLOATSUMcommuters_by_car_truck_vancarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
175commuters_by_ca_59febe6fcommuters_by_carpoolCommuters by Carpool. The number of workers ag...FLOATSUMcommuters_by_carpoolcarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
177commuters_drove_acf77a1commuters_drove_aloneCommuters who drove alone. The number of worke...FLOATSUMcommuters_drove_alonecarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
197employed_educat_958fdcfeemployed_education_health_socialWorkers employed in firms in educational servi...FLOATSUMemployed_education_health_socialcarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
201employed_other__a5acf594employed_other_services_not_public_adminWorkers employed in firms in other services ex...FLOATSUMemployed_other_services_not_public_admincarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
205employed_transp_66aedbfdemployed_transportation_warehousing_utilitiesWorkers employed in firms in transportation, w...FLOATSUMemployed_transportation_warehousing_utilitiescarto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...carto-do-public-data.usa_acs.demographics_soci...
\n", "
" ], "text/plain": [ " slug name \\\n", "79 median_income_57be5af4 Median Income \n", "165 no_car_2207f034 no_car \n", "166 no_cars_3a983c4e no_cars \n", "167 one_car_13b3a60b one_car \n", "168 two_cars_fec37223 two_cars \n", "169 three_cars_32e541e7 three_cars \n", "170 four_more_cars_297e8a8a four_more_cars \n", "174 commuters_by_ca_120481e3 commuters_by_car_truck_van \n", "175 commuters_by_ca_59febe6f commuters_by_carpool \n", "177 commuters_drove_acf77a1 commuters_drove_alone \n", "197 employed_educat_958fdcfe employed_education_health_social \n", "201 employed_other__a5acf594 employed_other_services_not_public_admin \n", "205 employed_transp_66aedbfd employed_transportation_warehousing_utilities \n", "\n", " description db_type agg_method \\\n", "79 Median Household Income in the past 12 Months.... FLOAT AVG \n", "165 Workers age 16 and over with no vehicle. All p... FLOAT SUM \n", "166 Car-free households. The number of households ... FLOAT SUM \n", "167 One car households. The number of households w... FLOAT SUM \n", "168 Two car households. The number of households w... FLOAT SUM \n", "169 Three car households. The number of households... FLOAT SUM \n", "170 Four car households. The number of households ... FLOAT SUM \n", "174 Commuters by Car, Truck, or Van. The number of... FLOAT SUM \n", "175 Commuters by Carpool. The number of workers ag... FLOAT SUM \n", "177 Commuters who drove alone. The number of worke... FLOAT SUM \n", "197 Workers employed in firms in educational servi... FLOAT SUM \n", "201 Workers employed in firms in other services ex... FLOAT SUM \n", "205 Workers employed in firms in transportation, w... FLOAT SUM \n", "\n", " column_name \\\n", "79 median_income \n", "165 no_car \n", "166 no_cars \n", "167 one_car \n", "168 two_cars \n", "169 three_cars \n", "170 four_more_cars \n", "174 commuters_by_car_truck_van \n", "175 commuters_by_carpool \n", "177 commuters_drove_alone \n", "197 employed_education_health_social \n", "201 employed_other_services_not_public_admin \n", "205 employed_transportation_warehousing_utilities \n", "\n", " variable_group_id \\\n", "79 None \n", "165 carto-do-public-data.usa_acs.demographics_soci... \n", "166 carto-do-public-data.usa_acs.demographics_soci... \n", "167 carto-do-public-data.usa_acs.demographics_soci... \n", "168 carto-do-public-data.usa_acs.demographics_soci... \n", "169 carto-do-public-data.usa_acs.demographics_soci... \n", "170 carto-do-public-data.usa_acs.demographics_soci... \n", "174 carto-do-public-data.usa_acs.demographics_soci... \n", "175 carto-do-public-data.usa_acs.demographics_soci... \n", "177 carto-do-public-data.usa_acs.demographics_soci... \n", "197 carto-do-public-data.usa_acs.demographics_soci... \n", "201 carto-do-public-data.usa_acs.demographics_soci... \n", "205 carto-do-public-data.usa_acs.demographics_soci... \n", "\n", " dataset_id \\\n", "79 carto-do-public-data.usa_acs.demographics_soci... \n", "165 carto-do-public-data.usa_acs.demographics_soci... \n", "166 carto-do-public-data.usa_acs.demographics_soci... \n", "167 carto-do-public-data.usa_acs.demographics_soci... \n", "168 carto-do-public-data.usa_acs.demographics_soci... \n", "169 carto-do-public-data.usa_acs.demographics_soci... \n", "170 carto-do-public-data.usa_acs.demographics_soci... \n", "174 carto-do-public-data.usa_acs.demographics_soci... \n", "175 carto-do-public-data.usa_acs.demographics_soci... \n", "177 carto-do-public-data.usa_acs.demographics_soci... \n", "197 carto-do-public-data.usa_acs.demographics_soci... \n", "201 carto-do-public-data.usa_acs.demographics_soci... \n", "205 carto-do-public-data.usa_acs.demographics_soci... \n", "\n", " id \n", "79 carto-do-public-data.usa_acs.demographics_soci... \n", "165 carto-do-public-data.usa_acs.demographics_soci... \n", "166 carto-do-public-data.usa_acs.demographics_soci... \n", "167 carto-do-public-data.usa_acs.demographics_soci... \n", "168 carto-do-public-data.usa_acs.demographics_soci... \n", "169 carto-do-public-data.usa_acs.demographics_soci... \n", "170 carto-do-public-data.usa_acs.demographics_soci... \n", "174 carto-do-public-data.usa_acs.demographics_soci... \n", "175 carto-do-public-data.usa_acs.demographics_soci... \n", "177 carto-do-public-data.usa_acs.demographics_soci... \n", "197 carto-do-public-data.usa_acs.demographics_soci... \n", "201 carto-do-public-data.usa_acs.demographics_soci... \n", "205 carto-do-public-data.usa_acs.demographics_soci... " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes.data.observatory import Dataset\n", "\n", "dataset = Dataset.get('acs_sociodemogr_d4b2cf03')\n", "variables_df = dataset.variables.to_dataframe()\n", "variables_df[variables_df['description'].str.contains('car', case=False, na=False)]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'slug': 'no_car_2207f034',\n", " 'name': 'no_car',\n", " 'description': 'Workers age 16 and over with no vehicle. All people in a geographic area over the age of 16 who do not own a car.',\n", " 'db_type': 'FLOAT',\n", " 'agg_method': 'SUM',\n", " 'column_name': 'no_car',\n", " 'variable_group_id': 'carto-do-public-data.usa_acs.demographics_sociodemographics_usa_censustract_2015_5yrs_20062010.car_ownership',\n", " 'dataset_id': 'carto-do-public-data.usa_acs.demographics_sociodemographics_usa_censustract_2015_5yrs_20062010',\n", " 'id': 'carto-do-public-data.usa_acs.demographics_sociodemographics_usa_censustract_2015_5yrs_20062010.no_car'}" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from cartoframes.data.observatory import Variable\n", "\n", "variable = Variable.get('no_car_2207f034')\n", "variable.to_dict()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from cartoframes.data.observatory import Enrichment\n", "\n", "enrichment = Enrichment()\n", "\n", "enriched_dataset_gdf = enrichment.enrich_polygons(\n", " census_track_gdf,\n", " variables=[variable],\n", " aggregation='SUM'\n", ")" ] }, { "cell_type": "code", "execution_count": 8, "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", "
OBJECTIDFULLTRACTIDTRACTIDgeometryno_car
0151013102901102901POLYGON ((-77.09099 38.84516, -77.08957 38.844...0.657821
1251013103000103000POLYGON ((-77.08558 38.82992, -77.08625 38.828...87.516848
2351013102902102902POLYGON ((-77.09520 38.84499, -77.09442 38.844...123.512837
\n", "
" ], "text/plain": [ " OBJECTID FULLTRACTID TRACTID \\\n", "0 1 51013102901 102901 \n", "1 2 51013103000 103000 \n", "2 3 51013102902 102902 \n", "\n", " geometry no_car \n", "0 POLYGON ((-77.09099 38.84516, -77.08957 38.844... 0.657821 \n", "1 POLYGON ((-77.08558 38.82992, -77.08625 38.828... 87.516848 \n", "2 POLYGON ((-77.09520 38.84499, -77.09442 38.844... 123.512837 " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "enriched_dataset_gdf.head(3)" ] }, { "cell_type": "code", "execution_count": 9, "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", " \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", " 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, color_continuous_style\n", "\n", "Layer(enriched_dataset_gdf, color_continuous_style('no_car'))" ] } ], "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 }