I have a data frame with two columns. The two columns contain integer numbers. The second column contains numbers that are linked to the first column. In case there is no link between the two columns, the number in the second column will have zero value. Here is an example of the table.
The expected output is a list of connections between the two columns. Using the attached table as an example, the output will be [[2, 3, 4, 5], [6, 7, 8]]
This question is similar but not the same as finding transitive relation between two columns in pandas.