Label Encoder

Map categorical values in a CSV column to integer codes.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Name a categorical column and get a new column of integer codes, one per distinct value, plus the mapping from value to code. Codes follow alphabetical order. The original column is kept.

How to use

1
Step 1
Paste the CSV or drop a file.
2
Step 2
Enter the column name.
3
Step 3
Press Process and copy the CSV with the new _label column.

How it works

The distinct values are sorted alphabetically and numbered from 0. A new column named column_label holds each row's code. The returned mapping lets you decode later. Integer codes imply an order, so they suit ordered categories or tree-based models better than linear ones.

Worked example

Encode region

Input
region: North, North, South, South, East, East, North
Output
mapping: East 0, North 1, South 2 region_label: 1, 1, 2, 2, 0, 0, 1
Walkthrough
East comes first alphabetically, so it gets 0.

Limitations

  • Codes follow alphabetical order, not the order of appearance or a custom order.
  • Linear and distance-based models read the codes as magnitudes. Use one-hot encoding for them.
  • One column per run.

Questions

How do I label-encode a column?
Enter the column name and press Process. A column_label column of integers is added.
Can I set my own order, like low, medium, high?
No. Codes are alphabetical, so low, medium, high would be coded 1, 2, 0. Recode ordinal columns yourself.
Is the mapping saved?
It is returned in the result so you can copy it.
Label encoding or one-hot encoding?
One-hot for nominal categories with linear models; label encoding for trees or ordered values.

Features

  • Integer codes
  • Mapping returned
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Learn JSON - Full Crash Course

    freeCodeCamp.org

    JSON is a primary interchange format for data utilities.

    Watch on YouTube
  • Machine Learning for Everybody

    freeCodeCamp.org

    Data prep context before ML-oriented helpers.

    Watch on YouTube
  • Fetch API

    MDN

    How browsers pull remote data into local tools.

  • Data Index

    Math is Fun

    Stats explainers when summarizing columns.