Find Data Quality Issues with EDA Before Modeling
EDA before modeling can surface signals of missing values, duplicates, time inconsistencies, and leakage. This guide shows how to check each against its source and prediction cutoff, preserve evaluation boundaries, and work through a hypothetical churn example with pandas.
Exploratory data analysis (EDA) before modeling helps reveal signals such as missing values, duplicate keys, mixed units, and timing errors that can distort model inputs or labels. Summaries and plots expose patterns that are easy to miss by inspecting a few rows, but a conspicuous value is not automatically an error. First define what one row represents and when a prediction is made; then compare unusual signals with source records and business rules, and record confirmed problems separately from unresolved assumptions.
This guide focuses on tabular prediction data. “Good data” is not defined by the model type alone. Required quality depends on the decision, its timing, and whether each row represents a customer, order, or customer-month. The GOV.UK Data Quality Framework describes quality as fitness for purpose and recommends setting checks such as completeness or valid ranges to match that purpose. [1]
Fix the prediction question before plotting
Write down four things before exploring:
Unit of observation: What does one row represent—for example, one customer’s status at month-end or one support event?
Prediction time: When must the real prediction be made? Only fields available at that time can be candidate inputs.
Outcome and observation window: What counts as a success, churn, or failure, and how many days after prediction will it be observed?
Scope and source: What period and population are included? Which system version, units, currency, and extraction rule apply?
Without these definitions, you might delete a repeated customer ID that represents separate events, use a cancellation reason created after the prediction as an input, or label a case as “no event” even though its observation window has not ended. EDA is an approach to uncover structure and check assumptions. NIST describes combining plots and summaries to examine distributions and relationships, model assumptions, and potential outliers. [2]
Which signals should you check?
The first column below lists signals to investigate, not confirmed errors. Compare each one with the row definition, data dictionary, source records, and subject-matter guidance.
| EDA signal | How to check it | What to decide next |
|---|---|---|
| Missing values cluster in a field | Compare missing rates overall and by month, source, and group | Determine whether this is a collection gap or a structural absence where the value does not apply. If it coincides with a system change, investigate whether the recording rule changed. |
| Duplicate keys or a sudden row-count increase | Check duplicates in a composite key that matches the row definition; compare row counts before and after joins | Distinguish repeat events from a many-to-many join that multiplied rows. Do not delete anything before confirming the key definition. |
| A sudden peak, long tail, or extreme value in a distribution | Combine histograms, box plots, time plots, quantiles, minimums, and maximums | Compare against source records to distinguish a digit error, unit change, cap code, genuine high value, or new operating pattern. An outlier flag identifies a review candidate; it is not an automatic deletion rule. [3] |
| Date and value combinations conflict | Compare start/end dates, event and record timestamps, and feature creation time with the prediction cutoff | Check for parsing or time-zone errors, out-of-scope records, or information created after prediction time. |
| Category or feature relationships change abruptly | Compare category counts, group distributions, feature-pair scatter plots, and summaries over time | A renamed code, excluded region/device, unit change, or policy change may explain it. Do not call a group erroneous just because its distribution differs. |
| Outcome rates or observation lengths differ over time | Tabulate outcome counts by period and check the label observation window | If the newest data has not completed the outcome window, do not treat an unobserved event as a negative case. |
A missingness rate per column may not be enough. If older systems rarely recorded usage while a newer system does, imputing both periods with one overall average will not erase the system transition. Check whether missingness clusters by time or group, then look for evidence about why values are absent. pandas isna() marks missing values recognized by the library, but it does not automatically treat empty strings or a custom sentinel such as -999 as missing. Check the source’s sentinel rules as well. [4]
A point far from the rest of a distribution could be an error or a meaningful case. NIST distinguishes outlier labeling (flagging for review), accommodation (using methods that limit its influence), and formal identification (testing). The conclusion can also depend on whether a distributional assumption is appropriate. Inspect the original row and collection process before deciding to correct or exclude it. If you cannot confirm an error, consider a robust method or record how sensitive the result is to that point instead of deleting it. [3]
Fictional example: four warnings in churn data
The following is a fictional scenario to explain the workflow. Suppose a team predicts for each customer at the end of each month whether a subscription will end in the next 30 days. One row represents customer ID + snapshot month; values recorded after the month-end cutoff are unavailable at prediction time.
The `customer ID + snapshot month` key repeats. Do not assume the entire rows are duplicates. Check the source rows: perhaps multiple service accounts belong to one customer, or a join duplicated the same monthly snapshot. The correct treatment depends on which is true.
Missing usage is concentrated after a new system was introduced. Before replacing it with zero, check whether the new system records values late, stores them in another table, or leaves the field empty when there was no usage. These cases mean different things.
A usage chart shows a tall stack of very high values. Compare the data dictionary and source logs to see whether `9999` is a cap code, units changed from minutes to seconds, or the values reflect genuinely heavy use.
`cancel_reason` almost perfectly matches the churn outcome. If the field is created only after cancellation, it is unavailable at prediction time and is a leakage feature. Reframe the input set around usage and support records that exist at the actual prediction moment.
Also, if extraction ends before 30 days have passed after the snapshot, the latest customer-months do not have a complete outcome window. Labeling them “did not churn within 30 days” simply because no event has appeared can inflate the negative class. Confirm the outcome only for rows with a complete observation window, or handle incomplete labels separately. This follows from the fictional task’s label definition; state the observation period and outcome definition for the real task.
Flag missingness and key duplicates with pandas
The following illustrative example assumes df is already a pandas DataFrame and snapshot_month identifies each customer’s snapshot month. The code was not run or tested during this work.
# Overall missing rate and usage missing rate by snapshot month
missing_rate = df.isna().mean().sort_values(ascending=False)
missing_by_month = df.groupby("snapshot_month")["usage_30d"].apply(
lambda values: values.isna().mean()
)
# Show every duplicate candidate if one row is expected per customer-month
key_columns = ["customer_id", "snapshot_month"]
duplicate_candidates = df.loc[
df.duplicated(subset=key_columns, keep=False)
]duplicated(..., keep=False) marks every row in a repeated key combination. The marked rows are only candidates. You can decide whether they indicate a quality issue only after confirming the customer-month row definition and checking the source data. isna() is a starting point for summarizing missingness patterns. Check empty strings, whitespace, infinity, and custom markers such as -999 under separate rules. [4][5]
Keep a verifiable record after exploration
For each issue, keep a short record of:
the signal and check used (for example, 12 repeated `customer_id + snapshot_month` rows)
scope and reproduction details (data version, period, extraction date, group, and code)
source-check result and status (confirmed error, valid exception, or unresolved)
likely effect on the model’s intended use and priority
decision and reason (correct, retain as a separate category, exclude, or investigate)
recheck after changes and any remaining limitation
Completeness, uniqueness, consistency, validity, and timeliness are useful quality lenses, but the same threshold cannot be applied to every dataset. Set checks to match the analytical purpose and business definitions. [1]
Protect the holdout set when evaluating predictive performance. If deployment follows time or records from the same customer depend on one another, choose a time-based or group-based split that resembles deployment. Fit data-learned preprocessing—such as imputation, scaling, or feature selection—using the training split only, then apply those learned rules to validation and test data. If you change preprocessing or features after inspecting test results, the evaluation data has entered development and the score can look too optimistic. The scikit-learn guide recommends splitting before preprocessing, fitting only on training data, and using a pipeline to preserve this boundary. [6]
EDA is complete when the row meaning and prediction cutoff are clear, each important signal has either an investigation result or a recorded reason it remains unresolved, and the training/evaluation boundary is preserved. That record helps you revisit whether a model problem came from the data definition, a collection change, or a real change in behavior.
References
GOV.UK, The Government Data Quality Framework
[1] fitness for purpose, quality dimensions, and checks tied to the use case. NIST/SEMATECH e-Handbook, What is EDA?
[2] EDA goals and graphical exploration. NIST/SEMATECH e-Handbook, Detection of Outliers
[3] outlier labeling, accommodation, testing, and limits of automatic deletion. pandas API, DataFrame.isna
[4] how missing values are marked, including empty strings not being treated as NA. pandas API, DataFrame.duplicated
[5] detecting duplicates over chosen columns. scikit-learn User Guide, Common pitfalls and recommended practices
[6] unavailable-at-prediction information, leakage, and fitting preprocessing after splitting.