Pivot Table
noun
say it: “PIV-ut TAY-bul” /ˈpɪvət ˈteɪbəl/
A table that summarizes data as a grid, with one kind of value down the side, another across the top, and a total or average in each square.
What is a pivot table?
A pivot table is a summary laid out as a grid: one column's values down the side, another's across the top, and a
total, count or average in every square. Spreadsheets have them, and pandas builds one with pivot_table().
import pandas as pd
orders = pd.DataFrame({"weekday": ["Fri", "Fri", "Sat"], "size": ["small", "large", "large"], "total": [12.0, 20.0, 22.0]})
print(orders.pivot_table(index="weekday", columns="size", values="total", aggfunc="sum", fill_value=0))
# size large small
# weekday
# Fri 20.0 12.0
# Sat 22.0 0.0
In a sentence
- “Every square of the pivot table held one weekday's sales of one size.”
- “The pivot table showed sales by weekday down the side and pizza size across the top.”
Level: Apprentice · More Python terms at this level
Updated