Skip to content

Introduction to Data Visualization with Seaborn

👋 Welcome to your workspace! Here, you can write and run Python code and add text in Markdown. Below, we've imported the datasets from the course Introduction to Data Visualization with Seaborn as DataFrames as well as the packages used in the course. This is your sandbox environment: analyze the course datasets further, take notes, or experiment with code!

# Importing course packages; you can add more too!
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# Importing course datasets as DataFrames
country_data = pd.read_csv('datasets/countries-of-the-world.csv', decimal=",")
mpg = pd.read_csv('datasets/mpg.csv')
student_data = pd.read_csv('datasets/student-alcohol-consumption.csv', index_col=0)
survey = pd.read_csv('datasets/young-people-survey-responses.csv', index_col=0)

mpg.head() # Display the first five rows of this DataFrame

Don't know where to start?

Try completing these tasks:

  • From country_data, create a scatter plot to look at the relationship between GDP and Literacy. Use color to segment the data points by region.
g = sns.relplot(x="GDP ($ per capita)", y="Literacy (%)", data=country_data, hue="Region",     kind="scatter")
g.fig.suptitle("GDP vs Literacy", y=1.03)
plt.show()
  • Use mpg to create a line plot with model_year on the x-axis and weight on the y-axis. Create differentiating lines for each country of origin (origin).
g = sns.relplot(x="model_year", y="weight", data=mpg, hue="origin", kind="line", ci=False)
g.fig.suptitle("Model vs Year", y=1.03)
plt.show()
  • Create a box plot from student_data to explore the relationship between the number of failures (failures) and the average final grade (G3).
g = sns.catplot(x="failures", y="G3", data=student_data, kind="box")
g.fig.suptitle("Failures vs Grade 3", y=1.03)
plt.show()
  • Create a bar plot from survey to compare how Loneliness differs across values for Internet usage. Format it to have two subplots for gender.
g = sns.catplot(x="Internet usage",y="Loneliness",data=survey, kind="bar", ci=None)
g.fig.suptitle("Internet vs Loneliness")
plt.xticks(rotation=45)
plt.show()