Export pandas dataframe as an interaction file: row \t value \t col
<p>With the below pd dataframe:</p>

<pre><code>print(df)
   A  B  C
X  1  2  3
Y  4  5  6
Z  7  8  9
</code></pre>

<p>I need to create a simple interaction network file, or SIF file, of the format:</p>

<pre><code>node1 xx node2
node1 xx node2
node1 yy node2
.
.
.
</code></pre>

<p>Where each line is an interaction on a df: row label, value, column label.  Below is an iterative (and naive) approach to writing such a file:</p>

<pre><code>with open ('interaction.sif', 'w') as sif:
    for row in df.index:
        for col in df.columns:
            sif.write('{}\t{}\t{}'.format(row, df[col][row], col))
</code></pre>

<p>The inefficient code above offers the ideal sif file for the dataframe <code>df</code>:</p>

<pre><code>X 1 A
X 2 B
X 3 C
Y 4 A
Y 5 B
Y 6 C
Z 7 A
Z 8 B
Z 9 C
</code></pre>

<p>Is there a dataframe method to write to a csv or table, for example, in the format above?  Or is there a way to vectorize this operation?</p>