Python 3 - Concatenate 2 CSV files into 1 file

Python 3 - Concatenate 2 CSV files into 1 file

1.CSV


1
2
3
4

2.CSV

A
B
C
D

I want to concatenate/append the 2 files to one:

Output.CSV

1,A
2,B
3,C
4,D

I can't find the solution anywhere, all I got is:

Output.CSV

1
2
3
4
A
B
C
D

Does anyone know the solution? I am using import CSV

 
Thanks again, it works perfectly. I made a small change by adding: a = (a.rstrip('\n'))

Code:
f = open('Output.CSV','w')
for a,b in zip(open('1.CSV'),open('2.CSV')):
    a = (a.rstrip('\n'))
    f.write(a+','+b)

I stripped the newline character from the first CSV file because it was pushing the 2nd CSV files contents down a row.
 
Look at this guy bringing in his fancy pandas.
1029699918.jpg
 
Back
Top