프로그램
[파이썬] 문제 : Text파일의 단어 빈도수(konlpy)
오디세이99
2022. 11. 29. 15:38
728x90
반응형
from konlpy.tag import Twitter
from konlpy.tag import Okt
from collections import Counter
f = open('news.txt','r',encoding='utf-8') # 파일 일기
news = f.read()
f.close()
nlpy = Twitter()
nouns = nlpy.nouns(news) # 면사 추출
# print(nouns)
count = Counter(nouns) # 단어 Counter
tag_count = []
tags = []
for n, c in count.most_common(100):
dics = {'tag': n, 'count': c} # 단어와 빈도수
if len(dics['tag']) >= 2:
tag_count.append(dics)
tags.append(dics['tag'])
for tag in tag_count:
print(" {0:<14} {1}".format(tag['tag'], tag['count']))
728x90
반응형