I want to merge about 8 *.csv files into one.
An example file:
ID, Average
34, 4.5
35, 5.6
36, 3.4
Another file could be:
ID, Max
34, 6
35, 7
36, 4
And I need the output to be:
ID, Average, Max
34, 4.5, 6
35, 5.6, 7
36, 3.4, 4
This only half works…. it appends all the data into the same two columns.
import glob, string
outfile = open('<directory>/<fileName>.csv','a')
files = glob.glob(r"<directory>/*.csv")
for y in files:
newfile = open(y,'r+')
data = newfile.read()
newfile.close()
outfile.writerow(y)
How can I append the data to new columns, and not repeat the “ID” field?
You have three problems here.
Code
Note that this will ignore data with an identical field name.
An alternative to the parser section is this: