I am looking to add another column to a CSV file w/ python.
file1 is Date.csv has format
ID, Date
0,"Jan 22, 2016"
1,"Jan 21, 2016"
2,"Jan 20, 2016"
3,"Jan 19, 2016"
and
file2 is Price.csv
ID, Price
0,27.89
1,26.80
2,26.78
3,26.00
My desired output is (in Date.csv)
ID, Date
0,"Jan 22, 2016", 27.89
1, "Jan 21, 2016", 26.80
2, "Jan 20, 2016", 26.78
3, "Jan 19, 2016", 26.00
but what I'm returning is the price repeating
0,27.89,27.89
1,26.80,26.80
2,26.78,26.78
3,26.00,26.00
My program is as follows
import csv
with open('C:/Users/User/OneDrive/Documents/Price.csv','r') as csvinput:
with open('C:/Users/User/OneDrive/Documents/Date.csv', 'w') as csvoutput:
writer = csv.writer(csvoutput, lineterminator='\n')
reader = csv.reader(csvinput)
all = []
row = next(reader)
for row in reader:
row.append(row[1])
all.append(row)
writer.writerows(all)
Appreciate some guidance, cheers
Date.csv