Recall & Review
beginner
What is cross-tabulation in pandas used for?
Cross-tabulation is used to compute a simple frequency table of two or more factors. It helps to understand the relationship between categorical variables by showing counts or other statistics in a matrix format.
Click to reveal answer
beginner
How can you add margins (totals) to a pandas crosstab?
Use the parameter
margins=True in pd.crosstab(). This adds row and column totals to the table, helping to see overall counts.Click to reveal answer
intermediate
What does the
normalize parameter do in pd.crosstab()?The
normalize parameter converts counts into proportions. You can normalize by 'index', 'columns', or 'all' to get relative frequencies instead of raw counts.Click to reveal answer
advanced
How do you include multiple aggregation functions in a pandas crosstab?
Use the
aggfunc parameter with a list of functions (e.g., [np.sum, np.mean]) and provide a values argument to specify the data to aggregate.Click to reveal answer
advanced
Explain how to create a multi-index crosstab with more than two categorical variables.
Pass multiple arrays or columns to the
index and/or columns parameters as lists. This creates a multi-level index in the resulting table, showing detailed breakdowns.Click to reveal answer
Which parameter in
pd.crosstab() adds row and column totals?✗ Incorrect
The
margins=True parameter adds totals for rows and columns in the crosstab.What does
normalize='index' do in a crosstab?✗ Incorrect
Normalizing by 'index' converts counts into proportions across each row.
How do you specify multiple aggregation functions in a crosstab?
✗ Incorrect
You pass a list of functions like
[np.sum, np.mean] to the aggfunc parameter.To create a multi-level index in a crosstab, you should:
✗ Incorrect
Passing multiple columns as lists to
index or columns creates multi-level indexes.Which of these is NOT a valid use of
pd.crosstab()?✗ Incorrect
Cross-tabulation does not create scatter plots; it summarizes categorical data.
Describe how to use pandas crosstab to analyze the relationship between three categorical variables with totals and normalized proportions.
Think about multi-index and normalization options in crosstab.
You got /3 concepts.
Explain how to apply multiple aggregation functions on numerical data within a pandas crosstab.
Consider how aggfunc and values work together.
You got /3 concepts.