In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use pandas for data analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
(1) obtain the data of Wechat friends
In order to get the data of Wechat friends, you need to use a tool called itchat.
Itchat is the encapsulation of the interface of Wechat on a web page.
A long time ago, Xiao Cheng introduced how to automatically send (batch) messages to WeChat groups, using itchat.
For the installation and use of itchat, readers can follow the official Wechat account of "Guangzhou Xiaocheng" and find the corresponding articles in the menu items of "Software Foundation".
Here is a direct introduction to using itchat to get Wechat friend information.
Try it, first calculate how many friends of the opposite sex Xiaocheng has, you can write the code like this:
Execute this code, and you can see the output like this:
For subsequent data analysis, next, Xiao Cheng extracts more specific friend data and saves it to a file, which uses pandas.
If the reader does not have pandas installed, you can install it like this:
Pip install pandas
The following is the code to get friend data:
Execute this code to generate a file locally: the friends_info.csv,csv file is usually plain text, a file used to hold records (usually all records have the same field).
If you open the csv file with excel, you can see this message (if the reader finds that excel opens with garbled code, you can first use word and choose to open it with utf8, then save it, and then open it with excel):
The content of this csv file is the basis of subsequent data analysis.
(2) Analysis of data
Once you have the basic data, you can use pandas for analysis and matplotlib for drawing.
Matplotlib is a practical tool for drawing. Xiao Cheng finds another opportunity to introduce it in detail. Readers can ignore this part of the content first, or simply understand it first, because there is a corresponding explanation in the code screenshot.
Here is a demonstration of data analysis on the gender and region of Wechat friends.
(1) introduce pandas and matplotlib
The code that introduces pandas and matplotlib, and the execution effect of the code is as follows:
(2) Analysis of gender
Here, a bar chart is drawn according to the number of gender categories.
First, let's take a look at the analysis of gender and the code drawn. The explanation in the screenshot is the key content:
Execute this code, and you can see the output and display like this:
As can be seen from the display picture, most of Xiao Cheng's friends are men.
(3) Analysis area
The idea of implementation is similar to gender analysis, and the code is as follows:
The effect of execution is as follows:
As can be seen from the display picture, Xiaocheng's friends are mainly Guangzhou and Shenzhen, and Xiaocheng's circle of friends is very narrow.
The above describes how to analyze gender and regional distribution data, in which the use of pandas is the focus of this article.
In the above code, the DataFrame and Series types of pandas are used, as well as the statistical function max of Series.
Next, make a brief introduction to the knowledge of pandas.
(3) knowledge of pandas
There are two types of pandas data. One is DataFrame, the other is Series.
DataFrame is a data table (made up of several columns), and Series is one of them (all the contents of a field).
For the content of data analysis, readers can refer to the article on "data Analysis" in Guangzhou Xiaocheng.
For DataFrame or Series variables, there are various functions that can complete data analysis, including: number, maximum, minimum, average, median, multiplicity, variance, peak, and so on.
For a detailed understanding of pandas, you can refer to this document: http://pandas.pydata.org/pandas-docs/stable/index.html
Readers can also learn while using it.
At this point, the main content has been introduced, the following is the attached content.
(3) word cloud map
Xiao Cheng's friend information includes the content of "signature". Generally speaking, you can get a word cloud picture to see the key information of the signature.
The following is the content of Xiao Cheng Shun Dai's introduction.
Install the module jieba, which is a Chinese word splitter:
Pip install jieba
Install the module PIL, which is an image processing library:
Pip install Pillow
Install wordcloud, which is a word cloud library:
Pip install wordcloud
The general idea of realizing the word cloud map of Wechat friends' signatures is as follows: use pandas to read a data table from the basic data, get the signature column from the data table and convert the contents of this column into list, process each signature of the list one by one, filter out some keywords, then use regular expressions to remove some special characters, and finally concatenate the processed signatures with spaces And call the word separator to process the word segmentation, and get a word segmentation list. Create the word cloud image object, set the background color, font, etc., and pass the word segmentation list, and finally display and save the image generated by the word cloud image object.
For the code of the implementation, please refer to the following figure:
By executing this code, you can see the effect:
As can be seen from the picture, Xiaocheng's friends have a lot of personality (like to say "oneself"), Xiaocheng's friends are inseparable from the "program", and Xiaocheng's friends have begun to talk about life and cooperation (probably older).
When generating the word cloud image, the background image (back.jpg) is set, which is used by Xiao Cheng here:
Thank you for reading this article carefully. I hope the article "how to use pandas for data Analysis" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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: 258
*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.