Skip to main content

Pivot Tables

VisiData's pivot table (Shift+W) gives you cross-tabulated aggregation in one keystroke — the terminal equivalent of Excel's PivotTable. No SQL, no Python, no setup beyond marking key columns and aggregators.

Learning Focus

The setup ritual: set key columns with ! → set aggregator with + → press Shift+W. Key columns become rows, the aggregator becomes the value.

Sample Data

cat > ~/github/practice-folder/visidata/01-loading/01-employees.csv << 'EOF'
name,role,region,salary
Alice,engineer,sg,85000
Bob,manager,kl,92000
Carol,engineer,sg,78000
Dave,manager,sg,95000
Eve,engineer,jk,72000
Frank,analyst,kl,65000
Grace,engineer,jk,70000
EOF

vd ~/github/practice-folder/visidata/01-loading/01-employees.csv

Create a Simple Pivot Table

Goal: Average salary by role.

Step 1 — Cast salary to float:

# Move to 'salary' column
%

Step 2 — Set aggregator:

+
# Enter: mean

Step 3 — Set key column (row dimension):

# Move to 'role' column
!
# 'role' header turns blue

Step 4 — Open pivot table:

Shift+W

Result:

role mean_salary
analyst 65000.0
engineer 76250.0
manager 93500.0

Multi-Key Pivot (Region × Role)

Mark two key columns to get a cross-tabulated view:

# Move to 'region' → press !
# Move to 'role' → press !
# Set salary mean aggregator: move to salary → + mean

Shift+W

Result:

region role mean_salary
jk engineer 71000.0
kl analyst 65000.0
kl manager 92000.0
sg engineer 81500.0
sg manager 95000.0

Drill Into Pivot Cells

Press Enter on a pivot row to see the source rows that make up that group:

# In the pivot table, move to 'jk engineer' row
Enter

Source rows sheet opens:

name role region salary
Eve engineer jk 72000
Grace engineer jk 70000

Press q to return to the pivot table.

For more precision, use zEnter to open rows matching both the row AND the specific column cell value:

# zEnter on a specific pivot cell
# → Opens only rows matching that exact row+column intersection

Quick Summary Line (zF)

For a quick aggregate without opening any new sheet:

# Move to 'salary' column
zF
# Status bar shows: count=7, distinct=7, min=65000, max=95000, mean=79571.4

Troubleshooting

ProblemCauseFix
Pivot shows only one columnNo key column setPress ! on the row dimension column first
Aggregator missing from pivotAggregator not setMove to value column and press +
Pivot is slowMany distinct key valuesUse frequency table instead for simple counts

Quick Reference

KeyAction
!Toggle key column (pivot row dimension)
+Set aggregator (pivot value)
Shift+WOpen pivot table
EnterDrill into source rows for a pivot cell
zEnterDrill into exact row+column intersection
zFQuick one-line summary on status bar

Hands-On Practice

vd ~/github/practice-folder/visidata/01-loading/01-employees.csv

# 1. Move to 'salary', press % → cast to float
# 2. Press + → enter: mean → set mean aggregator
# 3. Move to 'region', press ! → key column
# 4. Move to 'role', press ! → key column 2
# 5. Press Shift+W → pivot table opens
# 6. Press Enter on any row → see source rows
# 7. Press q → back to pivot table
# 8. Press q → back to source

What's Next