쉽게 배우는 카운팅

Python의 데이터 타입

Jason Myers

Instructor

Collections 모듈

  • 표준 라이브러리의 일부
  • 고급 데이터 컨테이너
Python의 데이터 타입

Counter

  • 데이터 카운팅 및 빈도 측정에 사용되는 특수 딕셔너리
from collections import Counter

nyc_eatery_count_by_types = Counter(nyc_eatery_types)
print(nyc_eatery_count_by_type)
Counter({'Mobile Food Truck': 114, 'Food Cart': 74, 'Snack Bar': 24,
'Specialty Cart': 18, 'Restaurant': 15, 'Fruit & Vegetable Cart': 4})
print(nyc_eatery_count_by_types['Restaurant'])
15
Python의 데이터 타입

Counter로 최빈값 찾기

  • .most_common() 메서드는 카운터 값을 내림차순으로 반환
print(nyc_eatery_count_by_types.most_common(3))
[('Mobile Food Truck', 114), ('Food Cart', 74), ('Snack Bar', 24)]
Python의 데이터 타입

연습해 봅시다!

Python의 데이터 타입

Preparing Video For Download...