ConstructColumns
ConstructColumns[tab,{col1,col2,…}]
constructs new tabular data formed by extracting columns coli from the tabular data tab.
ConstructColumns[tab,{ncol1f1,ncol2f2,…}]
returns new tabular data with columns ncoli constructed by applying the functions fi to each row of tab.
ConstructColumns[cspec]
represents an operator form of ConstructColumns that can be applied to tabular data.
Details and Options
- ConstructColumns is also known as create columns.
- ConstructColumns is typically used to extract or construct new columns of data, dropping everything that is not specified.
- Possible forms of tabular data tab include:
-
Tabular[…] type-consistent tabular data Dataset[…] general hierarchical data {assoc1,assoc2,…} list of associations with common keys matrix matrix of values - A mixed column specification such as {…,col,ncolf,…} indicates that the new column ncol must be placed after column col in the result. The column col is referred to as the anchor column for insertion of new columns.
- For anonymous tabular data tab, ConstructColumns[tab,{f1,f2,…}] returns new tabular data with column i constructed by applying functions fi to each row of tab.
- Functions fi are applied to individual rows of the input tabular data tab, with the row being an association <col1val1,… > if tab has column keys or a list {val1,…} if tab does not have column keys.
- ConstructColumns[tab,col] is equivalent to ConstructColumns[tab,{col}].
- ConstructColumns[cspec][tab] is equivalent to ConstructColumns[tab,cspec].
Examples
open allclose allBasic Examples (2)
Construct the difference of two columns "a" and "b" in a new column "c":
Include the column "a" in the result before the new column:
Include it after the new column:
Extract a single column from a Tabular object:
Scope (13)
Extraction (7)
Extract one column from a Tabular object:
This is equivalent to using a list with only that column:
Part extraction returns different results using "date" or {"date"}:
Extract several columns from a Tabular object:
This is equivalent to using Part extraction:
ConstructColumns preserves the column order of the original, but Part uses the new given order:
Use functional notation to extract columns:
Using existing column names preserves order, but using new keys allows column reordering:
Use the operator form of ConstructColumns to extract columns:
Extract columns from a Dataset object:
Extract a column from a list of associations:
Missing entries in any of the rows will be reported as Missing expressions:
Extract columns from a matrix using a list of functions in the second argument of ConstructColumns:
Part extraction provides a more direct syntax:
Creation (3)
Take a Tabular object with three columns:
Construct another Tabular object with two columns computed using given functions:
The functions receive each row as an association:
Take a Tabular object with three columns and no column keys:
Construct another Tabular object with columns computed as given by a list of functions of the rows:
Use Apply[f] instead of f to handle each column with a separate numbered slot:
Columnwise Operations (3)
Use ColumnwiseValue to subtract the mean of a column from its values:
This is equivalent to first computing the mean value once and then subtracting it in every row:
Find which elements in a column are above the median in this Tabular object:
The median value is computed once at the beginning and then used during the computation at each row:
Use ColumnwiseThread to compute a vector-valued transformation of an entire column:
With ColumnwiseValue, you get the same list for each row:
Applications (2)
Weather Data (1)
Weather data from JFK airport in C, mbar and km/h:
Create a Tabular object with new column and few selected columns from the original data:
Ozone Readings (1)
Take a Tabular object with data of monthly ozone readings for Los Angeles:
Compute descriptive statistics for each year:
Use InsertColumns to reinsert the "Year" column:
Properties & Relations (2)
ConstructColumns is a complementary operation to DeleteColumns:
ConstructColumns keeps only the listed columns:
TransformColumns keeps all the columns not being transformed:
Text
Wolfram Research (2025), ConstructColumns, Wolfram Language function, https://reference.wolfram.com/language/ref/ConstructColumns.html.
CMS
Wolfram Language. 2025. "ConstructColumns." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ConstructColumns.html.
APA
Wolfram Language. (2025). ConstructColumns. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ConstructColumns.html