I need to find all the connected elements in column ID.
for e.g. My main Element is 4120882840 in ID Column.
4120882840 is connected to 4120874920, 4120874720 (refer column ID2)
likewise, 4120874920 is connected to 4121482000 which is further connected to 4121480930 and so on
finally, all the elements that are connected to 4120882840 are [4120882840, 4120874920, 4121482000, 4121480930, 4121480780, 4120874720, 4120871840, 4120871830] total 8 in the list
But I am only getting first 7 i.e. [4120882840, 4120874920, 4121482000, 4121480930, 4121480780, 4120874720, 4120871840]
file link https://drive.google.com/file/d/1E5_cbGjtKoB6RDSsC7ned-X2RFoF6Rad/view?usp=sharing
This is my Code
import pandas as pd
df = pd.read_csv("Test.csv")
ID = df.iloc[:,1]
ID2 = df.iloc[:,2]
x = [4120882840]
for i in range (len(ID)):
for element in x:
if element == ID2[i]:
newID = ID[i]
#print (newID)
x.append (newID)
print (x)
