A Summary Table

The small table that goes under the chart.

One row per thing, one column per fact

A good summary table is small enough to read entirely. Count, mean and range per group is usually the whole story.

import pandas as pd

df = pd.DataFrame({"team": ["a", "a", "b"], "score": [90, 80, 70]})
out = df.groupby("team")["score"].agg(["count", "mean"]).round(1)
print(out.loc["a"].tolist())

Order it by the thing being compared

Sorting by the number under discussion means the reader's eye lands where the argument is, rather than on whichever group happens to be alphabetically first.

import pandas as pd

df = pd.DataFrame({"team": ["a", "b"], "score": [70, 90]})
out = df.groupby("team")["score"].mean().sort_values(ascending=False)
print(out.index.tolist())

Exercise

Try It Yourself

Write summary_table(df) returning a list of (team, count, mean) tuples, highest mean first, with the mean to one decimal place.

Press Run to see output

Check Your Understanding