Flight details#

Using a heatmap to find patterns in flight passengers’ data.

Importing libraries and packages#

 1# Warnings
 2import warnings
 3
 4# Mathematical operations and data manipulation
 5import pandas as pd
 6
 7# Plotting
 8import matplotlib.pyplot as plt
 9import seaborn as sns
10
11sns.set()
12warnings.filterwarnings("ignore")

Set paths#

1# Path to datasets directory
2data_path = "./datasets"
3# Path to assets directory (for saving results to)
4assets_path = "./assets"

Loading dataset#

1dataset = pd.read_csv(f"{data_path}/flight_details.csv")

Exploring dataset#

1# Shape of the dataset
2print("Shape of the dataset: ", dataset.shape)
3# View
4dataset
Shape of the dataset:  (144, 3)
Years Months Passengers
0 1949 January 112
1 1949 February 118
2 1949 March 132
3 1949 April 129
4 1949 May 121
... ... ... ...
139 1960 August 606
140 1960 September 508
141 1960 October 461
142 1960 November 390
143 1960 December 432

144 rows Ă— 3 columns

Preprocessing#

1dataset = dataset.pivot("Months", "Years", "Passengers")
2dataset
Years 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
Months
April 129 135 163 181 235 227 269 313 348 348 396 461
August 148 170 199 242 272 293 347 405 467 505 559 606
December 118 140 166 194 201 229 278 306 336 337 405 432
February 118 126 150 180 196 188 233 277 301 318 342 391
January 112 115 145 171 196 204 242 284 315 340 360 417
July 148 170 199 230 264 302 364 413 465 491 548 622
June 135 149 178 218 243 264 315 374 422 435 472 535
March 132 141 178 193 236 235 267 317 356 362 406 419
May 121 125 172 183 229 234 270 318 355 363 420 472
November 104 114 146 172 180 203 237 271 305 310 362 390
October 119 133 162 191 211 229 274 306 347 359 407 461
September 136 158 184 209 237 259 312 355 404 404 463 508
 1dataset = dataset.reindex(
 2    [
 3        "January",
 4        "February",
 5        "March",
 6        "April",
 7        "May",
 8        "June",
 9        "July",
10        "August",
11        "September",
12        "October",
13        "November",
14        "December",
15    ]
16)
17dataset
Years 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
Months
January 112 115 145 171 196 204 242 284 315 340 360 417
February 118 126 150 180 196 188 233 277 301 318 342 391
March 132 141 178 193 236 235 267 317 356 362 406 419
April 129 135 163 181 235 227 269 313 348 348 396 461
May 121 125 172 183 229 234 270 318 355 363 420 472
June 135 149 178 218 243 264 315 374 422 435 472 535
July 148 170 199 230 264 302 364 413 465 491 548 622
August 148 170 199 242 272 293 347 405 467 505 559 606
September 136 158 184 209 237 259 312 355 404 404 463 508
October 119 133 162 191 211 229 274 306 347 359 407 461
November 104 114 146 172 180 203 237 271 305 310 362 390
December 118 140 166 194 201 229 278 306 336 337 405 432

Visualisation#

1plt.figure(dpi=200)
2# Any sequential color palette can be used
3sns.heatmap(dataset, cmap=sns.cubehelix_palette(rot=-0.3, as_cmap=True))
4plt.title("Flight Passengers from 1949 to 1960")
5plt.show()
../../_images/7b4504378cc989f18e91c4ec2c2a097697ccdb9e1465e0c05ba2752dcbcda756.png