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
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 문제 : 함수로 리스트에 추가하기 (0) | 2022.11.29 |
---|---|
[파이썬] 문제 : nxn 다차원 배열에서 0,1이 체크판 패턴 만들기 (0) | 2022.11.29 |
[파이썬] 문제 : Text 파일 저장 및 Binary파일로 저장 (0) | 2022.11.29 |
[파이썬] 문제 : 딕셔너리 데이터를 pandas DataFrame으로 만들고 추가하기 (0) | 2022.11.29 |
[파이썬] 마이크 녹음(puaudio) (0) | 2022.11.29 |
댓글