Search icon CANCEL
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Interactive Data Visualization with Python - Second Edition

You're reading from  Interactive Data Visualization with Python - Second Edition

Product type Book
Published in Apr 2020
Publisher
ISBN-13 9781800200944
Pages 362 pages
Edition 2nd Edition
Languages
Authors (4):
Abha Belorkar Abha Belorkar
Profile icon Abha Belorkar
Sharath Chandra Guntuku Sharath Chandra Guntuku
Profile icon Sharath Chandra Guntuku
Shubhangi Hora Shubhangi Hora
Profile icon Shubhangi Hora
Anshu Kumar Anshu Kumar
Profile icon Anshu Kumar
View More author details

Table of Contents (9) Chapters

Preface 1. Introduction to Visualization with Python – Basic and Customized Plotting 2. Static Visualization – Global Patterns and Summary Statistics 3. From Static to Interactive Visualization 4. Interactive Visualization of Data across Strata 5. Interactive Visualization of Data across Time 6. Interactive Visualization of Geographical Data 7. Avoiding Common Pitfalls to Create Interactive Visualizations Appendix

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

  1. 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
  2. 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
  3. Generate a choropleth map using the plotly express module animated based on Year:
    import plotly.express as...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}