category-encoders
A package for encoding categorical variables for machine learning
What it is and what it does
Category-encoders is a scikit-learn-compatible library that converts categorical variables into numeric form using a range of encoding strategies. It provides both unsupervised methods (binary, one-hot, ordinal, hashing) that treat all categories equally, and supervised methods (target encoding, CatBoost encoding, leave-one-out) that leverage target information to create more predictive numeric representations. The library integrates seamlessly into sklearn pipelines and accepts numpy arrays or pandas dataframes as input.
The package is designed for machine learning workflows where categorical features must be converted to numeric form. It handles the common problem of deciding which encoding method to use by offering multiple techniques with different statistical properties and computational trade-offs. Supervised encoders can reduce overfitting through nested cross-validation wrappers, and the library supports both classification and regression tasks through specialized wrappers.
Use it for:
- Encode categorical features like gender or country in a classification pipeline using one-hot or binary encoding
- Apply target encoding to high-cardinality categorical variables to capture predictive signal from the target variable
- Use LeaveOneOut encoding in supervised settings to prevent overfitting while maintaining target information
- Build feature engineering pipelines that automatically encode all object-type columns in a pandas dataframe
- Compare multiple encoding strategies on the same dataset to select the best performing method
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Transforms categorical variables into numeric representations using scikit-learn-compatible encoders, supporting both unsupervised methods (one-hot, binary, ordinal) and supervised techniques (target encoding, CatBoost encoding).
Yes. The package is actively maintained, has low installation friction, carries no known vulnerabilities, and provides a well-documented suite of encoding methods that integrate directly into sklearn workflows. It solves a common data preprocessing problem with multiple proven techniques. Install it if you work with categorical data in machine learning projects.
Install
category-encoders on PyPI
pip
pip install category-encodersuv
uv add category-encoderspoetry
poetry add category-encodersInstalling category-encoders
Before you install
Low friction installation with a pure Python wheel. Depends on established numerical and statistical libraries (numpy, pandas, scikit-learn, scipy, statsmodels). Actively maintained with a recent release.
License in practice
BSD-3 permissive license allows commercial and private use with minimal restrictions; attribution required.
Quickstart
pip install category_encoders
from category_encoders import BinaryEncoder
import pandas as pd
X = pd.DataFrame({'gender': ['male', 'female'], 'age': [25, 32]})
enc = BinaryEncoder(cols=['gender']).fit(X)
numeric_X = enc.transform(X)
Verify before relying
- Whether supervised encoders (TargetEncoder, LeaveOneOut) handle class imbalance or missing values automatically
- Performance characteristics when encoding high-cardinality categorical features with many unique values
- Memory overhead of different encoding methods on large datasets
Package facts
| License | BSD-3 (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — numpy, pandas, patsy, scikit-learn, scipy, statsmodels |
| Maintenance | actively maintained — 19 days since the last release |
| First released | |
| Downloads | 3,123,199/month — #2,741 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: category_encoders-2.10.0-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
catboostCatBoost is a gradient boosting library that…
permissive · top 5,000 on PyPI
formulaic-contrastsBuilds arbitrary contrasts for statistical…
permissive · top 15,000 on PyPI
phikPhi_K computes a correlation coefficient that…
permissive · top 5,000 on PyPI
datasieveDataSieve extends scikit-learn's Pipeline to…
permissive · top 15,000 on PyPI
kmodesImplements k-modes and k-prototypes clustering…
permissive · top 15,000 on PyPI
sagemaker-scikit-learn-extensionExtends scikit-learn with additional estimators…
permissive · top 15,000 on PyPI
ngboostNGBoost implements Natural Gradient Boosting…
permissive · top 15,000 on PyPI
sklearndfWraps scikit-learn estimators to return pandas…
permissive · top 15,000 on PyPI
graycodeConverts between two's complement integers and…
permissive · top 15,000 on PyPI
gender-guesserGuesses the gender of a person from their first…
copyleft · top 5,000 on PyPI