1. Populating the database
With our table in place, we can now load the data into it. The US Census Agency gave us a CSV file full of data that we need to load into the table.
2. Part 2: populating the database
We'll start that by building a values_list like we did in chapter 4 with this exercise. We begin by defining an empty list then looping over the rows of the CSV. Then we build a dictionary for each CSV row that has the data for that row matched up with the column we want to store it in. Then we append the dictionary to the values list.
3. Part 2: Populating the Database
Now we can insert that values_list as we did in Chapter 4 like this example. We we start by importing the insert statement. Then we build an insert statement for our table, finally we use the execute method on our connection with the statement and values list to insert the data into the table. To review how many rows were inserted, we use the rowcount method of the ResultProxy.
4. Let's practice!
Time to get to work.