python绘制词云图

这篇具有很好参考价值的文章主要介绍了python绘制词云图。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

  • 作者简介:一名后端开发人员,每天分享后端开发以及人工智能相关技术,行业前沿信息,面试宝典。
  • 座右铭:未来是不可确定的,慢慢来是最快的。
  • 个人主页:极客李华-CSDN博客
  • 合作方式:私聊+
  • 这个专栏内容:BAT等大厂常见后端java开发面试题详细讲解,更新数目100道常见大厂java后端开发面试题。
  • 我的CSDN社区:https://bbs.csdn.net/forums/99eb3042821a4432868bb5bfc4d513a8
  • 微信公众号,抖音,b站等平台统一叫做:极客李华,加入微信公众号领取各种编程资料,加入抖音,b站学习面试技巧,职业规划

python绘制词云图

简介:本文讲解如何通过python绘制词云图。

需要注意的是,需要将代码中的your_excel_file_path.xlsx替换为你自己的Excel文件路径,column_name替换为你要生成词云图的那一列的列名。另外,还可以根据需要调整参数,如停用词、词云图大小、背景颜色等。

效果展示
词云图python,python数据分析,python,开发语言

import pandas as pd
import jieba
from collections import Counter
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# 读取评论数据
df = pd.read_excel(r'D:\系统默认\桌面\京东评论-当前商品最近评论.xlsx')
# 文本预处理
df['comment'] = df['comment'].apply(lambda x: ' '.join(jieba.lcut(x))) # 分词
# 读取停用词
with open('D:\系统默认\桌面\stop_words_eng.txt', 'r', encoding='utf-8') as f:
stop_words = f.read().split('\n')
df['comment'] = df['comment'].apply(lambda x: ' '.join([word for word in
x.split() if word not in stop_words])) # 去除停用词
# 统计单词出现频率
words = []
for comment in df['comment']:
words += comment.split()
word_count = Counter(words).most_common(100)
print(word_count)
生成词云图
font_path = r'C:\Windows\Fonts\msyh.ttc' # 指定微软雅黑字体路径
wordcloud = WordCloud(width=800, height=600, background_color='white',
font_path=font_path).generate_from_frequencies(word_count)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()

这里给一份常用的停词
stop_words_eng.txt文章来源地址https://www.toymoban.com/news/detail-523682.html

a
aaaaah	
aaahhh	
aaaoe	
aah	
about
above
ac
according
accordingly
across
actually
ad
adj
af
after
afterwards
again
against
al
albeit
all
almost
alone
along
already
als
also
although
always
am
among
amongst
amoungst
amount
an
and
another
any
anybody
anyhow
anyone
anything
anyway
anywhere
ap
apart
apparently
are
aren
arise
around
as
aside
at
au
auf
aus
aux
av
avec
away
b
back
be
became
because
become
becomes
becoming
been
before
beforehand
began
begin
beginning
begins
behind
bei
being
below
beside
besides
best
better
between
beyond
bill
billion
both
bottom
briefly
but
by
c
call
came
can
cannot
canst
cant
caption
captions
certain
certainly
cf
choose
chooses
choosing
chose
chosen
clear
clearly
co
come
comes
computer
con
contrariwise
cos
could
couldn
couldnt
cry
cu
d
da
dans
das
day
de
degli
dei
del
della
delle
dem
den
der
deren
des
describe
detail
di
did
didn
die
different
din
do
does
doesn
doing
don
done
dos
dost
double
down
du
dual
due
durch
during
e
each
ed
eg
eight
eighty
either
el
eleven
else
elsewhere
em
empty
en
end
ended
ending
ends
enough
es
especially
et
etc
even
ever
every
everybody
everyone
everything
everywhere
except
excepted
excepting
exception
excepts
exclude
excluded
excludes
excluding
exclusive
f
fact
facts
far
farther
farthest
few
ff
fifteen
fifty
fify
fill
finally
find
fire
first
five
foer
follow
followed
following
follows
for
former
formerly
forth
forty
forward
found
four
fra
frequently
from
front
fuer
full
further
furthermore
furthest
g
gave
general
generally
get
gets
getting
give
given
gives
giving
go
going
gone
good
got
great
greater
h
had
haedly
half
halves
hardly
has
hasn
hasnt
hast
hath
have
haven
having
he
hence
henceforth
her
here
hereabouts
hereafter
hereby
herein
hereto
hereupon
hers
herself
het
high
higher
highest
him
himself
hindmost
his
hither
how
however
howsoever
hundred
hundreds
i
ie
if
ihre
ii
im
immediately
important
in
inasmuch
inc
include
included
includes
including
indeed
indoors
inside
insomuch
instead
interest
into
inward
is
isn
it
its
itself
j
ja
journal
journals
just
k
kai
keep
keeping
kept
kg
kind
kinds
km
l
la
large
largely
larger
largest
las
last
later
latter
latterly
le
least
les
less
lest
let
like
likely
little
ll
long
longer
los
low
lower
lowest
ltd
m
made
mainly
make
makes
making
many
may
maybe
me
meantime
meanwhile
med
might
mill
million
mine
miss
mit
more
moreover
most
mostly
move
mr
mrs
ms
much
mug
must
my
myself
n
na
nach
name
namely
nas
near
nearly
necessarily
necessary
need
needed
needing
needs
neither
nel
nella
never
nevertheless
new
next
nine
ninety
no
nobody
none
nonetheless
noone
nope
nor
nos
not
note
noted
notes
nothing
noting
notwithstanding
now
nowadays
nowhere
o
obtain
obtained
obtaining
obtains
och
of
off
often
og
ohne
ok
old
om
on
once
onceone
one
only
onto
or
ot
other
others
otherwise
ou
ought
our
ours
ourselves
out
outside
over
overall
owing
own
p
par
para
part
particular
particularly
past
per
perhaps
please
plenty
plus
por
possible
possibly
pour
poured
pouring
pours
predominantly
previously
pro
probably
prompt
promptly
provide
provided
provides
providing
put
q
quite
r
rather
re
ready
really
recent
recently
regardless
relatively
respectively
reuters
round
s
said
same
sang
save
saw
say
second
see
seeing
seem
seemed
seeming
seems
seen
sees
seldom
self
selves
send
sending
sends
sent
serious
ses
seven
seventy
several
shall
shalt
she
short
should
shouldn
show
showed
showing
shown
shows
si
side
sideways
significant
similar
similarly
simple
simply
since
sincere
sing
single
six
sixty
sleep
sleeping
sleeps
slept
slew
slightly
small
smote
so
sobre
some
somebody
somehow
someone
something
sometime
sometimes
somewhat
somewhere
soon
spake
spat
speek
speeks
spit
spits
spitting
spoke
spoken
sprang
sprung
staves
still
stop
strongly
substantially
successfully
such
sui
sulla
sung
supposing
sur
system
t
take
taken
takes
taking
te
ten
tes
than
that
the
thee
their
theirs
them
themselves
then
thence
thenceforth
there
thereabout
thereabouts
thereafter
thereby
therefor
therefore
therein
thereof
thereon
thereto
thereupon
these
they
thick
thin
thing
things
third
thirty
this
those
thou
though
thousand
thousands
three
thrice
through
throughout
thru
thus
thy
thyself
til
till
time
times
tis
to
together
too
top
tot
tou
toward
towards
trillion
trillions
twelve
twenty
two
u
ueber
ugh
uit
un
unable
und
under
underneath
unless
unlike
unlikely
until
up
upon
upward
us
use
used
useful
usefully
user
users
uses
using
usually
v
van
various
ve
very
via
vom
von
voor
vs
w
want
was
wasn
way
ways
we
week
weeks
well
went
were
weren
what
whatever
whatsoever
when
whence
whenever
whensoever
where
whereabouts
whereafter
whereas
whereat
whereby
wherefore
wherefrom
wherein
whereinto
whereof
whereon
wheresoever
whereto
whereunto
whereupon
wherever
wherewith
whether
whew
which
whichever
whichsoever
while
whilst
whither
who
whoever
whole
whom
whomever
whomsoever
whose
whosoever
why
wide
widely
will
wilt
with
within
without
won
worse
worst
would
wouldn
wow
x
xauthor
xcal
xnote
xother
xsubj
y
ye
year
yes
yet
yipee
you
your
yours
yourself
yourselves
yu
z
za
ze
zu
zum

到了这里,关于python绘制词云图的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • [数据分析与可视化] Python绘制数据地图2-GeoPandas地图可视化

    本文主要介绍GeoPandas结合matplotlib实现地图的基础可视化。GeoPandas是一个Python开源项目,旨在提供丰富而简单的地理空间数据处理接口。GeoPandas扩展了Pandas的数据类型,并使用matplotlib进行绘图。GeoPandas官方仓库地址为:GeoPandas。GeoPandas的官方文档地址为:GeoPandas-doc。关于Geo

    2023年04月09日
    浏览(47)
  • python数据分析-matplotlib散点图-条形图的绘制以及完整方法归纳02

    散点图的绘制使用的是scatter()方法,传入的参数也是两个列表,分别为x,y坐标轴的值使用散点图可以显示若干数列序列中各数值之间是否存在相关性. 1.导入模块 from matplotlib import pyplot as plt import matplotlib 2.设置散点图所有字符的字体样式 matplotlib.rcParams[‘font.family’] = ‘Microsof

    2023年04月11日
    浏览(47)
  • Python(wordcloud):根据文本数据(.txt文件)绘制词云图

    本文将介绍如何利用python来根据文本数据(.txt文件)绘制词云图,除了绘制常规形状的词云图(比如长方形),还可以指定词云图的形状。 1、安装相关的库 2、 导入相关的库 3、 相关库的介绍 jieba: 结巴分词库,一个中文分词库。由于中文文本的每个汉字都是连续书写的,

    2024年04月16日
    浏览(58)
  • 【数据分析:语言篇】Python(03)创建Python虚拟环境

    根据实际开发需求,我们会不断的更新或卸载项目中依赖的Python类库,直接对我们的Python环境操作会让我们的开发环境和项目造成很多不必要的麻烦,并且当我们同时开发多个项目的时候,可能每个项目依赖的同一个Python库的版本还不一样,就会造成版本冲突,管理相当混乱

    2024年02月03日
    浏览(75)
  • 【100天精通Python】Day61:Python 数据分析_Pandas可视化功能:绘制饼图,箱线图,散点图,散点图矩阵,热力图,面积图等(示例+代码)

    目录 1 Pandas 可视化功能 2 Pandas绘图实例 2.1 绘制线图 2.2 绘制柱状图 2.3 绘制随机散点图/

    2024年02月08日
    浏览(54)
  • 5.Python数据分析项目之文本分类-自然语言处理

    预测类数据分析项目 流程 具体操作 基本查看 查看缺失值(可以用直接查看方式isnull、图像查看方式查看缺失值missingno)、查看数值类型特征与非数值类型特征、一次性绘制所有特征的分布图像 预处理 缺失值处理(填充)拆分数据(获取有需要的值) 、统一数据格式、特征

    2024年02月03日
    浏览(68)
  • 基于Python的影视数据智能分析系统开发

    数据分析与可视化是当今数据分析的发展方向,大数据时代,数据资源具有海量特征,数据分析和可视化主要通过Python数据分析来实现。 基于Python的数据分析可视化和技术实现是目前Python数据分析的主要目的,Python可以为数据分析可视化提供思路,在体现数据价值方面发挥着

    2024年02月02日
    浏览(38)
  • 一个Python开发的低代码数据分析工具:DataPrep

    更多Python学习内容:ipengtao.com 在数据科学和分析领域,数据的预处理和清理是一个非常重要且耗时的任务。为了简化这一过程,让数据分析师和数据科学家能够更快速地准备和探索数据,DataPrep(Data Preparation)成为了一个强大的工具。DataPrep是一个用于数据预处理和数据探索

    2024年02月02日
    浏览(68)
  • python绘制词云图

    作者简介 :一名后端开发人员,每天分享后端开发以及人工智能相关技术,行业前沿信息,面试宝典。 座右铭 :未来是不可确定的,慢慢来是最快的。 个人主页 :极客李华-CSDN博客 合作方式 :私聊+ 这个专栏内容 :BAT等大厂常见后端java开发面试题详细讲解,更新数目10

    2024年02月12日
    浏览(46)
  • Python绘制基础词云图

    Python的词云制作。 词云介绍: 词云是对文本进行可视化呈现的一种方式, 词云出现的次数越多,字体越大,颜色越醒目, 可以通过词云快速获取文本的主要内容 给大家看一下词云绘制的效果:     用来绘制词云的第三方库:wordcloud,在导入前需要下载。 在绘制之前需要先创

    2024年02月04日
    浏览(75)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包