Skip to content
induwara.lk
Premium
induwara.lkAI · Preprocessing

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.

By Induwara AshinsanaUpdated Jul 13, 2026
One-hot encode your column
OneHotEncoder · get_dummies

Up to 10,000 values / 500 distinct categories. Blank lines are ignored. Nothing leaves your browser.

Try
Drop first category

Fitted categories

0Blue×11Green×22Red×2

5 input rows → 3 columns.

One-hot matrix

#ValueLabelx_Bluex_Greenx_Red
1Red2001
2Green1010
3Blue0100
4Green1010
5Red2001

The Label column is single-integer label encoding of the same data, shown for contrast — it implies a false numeric order, which is exactly what one-hot encoding avoids.

Copy-ready output

from sklearn.preprocessing import OneHotEncoder
import numpy as np

X = np.array(["Red", "Green", "Blue", "Green", "Red"]).reshape(-1, 1)
  # lexicographic order == OneHotEncoder default (categories='auto')
enc = OneHotEncoder(
    categories=[["Blue", "Green", "Red"]],
    sparse_output=False,
)
onehot = enc.fit_transform(X)
# handle_unknown="ignore" only affects transform() of
# categories not seen here; on this fit set the matrix is unchanged.
print(enc.get_feature_names_out(["x"]))
print(onehot.astype(int))

Behaviour mirrors scikit-learn's OneHotEncoder and pandas get_dummies. Everything runs in your browser — no upload, no API key.

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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).
  5. 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

Colours — default settings (n = 3)

Red, Green, Blue, Green, Red · lexicographic · drop-first off

  1. Distinct = {Blue, Green, Red}; sorted → [Blue, Green, Red], K = 3
  2. Columns: x_Blue, x_Green, x_Red
  3. Red → [0,0,1] Green → [0,1,0] Blue → [1,0,0]
  4. Every row sums to 1; label encoding: Blue=0, Green=1, Red=2
  5. Drop-first drops x_Blue → Red [0,1], Green [1,0], Blue [0,0]

Ordinal sizes — teaching case (identity matrix)

S, M, L, XL · lexicographic

  1. ASCII order L(76) M(77) S(83) X(88) → [L, M, S, XL], K = 4
  2. One-hot = the 4×4 identity, each row exactly one 1, trace = 4
  3. Label encoding L=0, M=1, S=2, XL=3 — a false numeric spacing
  4. Lesson: ordered data wants an ordinal encoder, not label encoding

Single category + drop-first (edge case)

Yes, Yes · drop-first on

  1. Distinct = {Yes}; K = 1 before dropping
  2. Drop-first removes the only column → 0 columns remain
  3. Every row becomes the all-zero vector — no crash, no NaN
  4. Correct dummy-trap result: one category needs zero indicators

Frequently asked questions

Sources & references

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

Rate this tool
Be the first to rate

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.