Lesson 1.37mBeginner28.2k students

Reading files and CSVs

Real data arrives as a slightly wrong file. Encodings, delimiters, and missing values are the first three problems you will meet.

This lesson sits in Python Foundations for Data, part of Python for Data Work. It assumes what came before it and leads directly into the next lesson in the module.

In this lesson you will

  • Read and write files safely with context managers
  • Parse CSV data and handle encoding issues
  • Deal with missing and malformed rows on load

Pro tip

Open a file with a context manager. It closes even when the code inside raises.

Resources