Skip to content
svgtype-composition

Column type composition

What kinds of columns does this dataset hold?

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

How to read it

  1. Read the segments as how many columns are of each kind.
  2. Read the list below for which columns those are.
  1. Callout 1: Segment size: how many columns of this kind.
  2. Callout 2: The columns of each kind.

Watch out

  • Inferred kinds are guesses. Check the id-like and text groups for columns stored oddly.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Kinds: physical kind (numeric, temporal, categorical, boolean) refined to id-like (all non-missing values distinct, n ≥ 20) and text (long or multi-word strings, > 50 % distinct).
  • The profiler's semantic types (email, URL, currency, …) refine these further in Insights.
# Column type composition — Codesplash Chart Lab (recipe "type-composition")
# 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("type-composition-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["last_purchase"] = pd.to_datetime(df["last_purchase"])
df["last_login"] = pd.to_datetime(df["last_login"])
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"

KINDS = {"customer_id": "categorical", "email": "categorical", "signup_date": "temporal", "last_purchase": "temporal", "last_login": "temporal", "age": "numeric", "income": "numeric", "spend_30d": "numeric", "visits_30d": "numeric", "tenure_days": "numeric", "discount_pct": "numeric", "satisfaction": "numeric", "region": "categorical", "plan": "categorical", "device": "categorical", "country": "categorical", "churned": "boolean", "newsletter": "boolean", "mobile_app": "boolean", "comments": "categorical"}  # physical kinds from the app
inferred = {n: infer_kind(df[n], k) for n, k in KINDS.items()}
groups = [(k, [n for n, v in inferred.items() if v == k]) for k in KIND_ORDER]
groups = [(k, names) for k, names in groups if names]
fig, (bar, lst) = plt.subplots(2, 1, figsize=(8, 1.2 + 0.45 * len(groups)), gridspec_kw={"height_ratios": [1, len(groups)]})
left = 0
for k, names in groups:
    bar.barh(0, len(names), left=left, color=PALETTE[KIND_COLOUR[k]], edgecolor="white")
    bar.text(left + len(names) / 2, 0, str(len(names)), ha="center", va="center", color="white", fontsize=9, fontweight="bold")
    left += len(names)
bar.set_xlim(0, len(KINDS))
bar.axis("off")
bar.set_title(f"{len(KINDS)} columns", fontsize=9, loc="left")
for i, (k, names) in enumerate(groups):
    lst.text(0, -i, f"{k} ({len(names)})", color=PALETTE[KIND_COLOUR[k]], fontsize=9, va="center")
    lst.text(0.22, -i, ", ".join(names), fontsize=8, va="center")
lst.set_ylim(-len(groups) + 0.5, 0.5)
lst.axis("off")
plt.show()

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