Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to generate word Cloud Picture by python

Shulou Source: shulou.com Published: 2022-06-01 07:13:24 11月14日 Update

This article mainly introduces python how to generate word cloud map, the article is very detailed, has a certain reference value, interested friends must read it!

The generated word cloud image is as follows:

Install wordcloud,jieba, and install other packages by yourself:

Conda install-c conda-forge wordcloud

Conda install-c conda-forge jieba

Note: conda-forge is an organization of github that provides conda recipes libraries, which are interrelated things that can be packaged together. The specific usage is as above, first add conda-forge, and then install the required toolkit. This is the most recommended way to install the package, because it is the first choice for the community to use a package, version relevance and so on are tested.

The code example is as follows:

1. Import the libraries used, and see the notes for the role of each library.

two。 Read the file to be analyzed and preprocess the text.

Note: an error was encountered when opening the file, as follows, pay attention to the writing of open.

You can avoid similar errors by specifying the type of encoding when you open the file, as follows.

Fn=open ('ana_test.txt',encoding='utf-8')

3. The text is segmented and the result is put into object_list, using a user-defined dictionary.

4. Word frequency statistics, get the top 20 highest frequency words and output

5. Word frequency display, the image can be set to your favorite style.

6. Word cloud image display: see the annotation steps, generate word cloud from the dictionary (word frequency statistics), establish a color scheme from the background map, and set the word cloud color to the background map scheme to display the word cloud image.

7. Output result diagram, as follows:

The above is all the content of the article "how to generate word Cloud Picture by python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Cloud image generation file word frequency content dictionary text scheme comment article result background error color association statistics output thing code value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Tech Info Microsoft MySQL Linux