DEV Community

Xpect
Xpect

Posted on

Last 5 vs last 15: measuring football team form with pandas (Premier League, November 2026)

"Form" is one of the most quoted and least defined stats in football. Five games? Ten? League only? This post builds a small, reproducible pandas pipeline that computes form over two windows, the last 5 and the last 15 league matches, and uses the gap of the two to spot teams whose recent run differs from their longer baseline.

The data is real: every Premier League match of 2025/26 and 2026/27 up to 22 November 2026 (489 matches) from the SQLite database behind our football stats work.

Why two windows

A 5-match window reacts fast but is noisy: one red card or one deflected goal moves it a lot. A 15-match window is stable but slow. Neither is "right". The useful signal is the difference:

  • ppg_5 much higher than ppg_15: the team is on a run that is above its baseline.
  • ppg_5 much lower than ppg_15: a slump compared with how the team usually performs.
  • Both close: current results look like the team's normal level.

Early in a season, 15 league matches reach back into the previous campaign. That is a feature, not a bug: it gives promoted and rebuilt sides a context, and it is why we keep both seasons in the query.

The table

The source table has one row per match with home and away columns:

football_matches(league, season, date, home_team, away_team,
                 fthg, ftag, hc, ac, ...)
Enter fullscreen mode Exit fullscreen mode

fthg/ftag are full-time goals, hc/ac are corners.

Step 1: load and reshape to one row per team per match

Rolling windows are easiest when every match appears twice, once from each side.

import sqlite3
import pandas as pd

con = sqlite3.connect("football_stats.db")
matches = pd.read_sql(
    """SELECT season, date, home_team, away_team, fthg, ftag, hc, ac
       FROM football_matches
       WHERE league = 'APL' AND season IN ('2526', '2627')
         AND fthg IS NOT NULL AND date <= '2026-11-22'""",
    con, parse_dates=["date"],
)

home = pd.DataFrame({"date": matches.date, "team": matches.home_team,
                     "gf": matches.fthg, "ga": matches.ftag, "corners": matches.hc})
away = pd.DataFrame({"date": matches.date, "team": matches.away_team,
                     "gf": matches.ftag, "ga": matches.fthg, "corners": matches.ac})
long = pd.concat([home, away]).sort_values(["team", "date"])
long["pts"] = 3 * (long.gf > long.ga) + (long.gf == long.ga)
Enter fullscreen mode Exit fullscreen mode

3 * (gf > ga) + (gf == ga) turns booleans into league points without any apply.

Step 2: compute both windows

def window(g, n):
    t = g.tail(n)
    return pd.Series({f"ppg_{n}": t.pts.mean(), f"gf_{n}": t.gf.mean(),
                      f"ga_{n}": t.ga.mean(), f"corners_{n}": t.corners.mean()})

current = set(matches.loc[matches.season == "2627", "home_team"])
counts = long.groupby("team").size()
eligible = [t for t in counts[counts >= 15].index if t in current]

form = (long[long.team.isin(eligible)]
        .groupby("team")
        .apply(lambda g: pd.concat([window(g, 5), window(g, 15)])))
form["delta_ppg"] = form.ppg_5 - form.ppg_15
form["delta_gd"] = (form.gf_5 - form.ga_5) - (form.gf_15 - form.ga_15)
Enter fullscreen mode Exit fullscreen mode

Two filters matter:

  1. Only teams in the 2026/27 league. Without it, relegated clubs show up with "form" from May.
  2. At least 15 league matches in the sample. Promoted sides (Hull, Coventry, Ipswich) have 11 Premier League games here, so their 15-window would silently be an 11-window. They are excluded rather than mixed in.

That leaves 17 teams.

Step 3: the result

cols = ["ppg_5", "ppg_15", "delta_ppg", "delta_gd", "corners_5", "corners_15"]
print(form[cols].round(2).sort_values("delta_ppg").to_markdown())
Enter fullscreen mode Exit fullscreen mode
team ppg_5 ppg_15 delta_ppg delta_gd corners_5 corners_15
Man City 0.8 1.93 -1.13 -1.47 6.4 6.87
Man United 0.4 1.2 -0.8 -1.53 5.6 5.93
Crystal Palace 0 0.6 -0.6 -1.13 4.4 3.67
Newcastle 1 1.33 -0.33 0.07 4.2 4.47
Brentford 1 1.27 -0.27 -0.47 3.4 4.13
Nott'm Forest 0.8 0.93 -0.13 -0.27 4.8 4.27
Chelsea 1.2 1.33 -0.13 -0.27 4.8 5.4
Sunderland 1 1.13 -0.13 -0.2 3 4.07
Arsenal 2.6 2.67 -0.07 -0.07 6.4 4.87
Leeds 1.6 1.6 0 0.07 3.8 4.2
Brighton 1.8 1.67 0.13 -0.13 4.8 5.4
Everton 1.4 1.2 0.2 -0.07 4.2 4.67
Aston Villa 1.8 1.4 0.4 0.47 4.8 4.13
Fulham 1.8 1 0.8 0.67 6.4 6.13
Liverpool 2.4 1.53 0.87 1.27 8.4 6.47
Tottenham 2.4 1.47 0.93 1.27 8.2 7.47
Bournemouth 3 1.73 1.27 1.47 5.2 4.87

Brentford's 4-0 win over Everton on 23 November is after the cutoff, so it is not in these rows.

Reading it

  • Man City have the largest drop: 0.8 points per game over the last five against 1.93 over fifteen. Their corner count barely moved (6.4 vs 6.87), which suggests they still reach the final third about as often; the change is in goals (1.2 scored and 1.8 conceded over five, against 2.0 and 1.13 over fifteen).
  • Bournemouth are the opposite: five wins from five, a goal difference per game 1.47 better than their 15-match level.
  • Arsenal are the most stable side at the top: 2.6 vs 2.67. Their recent results match their baseline almost exactly.
  • Liverpool and Tottenham improved on both goal difference and corners, which is a stronger signal than points alone.

Caveats

  • Points per game over five matches can only take a few values, so delta_ppg is coarse. delta_gd is smoother.
  • The windows ignore opponent strength. A natural next step is to weight each match by the opponent's 15-match ppg.
  • groupby().apply() returning a Series is fine for 17 teams. For thousands, use groupby().rolling() on the long frame instead.

If you want team form, goals and corners without running the code yourself, they are in the Xpect football stats app, and the way each metric is defined is written up on the Xpect methodology page.

Analytics only, 18+

Top comments (0)