Timedora

Reliable Data Cleaning

A practical lesson on diagnosing data-quality issues, handling them transparently, and building reliable cleanup workflows.

Define and diagnose data quality

Define validity before cleaning

For each field, specify what counts as valid before changing the data. Record its expected type, allowed values or range, whether it is required, and any relationships it must satisfy with other fields. For example, quantity should be a nonnegative number, an order date should be a valid date, and a shipment date should not precede its order date. These rules give you a basis for distinguishing a genuine problem from an unfamiliar but acceptable value.

Next, profile the imported data while it is still unchanged. Check counts of missing values, distinct values, ranges, duplicate keys, and failed conversions. These checks help show where the data departs from expectations and how common each issue is. In pandas, isna() detects recognized missing values; blank strings and placeholders such as “N/A” may need separate checks.

Diagnose what kind of issue you have

Several problems can look similar at first, but call for different decisions:

  • Missing: no value was supplied. A blank date might mean “unknown,” “not applicable,” or an import failure; those meanings are not interchangeable.

  • Malformed: a value cannot be interpreted as the required type. “Twelve” in a numeric field or “2025-19-40” in a date field are examples.

  • Inconsistent: values are valid individually but differ in representation or meaning. “NY,” “New York,” and “new york” may refer to the same place, while prices in different currencies are not directly comparable.

  • Rule-breaking: a value has the right type but violates a business rule, such as a negative quantity or a delivery date earlier than the order date.

Inspect examples alongside the original source before deciding what to do. A failed conversion could be a typo, a legitimate special code, or evidence that the source format changed. Therefore, an unusual value is a reason to investigate—not proof that the value is wrong.

Handle issues without losing evidence

Match the response to the evidence

Once an issue is diagnosed, choose a handling policy that fits what is known about it:

  • Correct a value only when reliable evidence supports the intended value, such as a documented code mapping.

  • Preserve as missing when the value is unknown or cannot safely be inferred. If you impute an estimate, justify and document that choice.

  • Flag or quarantine malformed and rule-breaking records that need investigation. Retain the original value and a reason for the flag.

  • Remove rows only when exclusion is defensible, and record how many were removed and why.

  • Use a default only when a valid business rule defines it. Replacing every error with zero, for instance, can turn “unknown” into a false measurement.

A conversion that turns invalid input into a missing value can be useful for locating failures, but by itself it does not tell you whether the original input was blank or unparseable. Keeping the raw value or a separate error flag preserves that distinction for review.

Worked example: parse quantities without losing evidence

The pandas quantity example illustrates the logic as a sequence of checks. It treats blank strings and “n/a” as missing because they are documented blank markers in this example; another dataset needs its own documented marker rules.

  1. Keep the imported value. Copy the original quantity into a raw field before converting anything. This provides evidence for diagnosing later flags.

  2. Prepare and identify documented blanks. Convert the raw values to a string representation and trim surrounding whitespace. Mark values as blank if they were already missing, are now empty, or match “n/a” without regard to letter case. Trimming matters here because it lets a value with accidental surrounding spaces match the documented marker.

  3. Attempt numeric conversion without treating failure as a valid number. Exclude the identified blanks from conversion, then convert the remaining values with failures coerced to missing in the parsed result. At this stage, both intentional blanks and failed conversions may appear missing in the parsed field, so that field alone is not enough to distinguish them.

  4. Flag failed parses separately. Mark a row as an invalid quantity when it was not identified as a blank but its parsed result is missing. This distinguishes a nonblank value that could not be parsed from an intentional blank. Keep the raw field so the actual input can be inspected.

  5. Check the business rule after parsing. Flag parsed quantities below zero separately. These values passed numeric conversion, but violate the rule that quantity must be nonnegative. A type-valid value can therefore still require review.

  6. Select flagged rows for review. Bring together rows with either a failed parse or a negative quantity, showing the raw value, parsed value, and the two separate flags. Review or report them according to the intended use; do not silently discard them.

The key distinction is between what conversion produced and why a row needs attention. A missing parsed result can reflect an allowed blank marker or a failed conversion; the raw input and invalid flag preserve the reason. Likewise, the negative-quantity flag identifies a rule violation rather than a conversion failure.

Standardize and make checks repeatable

Standardize without erasing meaning

Apply normalization only under documented rules. Trimming accidental whitespace, standardizing letter case where case is not meaningful, and mapping known aliases to a canonical value can make equivalent labels consistent. But do not change codes or identifiers when case or leading zeros matter. Before comparing or combining quantities and amounts, confirm that their units and currencies are compatible.

Then recheck uniqueness and relationships between fields. Standardizing two labels to the same value can expose or create duplicate keys; a change in one field can also affect a cross-field rule. Validation should therefore follow , not stop before it.

Make checks repeatable and visible

Put validation and cleanup into named transformation steps that can be refreshed, rather than relying on one-time manual edits. On each refresh, report useful counts such as missing values, conversion failures, rule violations, and excluded rows. Comparing these counts over time can make unexpected changes visible.

Test the steps on representative edge cases, including blanks, malformed values, and new or unfamiliar categories. If a critical assumption no longer holds, make the refresh fail visibly or route the exceptions for review. A pipeline that silently produces a plausible-looking but incorrect dataset hides the very issue the checks are meant to reveal.

  • : The criteria that specify acceptable types, values or ranges, required fields, and relationships between fields.

  • : A systematic examination of imported data, including missing values, distinct values, ranges, duplicate keys, and conversion failures.

  • : The practice of retaining enough information to inspect and explain data-handling decisions.

  • : Replacing a missing value with a mean, default, or other estimate.