함수 Collections.Counter
분석대상의 빈도를 파악할 수 있음
매개변수를 어떻게 넣냐에 따라 스플릿(단어를 나누는) 기준이 다름.
기본적으로는 하나의 문자열마다 카운팅.
import collections
a='apple\tapple\tbanana'
collections.Counter(a)
type(collections.Counter(a))
데이터 타입은 collections.Counter
내부적으로는 사전 형식이나 외부적으로는 카운터 데이터 구조.
collections.Counter(a).most_common()
카운터 구조를 리스트구조로 바꾸어줌.
dict(Counter(a))
이렇게 할 시에는 사전구조로 바뀜.
-Counter와 사전 메소드
b=Counter(a)
b.items()
b.keys()
b.values()
사전구조에 해당되는 메소드들 사용가능
결과값
dict_items([('a', 5), ('p', 4), ('l', 2), ('e', 2), ('\t', 2), ('b', 1), ('n', 2)])
dict_keys(['a', 'p', 'l', 'e', '\t', 'b', 'n'])
dict_values([5, 4, 2, 2, 2, 1, 2])
'AI Researcher가 될끄야! > 자연어처리' 카테고리의 다른 글
자연어의 의미 이해 방법 Semantics (0) | 2022.01.03 |
---|---|
자연어의 특징 (0) | 2022.01.03 |
자연어 이해 기술이란? (NLU) (0) | 2022.01.03 |
[파이썬] 경로를 지정하는 모듈 (os 모듈) (0) | 2021.01.12 |
[자연어 처리] 정규표현 (0) | 2021.01.12 |
댓글