How to make word Cloud in Python
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: