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.
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 TimeSeries[…] collection of sampled time-value pairs EventSeries[…] series of temporal events {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 all close allBasic Examples (2)
Construct the difference of two columns "a" and "b" in a new column "c":
tab = Tabular[{{2, 2.78}, {1, 3.14}, {3, 1.68}}, {"a", "b"}]ConstructColumns[tab, "c" -> Function[#a - #b]]Include the column "a" in the result before the new column:
ConstructColumns[tab, {"a", "c" -> (#a - #b&)}]Include it after the new column:
ConstructColumns[tab, {"c" -> (#a - #b&), "a"}]Extract a single column from a Tabular object:
Tabular[{{1, 2}, {3, 4}, {5, 6}}, {"a", "b"}]ConstructColumns[%, "b"]Scope (13)
Extraction (7)
Extract one column from a Tabular object:
tab = Tabular[{{-1, Yesterday}, {0, Today}, {1, Tomorrow}}, {"n", "date"}]ConstructColumns[tab, "date"]This is equivalent to using a list with only that column:
ConstructColumns[tab, {"date"}]Part extraction returns different results using "date" or {"date"}:
tab[[All, "date"]]tab[[All, {"date"}]]Extract several columns from a Tabular object:
tab = Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}]ConstructColumns[tab, {"a", "c"}]This is equivalent to using Part extraction:
tab[[All, {"a", "c"}]]ConstructColumns preserves the column order of the original, but Part uses the new given order:
ConstructColumns[tab, {"c", "a"}]tab[[All, {"c", "a"}]]Use functional notation to extract columns:
tab = Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}]ConstructColumns[tab, {"a" -> Function[#a], "C" -> Function[#c]}]Using existing column names preserves order, but using new keys allows column reordering:
ConstructColumns[tab, {"c" -> Function[#c], "a" -> Function[#a]}]ConstructColumns[tab, {"C" -> Function[#c], "A" -> Function[#a]}]Use the operator form of ConstructColumns to extract columns:
Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}]%//ConstructColumns[{"b", "c"}]Extract columns from a Dataset object:
ds = Dataset[{<|"a" -> 1, "b" -> 2, "c" -> 3|>, <|"a" -> 4, "b" -> 5, "c" -> 6|>}]ConstructColumns[ds, "b"]ConstructColumns[ds, {"a", "c"}]Extract a column from a list of associations:
assocs = {<|"a" -> 1, "b" -> 2|>, <|"a" -> 3, "c" -> 4|>};ConstructColumns[assocs, "a"]Missing entries in any of the rows will be reported as Missing expressions:
ConstructColumns[assocs, "b"]ConstructColumns[assocs, {"a", "c"}]Extract columns from a matrix using a list of functions in the second argument of ConstructColumns:
MatrixForm[mat = {{1, 2, 3, 4}, {5, 6, 7, 8}}]ConstructColumns[mat, {First, Extract[3]}]//MatrixFormConstructColumns[mat, {#[[1]]&, #[[3]]&}]//MatrixFormConstructColumns[mat, {Apply[#1&], Apply[#3&]}]//MatrixFormPart extraction provides a more direct syntax:
mat[[All, {1, 3}]]//MatrixFormCreation (3)
Take a Tabular object with three columns:
tab = Tabular[{{1, 2, 3}, {4, 5, 6}}, {"a", "b", "c"}]Construct another Tabular object with two columns computed using given functions:
ConstructColumns[tab, {"b+a" -> Function[#b + #a], "b-a" -> Function[#b - #a]}]The functions receive each row as an association:
ConstructColumns[tab, {"total" -> Total, "echo" -> Echo}]Take a Tabular object with three columns and no column keys:
tab = Tabular[{{1, 2, 3}, {4, 5, 6}}]Construct another Tabular object with columns computed as given by a list of functions of the rows:
ConstructColumns[tab, {#[[2]] + #[[1]]&, #[[2]] - #[[1]]&}]Use Apply[f] instead of f to handle each column with a separate numbered slot:
ConstructColumns[tab, {Apply[#2 + #1&], Apply[#2 - #1&]}]The functions receive each row as a list of values:
ConstructColumns[tab, {Total, Echo}]Create a new column from a list of associations:
assocs = {<|"a" -> 1, "b" -> 2|>, <|"a" -> 3, "b" -> 4|>};ConstructColumns[assocs, "c" -> Function[#a ^ 2]]Columnwise Operations (3)
Use ColumnwiseValue to subtract the mean of a column from its values:
tab = ToTabular[<|"c" -> {3.71, -2.7, -5.29, 9.33, 6.26}|>, "Columns"]ConstructColumns[tab, "c-μ" -> (#c - ColumnwiseValue[Mean[#c]]&)]This is equivalent to first computing the mean value once and then subtracting it in every row:
mean = Mean[tab[[All, 1]]]ConstructColumns[tab, "c-μ" -> (#c - mean&)]Find which elements in a column are above the median in this Tabular object:
ToTabular[<|"c" -> {4.24, 1.14, 7.38, -6.74, 7.5}|>, "Columns"]The median value is computed once at the beginning and then used during the computation at each row:
ConstructColumns[%, "above median" -> (Echo[#c > ColumnwiseValue[Echo[Median[#c], "median:"]], #RowNumber]&)]Use ColumnwiseThread to compute a vector-valued transformation of an entire column:
tab = ToTabular[<|"v" -> {2.07, -0.75, 4.16, 7.28, 8.63, 7.93}|>, "Columns"];
ConstructColumns[tab, "z" -> (ColumnwiseThread[Accumulate[#v]]&)]With ColumnwiseValue, you get the same list for each row:
ConstructColumns[tab, "zlist" -> (ColumnwiseValue[Accumulate[#v]]&)]Applications (3)
Weather Data (1)
Weather data from JFK airport in C, mbar and km/h:
data = Tabular[IconizedObject[«JFK weather»]]Remove the rows containing at least one missing value:
data1 = Discard[data, Count[#, _Missing] > 0&]Define the wind chill factor (adapt the formula to the units of data):
chill[t_, v_] := If[t > 10 || v < 5, t, 13.12 + 0.6215 * t + (0.3965 * t - 11.37) * (v ^ 0.16), Missing[]];Create a Tabular object with a new column and a few selected columns from the original data:
ConstructColumns[data1, {"date", "temperature", "wind_chill" -> Function[chill[#temperature, #"wind_speed"]]}]DateListPlot[% -> {{"date", "temperature"}, {"date", "wind_chill"}}, PlotLegends -> {"temperature", "wind_chill"}]Ozone Readings (1)
Take a Tabular object with data of monthly ozone readings for Los Angeles:
tab = ResourceData["Sample Tabular Data: Los Angeles Ozone"]Compute descriptive statistics for each year:
With[{noYear = KeyDrop["Year"]}, ConstructColumns[tab, {"Year", "Mean" -> Mean @* noYear, "SD" -> StandardDeviation @* noYear, "Q1" -> (Quantile[#, .25]& @* noYear), "Median" -> Median @* noYear, "Q3" -> (Quantile[#, .75]& @* noYear)}]]Plot the quartiles yearly series:
ListLinePlot[% -> {{"Year", "Median"}, {"Year", "Q1"}, {"Year", "Q3"}}, PlotStyle -> {Automatic, LightGray, LightGray}, Filling -> 2 -> {3}, AxesLabel -> {"year", "pphm"}, PlotLegends -> {"Median", "Q1-Q3"}]Tree Data (1)
Get the data of a tree census in New York City:
tab = ResourceData["Sample Tabular Data: NYC Trees"]ColumnKeys[tab]Use ConstructColumns to combine "latitude" and "longitude" columns into one column of GeoPosition objects:
ConstructColumns[tab, "geoposition" -> Function[GeoPosition[{#latitude, #longitude}]]]Plot the first 1000 tree locations:
GeoGraphics[Point[Normal[%[ ;; 1000, "geoposition"]]]]Properties & Relations (2)
ConstructColumns is a complementary operation to DeleteColumns:
tab = Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["a" -> Association["ElementType" -> "Integer64"],
"b" -> Association["ElementType" -> "Integer64"],
"c" -> Association["ElementType" -> "Integer64"]], "KeyColumns" -> None,
"Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{5, 6, 9}, {}, None}, "ElementType" -> "Integer64"]],
TabularColumn[Association["Data" -> {{2, 1, 2}, {}, None}, "ElementType" -> "Integer64"]],
TabularColumn[Association["Data" -> {{3, 7, 5}, {}, None}, "ElementType" ->
"Integer64"]]}}]]]];ConstructColumns[tab, "b"]DeleteColumns[tab, {"a", "c"}]ConstructColumns keeps only the listed columns:
tab = Tabular[Association["RawSchema" -> Association["ColumnProperties" ->
Association["a" -> Association["ElementType" -> "Integer64"],
"b" -> Association["ElementType" -> "Integer64"],
"c" -> Association["ElementType" -> "Integer64"]], "KeyColumns" -> None,
"Backend" -> "WolframKernel"], "Options" -> {},
"BackendData" -> Association["ColumnData" -> DataStructure["ColumnTable",
{{TabularColumn[Association["Data" -> {{1, 3, 5}, {}, None}, "ElementType" -> "Integer64"]],
TabularColumn[Association["Data" -> {{2, 4, 6}, {}, None}, "ElementType" -> "Integer64"]],
TabularColumn[Association["Data" -> {{3, 7, 11}, {}, None}, "ElementType" ->
"Integer64"]]}}]]]];ConstructColumns[tab, "b" -> Function[#b * 2]]TransformColumns keeps all the columns not being transformed:
TransformColumns[tab, "b" -> Function[#b * 2]]Related Guides
Text
Wolfram Research (2025), ConstructColumns, Wolfram Language function, https://reference.wolfram.com/language/ref/ConstructColumns.html (updated 2026).
CMS
Wolfram Language. 2025. "ConstructColumns." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. 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
BibTeX
@misc{reference.wolfram_2026_constructcolumns, author="Wolfram Research", title="{ConstructColumns}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/ConstructColumns.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_constructcolumns, organization={Wolfram Research}, title={ConstructColumns}, year={2026}, url={https://reference.wolfram.com/language/ref/ConstructColumns.html}, note=[Accessed: 13-June-2026]}