1. Read, clean, and prepare data to build maps
1.1. Create your first choropleth world map
1.2. Create dictionaries: JSON and GeoJSON
1.3. Read and clean immigration data
2. Problem & Solution
2.1. Fusion of GeoJson and immigration data
2.2. Create your first map with pinpoints
2.3. Using WITS data to build a bar graph
2.4. Insert a bar graph in a pinpoint map
2.5. Obtaining the risk of each country
The next code helps to read the latitude and longitude coordinates of several countries from a CSV file.
import pandas as pd
import numpy as np
df_page_latlon = pd.read_html('https://developers.google.com/public-data/docs/canonical/countries_csv?hl=en')
data = df_page_latlon[0]
data
This will produce the following data frame:
The next code helps to eliminate rows whose country's data are empty with NaN.
data = data.dropna()
data
This will produce:
The command Marker from the library folium is useful to draw several pinpoints in a map according to latitude and longitude information:
# import the library
import folium
# Make an empty map
m = folium.Map(location=[20,0], tiles="OpenStreetMap", zoom_start=2)
# add marker one by one on the map
for i in range(0,len(data)):
folium.Marker(
location=[data.iloc[i]['latitude'], data.iloc[i]['longitude']],
popup=data.iloc[i]['name'],
lazy=True
).add_to(m)
# Show the map
m
The following map will be created:
The Python code with all the steps is summarized in this Google Colab (click on the link):
https://colab.research.google.com/drive/1eiD48mdzRgIoFmyOJT8S_IFRf9UjCbJ6?usp=sharing