Get startedGet started for free

Three table merge

To solidify the concept of a three DataFrame merge, practice another exercise. A reasonable extension of our review of Chicago business data would include looking at demographics information about the neighborhoods where the businesses are. A table with the median income by zip code has been provided to you. You will merge the licenses and wards tables with this new income-by-zip-code table called zip_demo.

The licenses, wards, and zip_demo DataFrames have been loaded for you.

This exercise is part of the course

Joining Data with pandas

View Course

Exercise instructions

  • Starting with the licenses table, merge to it the zip_demo table on the zip column. Then merge the resulting table to the wards table on the ward column. Save result of the three merged tables to a variable named licenses_zip_ward.
  • Group the results of the three merged tables by the column alderman and find the median income.

Hands-on interactive exercise

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

# Merge licenses and zip_demo, on zip; and merge the wards on ward
licenses_zip_ward = licenses.merge____ \
            			____

# Print the results by alderman and show median income
print(____.groupby(____).agg({'income':'median'}))
Edit and Run Code