Defining an aggregation
In this recipe, we examine the flights dataset and perform the simplest aggregation involving only a single grouping column, a single aggregating column, and a single aggregating function. We will find the average arrival delay for each airline. pandas has different syntaxes to create an aggregation, and this recipe will show them.
How to do it…
- Read in the flights dataset:
>>> import pandas as pd >>> import numpy as np >>> flights = pd.read_csv('data/flights.csv') >>> flights.head() 0 1 1 4 ... 65.0 0 0 1 1 1 4 ... -13.0 0 0 2 1 1 4 ... 35.0 0 0 3 1 1 4 ... -7.0 0 0 4 1 1 4 ... 39.0 0 0
- Define the grouping columns (
AIRLINE
), aggregating columns (ARR_DELAY
), and aggregating functions (mean
). Place...