# OrderedLabelEncoder

**Compatibility:** `categorical` data (ordinal)

The `OrderedLabelEncoder` transforms data that represents ordered categorical values into integers `0`, `1`, `2`, etc. corresponding to each category in the correct order.&#x20;

![](/files/cJvXj9s8WRUigSJmaeFt)

```python
from rdt.transformers.categorical import OrderedLabelEncoder
ole = OrderedLabelEncoder(order=['strongly_disagree', 'disagree', 'neutral',
                                 'agree', 'strongly_agree'])
```

## Parameters

(required) **`order`**: Apply a specific order to the values before assigning the labels

<table data-header-hidden><thead><tr><th width="220.5"></th><th></th></tr></thead><tbody><tr><td><code>[list &#x3C;value>]</code></td><td>An ordered list of the categories that appear in the real data. The first category in the list will be assigned a label of <code>0</code>, the second will be assigned <code>1</code>, etc. All possible categories must be defined in this list.</td></tr></tbody></table>

**`add_noise`**: Add noise to the label values

<table data-header-hidden><thead><tr><th width="215.5"></th><th></th></tr></thead><tbody><tr><td>(default) <code>False</code></td><td>Do not not add noise. Each time a category appears, it will always be transformed to the same label value.</td></tr><tr><td><code>True</code></td><td>Add noise. A category will be transformed to the same label with some noise added. For example instead of the label <code>1</code>, values might be noised to <code>1.001</code>, <code>1.456</code>, <code>1.999</code>, etc.</td></tr></tbody></table>

### Examples

```python
from transformers.categorical import OrderedLabelEncoder

# order the categories before assigning label values
# and then add noise to the labels
ole = OrderedLabelEncoder(order=['strongly_disagree', 'disagree', 'neutral',
                                 'agree', 'strongly_agree'],
                          add_noise=True)
```

## FAQs

<details>

<summary>What if my categorical column does not have an order?</summary>

This transformer is only defined for ordinal categorical data. If there is no order, your data is *nominal*. Use the [LabelEncoder](/rdt/transformers-glossary/categorical/labelencoder.md) instead.

</details>

<details>

<summary>What happens to missing values?</summary>

If there are missing values in your data, they should be defined as part of your order. Use the `None` keyword to denote a missing value.

In the example below, the missing value is added as the last item.

```python
ole = OrderedLabelEncoder(order=['strongly_disagree', 'disagree',
                                 'neutral', 'agree', 'strongly_agree', None])
```

Add the missing value to whatever ordering position makes sense for your data. If you are unsure, consider adding it to the beginning or the end of the list.

</details>

<details>

<summary>When should I add noise?</summary>

If you do not add noise, the transformer will convert each category to a distinct label. For example `'disagree'` is always converted to the label `1`. If you add noise, the transformer will generate some random variation so the numbers are not distinct. For example `'disagree'` may sometimes be `1.001` and other times be `1.999`-- but always in the interval`[1, 2)`.&#x20;

Adding noise creates a continuous distribution. Your decision to add noise is dependent on your use of the data. If you are using the data for machine learning (ML), consider whether the techniques you plan to use work better on continuous distributions.

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sdv.dev/rdt/transformers-glossary/categorical/orderedlabelencoder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
