上海市工程建设信息网官方网站,深圳装修网,百度企业查公司名录,免费网站制作知乎从excel和从txt文件#xff0c;绘制以句子、词为单位的词云图 写在最前面数据说明结论 从txt文件#xff0c;绘制以句子、词为单位的词云图自我介绍 从excel#xff0c;绘制以句子、词为单位的词云图读取excel绘制以句子、词为单位的词云图文章标题 写在最前面
经常绘… 从excel和从txt文件绘制以句子、词为单位的词云图 写在最前面数据说明结论 从txt文件绘制以句子、词为单位的词云图自我介绍 从excel绘制以句子、词为单位的词云图读取excel绘制以句子、词为单位的词云图文章标题 写在最前面
经常绘制词云图这次正好梳理一下方便之后自己直接copy微调代码。
代码功能说明 1、支持plt绘图的中文正常显示 2、以句为单位、和以词为单位进行词云图分析 3、支持excel的数据读取注意excel中nan数据必须先进行处理本文以’未提供’填充缺失数据。 4、支持txt文件的数据读取
数据说明结论 这份数据包含了我最近发布的文章标题。 为了更好地分析这些数据首先对数据进行清理和整理然后进行可视化分析并最后提出一些结论。 从txt文件绘制以句子、词为单位的词云图
import matplotlib.pyplot as plt
import seaborn as sns
from wordcloud import WordCloud
import jieba # 导入 jieba 分词库plt.rcParams[font.sans-serif] [SimHei] # 设置字体以便支持中文
sns.set(stylewhitegrid) # 设置图表风格# 生成词云的函数
def generate_wordcloud(text, title, use_jiebaFalse):plt.rcParams[font.sans-serif] [SimHei] # 设置字体以便支持中文if use_jieba:text .join(jieba.cut(text)) # 使用 jieba 进行分词wordcloud WordCloud(width800, height400, font_pathsimhei.ttf, background_colorwhite).generate(text)plt.figure(figsize(10, 5))plt.imshow(wordcloud, interpolationbilinear)plt.title(title, fontsize18)plt.axis(off)plt.show()# 读取 TXT 文件
file_path 自我介绍.txt # 替换为您的 TXT 文件路径
with open(file_path, r, encodingutf-8) as file:text file.read()title 自我介绍# 生成词云
generate_wordcloud(text, title)
generate_wordcloud(text, title, use_jiebaTrue)
自我介绍 从excel绘制以句子、词为单位的词云图
读取excel
import matplotlib.pyplot as plt
import seaborn as sns
from wordcloud import WordCloud
import jiebaimport pandas as pd# Load the provided Excel file for analysis
file_path score1.xlsx
try:data pd.read_excel(file_path)
except Exception as e:print(fError reading the Excel file: {e})# 处理数据
data.fillna(未提供, inplaceTrue)# Displaying the first few rows of the dataset to understand its structure and contents
data.head()文章标题URL发布时间阅读量收藏量点赞量评论量质量分0【力扣热题100】287. 寻找重复数弗洛伊德的乌龟和兔子方法https://blog.csdn.net/wtyuong/article/details/...2023-12-08 23:39:325961724149112024年大学生考试/考证年历框架https://blog.csdn.net/wtyuong/article/details/...2023-12-08 23:24:4736811122902【从0配置JAVA项目相关环境1】jdk VSCode运行java mysql ...https://blog.csdn.net/wtyuong/article/details/...2023-12-06 21:27:2619363960104973【从0配置JAVA项目相关环境2】node.js 前端 从配置到运行https://blog.csdn.net/wtyuong/article/details/...2023-12-06 21:26:33154425275934GPT-Crawler一键爬虫构建GPTs知识库https://blog.csdn.net/wtyuong/article/details/...2023-12-05 23:32:37181530312994
绘制以句子、词为单位的词云图
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from wordcloud import WordCloud
import jieba # 导入jieba分词库plt.rcParams[font.sans-serif] [SimHei] # 设置字体以便支持中文
sns.set(stylewhitegrid) # 设置图表风格# 生成词云的函数
def generate_wordcloud(text_series, title, use_jiebaFalse):plt.rcParams[font.sans-serif] [SimHei] # 设置字体以便支持中文text .join(text_series.astype(str)) # 将文本转换为字符串if use_jieba:text .join(jieba.cut(text)) # 使用jieba进行分词wordcloud WordCloud(width800, height400, font_pathsimhei.ttf, background_colorwhite).generate(text)plt.figure(figsize(10, 5))plt.imshow(wordcloud, interpolationbilinear)plt.title(title, fontsize18)plt.axis(off)plt.show()# 对不同的列生成词云
generate_wordcloud(data[文章标题], 标题)
generate_wordcloud(data[文章标题], 标题, use_jiebaTrue)
文章标题