Module 8 · Plotly and maps · Lesson 41 of 66
Choropleth exercises
Map world power use and the 2012 US voting-age population.
In this lesson · about 16 minutes
- Map countries by name
- Style a US map with lakes and a reversed color scale
Two maps to build on your own. Each table is already loaded. Look at it first with .head() in the editor and press Run.
Exercise
1. World power use
Map Power Consumption KWH by country. This table names countries in words (Country), so set locationmode='country names'. Use the text column for hover, the 'Viridis' color scale reversed (reversescale=True), the title '2014 Power Consumption KWH', and a 'mercator' projection.
Code that runs before yours
import pandas as pd
import plotly.graph_objects as go
df = pd.read_csv('2014_World_Power_Consumption.csv')Exercise
2. Voting-age population by state
Map the Voting-Age Population (VAP) of each state, using the State Abv column for locations and State for hover text. Use the reversed 'Viridis' color scale, the title '2012 General Election Voting Data', and a USA map that shows lakes in 'rgb(85,173,240)'.
Code that runs before yours
import pandas as pd
import plotly.graph_objects as go
usdf = pd.read_csv('2012_Election_Data.csv')Module review0 of 4 correct
Quiz score: 0 of 4
Exercises solved: 0 of 2
Noviq Academy's Data Science course is free and for learning. Python runs in your browser with Pyodide, which downloads about 20 MB the first time, plus a few more for scikit-learn. Your code and progress stay on this device. The salaries data is a sample of San Francisco's public pay records; the purchases, customers, housing, advertising and classified data are made up. The Titanic, tips, flights and iris data sets come from Seaborn's examples; the maps use public 2011 to 2014 US and world figures. The 911 data is a 20,000-call sample of Montgomery County, Pennsylvania's public 911 records; the movie ratings are the MovieLens 100K data from GroupLens Research; the reviews are a 3,000-review sample from the Yelp Dataset Challenge; the loans are public LendingClub data; the colleges are the College data from An Introduction to Statistical Learning; the bank notes, kyphosis and breast cancer data come from the UCI Machine Learning Repository. Spark and TensorFlow can't run in a browser, so those lessons use stand-ins that run here, and show the code for the real tools.