Search⌘ K

Reshaping the Data

Discover how to reshape datasets using Pandas pivot, pivot_table, and crosstab functions. Learn to transform long data formats to wide formats and vice versa, enabling better data aggregation and analysis. This lesson helps you manipulate data structures for clearer insights.

Pivot Table #

Somewhat like Excel, we can pivot our data using pandas pivot_table functionality. To do so, we will use the pivot_table() function.

The values parameter is the column being used for aggregation, the index parameter is for the index values that creates multiple rows, and the columns parameter is for the value on which you want to have multiple columns created.

You can also use the aggfunc parameter to pass a function with which to aggregate your pivots. ...