7. Avoiding Common Pitfalls to Create Interactive Visualizations
Activity 7: Determining Which Features to Visualize on a Scatter Plot
Solution
- Navigate to the folder where you have stored the .csv files and initiate a Jupyter Notebook.
- Import
pandas
,numpy
, andplotly.express
:import pandas as pd import numpy as np import plotly.express as px
- Create the same DataFrame, but instead of including only the
gdp
column from thegm
DataFrame, include thepopulation
,fertility
, andlife
columns as well:co2 = pd.read_csv('co2.csv') gm = pd.read_csv('gapminder.csv') 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, id_vars=['country', 'region']) columns = ['country', 'region...