DB_Table.rename_columns
rename_columnscolumn_mapcase_sensitivityerror_on_missing_columnson_problems
Group: Metadata
Documentation
Returns a new table with the columns renamed based on either a mapping from the old name to the new or a positional list of new names.
Arguments
column_map: Mapping from old column names to new or a vector of new column names to apply by position.Regexobjects can be used within the mapping to do pattern based renaming. Can also be supplied as aTableeither with a single column of new names or two columns with old (first column) and new names (second column).case_sensitivity: Controls whether to be case sensitive when matching column names.error_on_missing_columns: Specifies if a missing input column should result in an error regardless of theon_problemssettings. Defaults toTrue.on_problems: Specifies how to handle problems if they occur, reporting them as warnings by default.
Examples
Rename the "Alpha" column to "Beta"
table.rename_columns (Dictionary.from_vector [["Alpha", "Beta"]])
Rename the last column to "LastColumn"
table.rename_columns (Dictionary.from_vector [[-1, "LastColumn"]])
Rename the "Alpha" column to "Beta" and last column to "LastColumn"
table.rename_columns (Dictionary.from_vector [["Alpha", "Beta"], [-1, "LastColumn"]])
Rename the first column to "FirstColumn"
table.rename_columns ["FirstColumn"]
Add a prefix to all column names.
table.rename_columns (table.columns.map c-> "prefix_" + c.name)
For all columns starting with the prefix name=, replace it with key:.
table.rename_columns (Dictionary.from_vector [["name=(.*)".to_regex, "key:$1"]])
Errors
- If a column in
columnsis not in the input table, aMissing_Input_Columnsis raised as an error, unlesserror_on_missing_columnsis set toFalse, in which case the problem is reported according to theon_problemssetting. - If any of the new names are invalid, an
Invalid_Column_Nameserror is raised. - Other problems are reported according to the
on_problemssetting:- If a column is matched by two selectors resulting in a different
name mapping, a
Ambiguous_Column_Rename. - If in
By_Positionmode and more names than columns are provided, aToo_Many_Column_Names_Provided. - If any of the new names clash either with existing names or each
other, a
Duplicate_Output_Column_Names.
- If a column is matched by two selectors resulting in a different
name mapping, a