title: Mapping graph/relationship based values in a DataFrame in python
body: <p>I have an input DataFrame in the below format:</p>
  <pre><code>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)
  </code></pre>
  <p>Ignored the index for readability,</p>
  <pre><code>Value1  Value2
  1000    1002
  1002    1003
  1004    1000
  1010    1050
  1060    1002
  1050    1100
  1200    1250
  1300    1200
  </code></pre>
  <p>The output I am expecting is shown below. I need to map all related values (be it value1 -&gt; value2 or value2 -&gt; value1) and collect them all to ordered indexes(starting from 1) like below:</p>
  <pre><code>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
  </code></pre>
  <p>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)</p>