← median operator page · aggregate/median/ds_group_by/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

median at data set level grouped by Id_1, over one Integer measure.

Manual:

Median value, Example 1, output verbatim: "The operator returns the median value of the input values."

Expected:

5.0 for 2011, the middle of 3, 5 and 7, and 3.0 for 2012, the mean of 2 and 4: "The result is always a number, including when all operand values are integer."

script.vtl ⇩

DS_r := median ( DS_1 group by Id_1 );

input/DS_1.csv ⇩

Id_1Id_2Id_3Me_1
2011AXX3
2011AYY5
2011BYY7
2012AXX2
2012BYY4

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Time_Period", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Id_3", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Me_1
20115.0
20123.0

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Time_Period", "role": "Identifier"},
        {"name": "Me_1", "type": "Number", "role": "Measure"}
      ]
    }
  ]
}