Summarizing data with a pivot table
A pivot table is a data analysis tool that enables you to summarize, reorganize, and explore large datasets. It aggregates data, rotates perspectives, and filters, sorts, and groups information into meaningful categories.Key benefits
- Simplify Complex Data — Break down large datasets into manageable summaries
- Identify Trends — Reveal patterns not immediately obvious in raw data
- Flexible Analysis — Quickly change layout and structure to answer different questions
- Efficiency — Automate data analysis for faster, regular reporting
Pandas pivot table syntax
Practical example: analyzing odd lots in AAPL trades
This example demonstrates analyzing AAPL trade data by:- Extracting trades between 9:30 AM and 4 PM
- Creating an
odd_lotsboolean column (shares < 100) - Extracting hour from timestamp
- Pivoting to count shares by hour and lot size
- Calculating percentage of odd lots per hour

