सामग्री पर जाएँ

लेसन 11 · Data Quality

Data Profiling and Quality Rules

Profile a dataset to find patterns and surprises, then turn findings into clear, testable quality rules with severity, owners and a rule catalog you can run.

You cannot write good rules for data you have not looked at. Data profiling means examining a dataset to learn what it really contains: how many values are missing, which values repeat, what patterns they follow and what looks odd. It often reveals that the documentation and the data disagree.

What to profile

For each column, collect:

  • row count and number of missing values;
  • number of distinct values;
  • minimum and maximum (for numbers and dates);
  • the most frequent values;
  • text length range and patterns;
  • outliers and impossible values.

Across columns, look for dependencies (does every city fit its country?) and duplicate keys. Across tables, look for orphan references, such as orders pointing to a customer that does not exist.

A profiler in a few lines

This profiler turns each text value into a shape, replacing letters with A and digits with 9. Mixed shapes in one column are a strong hint that several formats are in use.

Python Profile columns and find value patterns

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output suggests questions: Is N/A a placeholder? Should basic and Basic be the same plan? Is age 212 an error, and does age 0 mean unknown? Profiling raises questions; a steward or business expert answers them. Do not "fix" values based on guesses.

From finding to rule

A good rule is specific enough that two people would implement it the same way.

Weak statement Testable rule
Phone numbers should be good Phone is empty or matches the agreed international format
Ages must make sense Age is empty or from 0 to 120; 0 means newborn, not unknown
Plans must be consistent Plan is one of: basic, pro (lowercase)

Each rule needs a rule record:

TEXT
Rule ID    : CUS-004
Dataset    : customer
Dimension  : validity
Logic      : plan in ('basic', 'pro')
Severity   : high (billing depends on it)
Target     : 99.9% pass
Owner      : Customer steward
On failure : quarantine row, create ticket
Last review: 2026-11

Severity

Not every failure deserves the same response. A simple scale:

  • Blocker: stop the load; wrong data would cause serious harm.
  • High: load, but flag rows and open an issue quickly.
  • Medium: track and fix in planned work.
  • Low: report for information.

Agree on the actions for each level ahead of time, so a failure at night does not require a debate.

A rule catalog you can run

Keeping rules as data, not buried in code, makes them easy to review. This SQL example stores rules with a query that returns the failing IDs.

SQL Run a small rule catalog in SQL

Press Run (or Ctrl + Enter) to see the result here.

GROUP_CONCAT is available in SQLite and MySQL; other databases offer similar functions such as STRING_AGG. The order of IDs inside it is not guaranteed unless your database lets you state one.

Where to run rules

You can check data at several points:

  1. At entry: forms and APIs reject or warn immediately. This is the cheapest place to stop errors.
  2. In pipelines: validate before publishing to others.
  3. In storage: constraints in databases.
  4. On a schedule: monitor what is already stored.

Prefer prevention at the source. A rule in a report that cleans data every night hides the real problem forever. For pipeline testing ideas, see data quality checks.

Handle sensitive data carefully

Profiling can expose real values in screenshots, logs and tickets. Show counts and shapes where possible, mask personal values in examples and run profiling with only the access you need.

Do not generate hundreds of rules automatically and enable them all. A flood of alerts trains people to ignore every alert, including the important ones.

A worked example: from surprise to decision

Profiling a fictional supplier table shows that 12% of records share the same tax identifier, 000000000. The tempting response is to blank them all. A better response:

  1. Ask the steward what the value means.
  2. Learn that staff type it when a supplier has no number yet, because the form requires one.
  3. Decide with the owner that the field may be empty for some supplier types, with a reason code.
  4. Change the form, then write rules: the identifier is present for domestic suppliers, and placeholder patterns are rejected.
  5. Plan a review of existing records.

The profile found a symptom, but the root of it was a form design that rewarded fake data.

Testing your rules

A rule can be wrong too. Before enabling it, run it on known examples: some that should pass, some that should fail and edge cases such as empty strings, extra spaces, lowercase letters and boundary values like 0 and 120. Show a sample of failing rows to someone who knows the data and ask whether they are really errors. If many are legitimate, such as names that your pattern rejects because of apostrophes or non-Latin letters, fix the rule. Rules that assume every name or address looks like those in one country are a common source of unfair and incorrect results.

Profile again after changes

A profile is a snapshot. Run it again when a source system changes, a new data supplier arrives, data is migrated or users report surprises. Keep earlier results, without sensitive values, so you can compare them. A new pattern in a stable column often reveals a change that nobody announced.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. What is the main purpose of data profiling?

    Profiling reveals patterns, gaps and surprises that guide rules.
  2. 2. Which is the most testable quality rule?

    It has a clear pass or fail result.
  3. 3. Where is it usually cheapest to stop bad data?

    Preventing errors at entry avoids downstream copies and rework.

Summary

  • Profile columns and relationships before writing rules.
  • Ask experts about surprises instead of guessing fixes.
  • Write rules with ID, dimension, logic, severity, owner and action.
  • Store rules where they can be reviewed and run.
  • Prevent at the source and avoid alert floods.

Next: Quality Monitoring and Root Cause Analysis

आपकी प्रगति इसी ब्राउज़र में सेव होती है। खाते की ज़रूरत नहीं है।