I'm trying to merge multiple csv files with the same format into one.
merge_list = glob.glob(gndlbsum+"*gndlbsum.csv")
filewriter_lbsum = target_dir+"gndlbsum_master.csv"
#get the list of csv files and set the output file
counter=0
for file in merge_list:
with open(file,"rU") as csv_file:
filereader = csv.reader(csv_file)
with open(filewriter_lbsum,"a") as f:
writer = csv.writer(f, delimiter = "|")
#check to see if it's the first file, if it is, add header,
#otherwise skip first row
if counter<1:
for row in filereader:
writer.writerow(row)
counter+=1
else:
header = next(filereader,None)
for row in filereader:
writer.writerow(row)
When I do it like this, each row in the output csv is entirely enclosed with double quotes, I tried to uselist.append(row)
instead, but it makes no difference, since the row is enclosed with double quotes. Is there a way to avoid this?
EDIT:
Here is a sample of the source file:
COL1|COL2|COL3
1|2|3
4|5|6
And the output:
"COL1|COL2|COL3"
"1|2|3"
"4|5|6"