Artificial Intelligence 12 min read

Analyzing WeChat Friend Data with Python: Gender, Avatar, Signature, and Location Insights

This article demonstrates how to use Python libraries such as itchat, jieba, matplotlib, snownlp, and TencentYoutuyun to retrieve WeChat friend information and perform data analysis on gender distribution, avatar usage, signature sentiment, and geographic location, presenting results with charts and word clouds.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Analyzing WeChat Friend Data with Python: Gender, Avatar, Signature, and Location Insights

The article introduces a Python‑based workflow for extracting and analyzing WeChat friend data, covering four dimensions: gender, avatar, signature, and location. It begins by listing the required third‑party modules (itchat, jieba, matplotlib, snownlp, PIL, numpy, wordcloud, TencentYoutuyun) and notes that they can be installed via pip .

Login to WeChat is performed with itchat.auto_login(hotReload=True) followed by friends = itchat.get_friends(update=True) . The resulting friends list contains dictionaries for each contact, from which fields such as Sex , HeadImgUrl , Signature , Province , and City are extracted.

Gender analysis extracts the Sex field, counts occurrences of Unknown, Male, and Female using collections.Counter , and visualizes the distribution with a pie chart via matplotlib.pyplot . The code snippet shows the full function def analyseSex(friends): and the plotting commands.

Avatar analysis downloads each friend's avatar, uses the Tencent Youtu SDK ( FaceAPI ) to detect faces and extract image tags, aggregates counts of face‑using versus non‑face avatars, and creates both a pie chart and a word‑cloud of extracted tags. The complete analyseHeadImage function is provided, with file handling, API calls, and visualization steps.

Signature analysis processes the Signature field: it cleans the text, performs Chinese word segmentation with jieba.analyse.extract_tags , builds a combined string for a word cloud, and applies SnowNLP to compute sentiment scores. The function def analyseSignature(friends): includes sentiment aggregation, word‑cloud generation, and a bar chart showing the proportion of negative, neutral, and positive sentiments.

Location analysis extracts Province and City for each friend and writes them to a CSV file using csv.DictWriter . The CSV can then be imported into a BI tool (e.g., BDP) to create a geographic distribution map.

The article concludes that visualizations are means to reveal insights, not ends in themselves, and that the presented analyses illustrate how Python can turn personal social data into meaningful statistics.

pythonimage processingdata analysissentiment analysisvisualizationWeChat
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.