A table row is an awkward object: some columns are numbers on
incompatible scales, others are categories, and some values are missing
altogether. Most of what one wants to do with rows — cluster them, find the
near neighbours of one, feed them to a model, plot them — presupposes that
they are already points in a metric space. Row2Vec performs that
conversion. It takes a DataFrame and returns one dense numeric
vector per row, handling the scaling, encoding, and imputation on the way,
and it offers both neural and classical methods behind a single call.
Installation
pip install row2vec
Example
import pandas as pd
from row2vec import learn_embedding
df = pd.read_csv("customers.csv") # mixed types, some values missing
embeddings = learn_embedding(df, mode="pca", embedding_dim=5)
embeddings.shape # (len(df), 5)
The returned object is a DataFrame of the
same length as the input, indexed alike, with one column per embedding
dimension. Choosing a different method is a change of the mode
argument — "unsupervised", "tsne",
"umap", "target", "contrastive" — and
the call site does not otherwise change.
The embedding
Methods
| Mode | Appropriate when | Parameter |
|---|---|---|
| pca | a fast linear baseline with interpretable components is wanted | embedding_dim |
| unsupervised | the structure is non-linear and an autoencoder is warranted | hidden_units, max_epochs |
| tsne | the goal is a two- or three-dimensional plot of local structure | perplexity |
| umap | local and global structure are both to be preserved | n_neighbors, min_dist |
| target | one vector per category of a column is wanted, not per row | reference_column |
| contrastive | pairs known to be alike or unalike are available for supervision | auto_pairs, margin |
What is handled for you
- Missing values. the pattern of missingness is analysed and an imputation strategy chosen per column.
- Categorical fields. encoded by a strategy selected from the column's cardinality — one-hot, ordinal, target, or learned entity embeddings.
- Scale. numeric columns are standardised; the output can additionally be scaled to a fixed range.
- Architecture. for the neural modes, the layer widths and the embedding dimension can be searched rather than guessed.
Documentation
Citation
@software{tresoldi_row2vec_2026,
author = {Tresoldi, Tiago},
title = {Row2Vec: Neural and classical embeddings
for tabular data},
year = {2026},
version = {0.2.0},
url = {https://github.com/tresoldi/row2vec}
}