From the course: Python: Working with Files

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Save tabular data with csv module

Save tabular data with csv module - Python Tutorial

From the course: Python: Working with Files

Save tabular data with csv module

- [Instructor] If you're working with tabular data, sometimes it can be useful to output it to a CSV file. With the CSV module, we can write data to a CSV file in a few different ways. If your data is stored as a list, one option is to use the CSV writer object. In order to do so, we'll need to open the file and write mode and create a writer object from the file. With the writer object, we can write individual rows to the CSV file. The data just needs to be in the format of a list. When this is written out, each item in the list will be in the CSV as an individual entry. These are the headers for the CSV. Let's add some data rows. We'll add an office chair. The ID is 41, the category is furnishing and there are 10 in stock, each priced at 85. Let's add some more data. Great. Let's call the function and save the data out to CSV. We'll run it in our terminal. If we run ls or dr on windows, we can see the new CSV…

Contents