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.
Cet exercice fait partie du cours
Introduction to Databases in Python
Instructions
- Create an empty list called
values_list
. - Iterate over the rows of
csv_reader
with a for loop, creating a dictionary calleddata
for each row and append it tovalues_list
.- Within the for loop,
row
will be a list whose entries are'state'
,'sex'
,'age'
,'pop2000'
and'pop2008'
(in that order).
- Within the for loop,
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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(____)