Cross Tabulation
pd.crosstab() computes frequency tables to show how often value combinations occur.
Basic Crosstab
Count combinations of values:
Loading Pandas Playground...
Adding Margins
Include row and column totals:
Loading Pandas Playground...
Normalizing Values
Show percentages instead of counts:
Loading Pandas Playground...
Aggregating Values
Apply functions to a third column:
Loading Pandas Playground...
Multiple Values
Crosstab with multiple row or column variables:
Loading Pandas Playground...
Crosstab vs Pivot Table
Compare the two approaches:
Loading Pandas Playground...
Exercise: Basic Crosstab
Loading Exercise...
Exercise: Percentage Crosstab
Loading Exercise...
Key Points
pd.crosstab()creates frequency tables- Counts combinations by default
margins=Trueadds totalsnormalize=for percentages ('all', 'index', 'columns')- Use
values=andaggfunc=to aggregate other data - Simpler than pivot_table for counting
Up next · Lesson 23 of 42
Named Aggregation & Window Patterns
2 min read
22 of 42 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

