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
Exercise instructions
- Starting with the
licensestable, merge to it thezip_demotable on thezipcolumn. Then merge the resulting table to thewardstable on thewardcolumn. Save result of the three merged tables to a variable namedlicenses_zip_ward. - Group the results of the three merged tables by the column
aldermanand find the medianincome.
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'}))