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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Write data to a file in Python3m 36s
-
(Locked)
Move and rename files with Python3m 23s
-
(Locked)
Copy with Python2m 29s
-
(Locked)
Delete files with Python3m 17s
-
(Locked)
Save tabular data with csv module4m 5s
-
(Locked)
Write data to a JSON file in Python1m 48s
-
(Locked)
Solution: Rename and Reorganize Photo Files2m 24s
-
(Locked)
</> Solution: Parse JSON file with Python1m 19s
-
-
-