Pivoting · pivot
---
config:
flowchart:
useMaxWidth: false
---
flowchart LR
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["Pivoting · pivot<br/>🟢1"]:::ok
v_basic["DS#91;pivot Id, Me#93;"]:::ok
v_basic --- O
click v_basic href "#form-basic"
Types
Takes any scalar · Gives any type
Comes from: any operator that returns a value
Goes to: whatever takes its input's type
Forms
DS[pivot Id, Me] 🟢 · any scalar → any type
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
pivot Id_2, Me_1, on a data set with the attributeAt_1, whose virality is not defined.- Manual:
Pivoting, Example 1, output verbatim: “It drops the Identifier Component identifier and all the Measure Components from VDS”, then “It groups VDS by the values of the remaining Identifiers”.
- Expected:
One data point per
Id_1, with the MeasuresA,BandC: 5, 2, 7 and 3, 4, 9.At_1is not kept: each group holds several of its values and the script gives “no explicit indication about the keeping of the Attribute”, so by the User Manual “If the virality is not defined, the Attribute is considered as non-viral” and “the non-viral Attributes are not kept in the result and their values are not considered”.- Erratum:
The page adds a Measure “for each distinct value of identifier in op” and types
Id_2String, but the Measures must be known without the data: they are the values of the value domain ofId_2(1-1-6-18without one), hereVD_1, ofA,BandC.
DS_r := DS_1 [ pivot Id_2, Me_1 ];
| Id_1 | Id_2 | Me_1 | At_1 |
|---|---|---|---|
| 1 | A | 5 | E |
| 1 | B | 2 | F |
| 1 | C | 7 | F |
| 2 | A | 3 | E |
| 2 | B | 4 | E |
| 2 | C | 9 | F |
| Id_1 | A | B | C |
|---|---|---|---|
| 1 | 5 | 2 | 7 |
| 2 | 3 | 4 | 9 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · value_domains/VD_1.json · example page ↗
Missing combination is null 🟢 pandas ✅ · DuckDB ✅
- Tests:
pivot Id_2, Me_1, whereId_1= 2 has no data point withId_2=B.Id_2is defined on the value domainVD_1, ofAandB, whose values give the Measures of the result.- Manual:
Pivoting: “For each distinct value of identifier in op, it adds a corresponding measure to VDS, named as the value of identifier. These Measures are initialized with the null value.”
- Expected:
Id_1and the MeasuresAandB: 5 and 2 forId_1= 1, and 3 and null forId_1= 2, whoseBkeeps the null it was initialized with.
DS_r := DS_1 [ pivot Id_2, Me_1 ];
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | 5 |
| 1 | B | 2 |
| 2 | A | 3 |
| Id_1 | A | B |
|---|---|---|
| 1 | 5 | 2 |
| 2 | 3 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · value_domains/VD_1.json · example page ↗