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
First, let's read data on Canadian immigration from an internet data file.
import pandas as pd
import numpy as np
df = pd.read_excel('https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/DV0101EN/labs/Data_Files/Canada.xlsx',
sheet_name='Canada by Citizenship',
skiprows=range(20),
skipfooter=2)
df
This will produce the following data frame:
For this purpose will employ the command drop.
df.drop(['AREA', 'REG', 'DEV', 'Type', 'Coverage', 'AreaName', 'RegName', 'DevName'], axis=1, inplace=True)
df
The following result will appear:
df.rename(columns={'OdName':'Country'}, inplace=True)
df
This will rename the column 'OdName' as 'Country':
The next code creates a new column with the total of immigration for all years per country.
df['Total'] = df.sum(axis=1)
df
This will result in:
The Python code with all the steps is summarized in this Google Colab (click on the link):
https://colab.research.google.com/drive/1OfDdV5wv_F8fkRpNWlcI8r553u0AsPZ1?usp=sharing