Write Data in CSV Format using Python
- Admin
- Jul 6, 2020
- 1 min read
In Python, the csv module implements classes to read and writer tabular data in CSV format. It has a class DictWriter which operates like a regular writer but maps a dictionary onto output rows. The keys of the dictionary are column names while values are actual data.
The csv.DictWriter constructor takes two arguments. The first is the open file handler that the CSV is being written to. The second named parameter, fieldnames, is a list of field names that the CSV is going to handle.
For Example

After running the above code, companies.csv will contain the following information:
name, type
Python3Space, Learning
Google, Search
Comments