Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
from cartoframes.auth import set_default_credentials
set_default_credentials(
username='mylab',
api_key='a2b69f4a20d4f9389560247a6c0aaf0bfecccc64'
)
from pandas import read_csv
from geopandas import GeoDataFrame, points_from_xy
from geopandas import read_file
remote_file_path = 'C:\\Users\\MYLAB_1\\Downloads\\file_par_client_mylab_brut.csv'
df = read_csv(remote_file_path)
# Clean rows where the `longitude` column is NULL
df = df[df['longitude'].notna()]
gdf = GeoDataFrame(df, geometry=points_from_xy(df['longitude'], df['latitude']))
gdf.head()
len(df)
208143
from cartoframes.utils import decode_geometry
from geopandas import read_file
remote_file_path='C:\\Users\\MYLAB_1\\Videos\\polygon_fin.csv'
df = read_csv(remote_file_path)
gpf = GeoDataFrame(df, geometry=decode_geometry(df['the_geom']))
gpf.head()
from cartoframes.utils import decode_geometry
remote_file_path='C:\\Users\\MYLAB_1\\Videos\\polygon_center.csv'
df = read_csv(remote_file_path)
grf = GeoDataFrame(df, geometry=decode_geometry(df['the_geom']))
grf.head()
from cartoframes.viz.widgets import category_widget, formula_widget
from cartoframes.viz import Layer, popup_element,basemaps
from cartoframes.viz import Layer, color_category_style
from cartoframes.viz import Layer, size_category_style,size_continuous_style
from cartoframes.viz import default_legend
from cartoframes.viz import Layer, Map ,histogram_widget
from cartoframes.viz import Layer, color_bins_style, basemaps
from cartoframes.viz import default_legend, basic_legend
map_viz= Map([Layer (gpf,color_bins_style('etat_active',stroke_color='grey',stroke_width=2, opacity='0.3'),popup_click=[popup_element('departement'),popup_element('etat_active')],title='Etat activé_Département',
widgets=[
histogram_widget(
'etat_active',
title='Etat activé par Département'
),
category_widget(
'departement',
title='Departement',
description='Sélectionner une catégorie à filtrer'
),
],legends=default_legend(title='Distribution état_active', footer='Data: Cdiscount_Energie')
),
Layer(
gdf,
'''
color: ramp(buckets($etat, ["ACTIVÉ", "RÉSILIÉ", "ABANDONNÉ","EN COURS DACTIVATION"]), [ #0000ff,orange, green , red ]),
width: 1.2
strokeWidth: 0.1
''',
popup_hover=[
popup_element('canal'), popup_element('etat'),popup_element('puissance_souscrite'),popup_element('type_contrat')], title='Distribution des clients',
widgets=[
formula_widget(
'puissance_souscrite',
operation='sum',
title='Puiss_Sum_Dép ',
),
formula_widget(
'puissance_souscrite',
operation='avg',
title='Puiss_Moy_Dép '),
category_widget(
'offre',
title='Offre',
description='Sélectionner une catégorie à filtrer'
),
histogram_widget(
'puissance_souscrite',
title='Puissance souscrite',
description='Intervalle de consommation_énergie',
buckets=6
),
category_widget(
'canal',
title='Canal',
description='Sélectionner une catégorie à filtrer'
),
category_widget(
'etat',
title='Etat',
description='Sélectionner une catégorie à filtrer'
),
category_widget(
'type_contrat',
title='Type_contrat',
description='Sélectionner une catégorie à filtrer'
),
],
legends = basic_legend(
title='Etat'
)
),
Layer(
grf,
size_continuous_style(
'puissance_souscrite_avg',
size_range=[15,30],
color='orange ',
stroke_color='pink',
opacity='0.5',
stroke_width=1,
),title='Puissance moyenne Kw'
),
Layer(
grf,
size_continuous_style(
'puissance_souscrite_sum',
range_min=1000,
range_max=60000,
size_range=[10,50],
color=' #b0e0e6 ',
stroke_color='pink',
opacity='0.8',
stroke_width=1,
),title='Puissance totale Kw'
)
],
layer_selector=True,viewport={'zoom': 4.85, 'lat': 46, 'lng': 2}, basemap=basemaps.voyager)