Cleaning Dirty Application Log Data with Python and Pandas on Raspberry Pi
Cleaning Dirty Application Log Data with Python and Pandas on Raspberry Pi
Application logs can generate a lot of useful information.
A web application or service might record when requests arrive, whether they succeed or fail, how long they take, and which part of the application handled them. Eventually somebody needs that data. A manager may want to examine it in Excel and report on application performance. A developer may want to feed the records into another program.
Before either happens, we need to clean it.
For this example, we'll work entirely from the Linux terminal on a Raspberry Pi using Python and Pandas. This time, instead of starting with CSV, we'll start with application-log data stored as JSON.
Pandas can read JSON data directly into a DataFrame using
read_json().
Our basic pipeline is simple:
dirty JSON → Pandas → clean data → CSV + JSON
The Dirty Application Log
Suppose an application produced a file called
application_log.json:
[
{
"timestamp": "2026-11-03 09:00:00",
"service": "orders",
"status": "SUCCESS",
"response_ms": 184
},
{
"timestamp": "2026-11-03 09:05:00",
"service": " Orders ",
"status": "success",
"response_ms": 201
},
{
"timestamp": "2026-11-03 09:10:00",
"service": "orders",
"status": "ERROR",
"response_ms": 892
},
{
"timestamp": "bad_timestamp",
"service": "orders",
"status": "success",
"response_ms": 215
},
{
"timestamp": "2026-11-03 09:20:00",
"service": "PAYMENTS",
"status": "error",
"response_ms": "1042"
},
{
"timestamp": "2026-11-03 09:25:00",
"service": "payments",
"status": "SUCCESS",
"response_ms": 244
},
{
"timestamp": "2026-11-03 09:25:00",
"service": "payments",
"status": "SUCCESS",
"response_ms": 244
},
{
"timestamp": "2026-11-03 09:30:00",
"service": "orders",
"status": "success",
"response_ms": null
}
]
There are only eight log entries, but several things have gone wrong.
One timestamp isn't really a timestamp. Service names and status values use inconsistent capitalization. One service name contains extra spaces. One response time is stored as text instead of a number. Another response time is missing entirely. And one log entry appears twice.
The JSON itself is valid.
The data inside it is dirty.
Installing Pandas
From the Linux terminal on your Raspberry Pi, we'll create a virtual environment and install Pandas:
python3 -m venv log-env
source log-env/bin/activate
python3 -m pip install pandas
Now create a program:
nano clean_logs.py
Cleaning the Data
Here's our program:
import pandas as pd
# INPUT
df = pd.read_json("application_log.json")
# PROCESSING
# Convert timestamps into datetime values
df["timestamp"] = pd.to_datetime(
df["timestamp"],
errors="coerce"
)
# Remove extra spaces and normalize text
df["service"] = (
df["service"]
.str.strip()
.str.lower()
)
df["status"] = (
df["status"]
.str.strip()
.str.lower()
)
# Convert response times to numeric values
df["response_ms"] = pd.to_numeric(
df["response_ms"],
errors="coerce"
)
# Remove records with invalid or missing values
df = df.dropna(
subset=["timestamp", "service", "status", "response_ms"]
)
# Remove duplicate log entries
df = df.drop_duplicates()
# Put the log entries in time order
df = df.sort_values("timestamp")
# Reset row numbers
df = df.reset_index(drop=True)
# OUTPUT
df.to_csv(
"application_log_clean.csv",
index=False
)
df.to_json(
"application_log_clean.json",
orient="records",
date_format="iso",
indent=2
)
print(df)
print("\nCreated application_log_clean.csv")
print("Created application_log_clean.json")
Run it:
python3 clean_logs.py
The program first loads the JSON records into a Pandas DataFrame. Pandas supports record-oriented JSON, where the data is represented as a list of objects like the log entries we're using here.
The timestamps are converted into actual datetime values, while response times
are converted into numbers. Once again,
errors="coerce"
lets unusable values become missing values that we can remove deliberately
rather than allowing bad input to stop the pipeline.
The program also removes unwanted spaces, normalizes the service names and status values, removes incomplete records and eliminates the duplicate log entry.
Finally, the remaining events are placed in timestamp order.
One Dataset, Two Audiences
After cleaning, the useful application-log records look like this:
09:00 orders success 184
09:05 orders success 201
09:10 orders error 892
09:20 payments error 1042
09:25 payments success 244
But we're saving them twice.
application_log_clean.csv
gives a manager a familiar tabular artifact that can be brought into Excel for
filtering, summaries, and charts. Response time could be plotted over time,
for example, or success and error events could be summarized for an
operational report. Those results could then become part of the manager's
normal reporting work in Excel, PowerPoint, or Word.
application_log_clean.json
preserves the same cleaned information for software. Another Python program
could filter the records, developers could select particular services or
errors, or the data could become input to another API or processing system.
Pandas supports record-oriented JSON as one of its standard JSON
representations.
The important point isn't whether CSV or JSON is better.
They serve different consumers.
We started with valid JSON containing inconsistent and incomplete application-log data. Python and Pandas converted it into clean, predictable records and then produced two useful artifacts from the same dataset.
dirty application-log JSON → Python/Pandas → clean data → CSV for people + JSON for software
That's another small but complete data pipeline running on a Raspberry Pi.
And now the same cleaned application data can move in two directions: toward human reporting or toward additional software processing.
Tomorrow, it could even go somewhere else entirely.
