---
title: "One-hot and label encode categories in Strata | Oplema"
description: "One-hot, label or ordinal encode text categories as numbers with Encode in Strata. For ordinal encoding, you set the order of the categories yourself."
url: "https://oplema.com/docs/strata/prep/encode"
updated: "2026-11-04"
---

# Encode

Turn text categories into number codes or indicator columns for models or other numeric work. Choose Label for category codes, One-hot for separate category flags or Ordinal for categories with a meaningful order.

**Learn this in context:** [More data tools: when you'd use each one](https://oplema.com/learn/table-to-dashboard/more-data-tools) (Build and publish a dashboard)

## Label

Label turns a product category into codes for a model to predict, keeping the original text beside them. The One-hot and Ordinal examples below use their own data.

Result
| category | category\_encoded |
| --- | --- |
| Tea | 1 |
| Coffee | 0 |
| Tea | 1 |
| Coffee | 0 |
|  |  |

1. Select the Encode block and select its output port. Label gives Coffee code 0 and Tea code 1 in `category_encoded`. The codes identify categories but don't rank them.

## One-hot

One-hot keeps channel and adds channel\_Web, channel\_Store and channel\_Phone. A Web row has 1 in channel\_Web and 0 in the other two columns. The indicator columns follow first appearance in the input.

Result
| channel | channel\_Web | channel\_Store | channel\_Phone |
| --- | --- | --- | --- |
| Web | 1 | 0 | 0 |
| Store | 0 | 1 | 0 |
| Phone | 0 | 0 | 1 |
| Web | 1 | 0 | 0 |
|  |  |  |  |

1. Select the Encode block and select its output port. Each row flags its channel, with no numeric ranking between channels.

## Ordinal

Ordinal keeps priority and adds priority\_ordinal. Low becomes 1, Medium becomes 2 and High becomes 3. Unlike the Label codes, these numbers stand for an order.

Result
| priority | priority\_ordinal |
| --- | --- |
| Low | 1 |
| High | 3 |
| Medium | 2 |
| High | 3 |
|  |  |

1. Select the Encode block and select its output port. Ordinal uses Levels set to `High,Medium,Low`, assigning priorities 3, 2 and 1.
2. Select the red arrow Override defaults beside Levels, then change Levels to `Low,Medium,High`. The ranks reverse: Low gets 3 and High gets 1.

## When to use

Use Encode when a model or calculation needs numbers but your column holds categories. Choose Label, One-hot or Ordinal depending on whether the categories have an order.

## Read the output

**Label** keeps `category` and adds `category_encoded`. Coffee becomes `0` and Tea becomes `1`, following text sort order. These are the two target classes to predict.

**One-hot** keeps `channel` and adds `channel_Web`, `channel_Store` and `channel_Phone`. A Web row has `1` in channel\_Web and `0` in the other two columns. The indicator columns follow first appearance in the input.

**Ordinal** keeps `priority` and adds `priority_ordinal`. Low becomes `1`, Medium becomes `2` and High becomes `3`. Unlike the Label codes, these numbers stand for an order.

Each flow keeps all five rows. Its missing value stays NULL in every encoded result, including all three One-hot indicators. Clearing **Separate Columns** removes the original text column and keeps the encoded results.

## Choose the order for Ordinal

The first category in **Levels** gets the highest number, with ranks ending at 1. Enter the categories highest first: `High,Medium,Low` assigns 3, 2 and 1 in that order.

Leaving Levels blank uses first appearance. In this example, Low appears first, so the automatic order would give it the highest rank. Levels you set must include every input category, or the block reports an error.

To rescale existing numeric values, use [Scale](https://oplema.com/docs/strata/prep/scale).

To parse text that represents actual numbers, use [Number](https://oplema.com/docs/strata/parse/number).

## Inputs and outputs

### Inputs

1 port

**In Required**

Accepts: Tables, Geospatial data.

Accepts one connection on this port.

### Outputs

1 port

**Out**

## Configure the block

Choose a method for each text column and whether to keep its original values. A chosen column missing from the input is skipped with a warning, and its settings are kept.

**Method**

None leaves the column unchanged. Label assigns codes starting at 0 in text sort order. One-hot creates a 0/1 column per category. Ordinal assigns ranks using your chosen order. Default: None.

**Levels**

Shown for Ordinal. Enter categories separated by commas, highest rank first. Include every category present in the input, with no empty or repeated entries. Leave blank to use order of first appearance.

**Label all text / One-hot all text / Ordinal all text**

Apply the chosen method to every text column. Other column types remain unchanged. These buttons also clear any custom Levels.

**Clear all**

Set every column's method to None and clear custom Levels.

**Separate Columns**

Keep source columns and append results. Label uses \_encoded, Ordinal uses \_ordinal and One-hot adds the category to each column name. When cleared, results replace their source columns. Default: false.

## Encode FAQs

**When should I use Label encoding?**

Use Label mainly for a classification target. Two classes become 0 and 1, and each extra class gets the next code. For unordered input features, One-hot is usually better, because a model may read Label codes as an order or distance that doesn't exist.

**When should I use One-hot encoding?**

Use One-hot when categories have no natural order and you need separate numeric indicators, such as Web, Store and Phone sales channels. Each category gets its own column, so no category is represented as larger than another.

**When should I use Ordinal encoding?**

Use Ordinal when categories have a meaningful order, such as Low, Medium and High priority. Set Levels highest first to make the ranks reflect that order. The ranks show position only. They don't measure the distance between levels.

**What happens to missing values?**

NULL stays NULL. One-hot produces NULL in every indicator column for that row, rather than zeros. Every input row stays.

**Are Label codes fixed across different inputs?**

No. They're calculated from the categories in the current input. Adding or removing categories can change the codes.

**How many categories are supported?**

One-hot and Ordinal support at most 64 categories per column and report an error if none are present. Label has no 64-category limit.

### Prepare your data. Build it in Strata.

Strata opens in your browser, with no account.

[Open Strata](https://oplema.com/editor?path=%2F%3Fopen%3Dstrata) [About Strata](https://oplema.com/strata)
