write sth. upfront
Now everyone has WeChat, a "let's add a WeChat chant" piggybacked on the friendship bridge between you and me, oblivious to their WeChat friends have been four or five hundred, or even thousands, thousands of them; however, that's the one, who is who, is a man or a woman can not be distinguished, and today we will count the ratio of men and women in your WeChat friends, to see whether you usually like to add male friends or female friends, and to see the ratio of men and women. To see whether you usually like to add male friends or female friends, haha, exposed it.
Without further ado, let's take a look at the details together!
Environment Installation
One interesting library is itchat, which is an open source personal interface to WeChat. Let's use itchat to count the gender ratio of our WeChat friends and present it in a bar chart so that we can see it at a glance.
(1) First install itchat:
pip install itchat
(2) In installing matplotlib:
pip install matplotlib
Log in to WeChat
itchat.auto_login(hotReload=True)
The WeChat QR code that pops up when you run the program requires your phone to scan the code and log in to WeChat before you can continue executing the code for statistics.
Below is the complete program code:
import itchat import as plt itchat.auto_login(hotReload=True) friends=itchat.get_friends(update=True)[0:] # Get all your friends' information male = female = other =0 for i in friends[1:]: sex=i["Sex"] if sex==1: male+=1 elif sex==2: female+=1 else: other+=1 total=len(friends[1:]) print("Male Buddy: %.2f%%" % (float(male)/total*100) + "\n" + "Female Friends: %.2f%%" % (float(female) / total * 100) + "\n" + "Unknown Gender Buddy: %.2f%%" % (float(other) / total * 100)) ("sex") ("count") ("Gender statistics") a=(1,1,1) (10, male, facecolor='red', width=3, label='male') (15, female, facecolor='yellow', width=3, label='female') (20, other, facecolor='blue', width=3, label='other') () ()
Run the above code to get the gender ratio of your WeChat friends:
For example, my WeChat friends stats are drawn as follows:
As you can see from the bar chart above, my WeChat Friends stats.
Male friends: 57.99%;
Female friends: 34.32%;
Friends of unknown gender: 7.69%;
As you can see I have a lot more male friends than female friends, which leads to the conclusion that I'm a polytechnic steel straight man, the almost hopeless kind, hahaha, I don't know how everyone else's is, once you try it you'll know, haha.
summarize
Above is the entire content of this article, I hope that the content of this article on your learning or work has a certain reference learning value, if there are questions you can leave a message to exchange, thank you for my support.