라이브러리 설치
pip install wordcloud
pip install matplotlib
텍스트의 빈도를 계산하여 클라우드 그리기
text = '''
파이썬 파이썬 자바 파이썬 C언어 GOLANG 파이썬 ASP 자바스크립트
파이썬 C++ C언어 델파이 파이썬
'''
from wordcloud import WordCloud
import matplotlib.pyplot as plt
wordcloud = WordCloud(font_path='NanumBarunGothic.ttf',
background_color='black').generate_from_text(text)
plt.figure(figsize=(5,5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
딕셔너리를 이용하여 카운트를 이용하여 그리기
text = {'파이썬':5,'자바':3,'C언어':4,'자바스크립트':2,'델파이':1,'GOLANG':1}
from wordcloud import WordCloud
import matplotlib.pyplot as plt
wordcloud = WordCloud(font_path='NanumBarunGothic.ttf',
background_color='white').generate_from_frequencies(text)
plt.figure(figsize=(5,5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
불용어 처리
text = '''
파이썬 파이썬 자바 파이썬 C언어 GOLANG 파이썬 ASP 자바스크립트
파이썬 C++ C언어 델파이 파이썬
'''
from wordcloud import WordCloud
from wordcloud import STOPWORDS
import matplotlib.pyplot as plt
stopwords = set(STOPWORDS)
stopwords.add('자바')
wordcloud = WordCloud(font_path='NanumBarunGothic.ttf',
background_color='white',
stopwords=stopwords).generate_from_text(text)
plt.figure(figsize=(5,5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
'Python > Python For Analytics' 카테고리의 다른 글
[ Python ] pandas plot 을 이용한 다양한 graph 그리기 (0) | 2023.05.24 |
---|---|
[ Python ] csv 파일 읽고, 쓰기 ( pandas / csv 모듈 ) (0) | 2023.05.16 |
[ Python ] matplotlib plot Shading Area (특정구간 강조) (0) | 2023.02.03 |
[ Python ] pandas를 이용한 bar graph (stacked) (0) | 2022.03.01 |
[Python] seaborn을 이용한 간단한 heatmap 그리기 (0) | 2020.11.28 |
[Python] pandas와 pymssql을 이용하여 MSSQL 연동 (0) | 2020.10.05 |
[Python] padnas Dataframe 에서 astype을 이용하여 숫자형으로 변환할 수 없을 때 to_numeric을 이용 (0) | 2020.08.02 |
[Python] matplotlib - 그래프에 값 표시 하기 (1) | 2020.08.02 |