how to add headers in csv file using python

Solutions on MaxInterview for how to add headers in csv file using python by the best coders in the world

showing results for - "how to add headers in csv file using python"
Sevan
07 May 2017
1import csv
2
3f = open("fruits.csv", "w")
4writer = csv.DictWriter(
5    f, fieldnames=["fruit", "count"])
6writer.writeheader()
7f.close()
8Outputfruits.csvfruit,count
9