# -*- coding: utf-8 -*-
import re
import jieba
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from sklearn.feature_extraction.text import CountVectorizer,TfidfTransformer,TfidfVectorizer
class DrawWordCloud(object):
_apBranchWordCol = '文本分词结果'
def __init__(self, path,colname):
self._path = path
self._colname = colname
# 分词方法
def branchword(self):
idata = pd.read_excel(self._path)
# 过滤非中文字符\w
idata['过滤非中文字符'] = idata[self._colname].astype(str).map(lambda x: re.sub('[^\u4e00-\u9fff]+', '', x))
idata[self._apBranchWordCol] = ""
idata[self._apBranchWordCol] = idata['过滤非中文字符'].map(lambda x: ' '.join(jieba.cut(x, cut_all=False)))
return idata
# 词频统计
def wordfreqcount(self,df_brachword):
_txts = []
for index, row in df_b
python(1)-------绘制词云图
最新推荐文章于 2024-06-19 19:38:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)