← pivot operator page · clause/pivot/basic/manual_ex_1
pandas ✅ · DuckDB ✅
pivot Id_2, Me_1, on a data set with the attribute At_1, whose virality is not defined.
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".
One data point per Id_1, with the Measures A, B and C: 5, 2, 7 and 3, 4, 9. At_1 is 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".
The page adds a Measure "for each distinct value of identifier in op" and types Id_2 String, but the Measures must be known without the data: they are the values of the value domain of Id_2 (1-1-6-18 without one), here VD_1, of A, B and C.
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 |
{
"datasets": [
{
"name": "DS_1",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "Id_2", "type": "VD_1", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true},
{"name": "At_1", "type": "String", "role": "Attribute", "nullable": true}
]
}
]
}
| Id_1 | A | B | C |
|---|---|---|---|
| 1 | 5 | 2 | 7 |
| 2 | 3 | 4 | 9 |
{
"datasets": [
{
"name": "DS_r",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier"},
{"name": "A", "type": "Integer", "role": "Measure"},
{"name": "B", "type": "Integer", "role": "Measure"},
{"name": "C", "type": "Integer", "role": "Measure"}
]
}
]
}
{
"name": "VD_1",
"type": "String",
"setlist": [
"A",
"B",
"C"
]
}