WhatsApp Chat Formatter
When a chat is exported from Whatsapp, the output is a zip folder with a txt file.
This GitHub repo changes the exported chat of a group or direct message of WhatsApp from an unreadable txt file to a csv file with the following columns: date, time, name, and message. The formatted csv file can be used for data analysis purposes.
In main.py
there are two functions:
open_txt_file(filename)
and format_data(data)
.
The first function takes in a string which is the name of the txt file
with the exported chat and returns a list with lists that each have a
line of the conversation. The second function takes in what is returned
from open_txt_file(filename)
which is a list with lists
that each have a line of the conversation and returns a pandas DataFrame
with four columns: date, time, name, message where each row of the
DataFrame contains a single message.
To run the file, run the following in the terminal:
python3 main.py directory_path filename
where
directory_path
is the path to the directory where
filename
is located. The common filename
is
_chat.txt
. A new file will be created in the
directory_path
directory named
{filename}_formatted.csv
which contains the result of
formatting the txt file into a readable csv.
The source code can be found here.