The same data can be laid out long or wide, and different jobs need different layouts.
Long data has one row per observation, such as one row for each store in each month.
Wide data spreads one variable across several columns, such as a column for each month.
Tidy data from module 01 is usually long, which suits filtering and grouping.
Reports, charts and some models want wide data, with one row per item and its values side by side.
The pivot method only reshapes, so every cell of the new grid must come from exactly one row.
The pivot_table function summarises first, so repeated pairs are combined with a sum, a mean or another calculation.
Pairs that never occur become blank cells, which fill_value can set to 0 where 0 is the honest answer.
Using several columns for the rows, such as region and store, gives layered row labels.
Wide tables grow with the data: a new month adds a new column, which breaks code that expects fixed columns.
That is one reason data is usually stored long and pivoted only for display.
The unstack method does the same reshaping from a layered index, and stack reverses it.
The spreadsheet pivot table from earlier in this module and pivot_table in pandas are the same idea in two tools.
In practice pivoting is often the last step before a chart or a report table.
The common confusion is between pivot, which only reshapes, and pivot_table, which also summarises.