Before You Clean, Before You Model: Data Profiling in Python (Part 1)
From the publisher’s feed, collected in the ZeroLabs newsroom.
Why do experienced data scientists spend more time understanding data than fixing itMost data science stories begin with confidence. “Let’s clean the data.”, “Let’s engineer features.”, “Let’s train a model.”But in real-world projects, confidence at the start is usually misplaced.Production datasets are rarely self-explanatory. They arrive without context, with undocumented columns, inconsistent logic, and silent assumptions baked into them. And when things go wrong later — strange model behavior, misleading insights, broken pipelines — the root cause almost always traces back to one moment:We started changing the data before we truly understood it.This article intentionally slows things down.Instead of rushing into cleaning or modeling, we’ll focus on data profiling :- the disciplined process of exploring a dataset to understand its structure, quality, and implicit rules before making any modifications.This is not about fancy tools or one-line summaries. This is about thinking like a data professional.This is Part 1 of a three-part, hands-on series:Part 1 (this article) :- Learning how to read an unfamiliar dataset the right wayPart 2 :- Digging deeper into distributions, relationships, and patternsPart 3 :- Cleaning data with intention, backed by evidence — not guessworkTogether, these parts mirror how data is handled in serious analytics and machine learning projects — not how it’s often presented in tutorials.Why Data Profiling Deserves Its Own SpaceData profiling answers questions that cleaning and modeling cannot:What does one row actually represent?Which columns are trustworthy — and which should be questioned?Are missing values random, systematic, or intentional?Are categories truly categorical, or just messy text?Do numeric values respect real-world constraints?Skipping profiling is like debugging without reading the error message.You might eventually fix something — but you won’t know why.Why We Are Using This DatasetFor this series, we deliberately chose the Flights dataset available through Seaborn.Why this dataset?Public and Reproducible :- Anyone can load it instantly. No downloads, no credentials, no environment issues.Runnable Locally :- You can execute every line of code in VS Code or Jupyter and see the same results.Simple on the Surface, Subtle Underneath :- At first glance, it looks clean and obvious.On closer inspection, it reveals:hidden ordering issuessemantic data type problemstime-series assumptionsaggregation pitfalls4. Representative of Real WorkMany real datasets are not messy in obvious ways — they’re messy in meaning. This dataset is perfect for demonstrating that distinction.In other words, it’s ideal for learning how to think, not just what to type.What We Will (and Will Not) Do in Part 1In This Article, We Will:Understand the structure and scale of the datasetIdentify data types and their implicationsInspect missing values without fixing themAnalyze column semantics and hidden assumptionsBuild a mental model of what the data representsWe Will NOT:Impute missing valuesTransform or normalize featuresEngineer new columnsTrain any modelsUse automated profiling librariesThose steps come later — after understanding.The Objective of Part 1By the end of this article, we should be able to:Open an unfamiliar dataset with confidenceAsk the right questions before writing transformationsSpot potential data issues earlyAvoid common analytical trapsApproach data cleaning with clarity instead of trial-and-errorIf you’ve ever thought: “I wish I had noticed this earlier…” Then this part of the series is exactly for you.A Professional Mindset to Keep in MindData profiling is not about finding problems. It’s about learning the personality of your data.Some datasets are honest.Some are inconsistent.Some are quietly misleading.Our job as a data analyst or data scientist is not to force the data to behave, but to understand why it behaves the way it does.In the next section, we’ll load the dataset and begin profiling it step by step, exactly how this would be done at the start of a real project.Let’s begin where professionals actually begin: by listening to the data before trying to fix it.Step 1: Loading the Dataset — No Assumptions YetBefore we analyze anything, the first discipline we build is neutral observation.In real projects, datasets often arrive with:little or no documentationcolumn names that look obvious but aren’thidden assumptions made by upstream systemsSo the rule here is simple: Load the data and observe — don’t interpret yet.Importing the Required LibrariesWe’ll keep things intentionally minimal. No automated profiling tools, no shortcuts — just pandas, NumPy, and Seaborn to load the dataset.import pandas as pdimport numpy as npimport seaborn as snsLoading the Dataset :-Loading data is not a technical step — it’s a psychological one. The moment data appears on the screen, our brains start forming stories. As a data scientist, your first responsibility is to resist interpretation. At this stage, we are not allowed to conclude anything. we are only allowed to observe. This discipline prevents confirmation bias later in the analysis.We’ll load the Flights dataset directly from Seaborn.df = sns.load_dataset("flights")Why this matters:No external files requiredConsistent schema across environmentsIdeal for local execution in VS Code or JupyterNow let’s look at the data, not analyze it.df.head()At first glance, the dataset appears extremely simple:three columnsclean numeric valuesno obvious noiseAnd this is exactly where many analysts become overconfident.Step 2: Understand the Shape Before the MeaningHow big is this dataset?df.shapeThis tells us:how many rows we’re dealing withhow many features existwhether the dataset is small enough for manual inspectionThis dataset is compact — which makes it perfect for learning profiling techniques without computational overhead.Shape determines strategy. A dataset with 500 rows invites different thinking than one with 500 million. Shape tells you whether manual inspection is realistic, whether sampling will be needed later, and whether certain algorithms will even be feasible. Many performance and modeling decisions are silently influenced by this one line of output.Before touching values, we ask one basic but powerful question:Step 3: Inspect Structure and Data TypesNow we ask pandas to tell us what it thinks the data looks like.df.info() is where professionals start trusting or distrusting a dataset. Data types are assumptions pandas makes on your behalf, and those assumptions often leak into models. When something is typed as object, it’s a warning sign, not a neutral fact. Most production bugs I’ve seen started with an ignored dtype mismatch.df.info()This single command is one of the most underrated tools in data analysis.From it, we immediately learn:column namesinferred data typesnon-null countsmemory footprintExpert InsightNotice something important here:month is stored as objectyear is numericpassengers is numericThis already raises a quiet but critical question: Is month really just text, or does it carry an implicit order? We don’t answer it yet — we note it.Profiling is about collecting questions before collecting answers.Step 4: Read Column Names Like a ContractColumn names are the API of your dataset. If we misunderstand them, every downstream decision is at risk. At this point, we should be able to explain what a single row represents in plain English. If we can’t, no amount of cleaning or modeling will save the analysis.Let’s explicitly list the columns.df.columns.tolist()Now pause and ask:What does one row represent?Is this transactional data?Is it aggregated?Is time encoded in one column or multiple?For this dataset:each row represents monthly passenger totalsyear + month together define timepassengers is the measured quantityThis mental model is essential.Without it, downstream aggregation and modeling decisions can quietly go wrong.Step 5: Missing Values — Confirm, Don’t AssumeMissing data is not a flaw — it’s a signal. Even when there are no missing values, confirming that fact matters. Assumptions are dangerous in data science because they propagate silently. Explicit confirmation is how professionals reduce uncertainty and build confidence in later steps.Never assume data is clean just because it looks clean.df.isna().sum()Looks good — no missing values.But professionals often go one step further:df.isna().mean() * 100Why percentages?they scale better to large datasetsthey make thresholds easier to reason aboutHere, we confirm:missing data is not a concern for this datasetThat confirmation itself is valuable — it removes uncertainty.Step 6: Initial Numeric Sanity CheckNumbers must obey reality. Before worrying about distributions or trends, ask whether values are even possible. Sanity checks catch more serious errors than most complex models. If the data violates domain logic, everything built on top of it becomes meaningless.Before plotting or modeling, we check basic numeric boundaries.df.describe()This gives us:central tendencyspreadextreme valuesNow isolate the metric column:df["passengers"].min(), df["passengers"].max()Ask yourself:Are negative values possible?Are extremely high values realistic?Do these numbers align with domain expectations?At this stage, we’re not judging — we’re validating plausibility.What We’ve Learned So Far (Without Cleaning Anything)Even without a single transformation, we now know:the dataset structurethe semantic meaning of each columndata types that may cause issues laterthat missing values are not a concernthat time is encoded implicitly, not explicitlyThis is already a huge advantage over jumping straight into cleaning.Why This Step Matters in Real ProjectsMost data issues are not technical — they’re conceptual.They happen because:time was treated as textcategories were assumed to be cleannumeric values were trusted blindlyProfiling protects you from these mistakes before they cost you hours.Step 7: Categorical Profiling — When Text Columns Hide StructureCategorical columns look simple, but they often carry the most hidden complexity. Spelling variations, casing issues, and inconsistent labels can quietly fragment your data. Profiling categories early protects you from feature explosions and misleading aggregations later.At first glance, categorical columns often look harmless. They don’t throw errors. They don’t break pipelines. And because they’re not numeric, they’re easy to ignore early.That’s a mistake.In real-world datasets, categorical columns are where many silent issues live:inconsistent labelshidden hierarchiesordering problemsexploding cardinalityIn our dataset, there is exactly one such column — month.Let’s inspect it properly.How Many Unique Categories Are We Dealing With?df["month"].nunique()This tells us how many distinct values exist. Twelve looks reasonable — but that alone isn’t enough.Now inspect the actual values.df["month"].value_counts()This answers important questions:Are all expected months present?Are spellings consistent?Are there unexpected variants?At this point, everything looks clean — but we’re not done yet.Step 8: The Hidden Ordering TrapThis step reveals one of the most common analytical mistakes: confusing labels with meaning. Months are not just strings — they encode sequence. When tools don’t understand that meaning, you must. Identifying this gap early prevents subtle but serious time-based errors.Here’s a subtle but critical issue that appears in countless datasets.Let’s try sorting by month.df.sort_values("month").head()The result looks… wrong.Why?Because pandas sorts strings alphabetically, not logically. And months are not just labels, they are ordered categories.This tells us something crucial: month carries temporal meaning that pandas does not understand by default.This is not a cleaning step yet. This is profiling insight, a note that will guide future transformations.Step 9: Profiling Time Dimensions Without PlottingTime-series mistakes are expensive. Duplicate time keys can silently double-count data and distort trends. Verifying uniqueness is a defensive habit , one that protects dashboards, forecasts, and business decisions from quiet corruption.Time-based data demands extra care. Before plotting trends or building models, ask:Is time encoded in one column or many?Are we safe to aggregate?Do combinations of columns uniquely identify time?Let’s verify uniqueness.df[["year", "month"]].duplicated().sum()This confirms:each year–month pair appears only onceaggregation logic will be safe laterWithout this check, time-series analysis can quietly double-count data.Step 10: Detecting Implicit Relationships EarlyThis is not analysis — it’s validation. Grouping checks confirm whether data behaves logically under basic operations. If simple aggregations already look suspicious, deeper analysis will only amplify confusion. Professionals validate structure before chasing insight.Now let’s do a light structural check — not analysis, just validation.df.groupby("year")["passengers"].sum().head()This answers:does aggregation behave as expected?are there any obvious discontinuities?do numbers scale reasonably over time?We’re not interpreting trends yet. We’re simply checking that the dataset behaves logically when grouped.Step 11: Duplicate Awareness (Not Removal)Duplicates are contextual. Sometimes they are errors, sometimes they are history. Profiling identifies their existence; domain knowledge determines their fate. Automatically dropping duplicates without understanding them is one of the fastest ways to lose trust in your data.Even when duplicates are unlikely, professionals still check.df.duplicated().sum()Zero duplicates confirms:each row is uniqueno accidental replication existsThis check is quick, cheap, and extremely valuable in real datasets.Step 12: Building the Mental Model (The Most Important Step)This is the most important step — and the least discussed. By now, we should be able to explain the dataset to someone else without looking at the code. This mental model is what guides correct cleaning, feature engineering, and modeling. Without it, you’re guessing.By now, we should be able to confidently say:One row = passenger count for one monthTime is represented by year + monthmonth is categorical with hidden orderNo missing data existsNo duplicates existThis mental model will guide:how we cleanhow we encode featureshow we visualizehow we modelSkipping this step is how analytical errors are born.Why Experienced Analysts Stop Here (For Now)Notice what we still haven’t done:no imputationno transformationsno feature engineeringno chartsAnd yet, we already understand the dataset far better than someone who rushed ahead.That’s intentional.Closing Part 1: What This Step Really Gave UsBy the end of Part 1, we have not cleaned a single value, transformed a column, or trained a model. That is intentional.What we gained instead is something far more valuable than early progress. We built understanding. We learned what one row actually represents. We identified which columns carry implicit meaning and which ones only appear simple on the surface. We confirmed what the data is and, just as importantly, what it is not.This is the work that prevents expensive mistakes later.Most data science failures do not happen because the algorithm was wrong. They happen because the data was misunderstood at the beginning. Once incorrect assumptions enter the pipeline, every downstream step amplifies them. Models look confident. Visualizations look convincing. Results look correct. And yet the conclusions are flawed.Part 1 exists to eliminate that risk.Why Profiling First Changes EverythingWhen data profiling is skipped, issues do not reveal themselves immediately. They surface later as confusing model behavior, unstable metrics, or insights that fail to hold when the data changes slightly. Debugging those problems often leads back to a simple realization. The data was never properly understood.Profiling slows you down at the right moment so you can move faster later. It replaces guesswork with evidence. It gives structure to your thinking before you touch the data. This is not academic caution. This is how professionals protect their work in real projects.Understanding data before cleaning it is not optional. It is foundational.What to Expect in Part 2In Part 2, we will move beyond structure and begin exploring behavior.This is where the data starts telling stories, and where intuition often fails if it is not guided by careful analysis. We will examine distributions, variability, and patterns over time. We will look at how simple visualizations can mislead when context is ignored. We will discuss correlation traps and why apparent relationships often disappear under scrutiny.Part 2 is about asking better questions of the data, not forcing answers out of it.Everything we do there will build directly on the profiling foundation established in Part 1.Final ThoughtsGood data science is not about speed. It is about sequence.First, understand the data.Then, change the data with intention.Only after that should modeling begin.If your analysis has ever surprised you in uncomfortable ways, the problem likely did not start with the model. It started before the data was truly understood. This series is designed to fix that, step by step.If this article helped you think more clearly about how to approach unfamiliar datasets, consider following me here on Medium. Your support helps this work reach readers who are trying to build better habits around data analysis and data science.If you have faced similar data challenges in your own projects, I would love to hear about them. Sharing real experiences in the comments often leads to deeper insights than any single article can provide.And if you found this useful, leaving a clap helps others discover it as well. Thoughtful discussions and shared learning are what strengthen this community. Thanks !!!Follow for Part 2, where we move from structure to insight and begin uncovering how data behaves, not just how it looks.Thank you for reading.Before You Clean, Before You Model: Data Profiling in Python (Part 1) was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.