实战:词频统计的词云之道德经

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿桂天山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值