Session Ready
Exercise

Determine the difference by state from the 2000 and 2008 censuses

In this final exercise, you will write a query to calculate the states that changed the most in population. You will limit your query to display only the top 10 states.

Instructions
100 XP
  • Build a statement to:
    • Select state.
    • Calculate the difference in population between 2008 (pop2008) and 2000 (pop2000).
  • Group the query by census.columns.state using the .group_by() method on stmt.
  • Order by 'pop_change' in descending order using the .order_by() method with the desc() function on 'pop_change'.
  • Limit the query to the top 10 states using the .limit() method.
  • Execute the query and store it as results.
  • Print the state and the population change for each result. This has been done for you, so hit 'Submit Answer' to see the result!