Exercise

Reading from a CSV file

You're now going to explore a CSV file, PPR-2021-Dublin.csv, containing a subset of the data to be processed in the ETL pipeline.

The full path to the file is saved in a variable called path which is printed in the IPython shell on the bottom right.

You're going to open it in read mode and get familiar with its header and rows. You'll discover that each row is a dict object.

You may have noticed the from pprint import pprint statement at the top of your script. pprint() is a built-in Python function that basically prints a dictionary with each key-value pair on its own line, rather than all key-value pairs on one line. It simply makes the output more humanly readable.

Instructions 1/2

undefined XP
    1
    2
  • Import the csv module so you can parse CSV files.
  • Open the file in read mode.
  • Read the CSV file with DictReader() so that each row in csv_file is a dictionary.