Column Quality and Distribution
Complete the full lesson to earn 25 points
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks and see fewer ads — read each lesson on a single page with Pro
Module: Prepare the Data
Section: Profile and Clean the Data
Lesson Title: Column Quality and Distribution
Data preparation is often described as the most time-consuming part of any data professional's job. While building a machine learning model or a high-impact dashboard is the exciting part of the process, these outputs are only as reliable as the data feeding them. Before you can transform, merge, or visualize your data, you must understand its health and its shape. This is where column quality and distribution analysis come into play. These two concepts serve as the diagnostic phase of data preparation, allowing you to identify errors, missing values, and statistical anomalies that could otherwise lead to incorrect business decisions.
Column quality refers to the cleanliness and accuracy of the data within a specific field. It answers questions like: Is this data complete? Are there errors in the formatting? Are there hidden "junk" values that look like data but aren't? On the other hand, column distribution focuses on the "shape" of the data. It looks at how values are spread across a range, how often certain values appear, and whether the data follows a predictable pattern. By mastering these two areas, you move from simply "having data" to "understanding your data," which is a prerequisite for any meaningful analysis.
In this lesson, we will explore the mechanics of profiling your data for quality and distribution. We will look at practical workflows using both visual tools like Power Query and programmatic approaches using Python and SQL. By the end of this guide, you will have a systematic approach to auditing any dataset you encounter, ensuring that your final reports and models are built on a foundation of integrity.
Understanding Column Quality: The Three Pillars
When we talk about column quality, we are essentially auditing the individual cells within a column to see if they are fit for purpose. Most modern data profiling tools categorize column quality into three distinct buckets: Valid, Error, and Empty. Understanding the nuances of these categories is the first step in cleaning your dataset.
1. Valid Data
Valid data represents the entries that match the expected data type and pass basic validation rules. However, just because data is "valid" in a technical sense doesn't mean it is correct. For example, if a "State" column contains the value "New York" in a field meant for "Country," a computer might see it as a valid string, but a human knows it is a data entry error. Therefore, checking for validity involves both checking the data type (is it a number?) and the domain (does the number make sense for this context?).
2. Data Errors
Errors occur when the data in a cell contradicts the defined data type or schema of the column. This often happens during data ingestion. For instance, if you are importing a CSV file where a "Price" column contains a string like "Call for Quote," a numeric conversion will fail, resulting in an error. Identifying these early is critical because errors can cause entire refresh processes to fail or lead to "NaN" (Not a Number) values that break your calculations.
3. Empty and Missing Values
Empty values, or Nulls, are the absence of data. They are perhaps the most common challenge in data preparation. A null value is not the same as a zero or a space; it represents an "unknown." When you encounter empty values, you have to decide whether they are missing at random or if there is a systemic reason for their absence. For example, if a "Social Security Number" column is 50% empty, is it because the users chose not to provide it, or because the data collection form had a bug?
Callout: The Difference Between Null, Blank, and Zero It is a common mistake to treat these three the same, but they have very different meanings in data analysis.
- Null: The value is truly unknown or does not exist. (e.g., A person who does not have a middle name).
- Blank/Empty String (""): The field was interacted with, but no text was entered.
- Zero (0): A specific numeric value. (e.g., A bank balance of $0 is very different from a null balance). Failing to distinguish between these can lead to incorrect averages and skewed results.
Analyzing Column Distribution
While column quality looks at individual rows, column distribution looks at the dataset as a whole. Distribution analysis helps you understand the "story" the data is telling. It involves looking at the frequency of values, the presence of outliers, and the overall spread of the data.
Value Counts and Frequency
The most basic form of distribution analysis is counting how many times each unique value appears in a column. This is particularly useful for categorical data, such as "Product Category" or "Region." If you see that 90% of your sales are coming from a single region, that is a significant insight. Conversely, if you see 500 unique values in a "Gender" column, you know you have a major data cleaning task ahead of you involving inconsistent spelling or formatting.
Statistics: Mean, Median, and Mode
For numeric data, distribution is defined by central tendency. The "Mean" (average) is sensitive to outliers, while the "Median" (the middle value) provides a better sense of what a "typical" record looks like if the data is skewed.
- Skewed Right: Most values are small, with a few very large outliers (e.g., household income).
- Skewed Left: Most values are large, with a few very small outliers (e.g., age at retirement).
- Normal Distribution: Values are centered around the mean, forming a bell curve (e.g., human heights).
Cardinality
Cardinality refers to the number of unique values in a column relative to the total number of rows.
- High Cardinality: A column with many unique values (e.g., UserID, TransactionID, Email Address).
- Low Cardinality: A column with few unique values (e.g., Boolean True/False, Gender, Order Status).
Understanding cardinality is vital for performance. High cardinality columns are harder to compress and can slow down your database queries or report visualizations. They are also usually poor candidates for slicing or filtering data in a dashboard.
Practical Implementation: Profiling in Python
While many tools offer "point-and-click" profiling, using a scripting language like Python (specifically the Pandas library) gives you much more control over the process. Below is a standard workflow for profiling column quality and distribution programmatically.
Step 1: Initial Data Audit
When you first load a dataset, you want a high-level overview of every column's health.
import pandas as pd
# Load the dataset
df = pd.read_csv('sales_data.csv')
# Get a summary of data types and non-null counts
print(df.info())
# Get basic descriptive statistics for numeric columns
print(df.describe())
The df.info() command is your first line of defense. It tells you the total number of rows and how many non-null values exist in each column. If you have 10,000 rows but your "Discount" column only has 2,000 non-null values, you immediately know that 80% of your data is missing for that field.
Step 2: Detailed Null Analysis
To get a better sense of quality, we can calculate the percentage of missing values for every column.
# Calculate the percentage of missing values per column
null_percentage = (df.isnull().sum() / len(df)) * 100
print(null_percentage.sort_values(ascending=False))
This snippet helps you prioritize your cleaning efforts. If a column is missing 95% of its data, it might be better to drop the column entirely rather than trying to fix it.
Step 3: Distribution and Outliers
To understand the distribution of numeric columns, we often look at the "spread" using the Interquartile Range (IQR).
# Check the distribution of a specific column
target_col = 'Order_Value'
# Calculate quantiles
q1 = df[target_col].quantile(0.25)
q3 = df[target_col].quantile(0.75)
iqr = q3 - q1
# Define outlier bounds
lower_bound = q1 - 1.5 * iqr
upper_bound = q3 + 1.5 * iqr
# Identify outliers
outliers = df[(df[target_col] < lower_bound) | (df[target_col] > upper_bound)]
print(f"Number of outliers in {target_col}: {len(outliers)}")
The IQR method is a standard industry practice for identifying outliers. Any value that falls significantly above or below the "middle" of the data is flagged for review. These aren't always errors—sometimes they are just extreme business cases—but they must be investigated.
Profiling with SQL
In many corporate environments, you will be profiling data directly in a data warehouse like Snowflake, BigQuery, or SQL Server. SQL is incredibly efficient for profiling large datasets because it processes the data where it lives.
Checking Column Quality (Nulls and Blanks)
To check the quality of a specific column, you can run a query that aggregates the different states of the data.
SELECT
COUNT(*) AS total_rows,
SUM(CASE WHEN customer_email IS NULL THEN 1 ELSE 0 END) AS null_count,
SUM(CASE WHEN customer_email = '' THEN 1 ELSE 0 END) AS empty_string_count,
COUNT(DISTINCT customer_email) AS unique_emails
FROM sales_table;
Analyzing Distribution (Frequency)
For categorical columns, a simple GROUP BY and ORDER BY is the most effective way to see the distribution.
SELECT
product_category,
COUNT(*) AS frequency,
ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER(), 2) AS percentage
FROM sales_table
GROUP BY product_category
ORDER BY frequency DESC;
This query not only tells you which categories are most common but also gives you the percentage of the total, which is much easier for a stakeholder to digest than raw numbers.
Step-by-Step Guide to Data Profiling
If you are starting a new project, follow this systematic process to ensure you don't miss any critical quality issues.
1. The Schema Check
Compare the actual data types to the expected data types. If a "Date" column is being read as a "String," you need to fix this immediately. Dates stored as strings cannot be used for time-series analysis or date-diff calculations.
2. The Completeness Audit
Look at the "Empty" percentage for every column.
- Action: If a column is missing >70% of its data, consider removing it.
- Action: If missing data is critical (e.g., CustomerID), investigate the source system.
3. The Uniqueness Test
Check for duplicate records. This is a common quality issue where the same transaction is recorded twice due to a system glitch.
- Pro Tip: Don't just look for identical rows. Look for "near-duplicates" where the names are spelled slightly differently but the address is the same.
4. The Range and Constraint Validation
Check if the values fall within a sensible range.
- Does a "Percentage" column have values over 100?
- Does an "Age" column have negative numbers or values over 150?
- Are there "Future Dates" in a "Birth Date" column?
5. The Shape Analysis
Review the distribution of your key metrics. Is the data skewed? Are there outliers that will pull your average in an unrealistic direction? If your data is heavily skewed, you may need to use the Median instead of the Mean in your final reports.
Note: Business Logic vs. Technical Logic A column can be technically perfect (no nulls, correct data type) but logically useless. For example, a "Ship_Date" that occurs before an "Order_Date" is technically a valid date, but it is a logical impossibility in a standard business flow. Always apply business context to your quality checks.
Comparison of Profiling Methods
| Feature | Visual Tools (Power Query) | Scripting (Python/Pandas) | Database (SQL) |
|---|---|---|---|
| Speed of Setup | Extremely Fast | Moderate | Fast (if data is already in DB) |
| Handling Large Data | Limited by local RAM | Moderate (Millions of rows) | Excellent (Billions of rows) |
| Customization | Limited to built-in features | Infinite | High |
| Reproducibility | Good (Applied Steps) | Excellent (Code Versioning) | Excellent (Saved Scripts) |
| Visual Feedback | Immediate histograms/bars | Requires extra libraries (Seaborn) | None (Text based) |
Best Practices for Column Quality and Distribution
To be successful in data preparation, you should adopt the following industry standards:
1. Profile Early and Often
Don't wait until you are building a chart to realize your data is messy. Profile the data the moment it enters your environment. The further "downstream" a data error travels, the more expensive and time-consuming it is to fix.
2. Automate the Quality Check
If you are working with a recurring data feed, write a script or a query that automatically flags quality issues. For example, if the null percentage in a critical column jumps from 2% to 20% in a single week, you should receive an automated alert.
3. Document Your Findings
Data profiling is a form of discovery. When you find that the "Region" column uses three different spellings for "North America," document it. This documentation will be invaluable for anyone else who uses the dataset later.
4. Handle Outliers with Care
Never delete outliers without a reason. Sometimes outliers are the most important part of the data (e.g., identifying fraudulent credit card transactions). If you decide to remove or cap outliers, make sure to document why and how it affects the final analysis.
5. Check for "Hidden" Nulls
Be wary of datasets where missing values have been filled with "placeholder" data. Common placeholders include:
9999or0for numeric fields."N/A","Unknown", or"None"for string fields.1900-01-01for date fields. These values won't show up in a "Null" count, but they are just as problematic for your analysis.
Common Pitfalls to Avoid
Even experienced data analysts fall into these traps. Being aware of them will save you hours of debugging.
Over-Cleaning the Data
It is tempting to want a "perfect" dataset where every null is filled and every outlier is removed. However, over-cleaning can strip away the reality of the business. If 30% of your customers don't provide a phone number, that is a real business fact. Filling those numbers with "000-000-0000" doesn't help; it just creates fake data that might be misleading.
Ignoring Data Type Precision
In many systems, there is a difference between a "Float" and a "Decimal." If you are working with financial data, using a floating-point number can introduce tiny rounding errors that add up over millions of rows. Always check the precision of your numeric columns during the profiling phase.
Trusting the "Top 1000 Rows"
Many profiling tools (like Power BI or Excel) only profile the first 1,000 rows by default to save on performance. This can be dangerous. The first 1,000 rows might look perfect, while row 1,001 contains a massive error that breaks your model. Always ensure you are profiling the entire dataset if the size allows, or at least a statistically significant random sample.
Misinterpreting Cardinality
A common mistake is thinking that high cardinality is always bad. In a "Primary Key" column, high cardinality is mandatory—every value must be unique. The problem arises when a column that should be categorical (like "Department") has high cardinality because of inconsistent data entry (e.g., "HR," "Human Resources," "H.R.").
Callout: The Cardinality-Granularity Connection Cardinality is closely tied to "Granularity." Granularity refers to the level of detail in your data. A "Transaction ID" column has the highest granularity (one row per transaction). When you profile distribution, you are essentially deciding at what level of granularity you want to perform your analysis. If you aggregate by a high-cardinality column, you get a very detailed but potentially messy view.
Frequently Asked Questions
Q: What is the difference between "Distinct" and "Unique" values in a distribution report?
A: "Distinct" values include all the different values present in a column, regardless of how many times they appear. "Unique" values are those that appear exactly once. For example, in a list [A, B, B, C], there are 3 distinct values (A, B, C) and 2 unique values (A, C).
Q: When should I use the Mean vs. the Median? A: Use the Mean when the data is normally distributed (symmetrical). Use the Median when the data is skewed or contains significant outliers, as the Median is much more resistant to being pulled by extreme values.
Q: How do I handle columns that are 100% unique? A: If a column is 100% unique, it is likely an ID or a key. These are great for joining tables but usually useless for visual analysis or machine learning features unless you can extract information from them (like extracting the domain from an email address).
Q: Why does my distribution look like a "Uniform" block? A: A uniform distribution means every value appears with roughly the same frequency. This is common in randomized IDs or specific types of sensor data. If you see this in a "Sales Amount" column, it might be a sign that the data is synthetic or corrupted.
Practical Example: A Retail Case Study
Imagine you are analyzing a dataset for a clothing retailer. You have a column called Discount_Percentage.
- Column Quality Check: You notice that 40% of the rows are empty. After talking to the business, you learn that an empty value means "No Discount" (0%). You decide to fill these nulls with 0.
- Column Distribution Check: You look at a histogram of the values. Most values are between 0 and 50. However, you see a small spike at 100.
- Investigation: You filter for the 100% discounts. You find these are all "Employee Appreciation" samples.
- Decision: Depending on your goal, you might keep these (to see total inventory movement) or remove them (to see actual revenue-generating sales).
Without profiling the quality (identifying the nulls) and the distribution (identifying the 100% spike), you might have reported an average discount that was much higher than what the typical customer actually receives.
Summary of Key Takeaways
- Data Profiling is Non-Negotiable: Never start analyzing data until you have audited its quality and distribution. It is the only way to ensure the "Garbage In, Garbage Out" rule doesn't ruin your work.
- Quality is More Than Nulls: While missing values are important, you must also look for data type errors and logical inconsistencies (like negative prices).
- Distribution Tells the Story: Use histograms and frequency counts to understand the shape of your data. This helps you choose the right statistical measures (Mean vs. Median) and identify outliers.
- Cardinality Impacts Performance: Be mindful of high-cardinality columns. They can slow down your reports and are often candidates for cleaning or grouping.
- Context is King: Always interpret profiling results through the lens of business logic. An outlier might be an error, or it might be the most profitable customer you have.
- Use the Right Tool for the Job: Use visual tools like Power Query for quick ad-hoc checks, but rely on SQL or Python for large-scale, reproducible, and automated profiling.
- Document Every Step: The decisions you make during the profiling phase (e.g., "I filled nulls with 0 because...") must be documented to maintain data lineage and trust.
By incorporating these practices into your workflow, you transform from a data consumer into a data expert. You will spend less time fixing broken reports and more time providing insights that are backed by clean, well-understood data.
Continue the course
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles your daily points limit so you progress twice as fast, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× daily points limit
- ✓ Distraction-free lessons