# Encode Values

Encodes values in a column through a variety of methods:

Label Encoding: Encode target labels with value between 0 and n\_classes-1. See scikit-learn's [LabelEncoder](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html#sklearn.preprocessing.LabelEncoder) for full documentation.

Target Encoding: Encode a categorical column with the average value of a target column for the corresponding value of the categorical column. See scikit-learn's [TargetEncoder](https://contrib.scikit-learn.org/category_encoders/targetencoder.html) for full documentation.

One Hot Encoding: Encode a categorical column as a 0 or 1 for each possible category, each of which will be it's own row.

## Parameters

| Name   | Type   | Description                                                                    | Is Optional |
| ------ | ------ | ------------------------------------------------------------------------------ | ----------- |
| method | string | Encoding method which will be used ('label', 'target', or 'oh')                |             |
| column | column | Column name to label encode                                                    |             |
| target | column | Required if method = 'target'. Numeric target column to use to create averages | True        |

## Example

```python
ds = rasgo.get.dataset(id)

ds2 = ds.label_encode(column='WEATHER_DESCRIPTION', method='oh')
ds2.preview()

ds3 = ds.target_encode(column='WEATHER_DESCRIPTION', target='DAILY_HIGH_TEMP')
ds3.preview()
```

## Source Code

{% embed url="<https://github.com/rasgointelligence/RasgoTransforms/blob/main/rasgotransforms/rasgotransforms/transforms/encode_values/snowflake/encode_values.sql>" %}


---

# 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.rasgoml.com/rasgo-docs/rasgo-0.1/all-transforms/encode_values.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.
