PivotTable
PivotTable[tab,f,rowcol,colcol]
constructs a table where the value at the position with keys {row,col} is given by applying the function f to the subtabulars corresponding to the rows of tab where rowcol has value row and colcol has value col.
PivotTable[tab,{key1f1,…},rowcols,colcols]
uses multiple aggregation functions fi denoted by keyi.
更多信息和选项
- PivotTable provides a way to summarize and reorganize data by applying an aggregation function to subtabulars specified by values of selected columns.
- PivotTable[tab,f,rowcols,colcols] produces a Tabular object in which rowcols are key columns.
- If the colcol specification is a list of several keys, the resulting table will have ExtendedKey column keys.
- For each group determined by Flatten[{rowcols,colcols}], there is a subtabular stab corresponding to a subset of rows of tab. The aggregation functions fi are applied to the association of columns given by FromTabular[stab,"Columns"].
- PivotTable[tab,{key1f1,…},rowcols,colcols] is effectively PivotToColumns[AggregateRows[tab, {key1f1,…}, Flatten[{rowcols,colcols}]],{colcols,{key1,…}}].
- The following option can be given:
-
IncludeGroupAggregates False whether to show margins giving the aggregation for subsets of the groups »
范例
打开所有单元关闭所有单元基本范例 (2)
Scope (2)
Options (1)
IncludeGroupAggregates (1)
Take a table of data about penguins in the Palmer Archipelago:
Create pivot table to count the number of penguins per species and per island:
Use IncludeGroupAggregates to get the values of the function for the whole category across the rows and across the columns:
Applications (2)
Transplant Patients (1)
The data contains information on kidney transplant patients—time in days to death or on-study time since transplant at the given age:
Show the mean survival time in years split according to gender and race:
Show group aggregate summaries:
Show the mean survival time in years split according to alive status versus gender and race:
Properties & Relations (2)
Perform a PivotTable operation with a given list of aggregation functions:
This is equivalent to using AggregateRows with the same aggregations, followed by PivotToColumns to restructure the result:
The group aggregate summaries can be obtained as follows:
Compare to the group aggregation row and columns of this result:
Use RowKey to access group aggregate values:
文本
Wolfram Research (2025),PivotTable,Wolfram 语言函数,https://reference.wolfram.com/language/ref/PivotTable.html.
CMS
Wolfram 语言. 2025. "PivotTable." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/PivotTable.html.
APA
Wolfram 语言. (2025). PivotTable. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/PivotTable.html 年