How to do it...

  1. Read in the flights dataset, and output the first five rows:
>>> flights = pd.read_csv('data/flights.csv')>>> flights.head()
  1. Before we start plotting, let's calculate the number of diverted, cancelled, delayed, and ontime flights. We already have binary columns for diverted and cancelled. Flights are considered delayed whenever they arrive 15 minutes or more later than scheduled. Let's create two new binary columns to track delayed and on-time arrivals:
>>> flights['DELAYED'] = flights['ARR_DELAY'].ge(15).astype(int)>>> cols = ['DIVERTED', 'CANCELLED', 'DELAYED']>>> flights['ON_TIME'] = 1 - flights[cols].any(axis=1)>>> ...

Get Pandas Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.