What if you could instantly see how two groups relate without counting by hand?
Why crosstab() for cross-tabulation in Pandas? - Purpose & Use Cases
Imagine you have a list of survey answers from a group of people, and you want to see how many men and women prefer different types of fruits. Doing this by hand means counting each category one by one, which is slow and confusing.
Manually counting combinations is easy to mess up, especially with many categories. It takes a lot of time and you might miss some pairs or count wrong. Updating counts when new data arrives is also painful.
The crosstab() function in pandas quickly counts how often each pair of categories appears. It organizes the results in a neat table, so you can see patterns instantly without errors or extra work.
counts = {}
for person in data:
key = (person['gender'], person['fruit'])
counts[key] = counts.get(key, 0) + 1
print(counts)import pandas as pd pd.crosstab(df['gender'], df['fruit'])
You can instantly explore relationships between two or more categories in your data, making it easier to find trends and make decisions.
A marketing team uses crosstab() to see which age groups prefer which product types, helping them target ads better.
Manual counting of category pairs is slow and error-prone.
crosstab() automates counting and displays results clearly.
This helps quickly understand relationships in data.