ETL
From raw CSVs to PostgreSQL with pandas
How the Champions League ETL separates extraction, transformation, and loading, and where I would harden each stage.
By Ijlal Ansari
The UEFA Champions League data arrives as separate CSVs for key stats, attack, and defence. Reading those files into independent DataFrames means each feed can have its own column mapping. I keep the raw files alongside processed CSVs so it is possible to inspect what changed before loading PostgreSQL.
The main transform renames the player and match fields and makes distance numeric. The published script uses a mean to fill missing distances. An alternative is to load nulls alongside a flag and only impute in an analysis view. That preserves the difference between a missing measurement and an estimated value.
The loader uses SQLAlchemy and pandas to write three tables. That is convenient for a snapshot. For a repeatable batch job I would load to staging, verify the expected schema and row counts, and publish the batch in a transaction. Handwritten table definitions are useful once column types and constraints become part of a contract.
I keep a small smoke query near the load step. A leaderboard checks that numeric values survived the trip and gives a reviewer a recognizable output. It complements checks that compare row counts and key coverage with the input.
SELECT "PLAYER", "CLUB", "GOALS"
FROM ucl_players
ORDER BY "GOALS" DESC, "PLAYER"
LIMIT 10;