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.

更多信息和选项

  • 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
    matrixmatrix 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].

范例

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

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

The functions receive each row as a list of values:

Create a new column from a list of associations:

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:

Remove the rows containing at least one missing value:

Define the wind chill factor (adapt the formula to the units of data):

Create a Tabular object with a new column and a few selected columns from the original data:

Visualize:

Ozone Readings  (1)

Take a Tabular object with data of monthly ozone readings for Los Angeles:

Compute descriptive statistics for each year:

Plot the quartiles yearly series:

Properties & Relations  (2)

ConstructColumns is a complementary operation to DeleteColumns:

Extract one column:

Delete two columns:

ConstructColumns keeps only the listed columns:

TransformColumns keeps all the columns not being transformed:

Wolfram Research (2025),ConstructColumns,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ConstructColumns.html.

文本

Wolfram Research (2025),ConstructColumns,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ConstructColumns.html.

CMS

Wolfram 语言. 2025. "ConstructColumns." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/ConstructColumns.html.

APA

Wolfram 语言. (2025). ConstructColumns. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ConstructColumns.html 年

BibTeX

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

BibLaTeX

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