WhatsApp Chat Sentiment Analysis using Python

WhatsApp is a great source of data to analyze many patterns and relationships between two or more people chatting personally or even in groups. If you want to know how we can analyze the sentiments of a WhatsApp chat, this article is for you. In this article, I will walk you through the task of WhatsApp chat sentiment analysis using Python.

WhatsApp Chat Sentiment Analysis

To analyze the sentiments of a WhatsApp chat, we need to collect data from WhatsApp. Most of you must be using this messaging app, so to collect data about your chat, simply follow the steps mentioned below:

  1. For iPhone:
    1. Open your chat with a person or a group
    2. Just tap on the profile of the person or the group
    3. You will see an option to export chat down below
  2. For Android:
    1. Open your chat with a person or a group 
    2. Click on the three dots above 
    3. Click on more
    4. Click on the export chat

You will see an option to attach media while exporting your chat. For simplicity, it is best not to attach media. Finally, enter your email and you will find your WhatsApp chat in your inbox.

WhatsApp Chat Sentiment Analysis using Python

Now let’s start with the task of WhatsApp chat sentiment analysis with Python. I’ll start this task by defining some helper functions because the data we get from WhatsApp is not a dataset that is ready to be used for any kind of data science task. So, to prepare your data for the sentiment analysis task, just define all the functions as defined below:

It doesn’t matter if you are using a group chat dataset or your conversation with one person. All the functions defined above will prepare your data for the task of sentiment analysis as well as for any data science task. Now here is how we can prepare the data we collected from WhatsApp by using the above functions:

Now here is how we can analyze the sentiments of WhatsApp chat using Python:

        Date      Time        Author  ... Positive  Negative  Neutral
0 2020-04-06  12:30 pm         Sapna  ...      0.0     0.000    1.000
1 2020-04-06  12:30 pm         Sapna  ...      0.0     0.000    1.000
2 2020-04-06  12:54 pm  Aman Kharwal  ...      0.0     0.000    1.000
3 2020-04-06  12:55 pm         Sapna  ...      0.0     0.383    0.617
4 2020-04-06   1:00 pm  Aman Kharwal  ...      0.0     0.000    1.000
Output:
Neutral 🙂

So, the data I used indicates that most of the messages between me and the other person are neutral. Which means it’s neither positive nor negative.

Also, Read – Python Projects with Source Code.

Summary

So this is how we can perform the task of sentiment analysis of WhatsApp chat. WhatsApp is a great source of data for the task of sentiment analysis and every data science task based on natural language processing. I hope you liked this article on the task of WhatsApp chat sentiment analysis using Python. Feel free to ask your valuable questions in the comments section below.

Default image
Aman Kharwal

Coder with the ♥️ of a Writer || Data Scientist | Solopreneur | Founder

Articles: 996

Leave a Reply