Book Image

Interactive Data Visualization with Python - Second Edition

By : Abha Belorkar, Sharath Chandra Guntuku, Shubhangi Hora, Anshu Kumar
Book Image

Interactive Data Visualization with Python - Second Edition

By: Abha Belorkar, Sharath Chandra Guntuku, Shubhangi Hora, Anshu Kumar

Overview of this book

With so much data being continuously generated, developers, who can present data as impactful and interesting visualizations, are always in demand. Interactive Data Visualization with Python sharpens your data exploration skills, tells you everything there is to know about interactive data visualization in Python. You'll begin by learning how to draw various plots with Matplotlib and Seaborn, the non-interactive data visualization libraries. You'll study different types of visualizations, compare them, and find out how to select a particular type of visualization to suit your requirements. After you get a hang of the various non-interactive visualization libraries, you'll learn the principles of intuitive and persuasive data visualization, and use Bokeh and Plotly to transform your visuals into strong stories. You'll also gain insight into how interactive data and model visualization can optimize the performance of a regression model. By the end of the course, you'll have a new skill set that'll make you the go-to person for transforming data visualizations into engaging and interesting stories.
Table of Contents (9 chapters)

3. From Static to Interactive Visualization

Activity 3: Creating Different Interactive Visualizations Using Plotly Express

Solution

  1. Open a new Jupyter notebook.
  2. Import the necessary Python libraries and packages:
    import pandas as pd
    import plotly.express as px
  3. Recreate the carbon dioxide emissions and GDP DataFrame from Exercise 22 in this notebook:
    url_co2 = 'https://raw.githubusercontent.com/TrainingByPackt/Interactive-Data-Visualization-with-Python/master/datasets/co2.csv'
    url_gm = 'https://raw.githubusercontent.com/TrainingByPackt/Interactive-Data-Visualization-with-Python/master/datasets/gapminder.csv'
    co2 = pd.read_csv(url_co2)
    gm = pd.read_csv(url_gm)
    df_gm = gm[['Country', 'region']].drop_duplicates()
    df_w_regions = pd.merge(co2, df_gm, left_on='country', right_on='Country', how='inner')
    df_w_regions = df_w_regions.drop('Country', axis='columns')
    new_co2 = pd.melt(df_w_regions...