RenameColumns

RenameColumns[tab,{col1newcol1,}]

renames column coli to newcoli in a Tabular object tab.

RenameColumns[tab,{newcol1,newcol2,}]

renames column i to newcoli in tab.

RenameColumns[renamings]

represents an operator form of RenameColumns that can be applied to a Tabular object.

Details

  • RenameColumns is typically used to change the names used for columns, e.g. to avoid name conflicts or for clarity of communication. It can also be used to attach column keys to a Tabular object without them.
  • Possible column specifications coli in coli include:
  • name or Key[name]or ExtendedKey[]column name
    indinteger column index
  • If RenameColumns[tab,{newcol1,newcol2,}] does not specify enough new column keys, then the string "Column4" will be used for the fourth column, and similarly for the rest.
  • RenameColumns[tab,None] removes the column keys of tab.
  • RenameColumns[tab,colnewcol] is equivalent to RenameColumns[tab,{colnewcol}].
  • RenameColumns[renamings][tab] is equivalent to RenameColumns[tab,renamings].

Examples

open allclose all

Basic Examples  (2)

Rename two columns of a Tabular object:

Alternatively, use indices to specify which columns to rename:

Rename the first two columns of a Tabular object:

Scope  (3)

Take a Tabular object:

Rename some of its columns by using rules oldkeynewkey:

Alternatively, use indices on the left-hand side of the rules:

Use a mixture of notations:

Take a Tabular object without column keys:

Add respective column keys, using "ColumnN" for the ^(th) column if not specified:

Use RenameColumns[tab,None] to remove all column keys from a Tabular object:

Properties & Relations  (4)

Renaming rules that do not correspond to any existing column are ignored:

With repeated renamings of the same column key, only the last one is used:

New names and old names can overlap, effectively implementing a permutation of column names:

A permutation of the columns themselves can be implemented with Part:

Tabular[tab,newcols] is equivalent to using RenameColumns to rename all column keys:

Possible Issues  (1)

Take a Tabular object:

Each rule is interpreted here as a column renaming, not as a new column name:

Use another rule to have rules as column keys:

However, using rules in keys requires a more complicated Slot construction, so it is not recommended:

Wolfram Research (2025), RenameColumns, Wolfram Language function, https://reference.wolfram.com/language/ref/RenameColumns.html.

Text

Wolfram Research (2025), RenameColumns, Wolfram Language function, https://reference.wolfram.com/language/ref/RenameColumns.html.

CMS

Wolfram Language. 2025. "RenameColumns." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RenameColumns.html.

APA

Wolfram Language. (2025). RenameColumns. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RenameColumns.html

BibTeX

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

BibLaTeX

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