일대다 병합
한 사업체에는 한 명 또는 여러 명의 소유자가 있을 수 있습니다. 이번 연습 문제에서는 사업주 정보가 담긴 biz_owners 테이블을 licenses 테이블에 병합하면서 일대다 병합 경험을 쌓아 보겠습니다. 영상 강의에서 배웠듯이, 일대다 관계에서는 왼쪽 테이블의 한 행이 오른쪽 테이블의 여러 행과 연결될 경우 반복될 수 있습니다. 이번 레슨에서는 가장 흔한 사업주 직함(예: 비서, CEO, 부사장 등)이 무엇인지 직접 확인해 보겠습니다.
licenses와 biz_owners DataFrame은 이미 로드되어 있습니다.
이 연습은 강의의 일부입니다
pandas로 데이터 조인하기
연습 안내
licenses테이블을 왼쪽에 두고biz_owners테이블을account열 기준으로 병합한 후, 결과를licenses_owners라는 변수에 저장하세요.licenses_owners를title로 그룹화하고 각 직함별 계정 수를 집계하세요. 결과를counted_df로 저장하세요.counted_df를 accounts 수 기준으로 내림차순 정렬하고, 그 결과를sorted_df라는 변수에 저장하세요..head()메소드를 사용하여sorted_df의 첫 몇 행을 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# 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(____)