[시각화] 파이썬으로 한글 워드클라우드(Word Cloud) 생성하고 원하는 이미지 형태로 출력하기 (doitgrow.com)
[시각화] 파이썬으로 한글 워드클라우드(Word Cloud) 생성하고 원하는 이미지 형태로 출력하기
안녕하세요. 오늘 소개해드릴 코드는 한글 문서의 단어를 추출하여 워드클라우드(Word Cloud)로 시각화하는 방법입니다. 파이썬에서 시각화는 거의 모두 matplotlib 라이브러리를 기반으로 하고 있습
doitgrow.com
워드클라우드 따라하기
#워드클라우드
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from collections import Counter
from konlpy.tag import Okt
from PIL import Image
import numpy as np
with open('./data/대한민국헌법.txt', 'r' , encoding='utf-8') as f :
text = f.read()
okt = Okt()
nouns = okt.nouns(text) #명사만 추출
word = [n for n in nouns if len(n) >1] #단어 길이가 1개는 제외
c= Counter(word) #단어별 빈도수 -딕셔너리 데이터
#첫글자가 대문자의 경우 class
wc = WordCloud(font_path='malgun', width=400, height=400, scale=2.0, max_font_size=250)
gen = wc.generate_from_frequencies(c) #c 는 횟수
plt.figure()
plt.imshow(gen)
판다스 프레임 생성(행,열) (0) | 2022.02.12 |
---|---|
daum영화 평점 가져오기 (셀레니움설치) (0) | 2022.02.12 |
20220212파이썬 수업 (0) | 2022.02.12 |
azul 설치 과정 (0) | 2022.02.06 |
스크래핑이란? (0) | 2022.02.05 |