I have two .csv files that I need to either join into a new file or append one to the other:
filea:
jan,feb,mar
80,50,52
74,73,56
fileb:
apr,may,jun
64,75,64
75,63,63
What I need is:
jan,feb,mar,apr,may,jun
80,50,52,64,75,64
74,73,56,75,63,63
What I'm getting:
jan,feb,mar
80,50,52
74,73,56
apr,may,jun
64,75,64
75,63,63
I'm using the simplest code I can find. A bit too simple I guess:
sourceFile = open('fileb.csv', 'r')
data = sourceFile.read()
with open('filea.csv', 'a') as destFile:
destFile.write(data
I'd be very grateful if anyone could tell me what I'm doing wrong and how to get them to append 'horizontally' instead of 'vertically'.
paste -d',' filea.csv fileb.csvwriterow, hence it is iterating over and comma-separating characters. You need to build a list representing each row['Jan', 'Feb', ..., 'Jun']and pass that towriterow.