Label Encoder
Map categorical values in a CSV column to integer codes.
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
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?
Can I set my own order, like low, medium, high?
Is the mapping saved?
Label encoding or one-hot encoding?
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 YouTubeMachine 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.