title: Stacking a number of columns into one column in python
body: <p>I have a pandas dataframe of 100 rows x 7 columns like this:</p>
  
  <p><a href="https://i.stack.imgur.com/CimWQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CimWQ.png" alt="enter image description here"></a></p>
  
  <p>Values in column <code>source</code> are connected to the values in the other columns. For example, <code>a</code> is connected to <code>contact_1, contact_2... contact_5</code>.
  In the same way, <code>b</code> is connected to <code>contact_6, contact_7 .... and contact_10</code>.</p>
  
  <p><strong>I want to stack these columns into two columns only (i.e. source and destination), to help me build a graph using edgelist format.</strong></p>
  
  <p>The expected output data format is:</p>
  
  <p><a href="https://i.stack.imgur.com/1fN0B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1fN0B.png" alt="enter image description here"></a></p>
  
  <p>I tried <code>df.stack()</code> but did not get the desired result, I got the following:</p>
  
  <p><a href="https://i.stack.imgur.com/EEw0Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EEw0Q.png" alt="enter image description here"></a></p>
  
  <p>Any suggestions?</p>