Importation et utilisation des contours des arrondissements

Carte choroplèthe simple

In [1]:
import folium
import json

geo = json.load(open("paris-arrondissements.geojson"))

centre = [48.86, 2.35]
carte = folium.Map(location = centre, zoom_start = 12)
folium.Choropleth(geo_data = geo).add_to(carte)
carte
Out[1]:

Nombre de mobiliers par arrondissement

In [2]:
import pymongo
import pandas

con = pymongo.MongoClient("mongodb://193.51.82.104:2343/")
horo = con.horodateurs
mob = horo.mobiliers

res = mob.aggregate([
    { "$group" : { "_id" : "$fields.arrondt", "nb" : { "$sum" : 1}}},
    { "$sort" : { "_id": 1}}
])
df = pandas.DataFrame(list(res)) 
df.columns = ["Arrondissement", "Effectif"]
df.head()
Out[2]:
Arrondissement Effectif
0 1 87
1 2 67
2 3 133
3 4 135
4 5 267
In [3]:
carte = folium.Map(location = centre, zoom_start = 12)
folium.Choropleth(geo_data = geo, key_on = "feature.properties.c_ar",
                 data = df, columns = ["Arrondissement", "Effectif"],
                 fill_color= "YlGn",
                 legend_name = "Nombre de mobiliers par quartier").add_to(carte)
carte
Out[3]: