One-hot encode a CSV categorical column

Paste CSV, pick a column, and expand it into one binary indicator column per category — with a droppable reference level, top-N capping, and your own 1/0 values.

Try:
Encoded CSV

About this tool

One-Hot Encoder expands a categorical CSV column into a block of binary indicator columns — one per distinct value — where every row carries a 1 in the column matching its category and a 0 in all the others. This is the transformation usually called one-hot encoding or dummy variables, and it is what most modelling libraries produce from a text column before it can be fed to a regression, a tree ensemble, or a neural net.

Pick the column and the tool does the rest: generated columns are named <prefix><separator><value> (the prefix defaults to the column's own name), and you can drop a reference level to avoid the dummy-variable trap, cap the expansion to the top N most frequent categories, ignore values seen fewer than N times, keep or remove the source column, and write true/false (or any other pair) instead of 1/0.

Worked example

CSV:

city,n
Paris,1
Rome,2
Paris,3

With column city and the defaults, the city column is replaced by one indicator per distinct value, in alphabetical order:

n,city_Paris,city_Rome
1,1,0
2,0,1
3,1,0

Set Reference level to drop to First category and the city_Paris column disappears — the rows that were Paris are now identified by being 0 in every remaining column, which is the k−1 encoding a linear model needs:

n,city_Rome
1,0
2,1
3,0

Capping a high-cardinality column

Columns like browser, merchant, or ZIP can hold thousands of distinct values, and one column each is rarely useful. Keep only the top N categories selects the N most frequent, and Add a combined 'other' column collects everything else into a single indicator. With max_categories = 2, other_column on, the original column kept, and frequency ordering:

browser,hits
chrome,10
chrome,20
chrome,30
safari,40
safari,50
lynx,60
browser,hits,browser_chrome,browser_safari,browser_other
chrome,10,1,0,0
chrome,20,1,0,0
chrome,30,1,0,0
safari,40,0,1,0
safari,50,0,1,0
lynx,60,0,0,1

Limits & edge cases

FAQ

What is one-hot encoding, and when should I use it?

One-hot encoding turns a categorical column into several binary columns, one per category, so that a model can use it without inventing an ordering. If you simply numbered categories 1, 2, 3 instead, most models would read that as "3 is bigger than 1", which is meaningless for values like city or browser. Use it for nominal columns with a manageable number of distinct values; for high-cardinality columns, cap it with the top-N setting or reach for a compact alternative such as frequency or target encoding.

What is the dummy-variable trap, and which drop option fixes it?

With one column per category, the indicators always sum to 1 for every row, so any one of them is perfectly predictable from the others. That perfect collinearity makes a linear regression's coefficients unstable or unsolvable. Dropping one category as a reference level fixes it: pick First category or Last category to get k−1 columns, and rows in the dropped category are then the ones that are 0 everywhere. Only if the column is binary drops a level only when there are exactly two categories, which is the common convention for yes/no columns. Tree-based models do not care, so None is a fine default for them.

How are blank cells handled?

The Blank cells setting decides. Zero in every indicator (the default) treats a blank as "none of the above", which matches what most encoder libraries do by default. Own NaN indicator column adds a <prefix>_NaN column, so missingness itself becomes a feature you can model. Leave the indicators empty writes empty cells so the gap stays visible downstream, and Reject the input fails with an error rather than silently choosing for you. Blank rows never get a category column of their own unless you choose the separate option.

How do I get true/false or Y/N instead of 1 and 0?

Set Value for a match and Value for a non-match to whatever pair you need — true/false, Y/N, or yes/no. They are written verbatim, so the output plugs straight into a tool that expects booleans rather than integers.

What happens to categories that the top-N or minimum-count limits exclude?

By default those rows are simply 0 in every generated column, exactly as if the value had never been listed. Turn on Add a combined 'other' column to give them a single shared indicator instead, so the information that the row held some rare value is preserved in one column rather than lost or spread across many. The two limits combine: a category must both be seen at least the minimum number of times and survive the top-N cut to get its own column.

Can I encode more than one column at a time?

Not in a single run — the tool takes one column per call. To encode several, run it repeatedly, feeding each run's output back in as the next run's input and changing only the column name. Because the generated columns are appended at the end and the source column is removed by default, the results stack cleanly without colliding.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool one-hot-encoder "city,n
Paris,1
Rome,2
Paris,3" 'column=city'

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/one-hot-encoder/?data=city%2Cn%0AParis%2C1%0ARome%2C2%0AParis%2C3&column=city&prefix=city&separator=_&drop=none&drop_original=true&missing=zeros&max_categories=0&min_count=0&other_column=true&positive=1&negative=0&case_sensitive=true&sort=alphabetical&has_header=true&delimiter=comma

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.