如何用python制作词云--wordcloud

如何用python制作词云–wordcloud

由于第一次写优快云博客,水平有限。写这份python制作词云,想帮助一些不太了解python但是想快速制作出词云的小伙伴。网上也有很多其他的方法,我简单做了一部分,用起来比较方便,感谢大家观看。

第一步 首先用python编辑你可以选择一个python的编辑器,然后做一点准备工作。要准备一段txt文档,,就是你想让它生产词云的文档。你可以选择一些语录、歌词、文章、留言等等。


英文词云

v1.0

首先在词云制作过程中,有英文和中文的区别,英文比较简单,中文需要更进一步。英文的编辑可以直接生成普通的词云。
我随便搜了一点英文文章,如下
aa bb cc rr fd gh ffe ed fdf hello water back forword name one two three thursday friday today hoop tell
proun Hooray! It’s snowing! It’s time to make a snowman.
James runs out. He makes a big pile of snow.
He puts a big snowball on top. He adds a scarf and a hat.
He adds an orange for the nose. He adds coal for the eyes and buttons.
In the evening, James opens the door. What does he see? The snowman is moving!
James invites him in. The snowman has never been inside a house.
He says hello to the cat. He plays with paper towels.
A moment later, the snowman takes James’s hand and goes out.
They go up, up, up into the air! They are flying! What a wonderful night!
The next morning, James jumps out of bed. He runs to the door.
He wants to thank the snowman. But he’s gone.
将这一段文字做成txt文件,放在程序的同一个文件夹下,方便直接调用。
代码如下:
下面展示一些 内联代码片

from wordcloud import WordCloud

def main():
    """
    主函数

    """
    # 1、读入txt文本数据
    with open("Englishwordcloud.txt", 'r') as fp:
        text = fp.read()
        # print(text)

    # 2、生成词云
    wordcloud = WordCloud().generate(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值