6. Interactive Visualizations of Data across Geographical Regions
Activity 6: Creating a Choropleth Map to Represent Total Renewable Energy Production and Consumption across the World
Solution
- Load the
renewable energy production
dataset:import pandas as pd renewable_energy_prod_url = "https://raw.githubusercontent.com/TrainingByPackt/Interactive-Data-Visualization-with-Python/master/datasets/share-of-electricity-production-from-renewable-sources.csv" renewable_energy_prod_df = pd.read_csv(renewable_energy_prod_url) renewable_energy_prod_df.head()
The output is as follows:
Figure 6.29: Renewable sources dataset
- Sort the production DataFrame based on the
Year
feature:renewable_energy_prod_df.sort_values(by=['Year'],inplace=True) renewable_energy_prod_df.head()
The output is as follows:
Figure 6.30: Renewable sources dataset after sorting by year
- Generate a choropleth map using the
plotly
express
module animated based onYear
:import plotly.express as...