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
probably something like: Code: f = open('Output.CSV','w') for a,b in zip(open('1.CSV'),open('2.CSV')): f.write(a+','+b)
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.
For future work of this kind, consider importing into pandas and manipulating tables there (as dataframes). Lot of flexibility.
Something wrong with the DNS server network. I typed elitetrader.com into my browser, and appear to have got stackexchange. GAT