Merge multiple *.csv, *.txt, or *.ascii files based on a common field using python
<p>I want to merge about 8 *.csv files into one.</p>

<p>An example file:</p>

<pre><code>ID, Average
34, 4.5
35, 5.6
36, 3.4
</code></pre>

<p>Another file could be:</p>

<pre><code>ID, Max
34, 6
35, 7
36, 4
</code></pre>

<p>And I need the output to be:</p>

<pre><code>ID, Average, Max
34, 4.5, 6
35, 5.6, 7
36, 3.4, 4
</code></pre>

<p>This only half works.... it appends all the data into the same two columns.</p>

<pre><code>import glob, string

outfile = open('&lt;directory&gt;/&lt;fileName&gt;.csv','a')    
files = glob.glob(r"&lt;directory&gt;/*.csv")

for y in files:
    newfile = open(y,'r+')       
    data = newfile.read()
    newfile.close()
    outfile.writerow(y)
</code></pre>

<p>How can I append the data to new columns, and not repeat the "ID" field?</p>
