How to Handle Missing Values in a Dataset
To handle missing values, first measure how much is missing per column and whether the gaps follow a pattern, then decide per column to drop rows, drop the column, or impute with the mean, median, mode or a constant. The right choice depends on why the data is missing (MCAR, MAR or MNAR) and whether missingness itself predicts your target. TensorTurn shows missing percentages, a missing-value presence grid and missingness-to-target dependence on upload, and fills or drops gaps with steps you approve.
Why missing values matter
Most algorithms cannot accept empty cells at all, and the ones that can still learn from whatever pattern the gaps leave behind. Silently dropping incomplete rows can shrink a dataset by half and bias it toward customers who fill in every form field. Filling everything with zero invents data. Missing values are a modelling decision, not a nuisance to delete, and the best approach is different for a column that is 2 percent empty than for one that is 70 percent empty.
The three types of missing data
| Type | Meaning | Example | Implication |
|---|---|---|---|
| MCAR (missing completely at random) | Missingness is unrelated to any value, observed or not | A sensor randomly drops readings due to a network glitch | Dropping rows loses data but does not bias results |
| MAR (missing at random) | Missingness depends on other observed columns | Younger respondents skip the income question more often | Imputation that uses other columns works well; simple dropping can bias |
| MNAR (missing not at random) | Missingness depends on the missing value itself | People with very high income decline to report it | No simple fix; the missingness is information, so model it explicitly |
You can rarely prove which type you have, but you can collect evidence. If missingness in one column lines up with values in another, it is not MCAR. If missingness lines up with the outcome you are predicting, treat it as a signal.
Measure before you fix
Start with the missing percentage per column, then look at the pattern. TensorTurn's column profile shows missing % for every column, and the missing-value presence grid shows where gaps fall across rows, so you can see whether several columns go missing together (often one system or form section failing) or whether gaps are scattered.
Drop or impute: choosing a method
| Method | When to use it | Risk |
|---|---|---|
| Drop rows with missing values | Few rows affected (a few percent) and data looks MCAR | Shrinks data and biases it if missingness is not random |
| Drop the column | Most of the column is empty and it carries little signal | Loses a feature that might matter, especially if MNAR |
| Fill with mean | Numeric, roughly symmetric distribution, light missingness | Shrinks variance; pulled by outliers |
| Fill with median | Numeric and skewed (income, prices, durations) | Shrinks variance, but robust to outliers |
| Fill with mode | Categorical columns with a dominant category | Over-represents the most common value |
| Fill with a constant ("Unknown", 0, -1) | Categoricals where missing is its own meaningful group, or where empty genuinely means zero | A numeric sentinel like -1 can mislead linear models |
| Add a missing indicator plus impute | Missingness may be informative (MAR or MNAR) | Adds columns; still needs an imputed value |
| Model-based (KNN, iterative imputation) | Strong relationships between columns, MAR | Slower, more complex, must be fitted on training data only |
TensorTurn's AI data editor covers the most common methods directly: drop rows with missing values, delete a column, and fill missing with mean, median, mode or a constant. Model-based imputation such as KNN or iterative imputation belongs in the training pipeline, and because TensorTurn's training notebooks are generated Python you can ask for it in plain English.
When missingness predicts the target
Sometimes the fact that a value is missing is one of the strongest signals in the data. A blank "last login date" may mean the customer never activated, which strongly predicts churn. A missing lab result may mean the doctor did not think the test was needed. TensorTurn's target analysis measures missingness-to-target dependence: for a chosen target column it checks whether rows with gaps in a feature have a different outcome rate or average than rows without. If they do, keep that information with a missing indicator rather than erasing it with a fill.
Avoid leakage when imputing
Imputation values are statistics, and statistics computed on the full dataset include the test rows. For quick analysis that is harmless, but for a strict model evaluation the mean, median or mode should be learned from the training split only and then applied to the test split, ideally inside a preprocessing pipeline. TensorTurn's preprocessing playbook for a target column suggests a per-column plan and can be exported as Python code, so imputation can run inside the training pipeline instead of before the split.
Step by step on TensorTurn
- Upload the dataset and sort the column profile by missing %.
- Open the presence grid to see whether columns go missing together.
- Pick a target column and check missingness-to-target dependence.
- Delete columns that are mostly empty and uninformative.
- In the AI data editor, give per-column instructions, for example "fill missing income with the median, fill missing plan with Unknown, drop rows where signup_date is missing".
- Review and approve the planned steps, then confirm the missing % dropped as expected.
- For model training, follow or export the preprocessing playbook so imputation is fitted on training data.
Common mistakes
- Filling every gap with zero, which invents values and distorts averages and correlations.
- Using the mean on heavily skewed columns where the median is far more representative.
- Dropping all incomplete rows without checking how many are lost and who they are.
- Imputing the target column itself. Rows without a label should be excluded from training, not filled.
- Erasing informative missingness instead of keeping an indicator.
Frequently asked questions
Should I drop or impute missing values?
Drop when very few rows are affected and the gaps look random, or when a column is mostly empty and uninformative. Impute when dropping would lose a meaningful share of data, using the median for skewed numbers, the mean for symmetric ones and the mode or "Unknown" for categories.
What is the difference between MCAR, MAR and MNAR?
MCAR means missingness is unrelated to any data, MAR means it depends on other observed columns, and MNAR means it depends on the missing value itself. MCAR is safest to drop, MAR suits imputation from other columns, and MNAR needs the missingness treated as information.
Is mean or median imputation better?
Median is usually safer because it is not pulled by outliers, which matters for skewed data like income or prices. Mean is fine for roughly symmetric numeric columns with light missingness.
How much missing data is too much?
There is no universal cut-off, but columns that are mostly empty rarely help unless the missingness itself predicts the target. Check missingness-to-target dependence before deleting a heavily missing column.
Can TensorTurn fill missing values automatically?
Yes. In the AI data editor you can ask it to fill missing values with the mean, median, mode or a constant, or to drop rows with missing values, and you approve each step before it is applied.