How to visualize a friend's lap data using Python word cloud and WordArt visualization tools

Source: Internet
Author: User
Tags python web crawler

The day before yesterday we crawl the data of the circle of friends through Python web crawler, interested friends can click to see, how to use the Python crawler to grasp the dynamic of the Circle of Friends (on) and how to use the Python crawler to crawl the circle of friends dynamic-with code (bottom). Today, the small series of people through the word cloud to visualize it, the specific tutorial is as follows.

1, in Python to do the word cloud, need to use the Wordcloud Library and Jieba Word Library, not installed partners can directly PIP installation.

2, after you may also need some fonts, such as SIMHEI.TTF, these fonts are available on the Internet, can be downloaded directly, when the word cloud will be used, as shown in.

3, in the items.py of the same class to establish the analyse.py file, define Analyse_words method, for the realization of Word cloud visualization, jieba.cut used to get word segmentation results, specific code implementation, as shown in. Because the resulting Moment.json data is stored in JSON format, you need to import the JSON module into the file to parse it.

This place needs to notice, because our Memoent.json file is a Chinese character, if the open () function does not include encoding= ' utf-8 ' words will lead to GBK coding error, remember to add the code.

4, after running the program, get keys.png picture file, the effect of the program run as shown. You can see that the keys.png is already under the items.py directory.

5. Double-click the Keys.png, as shown in.

6, have to admit that the word cloud picture content is indeed rich, but also very ugly. Small series use WordArt (a word cloud website) to visualize your friends ' data in a more flattering and beautiful format.

7. For example, visualize with an animal's pattern, as shown in.

8, if the data directly imported, WordArt will directly be the whole paragraph of the visualization, so it seems very redundant, it seems not too friendly, so you also need to use Python data to divide the statistics, and then import into the WordArt can see the desired effect. First, we need to process the JSON file and export the text to form a moment.txt file. The content is as shown.

9, write the code, the text Word segmentation, code implementation as shown below.

10, after the completion of the program, get the Moment_outputs.txt file, the content as shown, you can clearly see the word segmentation situation. The red part is the process of running the program.

11, continue to write code, the frequency of the statistical summary, the code implementation as shown.

12, the program run, get a TXT and Excel file, inside is about the word frequency statistics information, as shown. The red part is the result of the program running, and there is no error.

13. Import these keywords into WordArt for visualization, as shown in.

14, set a case, font, typesetting, color and so on, you can generate brilliant word cloud, is Wang word cloud.

15, is the small cloud word cloud, can bring a gluttonous feast to the vision.

Little friends, do you think it's magical? Favorite Words Welcome collection and Reprint Oh ~ ~

How to visualize a friend's lap data using Python word cloud and WordArt visualization tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.