Share on social networks!

Script to create CSV file with Python

CSV (Comma Separated Values) files are a type of simple text document used to represent data in table 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

aQ1 frFeyai0M37cbfpL0D5kZDJKmwgM51LmDlnD5ryZxnW2VyvZMWS8r Yc4INljjKyQCrTbygDUZPol4BtEI

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.

Subscribe to our newsletter to stay up to date with all the news

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SA as the person responsible for this website. The purpose of collecting and processing personal data is to respond to the query made as well as to send information about the services of the data controller. Legitimation is the consent of the interested party.
You can exercise your rights of access, rectification, limitation and deletion of data in compliance@grupomainjobs.com as well as the right to file a claim with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find in our Web page

Leave a comment