Enhance student data
1. Enhance student data
Let's understand how to use conditional statements and logical operators in KNIME with a hands-on example. In this video, we will use the student data containing the City, zip code, hours spent in various activities, and exam scores. The city and zip code information is stored in a column: City?Zipcode. The first task is to split the column into two separate columns. Use the node panel to search for the cell splitter node. Connect it to the CSV Reader node. Hover over the node and click the cog wheel to open the configuration dialog. In the dialog, select the Column to Split. Check the “Remove Input column” box, as we no longer need the original column. Next, specify the delimiter, the symbol separating the two values. In this case, the delimiter is an arrow symbol. As the values of the column City?Zipcode are being split into two columns, we can even split the column names by checking this box and assigning City to the first column and Zipcode to the second column. Click OK and execute. The output table now contains two columns, City and Zipcode. The next task is to rename the E-Activity column to “Extracurricular Activity” and the P-Activity column to “Physical Activity”. To rename these columns, use the column renamer node. In the node dialog, select the E-Activity column. In the new name field, enter Extracurricular Activity. Repeat the process for the other column. Click OK and execute. The output table shows the new names. The last task is to add a new column, Grades, and assign Grades based on the Exam Scores. If the exam score is greater than 70, assign Grade A. If it is from 65 to 70, assign Grade B. And for anything less than 65, assign Grade C. To add these conditional statements, use the Expression node. Open the node's configuration. The input columns are visible on the left. The Expression editor is at the center, and the functions list is available on the right. As we are formulating the conditional statements, go to the functions panel on the right and click on Condition. From the list, select the IF condition. The description is shown in the below panel. Upon double-clicking on the IF condition, the syntax of the IF condition is copied to your expression editor. Write down the first condition by selecting the exam scores column. Specify the comparison operator, along with the value 70, and if the condition is met, assign the grade as “Grade A”. Similarly, add the second condition if the score is between 65 to 70. This can be done by combining two conditions using AND operator. If both these conditions are met, assign the grade as “Grade B”. At last, if no conditions are met, assign “Grade C”. Click on “Evaluate first 10 rows” to check if the conditional statements work as expected. After executing the node, open the output table and notice the newly created grade column. Now that you've grasped how to formulate conditional statements in KNIME, it's time to put your knowledge into practice.2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.