|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import numpy as np |
|
import pandas as pd |
|
import random |
|
import json |
|
import plotly.express as px |
|
import streamlit as st |
|
|
|
st.set_page_config(layout="wide") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DATA = [ |
|
{'foyer': 1, 'quartier_id':1, "community_id": 0, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 2, 'quartier_id':1, "community_id": 0, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 3, 'quartier_id':1, "community_id": 0, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':1, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 5, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4}, |
|
{'foyer': 1, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':2, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':3, "community_id": 0, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':3, "community_id": 0, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 4, 'score': 4}, |
|
{'foyer': 3, 'quartier_id':3, "community_id": 0, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 2, 'score': 3}, |
|
{'foyer': 4, 'quartier_id':3, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':4, "community_id": 0, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':4, "community_id": 0, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':4, "community_id": 0, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':4, "community_id": 0, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
|
|
{'foyer': 1, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 2, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 3, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 5, 'quartier_id':5, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4}, |
|
{'foyer': 1, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 4, 'score': 4}, |
|
{'foyer': 3, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 2, 'score': 3}, |
|
{'foyer': 4, 'quartier_id':6, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':7, "community_id": 4, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':7, "community_id": 4, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':7, "community_id": 4, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':7, "community_id": 4, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
|
|
{'foyer': 1, 'quartier_id':8, "community_id": 9, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 2, 'score_foyer': 3, 'score': 5/2}, |
|
{'foyer': 2, 'quartier_id':8, "community_id": 9, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 0, 'score': 2}, |
|
{'foyer': 3, 'quartier_id':8, "community_id": 9, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':8, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 5, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4}, |
|
{'foyer': 1, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 0, 'score_foyer': 0, 'score': 0}, |
|
{'foyer': 4, 'quartier_id':9, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 4, 'score': 4}, |
|
{'foyer': 3, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 2, 'score': 3}, |
|
{'foyer': 4, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':10, "community_id": 9, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 0, 'score_foyer': 0, 'score': 0}, |
|
{'foyer': 2, 'quartier_id':11, "community_id": 9, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':11, "community_id": 9, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 1, 'score_foyer': 1, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':11, "community_id": 9, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
|
|
{'foyer': 1, 'quartier_id':16, "community_id": 5, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 2, 'quartier_id':16, "community_id": 5, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 3, 'quartier_id':16, "community_id": 5, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':16, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 5, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4}, |
|
{'foyer': 1, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':21, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':31, "community_id": 5, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':31, "community_id": 5, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 4, 'score': 4}, |
|
{'foyer': 3, 'quartier_id':31, "community_id": 5, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 2, 'score': 3}, |
|
{'foyer': 4, 'quartier_id':31, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':24, "community_id": 5, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':24, "community_id": 5, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':24, "community_id": 5, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':24, "community_id": 5, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
|
|
{'foyer': 1, 'quartier_id':17, "community_id": 6, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 1, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 2, 'quartier_id':17, "community_id": 6, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 3, 'quartier_id':17, "community_id": 6, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':17, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 5, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 4}, |
|
{'foyer': 1, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 1, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':32, "community_id": 6, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':32, "community_id": 6, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 4, 'score': 4}, |
|
{'foyer': 3, 'quartier_id':32, "community_id": 6, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 2, 'score': 3}, |
|
{'foyer': 4, 'quartier_id':32, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 3, 'score_foyer': 3, 'score': 3}, |
|
{'foyer': 1, 'quartier_id':23, "community_id": 6, 'nom': 'Foyer de Di', "mois": 1, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 2, 'quartier_id':23, "community_id": 6, 'nom': 'Foyer de Di', "mois": 2, 'annee':2000, 'score_sanitaire': 5, 'score_foyer': 5, 'score': 5}, |
|
{'foyer': 3, 'quartier_id':24, "community_id": 6, 'nom': 'Foyer de Di', "mois": 3, 'annee':2000, 'score_sanitaire': 4, 'score_foyer': 3, 'score': 1}, |
|
{'foyer': 4, 'quartier_id':25, "community_id": 6, 'nom': 'Foyer de Di', "mois": 4, 'annee':2000, 'score_sanitaire': 2, 'score_foyer': 3, 'score': 3}, |
|
] |
|
|
|
|
|
|
|
|
|
|
|
data = pd.DataFrame(DATA) |
|
data.head() |
|
|
|
|
|
|
|
|
|
|
|
data['score'] = (data['score_sanitaire'] + data['score_foyer']) / 2 |
|
data.head(2) |
|
|
|
|
|
|
|
|
|
|
|
data['score responsabilité'] = data['score_sanitaire'] - data['score_foyer'] |
|
|
|
|
|
|
|
|
|
|
|
data.head() |
|
|
|
|
|
|
|
|
|
|
|
np.average(data['score'], axis=0, weights=data.index) |
|
|
|
|
|
|
|
|
|
|
|
def moyenne_par_quartier(quartiers, id, scoring="score"): |
|
quartier = quartiers[quartiers.quartier_id == id] |
|
return quartier[scoring].mean() |
|
|
|
|
|
|
|
|
|
|
|
moyenne_par_quartier(data, 2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def moyenne_par_communaute(data, community_id, scoring="score"): |
|
community = data[data.community_id == community_id] |
|
avg = np.average(community[scoring], axis=0, weights=community.index) |
|
return avg |
|
|
|
|
|
|
|
|
|
|
|
moyenne_par_communaute(data, 4) |
|
|
|
|
|
|
|
|
|
|
|
def moyenne_par_mois_par_communaute(data, community_id, month, scoring="score"): |
|
filtered = data[(data.community_id == community_id) & (data.mois == month)] |
|
avg = np.average(filtered[scoring], axis=0, weights=filtered.index) |
|
return avg |
|
|
|
|
|
|
|
|
|
|
|
def moyenne_par_mois_par_quartier(data, quartier_id, month, scoring="score"): |
|
filtered = data[(data.quartier_id == quartier_id) & (data.mois == month)] |
|
avg = np.average(filtered[scoring], axis=0, weights=filtered.index) |
|
return avg |
|
|
|
|
|
|
|
|
|
|
|
def moyenne_par_annee_par_communaute(data, community_id, year, scoring="score"): |
|
filtered = data[(data.community_id == community_id) & (data.annee == year)] |
|
avg = np.average(filtered[scoring], axis=0, weights=filtered.index) |
|
return avg |
|
|
|
|
|
|
|
|
|
|
|
def moyenne_par_annee_par_quartier(data, quartier_id, year, scoring="score"): |
|
filtered = data[(data.quartier_id == quartier_id) & (data.mois == year)] |
|
avg = np.average(filtered[scoring], axis=0, weights=filtered.index) |
|
return avg |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import plotly.io as pio |
|
pio.renderers.default = 'browser' |
|
|
|
|
|
|
|
|
|
|
|
import geopandas as gpd |
|
import folium |
|
from IPython.display import display |
|
|
|
|
|
geojson_file_path = 'BNDA_TGO_2017-06-29_lastupdate.geojson' |
|
geojson_data = json.load(open(geojson_file_path, "r")) |
|
|
|
gdf = gpd.read_file(geojson_file_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
id_quartier = {} |
|
|
|
for row in gdf.iterrows(): |
|
id_quartier[row[0]] = row[1][4] |
|
|
|
|
|
|
|
|
|
|
|
|
|
quartier_id = {} |
|
|
|
for row in gdf.iterrows(): |
|
quartier_id[row[1][4]] = row[0] |
|
|
|
|
|
|
|
|
|
|
|
id_regions = {} |
|
|
|
for row in gdf.iterrows(): |
|
if row[1][3] not in id_regions.values(): |
|
id_regions[row[0]] = row[1][3] |
|
|
|
|
|
|
|
|
|
|
|
id_regions |
|
|
|
|
|
|
|
|
|
|
|
data['quartier_name'] = data['quartier_id'].apply(lambda x: id_quartier[x]) |
|
data['community_name'] = data['community_id'].apply(lambda x: id_regions[x]) |
|
data.head() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
quartiers = data['quartier_name'].unique().tolist() |
|
|
|
|
|
|
|
|
|
|
|
qm = {} |
|
for q in quartiers: |
|
qm[q] = moyenne_par_quartier(data, quartier_id[q]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ids = [quartier_id[q] for q in quartiers] |
|
|
|
|
|
|
|
|
|
|
|
quartiers = list(qm.keys()) |
|
|
|
|
|
|
|
|
|
|
|
scores = list(qm.values()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new_df = pd.DataFrame(data={ |
|
'quartier': quartiers, |
|
'scores': scores, |
|
"quartier_id": ids |
|
}) |
|
new_df.head() |
|
|
|
|
|
|
|
|
|
|
|
new_df.to_csv('new_df.csv', index=False) |
|
|
|
|
|
|
|
|
|
|
|
qs = new_df['quartier'].tolist() |
|
new_gdf_q = gdf[gdf.adm2nm.isin(qs)] |
|
|
|
|
|
|
|
|
|
|
|
gdf_merged_q = pd.merge(new_gdf_q, new_df, how='left', left_on="adm2nm", right_on="quartier") |
|
|
|
|
|
|
|
|
|
|
|
gdf_merged_q.head() |
|
|
|
|
|
|
|
|
|
|
|
geojson = gdf_merged_q.__geo_interface__ |
|
|
|
|
|
|
|
|
|
|
|
geojson |
|
|
|
|
|
|
|
|
|
|
|
gdf_merged_q[gdf_merged_q['adm2nm'] == "Blitta"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fig = px.choropleth_mapbox(gdf_merged_q, |
|
geojson=geojson, |
|
locations=gdf_merged_q.index, |
|
color='scores', |
|
mapbox_style="carto-positron", |
|
title="Scores de Propreté Pour Les Préfectures Du Togo", |
|
hover_name="adm2nm", |
|
color_continuous_scale="Viridis" |
|
) |
|
fig.update_layout(margin={'r':0, 't':0, "l": 0, 'r': 0}) |
|
st.plotly_chart(fig) |
|
|
|
|
|
|
|
gdf_merged_q.to_csv('merged_q.csv', index=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
id_regions |
|
|
|
|
|
|
|
|
|
|
|
regions_id = list(id_regions.keys()) |
|
scores = list() |
|
|
|
|
|
|
|
|
|
|
|
rm = {} |
|
for q in regions_id: |
|
print(q) |
|
rm[q] = moyenne_par_communaute(data, q) |
|
|
|
rm |
|
|
|
|
|
|
|
|
|
|
|
regions = [id_regions[i] for i in regions_id] |
|
scores = list(rm.values()) |
|
|
|
|
|
|
|
|
|
|
|
region_df = pd.DataFrame({ |
|
'region_id': regions_id, |
|
'region': regions, |
|
'scores': scores |
|
}) |
|
|
|
region_df.head() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qm = {} |
|
for q in quartiers: |
|
qm[q] = moyenne_par_quartier(data, quartier_id[q], scoring="score responsabilité") |
|
|
|
|
|
|
|
|
|
|
|
ids = [quartier_id[q] for q in quartiers] |
|
quartiers = list(qm.keys()) |
|
scores = list(qm.values()) |
|
|
|
|
|
|
|
|
|
|
|
respon_df = pd.DataFrame(data={ |
|
'quartier': quartiers, |
|
'scores': scores, |
|
"quartier_id": ids |
|
}) |
|
respon_df.head() |
|
|
|
|
|
|
|
|
|
|
|
gdf_merged_q_r = pd.merge(new_gdf_q, respon_df, left_on="adm2nm", right_on="quartier", how='left') |
|
gdf_merged_q_r.to_csv('merged_q_r.csv', index=False) |
|
gdf_merged_q_r.head() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fig = px.choropleth_mapbox(gdf_merged_q_r, |
|
geojson=geojson, |
|
locations=gdf_merged_q.index, |
|
color='scores', |
|
mapbox_style="carto-positron", |
|
title="Scores de Propreté Pour Les Préfectures Du Togo", |
|
hover_name="adm2nm", |
|
color_continuous_scale="Viridis" |
|
) |
|
fig.update_layout(margin={'r':0, 't':0, "l": 0, 'r': 0}) |
|
st.plotly_chart(fig) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|