4. Simplifying Visualizations Using Seaborn
Activity 4.01: Using Heatmaps to Find Patterns in Flight Passengers' Data
Solution:
Find the patterns in the flight passengers' data with the help of a heatmap:
- Create an
Activity4.01.ipynbJupyter notebook in theChapter04/Activity4.01folder to implement this activity. - Import the necessary modules and enable plotting within a Jupyter notebook:
%matplotlib inline import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set()
- Use pandas to read the
flight_details.csvdataset located in theDatasetsfolder. The given dataset contains the monthly figures for flight passengers for the years 1949 to 1960:data = pd.read_csv("../../Datasets/flight_details.csv") - Now, we can use the
pivot()function to transform the data into a format that is suitable for heatmaps:data = data.pivot("Months", "Years", "Passengers") data = data.reindex...