1.7.6 Counting and averaging by destination🔗ℹ

(define grouped-data
  (group-count (table-groupby (table-cut subset '(dest dep_delay)) '(dest))))
> (define by-dest
    (~> subset
        (group-by "dest")
        (agg (alias (count "dep_delay") "departed")
             (alias (mean "dep_delay") "mean_delay"))
        (sort "dest")))
> by-dest

shape: (96, 3)

┌──────┬──────────┬────────────┐

│ dest ┆ departed ┆ mean_delay │

│ ---  ┆ ---      ┆ ---        │

│ str  ┆ u32      ┆ f64        │

╞══════╪══════════╪════════════╡

│ ABQ  ┆ 4        ┆ -3.0       │

│ ACK  ┆ 4        ┆ 9.25       │

│ ALB  ┆ 8        ┆ 20.375     │

│ ATL  ┆ 271      ┆ 15.254613  │

│ AUS  ┆ 41       ┆ 13.439024  │

│ …    ┆ …        ┆ …          │

│ SYR  ┆ 28       ┆ 42.714286  │

│ TPA  ┆ 120      ┆ 13.141667  │

│ TUL  ┆ 6        ┆ 8.5        │

│ TYS  ┆ 8        ┆ 8.125      │

│ XNA  ┆ 17       ┆ 2.882353   │

└──────┴──────────┴────────────┘

count, like group-count, skips missing values: on the full file ATL has 16,898, the post’s figure, of 17,215 flights, and a mean delay of 12.5 minutes. The groups come back in no fixed order, as in Python; sort them to print.