collections 모듈

파이썬・ML

파이썬 collections 모듈 Counter 사용하기

최근에 pandas로 데이터를 가공하면서 Counter 객체를 요긴하게 사용한 기억이 있습니다. 이번 포스팅에서 collections 모듈의 Counter에 대해 알아보도록 하겠습니다. from collections import Counter 1. 기본 사용법 counter1 = Counter('banana') print(counter1) # Counter({'a': 3, 'n': 2, 'b': 1}) counter2 = Counter(['jason', 'harriet', 'john', 'john', 'harriet']) print(counter2) # Counter({'harriet': 2, 'john': 2, 'jason': 1}) 카운터 클래스는 파이썬 자료구조인 딕셔너리의 확장판입니다. 따라서 모..

truezero
'collections 모듈' 태그의 글 목록