Data types: numbers, categories, text and dates
Each column type needs different handling; spotting the right type is the first modeling decision.
Lesson 6 of 6610 minBeginner
You will learn to
- Tell numeric, categorical, ordinal, text and date columns apart
- Spot numbers that are really categories
- Choose a first preprocessing step per type
Intuition
A spreadsheet cell holds a value, but the same digits can mean very different things. The number 28001 might be a price, a number of visitors or a zip code. In the first two cases it is a quantity and averaging makes sense. As a zip code it is just a name for a place. A model that treats the zip code as a quantity will look for a pattern in "bigger zip codes", which is nonsense.
That is why the first modeling decision is not the algorithm. It is deciding what kind of thing each column is, because the type decides which operations make sense and how the column must be prepared.
Five types cover most columns:
- Numeric. A quantity where distances and averages mean something: age, price, temperature, number of visits.
- Categorical (nominal). A label from a set with no order: country, colour, product type.
- Ordinal. A label with a natural order but without equal steps: small, medium, large; or a satisfaction score from "poor" to "excellent".
- Text. Free-form language: reviews, comments, descriptions.
- Date and time. A point in time, which carries structure inside it: year, month, weekday, hour.
Two further kinds of column deserve a mention. Booleans (yes or no) behave like a category with two values. Identifiers (customer number, order id) are unique labels that name a row but say nothing about it.
Picture it
The traps come from columns that look like one type and are another:
| Looks like | Really is | Why it matters |
|---|---|---|
| Zip code, phone area code | Category | Arithmetic on labels is meaningless |
| Customer id, order number | Identifier | Unique per row; a model can only memorise it |
| A rating of 1 to 5 | Ordinal (often treated as numeric) | The step from 1 to 2 may not equal the step from 4 to 5 |
| A year such as 2026 | Numeric or date, depending on use | Check whether trend over time is the point |
| 0 and 1 flags | Boolean (a category) | The mean is a share, not a typical value |
The math
Preparation turns each type into numbers a model can use. Three small formulas cover the common cases.
One-hot encoding of a category with distinct values creates columns of 0 and 1. A row with value gets a 1 in column and 0 elsewhere. There is no order between the columns, which is exactly right for nominal data.
Ordinal encoding maps ordered values to ranks, for example small, medium, large to 1, 2, 3. It assumes that the steps are about equal, so check that this is reasonable.
Cyclic encoding is for values that wrap around, such as the month in a year of 12 months. Replace with two columns:
Each month becomes a point on a circle, and neighbouring months are neighbouring points, including December and January. The same trick works for weekday (period 7) and hour (period 24).
Worked example
Take an illustrative customer table with eight columns and decide the type and the first step for each.
| Column | Example values | Type | First step |
|---|---|---|---|
| customer_id | C-10492 | Identifier | Exclude from the model |
| age | 34, 61 | Numeric | Check the range; scale if the algorithm needs it |
| zip_code | 28001, 08002 | Category | One-hot encode, or group into regions |
| plan | basic, standard, premium | Ordinal | Map to 1, 2, 3 |
| country | ES, FR, PT, IT | Category | One-hot encode (4 columns) |
| signup_date | 2026-03-14 | Date | Extract month and weekday; compute days since signup |
| comment | "slow support" | Text | Drop at first, or count words |
| churned | yes, no | Boolean | This is the target to predict |
Check the cyclic encoding. For month 12 (December) the pair is . For month 1 (January) it is . The straight-line distance between these two points is , which is the same as between any two neighbouring months. December and June, on opposite sides of the circle, are at distance 2. As plain numbers, December and January would differ by 11 and be treated as far apart.
Count the columns. After these steps the model sees: age (1), plan (1), zip_code (one column per distinct code), country (4), month as sine and cosine (2), weekday (as needed), days since signup (1). A high-cardinality column like zip_code is the one to watch, because it can add thousands of columns. Grouping rare values or using a coarser region is often better.
How mlflow does it
The data profile reads every column and assigns one of five Type chips: numeric, categorical, datetime, boolean or text. To see it, open Data, choose a dataset and select Explore, then open the Columns tab. You can search columns, filter by type and expand a column to see statistics, top values or sample values.
Things to know:
- The profile guesses the type from the values. It does not know that a column of digits is a zip code, so check the chips yourself. There is no separate ordinal type; an ordered category appears as categorical, and you decide how to encode it.
- Columns that are unique on every row are flagged ID-like, and columns with one value for all rows are flagged Constant. Neither helps a model.
- In Pipelines, the Choose... list for a column groups transformations as Fill missing values, Scale numbers and Turn categories into numbers, which line up with the first steps in the table above.
Common mistakes
- Treating codes as numbers. Zip codes, product codes and similar labels look numeric. A model will look for order that is not there. Convert them to categories.
- Leaving an identifier in. A unique id lets a flexible model memorise rows. It looks excellent in training and fails on new customers. Exclude identifiers.
- One-hot encoding a column with thousands of values. It creates a huge, sparse table and slows everything. Group rare values or use a higher-level label.
- Encoding ordered values as unordered. One-hot encoding "small, medium, large" throws away the order. Use ranks when the order carries information.
- Using a raw date. A timestamp as one big number is almost useless. Extract the parts that matter (month, weekday, days since an event).
- Trusting the detected type blindly. Automatic detection is a first guess. A quick look at a few values per column catches the wrong ones.
Try it in mlflow
Open a dataset profile
- Open Data, find a dataset and choose Explore.
- Open the Columns tab and read the Type chip of every column.
- Find one column whose detected type is not what you would expect, such as a zip code stored as a number, and decide how it should be treated.