CSV (Comma Separated Values) files are a type of simple text document used to represent data in tabular form, where columns are separated by commas or semicolons and rows by line breaks.
CSV files are usually used to handle a large amount of data in table format, since being so lightweight, they do not generate much processing load.
That's why we're going to learn how to automatically create our CSV file with a few lines of code.
How to automatically create a CSV file with Python
We will import the CSV module, we will create our header fields with fieldnames and later we will write each row indicating the data of each one.
Finally we will launch a message on the screen showing that the data has been inserted.
In this simple way, a csv file will be created in the same folder with the data we inserted. Whenever we want to create a csv file with any data, we can run this script by simply updating the data.
We can modify it so that it collects data from a file or collects it by keyboard, but that will be later.