Skip to main content

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. Regex objects can be used within the mapping to do pattern based renaming. Can also be supplied as a Table either 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 the on_problems settings. Defaults to True.
  • 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 columns is not in the input table, a Missing_Input_Columns is raised as an error, unless error_on_missing_columns is set to False, in which case the problem is reported according to the on_problems setting.
  • If any of the new names are invalid, an Invalid_Column_Names error is raised.
  • Other problems are reported according to the on_problems setting:
    • If a column is matched by two selectors resulting in a different name mapping, a Ambiguous_Column_Rename.
    • If in By_Position mode and more names than columns are provided, a Too_Many_Column_Names_Provided.
    • If any of the new names clash either with existing names or each other, a Duplicate_Output_Column_Names.