> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/rdt/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/rdt/transformers-glossary/categorical/labelencoder.md).

# LabelEncoder

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

The `LabelEncoder` transforms data that represents categorical values into integers `0`, `1`, `2`, etc. corresponding to each category.&#x20;

![](https://2225246359-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVGX92M819eIp0rMg5elc%2Fuploads%2FfY3R09jzrnVVgZJoaxX5%2Frdt_transformers-glossary-categorical-labelencoder_June%2002%202025.png?alt=media\&token=0bc72c0b-d8e7-468f-b6ce-58576280b0c2)

```python
from rdt.transformers.categorical import LabelEncoder
le = LabelEncoder()
```

## Parameters

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

<table data-header-hidden><thead><tr><th width="228.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>

**`missing_value_encoding`**: Control how to encode missing values present in the categorical column.

<table data-header-hidden><thead><tr><th width="232.5"></th><th></th></tr></thead><tbody><tr><td>(default) <code>'new_category'</code></td><td>Treat missing values as a new category type, just like any non-missing values. <em>Any type of missing value (None, NaN, etc.) is treated as a single category of "missing".</em></td></tr><tr><td><code>None</code></td><td>Do not encode missing values. In this case, missing values will be kept as-is during the forward and reverse transforms.</td></tr></tbody></table>

### Examples

```python
from transformers.categorical import LabelEncoder

# order the values alphabetically before assigning the labels
# and then add noise to the labels
le = LabelEncoder(order_by='alphabetical', add_noise=True)
```

## FAQs

<details>

<summary>What if I'd like to sort the values by a custom order?</summary>

If the values in the column represent ordered categories, the column should be marked as *ordinal*, not *categorical*. Please see the transformers available for the [ordinal sdtype](/rdt/transformers-glossary/ordinal.md).

</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 `AMEX` 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 `AMEX` 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
