PivotFromColumns
PivotFromColumns[tab,cols{vars, vals}]
pivots to make a longer table with the columns cols replaced by two columns, vars containing the column names and vals containing the values from cols.
PivotFromColumns[tab,{prule1,prule2,…}]
pivots on multiple sets of columns specified by the pivot rules prulei.
更多信息
- PivotFromColumns is also known as gather and pivot longer.
- PivotFromColumns is typically used as a structural data-cleaning operation, where some columns are not variables but values of variables. PivotFromColumns pivots the role of variable and value by gathering the values from several columns, making the resulting tabular object longer.
- PivotToColumns is effectively the inverse of PivotFromColumns.
- PivotFromColumns takes the same options as Tabular.
范例
打开所有单元关闭所有单元基本范例 (1)
Pivot the keys of several columns into a column called "day" and their values into a column called "temp":
PivotToColumns can then be used to separate the columns for high and low temperatures:
Scope (2)
Take a Tabular object of populations of the G7 countries:
Pivot the country column names and population values into new columns "Country" and "Population":
Take tabular data of weekend temperature and sun information:
Pivot the "high" and "low" columns of temperature values:
Pivot "sunrise" with "high" and "sunset" with "low":
Alternatively, pivot "sunrise" with "low" and "sunset" with "high":
When the sets of different value columns have different lengths, both names and values are filled in with Missing:
Applications (2)
Create a Tabular object with measurements of soil pH at three depth levels of 0, 30 and 80 meters:
Pivot the depth values to create "depth" and "pH" columns and then sort by depth:
Take rectangular data organized by years and months:
Pivot the month columns into a "month" column and "data" column:
Properties & Relations (3)
Take tabular data of weekend temperature and sun information:
Pivot two sets of columns at the same time:
Changing the order of the rules will change the order of columns:
Take tabular data of weekend temperature and sun information:
Simultaneous pivoting is not equivalent to using the same rules in consecutive separate steps:
Use PivotFromColumns on a Tabular object:
PivotToColumns is effectively the inverse of PivotFromColumns:
Remove the common part in ExtendedKey to recover the original object:
文本
Wolfram Research (2025),PivotFromColumns,Wolfram 语言函数,https://reference.wolfram.com/language/ref/PivotFromColumns.html.
CMS
Wolfram 语言. 2025. "PivotFromColumns." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/PivotFromColumns.html.
APA
Wolfram 语言. (2025). PivotFromColumns. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/PivotFromColumns.html 年