# OrdinalEncoder

*noun*

say it: **“OR-dih-nul en-KOH-der”** **/ˈɔrdənəl ɛnˈkoʊdər/**

A scikit-learn tool that replaces each category in a column with a whole number, in a set order.

## What is **OrdinalEncoder**?

**OrdinalEncoder** is scikit-learn's tool that turns each category into one number: 0, 1, 2 and so on. It suits
categories with a real order, such as small, medium and large, given with `categories=`; for categories with no order,
one-hot encoding is safer.

```python
from sklearn.preprocessing import OrdinalEncoder
encoder = OrdinalEncoder(categories=[["small", "medium", "large"]])
print(encoder.fit_transform([["large"], ["small"], ["medium"]]).ravel())   # [2. 0. 1.]
```

## In a sentence

- “Using an **OrdinalEncoder** on species would have told the model rabbits come after dogs.”
- “The **OrdinalEncoder** turned small, medium and large into 0, 1 and 2.”

Level: Journeyman · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=3)

Updated: November 19, 2026

Source: https://www.ask-codey.com/glossary/ordinalencoder
