1.先看词云效果

2.上代码
#----------Ewangda 阿桂天山------------------------
import pandas as pd
from nltk import FreqDist
from test_cleanwords import clean_text
file_data = pd.read_csv('./data/道德经.csv',encoding='utf-8')
# print(file_data)#.head()
#去重
file_data =file_data.drop_duplicates()
#清洗 去除拼音等内容
# print(type(file_data['道德经']))
cleaned_text=[]
for str1 in file_data['道德经'].to_list():
# print(str1,type(str1))
cleaned_text.append(clean_text(str1))
# print(cleaned_text)
# ddj =''.join(cleaned_text)
# print(ddj)
# # file_data
#jeiba精准划分方式
import jieba
cut_words = jieba.lcut(str(cleaned_text),cut_all=False)
# print(cut_words)
#---加载停用词列表
with open('./data/停用词表.txt',encoding='utf-8') as f:
stop_words=f.read()
# print(stop_words)
remain_list=[]
for word in cut_words:
if word not in stop_words:
remain_list.append(word)
# print(remain_list)
# #----词频统计------------------
# freq_list =FreqDist(remain_list)
# most_common_words =freq_list.most_common()
# print(most_common_words)
from wordcloud import WordCloud
from matplotlib import pyplot as plt
wc=WordCloud(font_path='./font/simhei.ttf',background_color='white',width=1000,height=800).generate(' '.join(remain_list))
plt.imshow(wc)
plt.axis('off')
plt.show()

438

被折叠的 条评论
为什么被折叠?



