0

I have a csv file with the data :

TableName  , Rows , Columns , StartTime
DimAccount ,  40  ,   12    ,  18.7

I need to append a new column to this CSV, such that the output is :

TableName  , Rows , Columns , StartTime , EndTime
DimAccount ,  40  ,   12    ,  18.7     ,  20

I tried using :

fieldnames = ['EndTime']
with open(data.csv', 'a') as csvfile:
     writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
     writer.writeheader()
     writer.writerow({'EndTime': 20})

but it gives output as :

TableName  , Rows , Columns , StartTime
DimAccount ,  40  ,   12    ,  18.7
Endtime
20
krx
  • 45
  • 4
  • You should refer to this article: [link](https://stackoverflow.com/a/54548840/11278588). Note: open file mode "a" - open for writing, appending to the end of the file if it exists – THAAD May 02 '22 at 18:26

0 Answers0