Icon

Creating a Pivot Table

<p><strong>Creating a Pivot Table</strong></p><p>A pivot table aims to arrange a table so that other stakeholders can easily share and understand data. This workflow demonstrates how to create a pivot table using KNIME Analytics Platform.</p><p>💡 <em>To view each node's configuration, select the node and see the configuration pane on the right side of the workflow editor.</em></p><p>Let's walk through the different nodes involved in this operation:</p><p><strong>Excel Reader node:</strong></p><ul><li><p>Since the folder with the data is already included when you download the workflow, in the "File and Sheet" tab, we choose to "Read from" the "Current workflow data area" and select the dataset.</p></li><li><p>In the "Data Area" tab, we select to read the "Whole sheet" and unflagged to skip "empty rows". This configuration allows us to read the sheet as it is. The intent is to respect its original structure.</p></li></ul><p><strong>Row Aggregator node:</strong></p><ul><li><p>We aggregate the data to get the total sum of medals won by each country.</p></li><li><p>We calculate the sum of columns "bronze", "silver", "gold", and "total", using the "country" column as category column.</p></li></ul><p><strong>Expression node:</strong></p><ul><li><p>We want to label the data according to the total number of medals won. For countries that won more than 600 medals, we assign the country as label, for the other countries who won less than 600 medals, we assign the label "Other". The aim is to reduce the number of columns shown in the pivot table.</p></li><li><p>We implement the following expression:</p><p>if($["total"]&gt;600, $["country"],</p><p>&nbsp; &nbsp; "Other")</p></li><li><p>We append the label as new column ("country_renamed").</p></li></ul><p><strong>Value Lookup node:</strong></p><ul><li><p>We append the labels of the new column "country_renamed" to the input data table.</p></li><li><p>Lookup column and key column are both "country", the column in the Input panel is "country_renamed".</p></li></ul><p><strong>Pivot node:</strong></p><p>The Pivot node accomplishes the same task as the pivot function in Excel: Creating a pivot table.</p><ul><li><p>Group column: edition (specifies the unique row identifier)</p></li><li><p>Pivot column: country_renamed (its values will be transformed into columns)</p></li><li><p>Aggregation method: Sum of totals</p></li></ul><p>The resulting pivot table has 29 rows (all of the Summer Olympic Games editions) and 9 columns (the countries and "Other").</p><p><strong>Column Resorter node:</strong></p><ul><li><p>We move the column "Other" to the back of the table so that first the individual country columns are shown.</p></li></ul><p><strong>Missing Value node:</strong></p><ul><li><p>Some countries didn't win any medals in certain years. We replace the missing value by specifying to replace all missing integers with 0.</p></li></ul><p><strong>Excel Writer node:</strong></p><ul><li><p>We append the dataset to a new sheet called "pivot_table" in the existing Excel file located in the workflow data area.</p></li><li><p>After executing the node, the file will open automatically.</p></li></ul>

Data access

Read file located in workflow data area

Data export

Append pivot table to new sheet in existing Olympics data

Data manipulation

Create Pivot table

  • Groups: edition

  • Pivots: country_renamed

  • Aggregation: Sum of totals

Data cleaning

Creating a Pivot Table


This workflow demonstrates how to create a pivot table and export it to an external file.

In this example, we access the medal counts of the 1896-2020 Olympic Games. We then aggregate the data to calculate the total sum of medals for each country and combine countries with less than 600 total medals under the label "Other". We proceed creating the pivot table, change the column order and replace missing values. Lastly, we export the pivot table to a new sheet in the existing Excel file.

For a detailed overview of each node in this workflow, refer to the workflow description in the Info panel.


💡 To view each node's configuration, select the node and see the configuration pane on the right side of the workflow editor.

Read Olympics data
Excel Reader
Calculate total sumof all medalsby each country
Row Aggregator
Append column"country_renamed"to input dataset
Value Lookup
Groups: edition;Pivots: country_renamed;Aggregation: Sum of totals
Pivot
Append new sheetto dataset:"pivot_table"
Excel Writer
Replace missingvalues with 0
Missing Value
Put column "Other"at end of the table
Column Resorter
Label countries withless than 600 medalsas "Other"
Expression

Nodes

Extensions

Links