One-Hot Encoding Calculator, Categorical to Numeric
Paste a categorical column and instantly get the one-hot encoded 0/1 matrix, matching scikit-learn's OneHotEncoder and pandas get_dummies, with copy-ready Python, CSV, and NumPy. It runs entirely in your browser, so nothing is uploaded.
How it works
One-hot encodingconverts a categorical column into a set of numeric 0/1 indicator columns, one per distinct category, so a model that only understands numbers can use it without inferring a fake ordering. This tool reproduces the deterministic behaviour of scikit-learn's OneHotEncoder and pandas get_dummies, so its output matches a fresh notebook. Every step is a plain string operation and never leaves your device.
- Parse. Your text is split on new lines and commas, each value is trimmed, and blank entries are dropped. You get an ordered list of category tokens, kept in the original row order.
- Fit the categories.The distinct tokens become the encoder's vocabulary. The order is resolved by your choice: lexicographicsorts them as strings, matching scikit-learn's default
categories='auto'(sorted unique); numeric sorts numerically when every value is a number, otherwise it falls back to lexicographic with a note; first-seen keeps the order each category first appears. - Transform.For each input row the tool emits a vector of length K (the number of fitted categories) with a 1 in that row's category position and 0 elsewhere, the formula
onehot(x)[j] = 1 if x == category[j] else 0. Exactly one column is 1 per row, so every row sums to 1. - Drop-first (optional). To avoid the dummy-variable trap, the perfect collinearity that breaks linear and logistic regression, the first category's column can be dropped. That category is then represented by an all-zero row, matching
get_dummies(drop_first=True). - Name and count. Columns are named
{prefix}_{category}, the same convention as get_dummies, and each category's frequency is tallied so you can see the class balance at a glance.
The result is cross-checked by an independent inverse transform: every row of the matrix is decoded back to a category by taking the position of its 1 (or the dropped category for an all-zero row) and compared against the original input. When all rows round-trip exactly. They always should, the tool shows an "inverse-verified" badge. Alongside the matrix, a single integer label-encoding column is shown for contrast: it is compact but imposes a false numeric order, which is precisely what one-hot encoding avoids. What this tool deliberately does not do is encode multiple columns at once, or apply target, frequency, or binary encoders. It is a focused one-hot encoder for a single column.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn: OneHotEncoder (categories='auto', drop='first', handle_unknown)
- pandas: get_dummies (prefix, drop_first, column naming)
- scikit-learn: Encoding categorical features (user guide)
The behaviour and worked examples on this page were last reconciled against these sources on 2026-07-13. The definitions are standard and stable; the page is reviewed if the reference implementations change their default behaviour.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us, our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] , most fixes ship within 24 hours.