1. Conditional statements and logical operators
Welcome to Data Transformation in KNIME!
2. About me
My name is Mahantesh. I am a Sr. Data Scientist by profession. I have worked at KNIME as an Evangelist and taught KNIME courses for over three years.
3. Conditional statements
Let's get started with Conditional statements.
Conditional statements allow you to specify conditions and then assign values based on them. If the condition is met, a desired value is assigned; if none are met, a default value is assigned. The "IF" statement is an example of a conditional statement.
4. IF statement
The "IF" statement is used to specify one or more conditions.
If condition one is met, value one is assigned. Optionally, additional conditions can be added.
If none of these conditions are met, the default value, that is "value if all false," is assigned.
5. Comparison operators
True to their name, comparison operators are used to compare column values against other column values or constants.
The "equal to" operator checks if values are equal. The "greater than" and "less than" operators check if the column value is greater or lesser than a specific value, respectively.
The "greater than or equal to" and "less than or equal to" operators also compare equality.
6. Comparison operators
Suppose you have a table with the columns "Name" and "Age." Your task is to create a column called "Age Group" based on the condition that if the age is greater than 18, the Age Group should be "Adult" or else "Non-Adult."
We can define the conditional statement shown in the Syntax using comparison operators.
Notice that the new column "Age Group" is created based on the conditions specified.
7. Logical operators
Logical operators can combine two or more conditional statements. It adds a level of complexity to your expression and outputs a boolean value.
The "AND" operator returns a true value if all the conditions are met. "OR" returns a true value if any conditions are met. The "NOT" operator returns the negation of the boolean expression.
8. Logical operators
An example.
Consider the task of assigning a day, either as weekday or weekend.
The first condition is to check if the day is a Sunday.
The second is to check if the day is a Saturday.
An OR operator will check if any conditions are true and assign the day as the weekend.
9. Cell splitting
Statements based on a delimiter can also be used to split cells.
For example, the "Residence" column is split using the hyphen delimiter into two columns: "City" and "Country". In KNIME, this is done using the Cell Splitter node.
10. Our dataset
For the exercises, we will use order data from KIA, an online furniture shopping company.
The data contains information regarding the customer profile, the products they purchased, and their category. It also contains the sales and cost price of the products.
11. Let's practice
Let's do some exercises.