[Python] 위드클라우드

정현석·2020년 10월 12일
0
from wordcloud import WordCloud
from PIL import Image
import numpy as np

text = ''
with open("kakao.txt", "r", encoding="utf-8") as f:
    lines = f.readlines()
    for line in lines[1:]:
        text += line.split(',"')[-1]..replace('근데',' ').replace('오빠',' ').replace('아니',' ').replace('나도',' ').replace('ㅎ',' ').replace('ㅋ',' ').replace(' ㅠ ', '').replace(' ㅜ ', '').replace('이모티콘', '').replace('사진', '').replace('삭제된 메세지입니다\n ', '').replace('', '').replace('동영상', '')

# print(text)




mask = np.array(Image.open('cloud.png'))
wc = WordCloud(font_path='/System/Library/Fonts/AppleSDGothicNeo.ttc', background_color="white", mask=mask)
wc.generate(text)
wc.to_file("result_masked.png")
profile
기록하는 벨로그

0개의 댓글