Initializing playground…
← Back to roadmap

🗂️ MultiIndex — Interactive Playground

Hierarchical multi-level index — mirrors pandas.MultiIndex. Build composite keys from tuples, arrays, or Cartesian products and use them for advanced label-based look-ups.
Edit any code block below and press ▶ Run (or Ctrl+Enter) to execute it live in your browser.

1 · Create from tuples

The most common way: pass an array of label-tuples.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

2 · Create from arrays

Supply one array per level — a column-oriented alternative to fromTuples.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

3 · Create from Cartesian product

fromProduct generates every combination from a list of iterables — very handy for experiment grids.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

4 · Look-up by label

Use getLoc to find the position of a tuple. contains for a quick existence check.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

5 · Level operations: droplevel & swaplevel

Restructure the level hierarchy without touching the data.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

6 · Set operations

union, intersection, difference — same semantics as pandas.MultiIndex.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

7 · Sorting and deduplication

Sort tuples lexicographically and detect or remove duplicates.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

8 · Missing values

Detect and remove tuples that contain null or undefined in any level.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

API Reference

Key static constructors and instance methods on MultiIndex.

// Static constructors
MultiIndex.fromTuples(tuples, { names? }): MultiIndex
MultiIndex.fromArrays(arrays, { names? }): MultiIndex
MultiIndex.fromProduct(iterables, { names? }): MultiIndex

// Properties
mi.nlevels: number        // number of levels
mi.size: number           // number of entries
mi.names: string[]        // level names

// Look-up
mi.at(i): unknown[]                  // tuple at position
mi.getLoc(tuple): number | number[]   // position(s) of tuple
mi.contains(tuple): boolean          // existence check

// Restructure
mi.droplevel(level): MultiIndex | Index
mi.swaplevel(i, j): MultiIndex

// Set operations
mi.union(other): MultiIndex
mi.intersection(other): MultiIndex
mi.difference(other): MultiIndex

// Sorting & deduplication
mi.sortValues(): MultiIndex
mi.dropDuplicates(): MultiIndex
mi.duplicated(keep?): boolean[]

// Missing values
mi.isna(): boolean[]
mi.dropna(): MultiIndex