범주형 변수 개수 세기
개수 세기는 데이터를 전반적으로 파악하고, 그냥 지나치기 쉬운 흥미로운 패턴을 발견하는 데 효과적인 방법입니다. 이번 연습 문제에서는 이전에 만든 DataFrame을 활용하여 매장의 개수를 유형별로 그리고 부서 번호별로 세어 보겠습니다.
# Drop duplicate store/type combinations
store_types = sales.drop_duplicates(subset=["store", "type"])
# Drop duplicate store/department combinations
store_depts = sales.drop_duplicates(subset=["store", "department"])
이전 연습 문제에서 생성한 store_types와 store_depts DataFrame을 사용할 수 있으며, pandas는 pd로 임포트되어 있습니다.
이 연습은 강의의 일부입니다
pandas를 이용한 데이터 다루기
연습 안내
store_types에서 각 매장type별 매장 수를 세어보세요.store_types에서 각 매장type별 매장 비율을 계산해보세요.store_depts에서 각department별 매장 수를 세고 내림차순으로 정렬해보세요.store_depts에서 각department별 매장 비율을 계산하고 내림차순으로 정렬해보세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Count the number of stores of each type
store_counts = ____
print(store_counts)
# Get the proportion of stores of each type
store_props = ____
print(store_props)
# Count the number of stores for each department and sort
dept_counts_sorted = ____
print(dept_counts_sorted)
# Get the proportion of stores in each department and sort
dept_props_sorted = ____.____(sort=____, normalize=____)
print(dept_props_sorted)