The Pivot Table Function

Learn how to create pivot tables with Pandas.

What is a pivot table?

A pivot table is a summary table obtained by grouping and aggregating values of a more extensive table. Suppose we have an orders table that contains the day, order amount, and customer code for each order. A pivot table can be created to show the daily total order amounts. We need to group the rows by day and then aggregate by taking the sum.

Creating pivot tables with Pandas

A pivot table is a great tool to summarize, sort, group, and aggregate tabular data. Thanks to the pivot_table function, we can easily create pivot tables with Pandas. It has several parameters that provide flexibility comparable to Excel.

Let’s create a pivot table to see the weekly total sales quantities of the product groups in the grocery.

Get hands-on with 1400+ tech skills courses.