Transform three columns into a matrix

Hi Knimers,

the following problem:
Three columns (starting location, destination, distance) are to be transformed into a matrix, i.e. as follows:

Is there a way to do this?
(Two difficulties, if I see it correctly: Firstly, the distance from i.e. A to B may differ from the distance from B to A, depending on the routing.
Secondly, “zero-rows”, i.e. from A to A equals 0, would still have to be inserted – maybe before creating the matrix.)

It would be great if someone could help further.

Thank you


Does this help?
table to matrix.knwf (44.2 KB)

Hello @rd2575691,

you can simply use Pivoting node with From as grouping column, To as pivoting column and First aggregation on Distance column. Then use Column Resorter and Missing Value nodes to resort columns and replace missing values on diagonal with zeros if necessary.



@ipazin: So simple and so perfect - thank you very much! :upside_down_face:

1 Like

@rd2575691: Thank you for the workflow and the script. Although the Python node stops at 30% in my workflow, I have finally installed the Anaconda Environment in KNIME :wink: :nerd_face:.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.