Chat
parse_chat_history
parse_chat_history(chat_history)
Parse WhatsApp chat history from a text file and convert it to a structured DataFrame.
This function takes a chat history file (typically exported from WhatsApp) and parses it into a structured pandas DataFrame with columns for DateTime, Sender, and Message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chat_history
|
InformationContainer
|
An InformationContainer object containing the chat history data as a byte stream that can be downloaded and decoded. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A DataFrame with the following columns: - DateTime (datetime): Parsed timestamp of each message - Sender (str): Name of the message sender - Message (str): Content of the message |
Raises:
Type | Description |
---|---|
UnicodeDecodeError
|
If the chat history data cannot be decoded as UTF-8. |
ValueError
|
If the datetime format in the chat history doesn't match the expected format "%d/%m/%Y, %H:%M". |
Note
The function expects chat history in WhatsApp's standard export format: "DD/MM/YYYY, HH:MM - Sender: Message"
Malformed lines are silently skipped to handle edge cases in chat exports.
Examples:
>>> from workbench.bindings.base_classes import InformationContainer
>>> chat_data = InformationContainer(...) # Your chat history data
>>> df = parse_chat_history(chat_data)
>>> print(df.head())
DateTime Sender Message
0 2023-01-01 10:30:00 John Doe Hello there!
1 2023-01-01 10:31:15 Jane Smith Hi John!