WhatsApp Chat Analysis with Python

WhatsApp is one of the most used messenger applications today with more than 2 Billion users worldwide. It was found that more than 65 billion messages are sent on WhatsApp daily so we can use WhatsApp chats for analyzing our chat with a friend, customer, or a group of people. In this article, I will take you through the task of WhatsApp Chat Analysis with Python.

WhatsApp Chat Analysis

You can use your WhatsApp data for many data science tasks like sentiment analysis, keyword extraction, named entity recognition, text analysis and several other language processing tasks. natural. It also depends on who you are analyzing your WhatsApp messages with because you can find a lot of information from your WhatsApp messages which can also help you to solve business problems.

Before starting with the task of WhatsApp Chat analysis with Python you need to extract your WhatsApp data from your smartphone which is a very easy task. To extract your WhatsApp chats, just open any chat with a person or a group and follow the steps mentioned below:

  1. If you are having an iPhone then tap on the Contact Name or the Group NameIn case you are having an Android smartphone then tap on the 3 dots above.
  2. Then scroll to the bottom and top on Export Chat.
  3. Then select without media for simplicity if it asks you whether you want your chats with or without media.
  4. Then email this chat to yourself and download it to your system.

So this is how you can easily get your WhatsApp chats with any person or a group for the task of WhatsApp chat analysis. In the section below, I will take you through WhatsApp chat analysis with Python.

WhatsApp Chat Analysis with Python

I hope you now have understood how to get your WhatsApp data for the task of WhatsApp chat analysis with Python. Now let’s start this task by importing the necessary Python libraries that we need for this task:

The dataset we are using here requires a lot of preparation, so I suggest you take a look at the data you are using before starting this WhatsApp chat analysis task. As I have already walked through the dataset, so I’ll start by writing a few Python functions to prepare the data before importing it:

Now let’s import the data and prepare it in a way that we can use it in a pandas DataFrame:

Our dataset is completely ready now for the task of WhatsApp chat analysis with Python. Now let’s have a look at the last 20 messages and some other insights from the data:

WhatsApp chats analysis

Now let’s have a look at the total number of messages between this WhatsApp chat:

total_messages = df.shape[0]

Now let’s have a look at the total number of media messages present in this chat:

media_messages = df[df["Message"]=='<Media omitted>'].shape[0]

Now let’s extract the emojis present in between the chats and have a look at the emojis present in this chat:


Now let’s extract the URLs present in this chat and have a look at the final insights:

Chats between Aman and Sapna
Total Messages:  1288
Number of Media Shared:  11
Number of Emojis Shared 367
Number of Links Shared 1

Now let’s prepare this data to get more insights to analyze all the messages sent in this chat in more detail:

Stats of Aman Kharwal -
Messages Sent 687
Average Words per message 6.165938864628821
Media Messages Sent 9
Emojis Sent 228
Links Sent 1

Stats of Sapna -
Messages Sent 590
Average Words per message 6.3830508474576275
Media Messages Sent 2
Emojis Sent 139
Links Sent 0

Now let’s prepare a visualization of the total emojis present in the chat and the type of emojis sent between the two people. It will help in understanding the relationship between both the people:

emojis shared in a whatsapp chat

Now let’s have a look at the most used words in this WhatsApp chat by visualizing a word cloud:


Now let’s have a look at the most used words by each person by visualizing two different word clouds:

Author name Aman Kharwal
wordcloud of chats
Author name Sapna
whatsapp chat analysis with python


So this is how we can easily analyze any WhatsApp chat between you and your friend, customer, or even a group of people. You can further use this data for many other tasks of natural language processing. I hope you liked this article on the task of WhatsApp chat analysis with Python. Feel free to ask your valuable questions in the comments section below.

Default image
Aman Kharwal

I am a programmer from India, and I am here to guide you with Data Science, Machine Learning, Python, and C++ for free. I hope you will learn a lot in your journey towards Coding, Machine Learning and Artificial Intelligence with me.

Leave a Reply

Data Science | Machine Learning | Python | C++ | Coding | Programming | JavaScript