I've got a DataFrame containing 3 columns (and ~1100 rows, but may be more or less). Each column contains IDs made of long integers, which can exist in more than one row and column. I need to merge every single row linked by at least one common ID with any degree of separation (i've posted an simple example of the DF which should clarify this part). The only way i've come up with is taking me ages to calculate.
#Dataframe:
A B C
X Y Z
D E F
T U V
C D E
E N Z
AA BB CC
HH CC U
#Final needed result (the order is irrelevant):
A B C D E F N Z X Y
T U V HH CC AA BB