I have an input DataFrame in the below format:
input_data = [[1000, 1002], [1002, 1003], [1004, 1000],[1010,1050],[1060,1002],[1050,1100],[1200,1250],[1300,1200]]
input_df = pd.DataFrame(input_data, columns = ['Value1', 'Value2'])
print(input_df)
Ignored the index for readability,
Value1 Value2
1000 1002
1002 1003
1004 1000
1010 1050
1060 1002
1050 1100
1200 1250
1300 1200
The output I am expecting is shown below. I need to map all related values (be it value1 -> value2 or value2 -> value1) and collect them all to ordered indexes(starting from 1) like below:
Index Value
1 1000
1 1002
1 1003
1 1004
1 1060
2 1010
2 1050
2 1100
3 1200
3 1250
3 1300
3 1200
What I have tried? I did try looping over the rows in input. I'm able to relate if values in a single row are related. But I'm finding it hard to use this logic when the relationships spans across multiple rows and multiple columns(Value1 and Value2)