In [1]:
import requests
import os
import pandas as pd
import geopandas as gpd
In [2]:
# com_pend_list = list()
# for cod_reg in range(1,21):
# print(f'Elaboro {cod_reg}')
# api_url_decoded = f"https://services1.arcgis.com/P14CytrnPG76qvy4/arcgis/rest/services/Mobilità_Comuni/FeatureServer/35/query?f=json&cacheHint=true&resultOffset=0&resultRecordCount=1600&where=(Cod_reg={cod_reg}) AND (Codice_indicatore='T_spotfuo')&orderByFields=Posto_in_graduatoria ASC&outFields=*&resultType=standard&returnGeometry=false&spatialRel=esriSpatialRelIntersects"
# r = requests.get(api_url_decoded)
# pend = r.json()
# com_pend = [d['attributes'] for d in pend['features']]
# df = pd.DataFrame(com_pend)
# com_pend_list.append(df)
# com_pend_df = pd.concat(com_pend_list)
In [3]:
cod_reg = 12 # Lazio
api_url_decoded = f"https://services1.arcgis.com/P14CytrnPG76qvy4/arcgis/rest/services/Mobilità_Comuni/FeatureServer/35/query?f=json&cacheHint=true&resultOffset=0&resultRecordCount=1600&where=(Cod_reg={cod_reg}) AND (Codice_indicatore='T_spotfuo')&orderByFields=Posto_in_graduatoria ASC&outFields=*&resultType=standard&returnGeometry=false&spatialRel=esriSpatialRelIntersects"
r = requests.get(api_url_decoded)
pend = r.json()
com_pend = [d['attributes'] for d in pend['features']]
com_pend_df = pd.DataFrame(com_pend)
com_pend_df['PRO_COM_T'] = com_pend_df['PRO_COM_T'].astype(str).str.zfill(6)
In [4]:
com_pend_df.head()
Out[4]:
| OBJECTID | Anno | Area_tematica | Cod_reg | Den_reg | Cod_prov | Den_UTS | PRO_COM_T | Denominazione | Codice_indicatore | Alias | Valore_tasso | Valore_assoluto | Base_Tasso | Popolazione_al_31_12 | Posto_in_graduatoria | GlobalID | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 202718 | 2019 | Spostamenti quotidiani per studio o lavoro | 12 | Lazio | 58 | Roma | 058035 | Colonna | T_spotfuo | Spostamenti per studio o lavoro fuori del comu... | 42.3 | 1780 | per cento ab. | 4206 | 1 | 4c47f90a-ab57-439c-abb5-c2396990148c |
| 1 | 202710 | 2019 | Spostamenti quotidiani per studio o lavoro | 12 | Lazio | 58 | Roma | 058027 | Cerreto Laziale | T_spotfuo | Spostamenti per studio o lavoro fuori del comu... | 42.2 | 454 | per cento ab. | 1075 | 2 | f5929041-b533-4b89-8cc5-6c65bf65de7b |
| 2 | 202781 | 2019 | Spostamenti quotidiani per studio o lavoro | 12 | Lazio | 58 | Roma | 058098 | Sant'Angelo Romano | T_spotfuo | Spostamenti per studio o lavoro fuori del comu... | 41.8 | 2014 | per cento ab. | 4818 | 3 | 914a18e4-eb64-4665-8b5c-d220b9e6fa5d |
| 3 | 202708 | 2019 | Spostamenti quotidiani per studio o lavoro | 12 | Lazio | 58 | Roma | 058025 | Castel San Pietro Romano | T_spotfuo | Spostamenti per studio o lavoro fuori del comu... | 41.7 | 352 | per cento ab. | 845 | 4 | 77796576-9a70-442a-9007-427cede8f837 |
| 4 | 202732 | 2019 | Spostamenti quotidiani per studio o lavoro | 12 | Lazio | 58 | Roma | 058049 | Labico | T_spotfuo | Spostamenti per studio o lavoro fuori del comu... | 41.5 | 2646 | per cento ab. | 6371 | 5 | 82664345-7f54-45b1-a63f-0d30212088f4 |
In [5]:
ilab_path = os.path.join(os.path.expanduser('~'), 'ILAB_DATA')
istat_path = os.path.join(ilab_path, 'ISTAT', 'DATA')
comuni = gpd.read_parquet(os.path.join(istat_path, 'comuni_pop.parquet'))
comuni_out = comuni.merge(com_pend_df, left_on='pro_com_t', right_on='PRO_COM_T')
In [6]:
comuni_out.explore(column='Valore_tasso')
Out[6]:
Make this Notebook Trusted to load map: File -> Trust Notebook