how to write a matrix to a csv file in python with adding static headers in first row and first column?
<p>I have a matrix which is generated after running a correlation - <code>mat = Statistics.corr(result, method="pearson")</code>. now I want to write this matrix to a csv file but I want to add headers to the first row and first column of the file so that the output looks like this:</p>

<pre><code>index,col1,col2,col3,col4,col5,col6
col1,1,0.005744233,0.013118052,-0.003772589,0.004284689
col2,0.005744233,1,-0.013269414,-0.007132092,0.013950261
col3,0.013118052,-0.013269414,1,-0.014029249,-0.00199437
col4,-0.003772589,-0.007132092,-0.014029249,1,0.022569309
col5,0.004284689,0.013950261,-0.00199437,0.022569309,1
</code></pre>

<p>I have a list which contains the columns names - <code>colmn = ['col1','col2','col3','col4','col5','col6']</code>. The <code>index</code> in the above format is a static string to indicate the index names. i wrote this code but it only add the header in first row but i am unable to get the header in the first column as well:</p>

<pre><code>with open("file1", "wb") as f:
        writer = csv.writer(f,delimiter=",")
        writer.writerow(['col1','col2','col3','col4','col5','col6'])
        writer.writerows(mat)
</code></pre>

<p>How can I write the matrix to a csv file with heading static headers to the first row and 1st column?</p>