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 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

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.

EIP

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, SAU as the party responsible for this website. The purpose of collecting and processing personal data is to manage your subscription to the newsletter as well as to send commercial information about the services of the data controller. The legitimacy is the explicit consent of the interested party. Data will not be transferred to third parties, except under legal obligation. You may exercise your rights of access, rectification, limitation and deletion of data at compliance@grupomainjobs.com, as well as the right to lodge a complaint with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find on our website.
marter-in-python

Leave a comment

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SAU as the party responsible for this website. The purpose of collecting and processing personal data is to manage your subscription to the newsletter as well as to send commercial information about the services of the data controller. The legitimacy is the explicit consent of the interested party. Data will not be transferred to third parties, except under legal obligation. You may exercise your rights of access, rectification, limitation and deletion of data at compliance@grupomainjobs.com, as well as the right to lodge a complaint with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find on our website.