As a Python enthusiast blending creativity and data, I wanted to see how football teams stack up—not just by wins, but by the full story: draws, losses, and overall probability of outcomes.
I started with a clean dictionary that holds each team's season performance: wins, draws, and losses. To make this data usable, I reshaped it using a simple list comprehension to feed a Pandas DataFrame. This gave me the flexibility to calculate new metrics and play with the data intuitively.
Key steps:
- Added a (Games Played) column to reflect total matches.
- Computed (Win), (Draw), and (Loss Probability) for each team to highlight performance trends at a glance.
- Rounded values to 3 decimal places for clarity and neatness.
What I love most: this opens the door for visualizations and storytelling. With just a few lines, we can turn raw stats into insights—whether it's identifying underdogs, consistency kings, or draw-heavy squads.
Would love to hear your thoughts!
Python #Pandas #DataScience #FootballStats
import pandas as pd
# Dictionary with team stats: (wins, draws, losses)
team_stats = {
"Liverpool": (25, 9, 4),
"Arsenal": (20, 14, 4),
"Manchester City": (21, 7, 10),
"Chelsea": (20, 9, 9),
"Newcastle United": (20, 6, 12),
"Aston Villa": (19, 9, 10),
"Nottingham Forest": (19, 8, 11),
"Brighton": (16, 13, 9),
"Bournemouth": (15, 11, 12),
"Brentford": (16, 8, 14),
"Fulham": (15, 9, 14),
"Crystal Palace": (13, 13, 12),
"Everton": (11, 15, 12),
"West Ham United": (11, 10, 17),
"Manchester United": (11, 9, 18),
"Wolves": (12, 6, 20),
"Tottenham Hotspur": (11, 5, 22),
"Leicester City": (6, 7, 25),
"Ipswich Town": (4, 10, 24),
"Southampton": (2, 6, 30),
}
# Convert to DataFrame
df = pd.DataFrame([
{"Team": team, "Wins": w, "Draws": d, "Losses": l}
for team, (w, d, l) in team_stats.items()
])
# Add a Games Played column
df["Games Played"] = df["Wins"] + df["Draws"] + df["Losses"]
# Optional: Add probability columns
df["Win Probability"] = (df["Wins"] / df["Games Played"]).round(3)
df["Draw Probability"] = (df["Draws"] / df["Games Played"]).round(3)
df["Loss Probability"] = (df["Losses"] / df["Games Played"]).round(3)
print(df.head()) # View first few rows
Top comments (0)