I'm trying to add a new column header and values to an existing csv file with python. Every thing I've looked up appends the header to the last row of the last column. This is what I want my results to be essentially.
Header Header2 Header3 NewHeader
Value Value2 Value3 NewValue
What I'm currently getting is this:
Header Header2 Header3
Value Value2 Value3**NewHeader
NewValue`
This is my code:
import csv
with open('filename.csv', 'a') as csvfile:
fieldnames = ['pageviewid']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'pageviewid': 'Baked'})
writer.writerow({'pageviewid': 'Lovely'})
writer.writerow({'pageviewid': 'Wonderful'})
'a'meansappendbut it can only append at the end of file.