Get startedGet started for free

Reading the data from the CSV

Leverage the Python CSV module from the standard library and load the data into a list of dictionaries.

It may help to refer back to the Chapter 4 exercise in which you did something similar.

This exercise is part of the course

Introduction to Databases in Python

View Course

Exercise instructions

  • Create an empty list called values_list.
  • Iterate over the rows of csv_reader with a for loop, creating a dictionary called data for each row and append it to values_list.
    • Within the for loop, row will be a list whose entries are 'state' , 'sex', 'age', 'pop2000' and 'pop2008' (in that order).

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create an empty list: values_list
values_list = ____

# Iterate over the rows
for row in csv_reader:
    # Create a dictionary with the values
    data = {____: row[____], ____: row[____], ____:____, ____: ____,
            ____: ____}
    # Append the dictionary to the values list
    values_list.append(____)
Edit and Run Code