Pivot

The pivot operation reshapes your dataset by creating a new table with a specified column as the new index, another column as the new columns, and a third column as the values. This is useful when you have long-format data that you want to reshape into a wide-format.

- Index: The index is the column you want to use as the row labels in the resulting pivoted table. It acts as a key to group the data in the new table. Each unique value in the index column becomes a row label in the pivoted table.
- Columns: The columns are the new column labels in the pivoted table. Each unique value in the specified column will become a new column label in the resulting table. The data from the original table will be spread across these new columns based on the specified values.
- Values: The values are the data that you want to fill the cells of the pivoted table. The pivot function aggregates the values based on the index and columns specified, and the resulting table will contain these aggregated values.
In summary, the pivot function in data manipulation tools reorganizes the data based on the index, columns, and values you specify, making it easier to analyze and understand the data.
Example
Dataset:
Date | Category | Sales |
---|---|---|
2023-01-01 | Shoes | 100 |
2023-01-01 | Bags | 200 |
2023-01-02 | Shoes | 150 |
2023-01-02 | Bags | 250 |
Result: (Pivot on Date and Category)

Updated 5 months ago