Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make word Cloud in Python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to make word cloud in Python". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to make a word cloud with Python".

The effect is as follows:

(word cloud-the more frequent the word, the larger the font)

Tools section

1. Install the visualization library

Pip3 install matplotlib

3. Install the "stuttering" library, which is a real name, and give developers a like.

Pip3 install jieba

This library is used to parse Chinese, parsing a sentence into individual words.

Our Chinese is not like English. There are spaces between every word. It needs to be split into phrases according to semantic analysis.

Let's use an example of a conversation from "Sword Rain":

Import jieba # introduced stuttering Ku str=' master. Why did he say that the Zen machine has arrived,\ Buddha enlightens the world and pays attention to the opportunity,\ the Zen machine dies as soon as it passes, and the Zen machine doesn't arrive and doesn't hit the point? what do I want to be incarnated by Ishiqiao? 'print (str) # parsing the method of splitting the phrase lcut words = jieba.lcut (str) print (words)

The effect is as follows:

(split the complete sentence into individual words and look at it intermittently. Maybe this is the origin of the stutter. The stuttering library has been done for the most difficult part. This is also the reason why python is powerful. There are all kinds of libraries.)

Stuttering library

Download Journey to the West in txt format

After the download is completed, convert it to utf-8 format and save it.

Conversion method: select the encoding format UTF-8 when saving notepad as

Format formatted output:

# column header formatprint ("{0:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report