← if_then_else operator page · conditional/if_then_else/ds/manual_ex_1
pandas ✅ · DuckDB ✅
a data set condition, if ( DS_1#Id_4 = "F" ) then DS_2 else DS_3, that sends each data point to one of two data sets.
if-then-else, Example 1, output verbatim: "returns the Data Point from thenOperand when the Data Point of condition having the same Identifiers’ values evaluates to true, and returns the Data Point from elseOperand otherwise". The page's introduction names the operands DS_cond, DS_1 and DS_2 where the script uses DS_1, DS_2 and DS_3, a slip of the prose and not of the example, and the page's TimePeriod type is written Time_Period, as vtlengine does.
the page's six data points: those of DS_2 where Id_4 is F, for Id_2 S, F and I (25.8, null and 20.9), and those of DS_3 where it is M, for Id_2 B, G and S (0.12, 22.5 and 23.7). A data point that is missing from the branch it is sent to, such as B with Id_4 F in DS_2, is left out.
DS_r := if ( DS_1#Id_4 = "F" ) then DS_2 else DS_3;
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | M | 5451780 |
| 2012 | B | Total | F | 5643070 |
| 2012 | G | Total | M | 5449803 |
| 2012 | G | Total | F | 5673231 |
| 2012 | S | Total | M | 23099012 |
| 2012 | S | Total | F | 23719207 |
| 2012 | F | Total | M | 31616281 |
| 2012 | F | Total | F | 33671580 |
| 2012 | I | Total | M | 28726599 |
| 2012 | I | Total | F | 30667608 |
| 2012 | A | Total | M | |
| 2012 | A | Total | F |
{
"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": "Id_4", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Number", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | S | Total | F | 25.8 |
| 2012 | F | Total | F | |
| 2012 | I | Total | F | 20.9 |
| 2012 | A | Total | M | 6.3 |
{
"datasets": [
{
"name": "DS_2",
"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": "Id_4", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Number", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | B | Total | M | 0.12 |
| 2012 | G | Total | M | 22.5 |
| 2012 | S | Total | M | 23.7 |
| 2012 | A | Total | F |
{
"datasets": [
{
"name": "DS_3",
"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": "Id_4", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Number", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_2 | Id_3 | Id_4 | Me_1 |
|---|---|---|---|---|
| 2012 | S | Total | F | 25.8 |
| 2012 | F | Total | F | |
| 2012 | I | Total | F | 20.9 |
| 2012 | B | Total | M | 0.12 |
| 2012 | G | Total | M | 22.5 |
| 2012 | S | Total | M | 23.7 |
{
"datasets": [
{
"name": "DS_r",
"DataStructure": [
{"name": "Id_1", "type": "Time_Period", "role": "Identifier"},
{"name": "Id_2", "type": "String", "role": "Identifier"},
{"name": "Id_3", "type": "String", "role": "Identifier"},
{"name": "Id_4", "type": "String", "role": "Identifier"},
{"name": "Me_1", "type": "Number", "role": "Measure"}
]
}
]
}