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.

更多信息

范例

打开所有单元关闭所有单元

基本范例  (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:

Find mean pH for each depth:

Take rectangular data organized by years and months:

Pivot the month columns into a "month" column and "data" column:

It is now easy to compute yearly means:

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.

文本

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 年

BibTeX

@misc{reference.wolfram_2025_pivotfromcolumns, author="Wolfram Research", title="{PivotFromColumns}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/PivotFromColumns.html}", note=[Accessed: 15-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_pivotfromcolumns, organization={Wolfram Research}, title={PivotFromColumns}, year={2025}, url={https://reference.wolfram.com/language/ref/PivotFromColumns.html}, note=[Accessed: 15-January-2025 ]}