One-hot encoder

Paste a column of categorical values, one per line — colours, sizes, countries — and get the one-hot encoded table: one column per distinct category, 1 where the row has it and 0 elsewhere. Drop the first column for the k − 1 dummy variables a regression needs.

Output
Column order

5 rows, 3 categories, 3 0/1 columns

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Paste the values of one categorical column, one per line.
  2. Choose CSV, TSV (pastes into a spreadsheet) or JSON.
  3. Choose the column order: as the categories first appear, or sorted.
  4. Tick Drop the first category for dummy coding, and decide whether to keep the original value column.

How it works

The tool collects the distinct values in the chosen order. For each input row it writes a 0 for every category column and a 1 in the column of the row’s own value. In CSV, a category that contains a comma, quote or line break is quoted as the CSV standard requires. With dummy coding, the first category in the order is removed, so its rows are all zeros.

Worked example

The values red, green, red, blue in order of appearance give three columns:

value,red,green,blue
red,1,0,0
green,0,1,0
red,1,0,0
blue,0,0,1

Sorted with the first category dropped, the columns are green and red; blue, now first in the sorted order, is dropped and its row becomes 0,0.

Tips

  • Many categories mean many columns. For hundreds of values, consider grouping rare ones into “other” first.
  • Fit the categories on training data. In a model pipeline, a category that only appears in new data needs a rule — an all-zero row or an “unknown” column.
  • To split the encoded data into training and test sets, see the train/test split calculator.

Frequently asked questions

What is one-hot encoding?

A way to turn a categorical variable into numbers for machine learning. Each distinct category gets its own column; a row has 1 in the column of its category and 0 in all others. Unlike numbering the categories 1, 2, 3, it does not suggest an order or distance between them.

What is the difference between one-hot and dummy encoding?

Dummy encoding drops one category's column, leaving k − 1 columns for k categories. The dropped category is the row of all zeros. Linear regression needs this, because the k one-hot columns always add up to 1 and would be perfectly collinear with the intercept (the dummy variable trap).

How are empty lines and spaces handled?

Each value is trimmed, and empty lines are skipped. Values are case-sensitive: Red and red become two categories. Clean the data first if they should be the same.

Is this the same as pandas get_dummies or scikit-learn OneHotEncoder?

The result is the same idea. pandas.get_dummies sorts the categories and has drop_first; scikit-learn's OneHotEncoder also sorts them and has drop='first'. Choose Sorted here to match their column order.

More in Developer

All tools in this category: Developer ·Updated November 7, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.