Search⌘ K
AI Features

Solution: Visualizing Seaborn Datasets

Explore how to visualize datasets using Seaborn in Python. Understand how to create heatmaps by reshaping data with pivot tables and format them for clarity. Learn to plot regression lines to identify and interpret relationships between variables.

We'll cover the following...

Heatmap solution #

Python 3.5
import pandas as pd
import seaborn as sns
df = sns.load_dataset('flights') # Reading flights dataset from seaborn package
# Reshaping the DataFrame
df = pd.pivot_table(df, values = 'passengers', index = ['month'], columns = 'year')
# Plotting the heatmap
sns.heatmap(df, annot = True, fmt = '')

The above problem plots the data on a heatmap after reshaping it.

On line 7, the pivot_table function is used to ...