Created
July 26, 2023 18:07
-
-
Save kururu-abdo/3428710688e82ccda5c6ba5acec87c01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df_can = pd.read_csv('https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/Canada.csv') | |
print('Data downloaded and read into a dataframe!') | |
! wget --quiet https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/world_countries.json | |
print('GeoJSON file downloaded!') | |
world_geo = r'https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/world_countries.json' # geojson file | |
# create a plain world map | |
world_map = folium.Map(location=[0, 0], zoom_start=2) | |
world_map.choropleth( | |
geo_data=world_geo, | |
data=df_can, | |
columns=['Country', 'Total'], | |
key_on='feature.properties.name', | |
fill_color='YlOrRd', | |
fill_opacity=0.7, | |
line_opacity=0.2, | |
legend_name='Immigration to Canada' | |
) | |
# display map | |
world_map | |
world_geo = r'world_countries.json' | |
# create a numpy array of length 6 and has linear spacing from the minimum total immigration to the maximum total immigration | |
threshold_scale = np.linspace(df_can['Total'].min(), | |
df_can['Total'].max(), | |
6, dtype=int) | |
threshold_scale = threshold_scale.tolist() # change the numpy array to a list | |
threshold_scale[-1] = threshold_scale[-1] + 1 # make sure that the last value of the list is greater than the maximum immigration | |
# let Folium determine the scale. | |
world_map = folium.Map(location=[0, 0], zoom_start=2) | |
world_map.choropleth( | |
geo_data=world_geo, | |
data=df_can, | |
columns=['Country', 'Total'], | |
key_on='feature.properties.name', | |
threshold_scale=threshold_scale, | |
fill_color='YlOrRd', | |
fill_opacity=0.7, | |
line_opacity=0.2, | |
legend_name='Immigration to Canada', | |
reset=True | |
) | |
world_map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment