I am trying to add a header to a CSV file.
I am importing data from a CSV file that has two columns of data, each of which contains floating point numbers. Example:
11 22 33 44 55 66
Now I want to add a header for both columns, for example:
ColA ColB 11 22 33 44 55 66
I tried this:
with open('mycsvfile.csv', 'a') as f: writer = csv.writer(f) writer.writerow(('ColA', 'ColB'))
I used 'a' to add data, but this added values ββto the bottom line of the file instead of the first line. Is there any way to fix this?
python csv
Sakil chowdhury
source share