One-to-many merge
A business may have one or multiple owners. In this exercise, you will continue to gain experience with one-to-many merges by merging a table of business owners, called biz_owners
, to the licenses
table. Recall from the video lesson, with a one-to-many relationship, a row in the left table may be repeated if it is related to multiple rows in the right table. In this lesson, you will explore this further by finding out what is the most common business owner title. (i.e., secretary, CEO, or vice president)
The licenses
and biz_owners
DataFrames are loaded for you.
This is a part of the course
“Joining Data with pandas”
Exercise instructions
- Starting with the
licenses
table on the left, merge it to thebiz_owners
table on the columnaccount
, and save the results to a variable namedlicenses_owners
. - Group
licenses_owners
bytitle
and count the number of accounts for each title. Save the result ascounted_df
- Sort
counted_df
by the number of accounts in descending order, and save this as a variable namedsorted_df
. - Use the
.head()
method to print the first few rows of thesorted_df
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Merge the licenses and biz_owners table on account
licenses_owners = ____
# Group the results by title then count the number of accounts
counted_df = licenses_owners.groupby(____).agg({'account':'count'})
# Sort the counted_df in descending order
sorted_df = counted_df.sort_values(____)
# Use .head() method to print the first few rows of sorted_df
print(____)