Cross-tabulations

We can customize the pandas dataframe with another technique called cross-tabulation. This allows us to cope with groupby and aggregation for better data analysis. pandas has the crosstab function, which helps when it comes to building a cross-tabulation table. The cross-tabulation table shows the frequency with which certain groups of data appear. Let's take a look:

  1. Let's use pd.crosstab() to look at how many different body styles cars are made by different makers:
pd.crosstab(df["make"], df["body-style"])

The output of the preceding code is as follows:

Let's apply margins and the margins_name attribute to display the ...

Get Hands-On Exploratory Data Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.