Mapping the quality of life with Folium

 Visualization


Some time ago, I got interested in chronic illnesses, their implications in the quality of life, and how they distribute across my country. So, I downloaded the results from the national survey of quality of life (ENCAVI) and used Folium to visualize it.
To make the code available to others, I created a Jupyter notebook that loads and modifies the data from the survey, loads a GeoJSON file with the country’s regions, and finally generates a single or a dual map with selected variables. You can find the repository containing the notebook here .

To use it, simply run all the cells of the notebook and play around with the variables.
For example, to generate a single map showing the prevalence of asthma in each region, we can do:

has_asthma_tuple = ('has_asthma', False)
# Tuple with format (variable name, positive indicator).
# Positive indicator should be true for variables where 'bigger is better' is true.
# Variables like happiness, optimist, etc. should have positive indicator = True
m = get_singlemap(chilean_map, has_asthma_tuple)
m  # The map below is live, so you can interact with it.

To generate dual maps, the process is really similar.
For example, to compare worried and has_hypertension in each region, we can do:

has_diabetes_tuple = ('worried', False)  # Tuples with the same format as before.
has_hypertension_tuple = ('has_hypertension', False)
m = get_dualmap(chilean_map, has_diabetes_tuple, has_hypertension_tuple)
m  # The map below is live, so you can interact with it.

 

You can find all the code here and play with an online Jupyter Notebook here Binder .