🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Data Cleaning: Missing Values, Outliers and Types

Module 2: NumPy and Pandas🟢 Free Lesson

Advertisement

Data Cleaning: Missing Values, Outliers and Types

Master data cleaning — handling missing values, outliers, duplicates, and type conversions.

Data Cleaning PipelineMissingNaN, None, NAMCAR / MAR / MNARImpute or DropHigh ImpactOutliersIQR MethodZ-Score MethodDBSCAN / IsolationDomain ExpertiseDuplicatesExact DuplicatesFuzzy Matchingkeep='first'/last'Quick WinsTypesastype()pd.to_datetime()pd.to_numeric()Category TypeTextWhitespaceCase NormalizationRegex CleaningEncoding IssuesImpact on Downstream AnalysisMissing → Biased EstimatesOutliers → Distorted ModelsDuplicates → Inflated CountsClean data → Reliable analysis → Trustworthy models

Missing Data Mechanisms

Missing Data MechanismsMCARMissingness independent of all dataP(Missing | X, Y) = P(Missing)Deletion is unbiased (but loses power)Most common in clinical trialsMARMissingness depends on observed dataP(Missing | X, Y) = P(Missing | X)Multiple imputation works wellMost real-world missing dataMNARMissingness depends on missing valuesP(Missing | X, Y) ≈  f(X)Requires sensitivity analysisPattern-mixture models needed

Detecting Missing Values

Handling Missing Values

Deletion

Imputation

Advanced Imputation

Outlier Detection

Outlier Detection MethodsIQR MethodQ1 = 25th percentileQ3 = 75th percentileIQR = Q3 - Q1Lower: Q1 - 1.5*IQRUpper: Q3 + 1.5*IQRRobust to non-normal dataZ-Score Methodz = (x - Μ) / σ|z| > 2 → Moderate outlier|z| > 3 → Extreme outlierAssumes normal distributionSensitive to Μ, σ from outliersMAD MethodMAD = median(|x - median(x)|)z_modified = 0.6745*(x-med)/MAD|z| > 3.5 → OutlierRobust: uses median, not mean0.6745 = z for 75th percentile

IQR Method

Z-Score Method

Handling Outliers

Duplicates

Type Conversions

Text Cleaning

Complete Cleaning Pipeline

Key Takeaways

Practice Exercise

  1. Given a dataset with 20% MCAR missing values, compare the bias introduced by mean imputation, median imputation, KNN imputation, and listwise deletion. Compute the difference between imputed and true means.
  2. Write a function that detects outliers using IQR, MAD, and Z-score methods simultaneously, then creates a consensus flag (outlier if 2+ methods agree).
  3. Build a text cleaning pipeline that handles: extra whitespace, mixed case, special characters, encoding issues (mojibake), and inconsistent formatting (e.g., "NY", "New York", "NYC" → "New York").
  4. Given a DataFrame with mixed types and messy data, implement the complete cleaning pipeline and verify data quality with a summary report.
  5. Analyze the missing data mechanism in a real-world dataset using Little's MCAR test or pattern analysis with missingno library.

Need Expert Data Science Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement