[TroubleShooting] WordCloud 한글 폰트 문제 해결

리쫑·2023년 1월 14일
0

TroubleShooting

목록 보기
1/2

WordCloud 한글 폰트 문제 해결 과정에 대한 글 입니다.

👻WordCloud 한글 폰트 문제

  • 네이버 영화 리뷰 데이터를 wordcloud로 시각화 하는 과정에서 한글 폰트를 입력하는 부분에서 발생한 오류를 해결하는 과정을 담았습니다.
from wordcloud import WordCloud
import matplotlib.pyplot as plt
%matplotlib inline

wordcloud = WordCloud(font_path=os.path.join(DATA_IN_PATH, 'NanumGothic.ttf')).generate(" ".join(train_review))

plt.figure(figsize=(10, 8))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()

🤬Error

  Output exceeds the size limit. Open the full output data in a text editor
  ---------------------------------------------------------------------------
  OSError                                   Traceback (most recent call last)
  c:\Users\user\Desktop\github\NLP\NLP.ipynb Cell 138 in <cell line: 6>()
        3 import matplotlib.pyplot as plt
        4 get_ipython().run_line_magic('matplotlib', 'inline')
  ----> 6 wordcloud = WordCloud(font_path=os.path.join(DATA_IN_PATH, 'NanumGothic.ttf')).generate(" ".join(train_review))
        8 plt.figure(figsize=(10, 8))
        9 plt.imshow(wordcloud, interpolation='bilinear')
  File c:\Users\user\anaconda3\envs\nlpproject\lib\site-packages\wordcloud\wordcloud.py:639, in WordCloud.generate(self, text)
      624 def generate(self, text):
      625     """Generate wordcloud from text.
      626 
      627     The input "text" is expected to be a natural text. If you pass a sorted
     (...)
      637     self
      638     """
  --> 639     return self.generate_from_text(text)
  File c:\Users\user\anaconda3\envs\nlpproject\lib\site-packages\wordcloud\wordcloud.py:621, in WordCloud.generate_from_text(self, text)
      604 """Generate wordcloud from text.
      605 
      606 The input "text" is expected to be a natural text. If you pass a sorted
     (...)
      618 self
  ...
      251     )
      252 else:
      253     load_from_bytes(font)
  OSError: cannot open resource

👩‍🏫내가 설정한 경로에 font를 넣어주자

wordcloud = WordCloud(font_path=os.path.join(DATA_IN_PATH, 'NanumGothic.ttf')).generate(" ".join(train_review))
  • 저기 font_path에 NanumGothic.ttf를 직접 다운 받아서 넣어주면 해결!!
    * 저는 나눔고딕.ttf 여기서 다운받았습니다.

🤑clear!!

wordcloud = WordCloud(font_path=os.path.join(DATA_IN_PATH, 'NanumGothic.ttf')).generate(" ".join(train_review))

plt.figure(figsize=(10, 8))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()

profile
AI, Data Scientist 취업 준비생 입니다. 공부한 내용을 포스팅하고자 합니다. 방문해주셔서 감사합니다

0개의 댓글