#!/usr/bin/env python # coding: utf-8 # ## Paris Remarkable Trees from 1700 to 2000 # In[1]: import requests from pandas import DataFrame, json_normalize data_json = requests.get('https://libs.cartocdn.com/cartoframes/samples/arbres_remarquables_paris.json').json() df = DataFrame(json_normalize(data_json['records'])) df.head() # In[2]: df.columns = df.columns.str.replace('.', '_') df[['lon','lat']] = DataFrame(df['geometry_coordinates'].values.tolist(), index=df.index) df.loc[:, ['geometry_coordinates', 'lon', 'lat']] # In[3]: from geopandas import GeoDataFrame, points_from_xy gdf = GeoDataFrame(df, geometry=points_from_xy(df['lon'], df['lat'])) gdf.head() # In[4]: from cartoframes.viz import Layer Layer(gdf) # In[5]: from pandas import to_datetime, to_numeric gdf['plantation_date'] = to_datetime(gdf['fields_dateplantation'], errors='coerce') gdf = gdf[gdf['plantation_date'].notnull()] gdf['plantation_year'] = to_numeric(gdf['plantation_date'].dt.strftime('%Y')) gdf.loc[:, ['plantation_date', 'plantation_year']] # In[6]: from cartoframes.viz import Layer, color_bins_style Layer(gdf, color_bins_style('plantation_year', breaks=[1700, 1800, 1900, 2000], palette='Mint'))