Calculate student scores
1. Calculate student scores
Let's understand how to perform expression-based transformations in KNIME. Notice the Name column in the student's data. It has the first and last name combined with an underscore symbol. So, the first task is to transform this column to display names in a standard format. This task requires string manipulation, so drag the Expression node and add it to the workflow. In the configuration dialog of the node, notice that the right panel is the functions panel. It provides various function categories for string and math operations. Click on any category to get the list of all available functions. Now, click on any function, and the lower panel will display the function syntax and description. To replace the underscore sign, go to the String - Extract & Replace category and select the replace function. Specify the string as the Name column, pattern as underscore, and replacement text as blank space. In the output column section, choose replace and select the column to be replaced as Name. Evaluate the node and see that the name column contains the first and last names separated by blank spaces. The next task is to standardize these names, which means making the first letter of each word uppercase. To perform this, we will use the capitalize function. Provide the string expression of the name column as an input to the capitalize function. Now, execute the node and notice that the name column that contains the standardized names. Next, we have the attendance percentage for each student. Since the school was functional for 300 days, we will calculate the number of days a student attended the school. This can be done using a simple arithmetic expression. We will use the expression node to perform this operation. Open the expression node editor and multiply the attendance percentage column by the total number of days, i.e., 300. Name the column being created as Days attended. Let's round off this number to the nearest integer, as this might produce decimal numbers. In the Math-Round category, use the round function to round off the values to the precision provided. Include the arithmetic expression inside the round function and specify the precision value as 0. Execute, and the output table shows the new column added. The last task is challenging. Given the scores in subjects one and two, we are asked to calculate the average score and express it as a string column. You might have guessed this requires a mixed expression. First, let's calculate the average score. Select the average function and specify the values. Let's convert this average value to string format by using the string function and specifying the math expression inside it. This will convert the average values to string format. We need to add the string "Average score is" to each row. Use the join function, specify the separator as blank, and enter the string values. As seen in the expression, the join function will concatenate the strings. Execute the node and notice that the Average score column now contains strings with a commentary on the average score. Now that you know expression based transformations, practice them using the furniture sales data in the upcoming exercises.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.