Python Central HubSign in

Data Analytics with Python / Phase 4: Data Preprocessing and Cleaning

Understanding Data Quality

Learn the main dimensions of data quality (accuracy, completeness, consistency) and how to diagnose problems.

Why data quality matters

Bad data quality leads to:

  • Wrong decisions
  • Broken dashboards
  • Unreliable ML models
  • Loss of trust

Data preprocessing is the discipline of making data usable and trustworthy.

Key dimensions of data quality

1) Completeness

Are required values missing?

  • df.isna().sum()
  • Missing percentage per column

2) Accuracy

Do values match reality?

  • Negative ages
  • Impossible dates (future DOB)
  • Wrong units (โ‚น vs paise)

3) Consistency

Do values follow the same format across rows?

  • "delhi", "Delhi", " DELHI "
  • Mixed currencies

4) Validity

Do values fit the allowed set/range?

  • status should be one of: closed
  • rating must be 1โ€“5

5) Uniqueness

Are there duplicates?

  • Duplicate rows
  • Duplicate IDs

Practical quality checks (Pandas)

Python
# shape
print(df.shape)
 
# schema
print(df.dtypes)
 
# missing
print(df.isna().sum().sort_values(ascending=False).head(20))
 
# duplicates
print("Duplicate rows:", df.duplicated().sum())
 
# basic stats
print(df.describe(include="all"))

Typical preprocessing outputs

  • Cleaned columns (trimmed text, fixed casing)
  • Correct dtypes (numeric/date)
  • Handled missing values
  • Outlier strategy selected (remove/cap/keep)
  • Encoded categories for modeling

Rule of thumb

Always document:

  • What you changed
  • Why you changed it
  • What assumptions you made

Visualize it

Think of data quality as a pipeline of checks. Raw data only becomes "trustworthy" once it has passed through each dimension below.

diagram Data quality workflow mermaid
Raw data passes through a series of checks before it can be trusted for analysis or modeling.

๐Ÿงช Try It Yourself

Exercise 1 โ€“ Count missing values

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 โ€“ Find duplicate rows

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 โ€“ Check validity of a range

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Check your understanding

quizCheck yourself
  1. Which dimension of data quality is violated by city values delhi, Delhi and DELHI?

    Show answer

    A โ€” Consistency โ€” Consistency asks whether values follow the same format across rows.

  2. A rating column must be 1 to 5 but contains 9. Which dimension fails?

    Show answer

    A โ€” Validity โ€” Validity checks that values fit the allowed set or range, like status being open or closed.

  3. Which call counts duplicate rows?

    Show answer

    A โ€” df.duplicated().sum() โ€” duplicated() flags repeated rows and sum() counts them. That checks uniqueness.

  4. Negative ages or a future date of birth are examples of which problem?

    Show answer

    A โ€” Accuracy โ€” Accuracy asks whether values match reality, including wrong units like rupees versus paise.

Next

Once you know where the quality problems are, the next step is usually fixing dtypes โ€” head to Outlier Detection (IQR Method) to start finding the extreme values hiding in your numbers.

Was this page helpful?

Let us know how we did