Criminalità Italia - Data Visualization

Librerie

  1. Folium
    • conda install -c conda-forge folium=0.2.1

In [12]:
# Librerie
import os
import pandas as pd
import numpy as np
import folium
import matplotlib.pyplot as plt
plt.style.use('ggplot')
%pylab inline


Populating the interactive namespace from numpy and matplotlib
/Users/cesar/anaconda/lib/python3.6/site-packages/IPython/core/magics/pylab.py:161: UserWarning: pylab import has clobbered these variables: ['colors', 'text']
`%matplotlib` prevents importing * from pylab and numpy
  "\n`%matplotlib` prevents importing * from pylab and numpy"

In [13]:
# Cartelle Input/Output
dir_df = os.path.join(os.path.abspath(''),'stg')
dir_out = os.path.join(os.path.abspath(''),'output')

In [14]:
df_reg_filename = r'df_reg.pkl'
df_reg_fullpath = os.path.join(dir_df, df_reg_filename)
df_reg = pd.read_pickle(df_reg_fullpath)

Totale Omicidi Volontari Italia


In [4]:
df_reg.sum()


Out[4]:
Territorio    AbruzzoBasilicataCalabriaCampaniaEmilia-Romagn...
Value                                                       469
dtype: object

Distribuzione Omicidi Volontari per Regione Italiana


In [5]:
regioni_geo_filename = r'regioni.geojson'
regioni_geo = os.path.join(dir_df, regioni_geo_filename)

reg_map = folium.Map(location=[42, 12], zoom_start=5)
reg_map.choropleth(geo_path=regioni_geo, data=df_reg,
                  columns=['Territorio', 'Value'],
                  key_on='feature.properties.NOME_REG',
                  fill_color='YlOrRd')

reg_map.save(os.path.join(dir_out,r'omicidi_volontari.html'))
reg_map


/Users/cesar/anaconda/lib/python3.6/site-packages/ipykernel/__main__.py:8: FutureWarning: 'threshold_scale' default behavior has changed. Now you get a linear scale between the 'min' and the 'max' of your data. To get former behavior, use folium.utilities.split_six.
Out[5]: