Reshape DataFrames — mirrors pandas.DataFrame.pivot() and
pandas.pivot_table().
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
pivot reshapes a DataFrame using unique values in one column as the
new column headers. Requires one unique value per (row, column) pair.
When values is omitted, all non-index/non-column columns are used.
Column names become valCol_colHdr.
pivotTable aggregates values when multiple rows map to the same
(index, column) cell.
Use aggfunc: "sum" to total up values per cell, and
fill_value to replace missing cells.
Use aggfunc: "count" to count how many rows fall into each cell.
pivot requires one unique value per (index, column) pair.
pivotTable aggregates when duplicates exist.
// Reshape without aggregation
pivot(df, {
index: string, // column → row labels
columns: string, // column → new column headers
values?: string, // column → cell values (all remaining if omitted)
}): DataFrame
// Reshape with aggregation
pivotTable(df, {
index: string, // column → row labels
columns: string, // column → new column headers
values: string, // column → cell values
aggfunc?: "mean" | "sum" | "count" | "min" | "max", // default "mean"
fill_value?: number, // replace missing cells
}): DataFrame