Data quality · Statistics Library

Mixed-type column

A mixed-type column contains values of more than one kind (numbers mixed with text, or numbers stored with inconsistent formatting), so software cannot treat the whole column consistently as either numeric or categorical.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

Spreadsheets are forgiving about what goes in a column, which is exactly the problem: a column meant to hold ages might have '34' in most rows but 'unknown', 'N/A', or '34 yrs' in a few others. To a human reading the sheet, this is obviously still 'age'; to software trying to compute a mean, the non-numeric entries either break the calculation or silently get dropped without saying so.

Common causes: a missing-value placeholder typed as text ('N/A', 'missing', '-') mixed in with real numbers; a units suffix accidentally left on some entries ('12kg' instead of '12'); or a column that legitimately switched meaning partway through (an ID column that used to be numeric and started including letters).

The fix depends on the cause: a genuine missing-value placeholder should become an actual missing value, not a number pretending to be one (do not code 'unknown' as 0 or -999 and average it in); a units suffix should be stripped consistently; a genuinely mixed-meaning column probably needs to be split or recoded.

A sentinel value is a stand-in code such as -999 or 'N/A' typed into a column to mean 'missing', which software will otherwise read as a real number or as text. Type inference is the software's guess, from the values it sees, about whether a column holds numbers, text or dates. A data type mismatch is when a column meant to hold numbers also holds text, so the software cannot treat it as numeric. Coercion to null means turning the values that cannot be read as numbers into missing values, which makes the column numeric but silently loses those entries.

Practitioner explanation

Type inference at import is the vulnerable moment: Polars/pandas infer a column's dtype from a sample or the whole column, and a single non-numeric token can force the entire column to object/string dtype, silently disabling numeric operations on values that otherwise look like ordinary numbers, or coerce non-numeric entries to null without necessarily surfacing that as a separate signal from genuine missingness.

The dangerous silent failure is a SENTINEL VALUE (-999, 0, 9999) used historically to represent 'missing' in a numeric column: unlike a text placeholder, a sentinel is syntactically a valid number and will be silently averaged into the mean, understating or overstating it depending on the sentinel's value and how common it is, with no error or warning at all.

KernelStats' importer reads the common missing-value tokens (empty, NA, N/A, NULL, #N/A, NaN, '.', '?') as genuine missing values; any other text token in an otherwise numeric column (for example '34 yrs' or 'unknown') makes the whole column import as text, which the Column metadata shows as a non-continuous column rather than silently coercing the stray entries to null. Numeric sentinels are caught separately: the column-health triage and the EDA report's data-quality section flag a round value (such as 999 or -999) that repeats unusually often and sits far outside the column's normal range. A sentinel that falls inside the normal range (a 0 in a column that legitimately contains zeros) cannot be detected from the numbers alone and still needs a codebook check. Two further flags on a text column come with a one-click fix on the Data tab: a category spelled more than one way ('Yes' in 76 rows and 'yes' in 24; 'Make spelling consistent' rewrites the minority spellings to the majority one) and a column that mixes several date formats ('Convert to dates' parses every value as a date); each flag names its rows, and both fixes go through the ordinary edit path, so Ctrl+Z undoes them.

When to use it

Consider it when

Check column types immediately after import, especially for any numeric-looking column, before running any calculation on it.

Use caution when

Do not assume a column that LOOKS numeric was correctly parsed as numeric; a single stray text entry, or a sentinel-coded missing value, can silently distort a calculation without raising an error.

Common misconceptions

Misconception

If a column's summary statistics compute without an error, its type was parsed correctly.

Correction

A numeric-looking sentinel value (like -999 for 'missing') parses as a perfectly valid number and will be silently included in a mean or standard deviation with no error at all; the absence of an error is not evidence the column is clean.

References

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §2.2 Data quality checks, NIST/SEMATECH (2012), §2.2.