我有一个5列的csv文件,我想在第6列添加数据.我拥有的数据是一个数组.
现在,我所拥有的代码只会在csv文件中已经存在的所有数据之后插入我想要的第6列数据.
比如我有:
wind, site, date, time, value
10, 01, 01-01-2013, 00:00, 5.1
89.6 ---> this is the value I want to add in a 6th column but it puts it after all the data from the csv file
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码:
csvfile = 'filename'
with open(csvfile, 'a') as output:
writer = csv.writer(output, lineterminator='\n')
for val in data:
writer.writerow([val])
Run Code Online (Sandbox Code Playgroud)
我认为使用'a'会将数据附加到一个新列中,但它只是将它放在('下')所有其他数据之后......我不知道该怎么办!
python ×1