In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use python to generate word clouds. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Generate word cloud
The word cloud, also known as the word cloud, is the visual prominent presentation of the "keywords" with high frequency in the text data, forming the rendering of the keywords to form a color picture similar to the cloud, so that you can appreciate the main expression meaning of the text data at a glance.
But as an old code farmer, I still like to use my own code to generate my own word cloud. Is it complicated? Will it take a long time? A lot of text describes a variety of methods, but in fact it only takes 10 lines of python code.
Install the necessary libraries first
Pip install wordcloudpip install jiebapip install matplotlibimport matplotlib.pyplot as pltfrom wordcloud import WordCloudimport jiebatext_from_file_with_apath = open ('/ Users/linuxmi/linuxmi.txt'). Read () wordlist_after_jieba = jieba.cut (text_from_file_with_apath, cut_all = True) wl_space_split = .join (wordlist_after_jieba) my_wordcloud = WordCloud () .generate (wl_space_split) plt.imshow (my_wordcloud) plt.axis (off) plt.show ()
That's all, a word cloud generated goes like this:
Read these 10 lines of code:
1x 3 lines, imported the library of drawing matplotlib, the word cloud generation library wordcloud and the lexicon of jieba, respectively
4 lines, is to read the local file
Line 5: 6, use jieba for word segmentation, and separate the results of the word segmentation with spaces
7 lines to generate word clouds for the text after word segmentation
Line 8: 10, use pyplot to show the word cloud picture.
Thank you for reading! This is the end of the article on "how to use python to generate word cloud". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.