From the course: Python Standard Library Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Reading CSV files - Python Tutorial
From the course: Python Standard Library Essential Training
Reading CSV files
- [Instructor] It's pretty common knowledge by now that Python excels when working with data and for some scenarios, you don't need any other modules than what comes built in to the standard library. In this example, I'm going to read data from and write data to CSV or comma separated value files. This is a fairly common data format, used with spreadsheets to represent tabular data. So, here in my csvfiles_start example, you can see I've imported the csv module from the standard library. So, let's start by writing a function to read a CSV file. So, the CSV file we're going to be working with is this one. It contains a whole bunch of historical stock quotes for a particular symbol. So, I'll fill out my readerSample function and I will start by opening the file using the standard open function we learned about already. So, I'm going to write with open and I'll say StockQuotes.csv as data file. Then, I just need to create a reader object with the CSV module's reader function. And I'll…
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.