import pandas as pd
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
import wordcloud
from wordcloud import WordCloud,STOPWORDS
# Read the whole text.
remarks = open(r'C:\Users\marmar\Documents\Remarks.txt').read()
#Create words over an image
mask = np.array(Image.open(r'C:\users\marmar\Documents\cloud.png'))
#set the stopwords list
stopwords= set(STOPWORDS)
#append new words to the stopwords list
new_words =open(r'C:\Users\marmar\comments.txt').read()
new_stopwords=stopwords.union(new_words)
#generate the word cloud with parameters
wc = WordCloud(background_color="white",
max_words=2000,
mask=mask,
min_font_size =12,
max_font_size=20,
relative_scaling = 0.5,
stopwords=new_stopwords,
normalize_plurals= True)
wc.generate(remarks)
plt.figure(figsize=(25,25))
plt.imshow(wc, interpolation="bilinear")
plt.axis("off")
#Show the wordcloud
plt.show()
기본적으로 Python 3 (Jupyter Notebook)을 사용하여 실제 클라우드 그림이있는 워드 클라우드를 만듭니다. WordCloud 패키지에는 실제로 자체 중지 단어 기능이 있습니다. 그러나, 나는 내 구름에보고 싶지 않은 단어를 정지 단어 목록에 포함시키고 자합니다. 해당 텍스트 파일에 일부 단어를 포함 시키려고했지만 해당 단어를 내 클라우드에서 볼 수 있습니다. 예 : 텍스트 파일은 고객, CSR 고객, 만족 됨, 항목 완료내 워드 클 라우드에서 단어를 제거하려면 어떻게해야합니까? (Python 3)
목록에 단어를 더 추가하려면 어떻게해야합니까? 나는이 함수들을 모두 추가, 추가하려고 시도했지만 작동하지 않을 것이다.
미리 감사드립니다.
나는 stopwords.add ('CSR Comment')를 시도했지만 여전히 클라우드에서 볼 수있었습니다! – marmar
'WordCloud' 생성자에 대한 호출에서'stopwords = stopwords'를 전달하는 것처럼 보입니다. 'stopwords = new_stopwords'를 사용하지 않으시겠습니까? – RagingRoosevelt
또한 파일을 모두 토큰 화하여 모든 파일이 단어별로 분리되도록하십시오. 'open (...). read(). split()'과 같은 것을 사용할 수 있습니다. – RagingRoosevelt