Try not to use writerow to write your headers. You can look at DictWriter in the CSV python module, writing headers and writing rows will be done more efficiently!
list_of_headers = ['No.', 'Image Name', 'Epsilon']
dictionary_content = {'No.': 1, 'Image Name': 'image_123', 'Epsilon': 'what?'}
w = csv.DictWriter(my_csvfile, fieldnames= list_of_headers)
w.writeheader()
w.writerow(dictionay_content)
Hope this helps, let me know if there is any rectification to be made!
Edit: Answering 'where & when should writeheader be done'
I use the os python module to determine whether the file exists, if not I'm going to create one!
if os.path.isfile(filename):
with open(filename, 'a', newline='') as my_file:
w = csv.DictWriter(my_file, fieldnames= list_of_headers)
w.writerow(dictionay_content)
else:
with open(filename, 'w', newline='') as my_file:
w = csv.DictWriter(my_file, fieldnames= list_of_headers)
w.writeheader()
w.writerow(dictionay_content)
!!! Take note of the 'a' which is to append whereas 'w' means to write. Hence appending with new rows of your data from where it left off/last occupied.