Skip to content
svgcolumn-sparkline

Column sparklines

What does each column look like at a glance?

Demo data · seed 20261101 · 600 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Scan the tiles for a first look at each column: kind, missing share and distinct count.
  2. Read the mini chart for shape: a histogram for numbers, top values for categories.
  3. Look for surprises: a spike, a red missing bar, one value dominating.
  1. Callout 1: Column name and its inferred kind.
  2. Callout 2: A mini histogram: spikes and long tails stand out.
  3. Callout 3: A red bar: a large missing share.

Watch out

  • An inferred kind is a guess. An id stored as a number still gets a histogram.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Numeric and temporal columns: 18 equal-width [a, b) bins over [min, max] (fewer when there are fewer distinct values).
  • Categorical and boolean columns: the 4 most frequent levels (ties alphabetical) plus “Other”.
  • Kinds: id-like = every non-missing value distinct (n ≥ 20, integers or short strings); text = strings averaging > 30 characters or > 3 words with > 50 % distinct.
  • Missing bar: grey below 5 %, amber 5–40 %, red above 40 %.
# Column sparklines — Codesplash Chart Lab (recipe "column-sparkline")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("column-sparkline-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["signup_date"] = pd.to_datetime(df["signup_date"])
df["region"] = pd.Categorical(df["region"].astype("string"), categories=["North", "South", "East", "West"])
df["plan"] = pd.Categorical(df["plan"].astype("string"), categories=["Basic", "Plus", "Pro"])

KIND_ORDER = ["numeric", "temporal", "categorical", "boolean", "text", "id-like"]
KIND_COLOUR = {"numeric": 0, "temporal": 2, "categorical": 1, "boolean": 4, "text": 5, "id-like": 7}

def infer_kind(s, kind):
    """id-like = every non-missing value distinct (n ≥ 20; integers or short strings);
    text = strings averaging > 30 characters, or > 3 words with > 50 % distinct."""
    if kind in ("boolean", "temporal"):
        return kind
    present = s.dropna()
    distinct = present.astype(str).nunique()
    unique = len(present) >= 20 and distinct == len(present)
    if kind == "numeric":
        ints = bool(np.all(np.mod(present.to_numpy(dtype=float), 1) == 0))
        return "id-like" if unique and ints else "numeric"
    strs = present.astype(str)
    avg_len = strs.str.len().mean() if len(strs) else 0
    avg_words = strs.str.strip().str.split().str.len().mean() if len(strs) else 0
    if avg_len > 30 or (avg_words > 3 and distinct > 0.5 * len(strs)):
        return "text"
    return "id-like" if unique else "categorical"
def tile(s, kind, bins=18, top_k=4):
    """Numeric/temporal: equal-width [a, b) bins over [min, max] (fewer when fewer distinct values);
    categorical/boolean: the top 4 levels (ties A→Z) plus Other."""
    present = s.dropna()
    if kind in ("numeric", "temporal") and len(present):
        v = present.astype("int64").to_numpy() if kind == "temporal" else present.to_numpy(dtype=float)
        k = max(1, min(bins, present.nunique()))
        counts, edges = np.histogram(v, bins=k, range=(v.min(), v.max() if v.max() > v.min() else v.min() + 1))
        return "bins", counts, edges
    if kind in ("categorical", "boolean"):
        vc = present.astype(str).value_counts()
        levels = sorted(vc.index, key=lambda l: (-vc[l], l))
        top = [(l, int(vc[l])) for l in levels[:top_k]]
        other = int(len(present) - sum(n for _, n in top))
        return "levels", top + ([("Other", other)] if other else []), None
    return "none", None, None

KINDS = {"signup_date": "temporal", "age": "numeric", "income": "numeric", "region": "categorical", "plan": "categorical", "churned": "boolean", "satisfaction": "numeric", "comments": "categorical"}  # physical kinds from the app
COLS = list(KINDS)
cols = 4
rows = int(np.ceil(len(COLS) / cols))
fig, axes = plt.subplots(rows, cols, figsize=(3 * cols, 1.9 * rows), squeeze=False)
for ax, name in zip(axes.flat, COLS):
    s = df[name]
    kind = infer_kind(s, KINDS[name])
    share = s.isna().mean()
    miss_colour = "#6e7278" if share < 0.05 else PALETTE[1] if share <= 0.4 else PALETTE[3]  # grey < 5 %, amber ≤ 40 %, red above
    what, a, b = tile(s, kind)
    colour = PALETTE[KIND_COLOUR[kind]]
    if what == "bins":
        ax.bar(b[:-1], a, width=np.diff(b), align="edge", color=colour, edgecolor="white", linewidth=0.4)
    elif what == "levels":
        labels = [l for l, _ in a][::-1]
        ax.barh(labels, [n for _, n in a][::-1], color=[colour if l != "Other" else "#9aa0a6" for l in labels])
        ax.tick_params(axis="y", labelsize=7)
    else:
        ax.text(0.5, 0.5, f"{s.dropna().astype(str).nunique():,} distinct", ha="center", va="center", transform=ax.transAxes, fontsize=9)
    ax.set_title(f"{name} · {kind}", fontsize=9, loc="left")
    ax.text(1, 1.02, f"{share:.0%} missing", transform=ax.transAxes, ha="right", va="bottom", fontsize=8, color=miss_colour)
    ax.set_xticks([])
    if what != "levels":
        ax.set_yticks([])
    ax.grid(False)
for ax in list(axes.flat)[len(COLS):]:
    ax.set_visible(False)
fig.tight_layout()
plt.show()

Needs pandas, numpy, matplotlib · reads column-sparkline-demo.csv · app theme from the optional codesplash helper