# Explore the Transfermarkt dataset with dcupl

The Transfermarkt dataset on Kaggle holds football players, clubs and more than half a million market valuations scraped from transfermarkt.co.uk. In this example you turn three of its CSV files into a dcupl workspace, link them with references, and answer questions like "who are the most valuable players right now" or "how did a player's market value develop" from your terminal.

**Time required:** 15 minutes

**What you will learn:** generate models from CSV files, turn a foreign-key column into a reference, derive values across that reference, and query the result with facets, sorting and group-bys.

## The dataset

The dataset is [player-scores on Kaggle](https://www.kaggle.com/datasets/davidcariboo/player-scores), maintained in the open at [dcaribou/transfermarkt-datasets](https://github.com/dcaribou/transfermarkt-datasets). Its updates are paused: at the time of writing it is a snapshot current to 6 July 2026, with valuations up to 12 June 2026. This example uses three of its files:

| File                    | Rows (at the time of writing) | What a row is                                                   |
| ----------------------- | ----------------------------: | --------------------------------------------------------------- |
| `players.csv`           |                        50,149 | A player: position, foot, height, current club and market value |
| `clubs.csv`             |                           796 | A club: competition, stadium, squad size                        |
| `player_valuations.csv` |                       656,301 | One market valuation of a player at a date, in EUR              |

The other files (games, appearances, game events, transfers) fit the same pattern once you have done this one. Check the dataset's licence on its Kaggle page before you publish anything built on it. If the maintainers resume the updates, your counts and values will differ from the outputs below.

## Prerequisites

- The [dcupl CLI](/cli/installation) installed (`dcupl --version` to check)
- A Kaggle account to download the dataset

## Step 1: create the workspace

Scaffold an empty workspace and download the CSV files into its data folder:

```bash filename="terminal"
dcupl init transfermarkt --starter empty
cd transfermarkt
```

Download the dataset as a ZIP from its [Kaggle page](https://www.kaggle.com/datasets/davidcariboo/player-scores) and copy `players.csv`, `clubs.csv` and `player_valuations.csv` into `dcupl/data/`. With the Kaggle CLI, this is one command:

```bash filename="terminal"
kaggle datasets download -d davidcariboo/player-scores --unzip -p dcupl/data
```

## Step 2: generate the models

Let the CLI read each file and write a model for it. `--register` also adds the model and its CSV file as resources to the workspace's loader configuration, `dcupl/dcupl.lc.json`:

```bash filename="terminal"
dcupl generate model --from dcupl/data/clubs.csv --name Club --register
dcupl generate model --from dcupl/data/players.csv --name Player --register
dcupl generate model --from dcupl/data/player_valuations.csv --name Valuation --register
```

The generator types every column from its values (`int`, `float`, `date`, `string`) and picks a key: `club_id` for `Club` and `player_id` for `Player`, the only unique columns of their files. A valuation has no unique column, so `Valuation` gets generated keys. The property keys are the CSV column names, which keeps the models in step with the files.

## Step 3: link the models

The generated models are flat: `current_club_id` on a player and `player_id` on a valuation are plain numbers. Turn them into references, so dcupl resolves them to the club and the player:

```mermaid
classDiagram
  direction LR
  class Club {
    club_id : key
    name : string
    stadium_name : string
  }
  class Player {
    player_id : key
    current_club_id : Club
    stadium_name : derived
  }
  class Valuation {
    player_id : Player
    player_name : derived
    position : derived
  }
  Player --> Club : current_club_id
  Valuation --> Player : player_id
```

In `dcupl/models/Player.dcupl.json`, delete the `{ "key": "current_club_id", "type": "int" }` entry from `properties` and set `references` (generated as `[]`) to:

```json title="Player.dcupl.json: references"
[{ "key": "current_club_id", "type": "singleValued", "model": "Club" }]
```

Then add a property at the end of `properties` that derives the club's stadium through the reference:

```json title="Player.dcupl.json: add to properties"
{
  "key": "stadium_name",
  "type": "string",
  "derive": { "localReference": "current_club_id", "remoteProperty": "stadium_name" }
}
```

Do the same in `dcupl/models/Valuation.dcupl.json`: delete the `player_id` property, reference the player, and derive the player's name and position, so you can filter valuations by them without a second query:

```json title="Valuation.dcupl.json: references"
[{ "key": "player_id", "type": "singleValued", "model": "Player" }]
```

```json title="Valuation.dcupl.json: add to properties"
{ "key": "player_name", "type": "string", "derive": { "localReference": "player_id", "remoteProperty": "name" } },
{ "key": "position", "type": "string", "derive": { "localReference": "player_id", "remoteProperty": "position" } }
```

A derived property copies a value from the referenced item into this one when the data loads; see [Derived properties](/sdk/advanced/derived-properties).

## Step 4: load the data

Start a local data app that loads the workspace: models, data and loader configuration in one go. `--auto-serve` serves the workspace files to the app while it loads:

```bash filename="terminal"
dcupl app create --load --auto-serve
```

The app keeps all three models in memory, about 700,000 items, and answers every command below without reading the files again. See [Local data apps](/cli/local-data-apps) for the app's lifecycle.

## Step 5: query the data

### The most valuable players

Players who played in the latest season, sorted by market value:

```bash filename="terminal"
dcupl app query execute --model Player \
  --query '{"attribute":"last_season","operator":"eq","value":2025}' \
  --sort market_value_in_eur:desc --limit 5 \
  --projection name,current_club_name,market_value_in_eur --json
```

```json title="Output"
[
  {
    "key": "418560",
    "name": "Erling Haaland",
    "current_club_name": "Manchester City",
    "market_value_in_eur": 200000000
  },
  { "key": "937958", "name": "Lamine Yamal", "current_club_name": "FC Barcelona", "market_value_in_eur": 200000000 },
  { "key": "342229", "name": "Kylian Mbappé", "current_club_name": "Real Madrid", "market_value_in_eur": 180000000 },
  { "key": "566723", "name": "Michael Olise", "current_club_name": "Bayern Munich", "market_value_in_eur": 150000000 },
  { "key": "683840", "name": "Pedri", "current_club_name": "FC Barcelona", "market_value_in_eur": 150000000 }
]
```

### Players by position

A facet counts the items per value of an attribute, the numbers next to the options of a filter:

```bash filename="terminal"
dcupl app fn facets --model Player --attribute position \
  --query '{"attribute":"last_season","operator":"eq","value":2025}' --sort size-desc --json
```

```json title="Output"
[
  { "value": "Defender", "count": 7151 },
  { "value": "Midfield", "count": 6285 },
  { "value": "Attack", "count": 5994 },
  { "value": "Goalkeeper", "count": 2608 },
  { "value": "Missing", "count": 254 }
]
```

### Squad value per Premier League club

Group the current Premier League players (competition `GB1`) by club, add up their market values and keep the top three. An aggregate is sortable as `<attribute>_<type>`; `jq` only shortens the output:

```bash filename="terminal"
dcupl app fn groupBy --model Player --attribute current_club_name \
  --query '[{"attribute":"current_club_domestic_competition_id","operator":"eq","value":"GB1"},{"attribute":"last_season","operator":"eq","value":2025}]' \
  --aggregate market_value_in_eur:sum --sort market_value_in_eur_sum:desc --limit 3 --json \
  | jq '[.items[] | {club: .key, players: ._meta.size, squad_value: ._aggregates[0].sum}]'
```

```json title="Output"
[
  { "club": "Manchester City", "players": 43, "squad_value": 1383800000 },
  { "club": "Arsenal FC", "players": 38, "squad_value": 1281050000 },
  { "club": "Chelsea FC", "players": 43, "squad_value": 1166100000 }
]
```

A query passed as an array combines its conditions with AND.

### A player's market value over time

The derived `player_name` lets you filter the valuations by name. Each valuation also carries the club the player was at on that date:

```bash filename="terminal"
dcupl app query execute --model Valuation \
  --query '{"attribute":"player_name","operator":"eq","value":"Erling Haaland"}' \
  --sort date:asc --projection date,market_value_in_eur,current_club_name --json
```

```json title="Output (shortened)"
[
  { "date": "2016-12-18T00:00:00.000Z", "market_value_in_eur": 200000, "current_club_name": "Bryne FK" },
  { "date": "2017-12-23T00:00:00.000Z", "market_value_in_eur": 300000, "current_club_name": "Molde FK" },
  { "date": "2019-06-03T00:00:00.000Z", "market_value_in_eur": 5000000, "current_club_name": "Red Bull Salzburg" },
  { "date": "2020-02-11T00:00:00.000Z", "market_value_in_eur": 60000000, "current_club_name": "Borussia Dortmund" },
  { "date": "2022-11-03T00:00:00.000Z", "market_value_in_eur": 170000000, "current_club_name": "Manchester City" },
  { "date": "2026-06-03T00:00:00.000Z", "market_value_in_eur": 200000000, "current_club_name": "Manchester City" }
]
```

### Goalkeeper heights

Aggregate one attribute over a filtered result:

```bash filename="terminal"
dcupl app fn aggregate --model Player --attribute height_in_cm --types avg,min,max \
  --query '{"attribute":"position","operator":"eq","value":"Goalkeeper"}' --json
```

```json title="Output"
{ "attribute": "height_in_cm", "types": ["avg", "min", "max"], "avg": 189.42288745737022, "min": 170, "max": 210 }
```

When you are done, stop the app with `dcupl app destroy`.

## Use it in your application

The workspace is a regular dcupl project: the same models and loader configuration load in the browser or in Node.js with the [loader](/sdk/api/loader), and the same queries run through the SDK (`list.catalog.fn.facets()`, `groupBy()`, `aggregate()`). To serve the data from the dcupl cloud instead of local files, push the workspace with [`dcupl files push`](/cli/cloud-sync). `player_valuations.csv` alone is about 30 MB; in a browser app, load only the files a page needs, for example with one loader application per use case.

## Next steps

- [Fashion products example](/learn/examples/fashion-products) — a product catalogue with facets and a loader transformer
- [Local data apps](/cli/local-data-apps) — every `dcupl app` command
- [Derived properties](/sdk/advanced/derived-properties) — copy values across references
- [groupBy()](/sdk/fn/group-by) — groups with per-group aggregates
