Python Quest

Track 8 · Lesson 5 of 11

Reading CSV files

Read spreadsheet-style CSV data with csv.reader and csv.DictReader, handle headers, quoting and delimiters, and convert text fields to numbers.

About 40 minIntermediate4 exercises

You will be able to

  • Explain why splitting lines on commas breaks on real CSV files
  • Read rows with csv.reader and skip or use the header row
  • Read records as dictionaries with csv.DictReader and look up columns by name
  • Convert CSV fields, which are always strings, to int and float
  • Read files that use a different delimiter, such as semicolons

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.