Icon

03 Loops and Switches LAB

03 Loops and Switches - Exercise

This workflow shows a hands-on exercise in the L2-DW Introduction to KNIME Analytics Platform for Data Wranglers - Advanced course

Task 1: Build a Group LoopYour task is to build a group loop that compares the life expectancy in each country to the average value on the continent where it'slocated.1. Read the JoinedCountryTable.table file by executing the top Table Reader node. This table contains information about thedemographics, geolocation, and travel risks in the different countries/territories in 2020.2. Start a group loop that handles each continent in a separate iteration3. Build the loop body:- Calculate the average overall life expectancy on the continent- Transform the value into a flow variable- Assign each country the value "below" if their overall life expectancy is below the average and the value "above" otherwise. Use theRule Engine node and append a new column. 4. Close the loop by concatenating the rows from the different iterations Task 2: Build a Counting LoopYour task it to build a counting loop that forecasts the population in the next five years.1. Execute the provided workflow2. Start a counting loop with 5 iterations on the top output of the Column Splitter node3. Forecast the population in 2020 by adding the value in the Change column to the value in the Population (2019/07/01) column oncein the first iteration. Forecast the population value in 2021 by adding it two times in the second iteration, and so on. Use the MathFormula node and append a new column called "Forecast".4. Name the Forecast according to the year: - Add the value of the currentIteration flow variable to 2020. Use the Math Formula (Variable) node.- Create a column name which contains the value of this flow variable, for example: "Forecasted population in 2020". Use the StringManipulation (Variable) node.- Rename the Forecast column5. Exclude all other columns but the newly renamed forecast column6. Close the loop by joining the columns from the different iterations7. Join the country names from the bottom output of the Column Splitter node to the loop output meteorite data5 iterationsNode 38Node 40Node 41Node 42meteorite data GroupBy Math Formula String Manipulation(Variable) Math Formula(Variable) Column Rename Loop End (ColumnAppend) Column Filter Column Splitter Joiner CSV Reader Counting Loop Start Group Loop Start Table Rowto Variable Rule Engine Loop End CSV Reader Task 1: Build a Group LoopYour task is to build a group loop that compares the life expectancy in each country to the average value on the continent where it'slocated.1. Read the JoinedCountryTable.table file by executing the top Table Reader node. This table contains information about thedemographics, geolocation, and travel risks in the different countries/territories in 2020.2. Start a group loop that handles each continent in a separate iteration3. Build the loop body:- Calculate the average overall life expectancy on the continent- Transform the value into a flow variable- Assign each country the value "below" if their overall life expectancy is below the average and the value "above" otherwise. Use theRule Engine node and append a new column. 4. Close the loop by concatenating the rows from the different iterations Task 2: Build a Counting LoopYour task it to build a counting loop that forecasts the population in the next five years.1. Execute the provided workflow2. Start a counting loop with 5 iterations on the top output of the Column Splitter node3. Forecast the population in 2020 by adding the value in the Change column to the value in the Population (2019/07/01) column oncein the first iteration. Forecast the population value in 2021 by adding it two times in the second iteration, and so on. Use the MathFormula node and append a new column called "Forecast".4. Name the Forecast according to the year: - Add the value of the currentIteration flow variable to 2020. Use the Math Formula (Variable) node.- Create a column name which contains the value of this flow variable, for example: "Forecasted population in 2020". Use the StringManipulation (Variable) node.- Rename the Forecast column5. Exclude all other columns but the newly renamed forecast column6. Close the loop by joining the columns from the different iterations7. Join the country names from the bottom output of the Column Splitter node to the loop output meteorite data5 iterationsNode 38Node 40Node 41Node 42meteorite data GroupBy Math Formula String Manipulation(Variable) Math Formula(Variable) Column Rename Loop End (ColumnAppend) Column Filter Column Splitter Joiner CSV Reader Counting Loop Start Group Loop Start Table Rowto Variable Rule Engine Loop End CSV Reader

Nodes

Extensions

Links