RenameColumnsOp

class RenameColumnsOp(parameters)[source]

Rename columns in a tabular file.

Required remodeling parameters:
  • column_mapping (dict): The names of the columns to be renamed with values to be remapped to.

  • ignore_missing (bool): If true, the names in column_mapping that are not columns and should be ignored.

Methods

RenameColumnsOp.__init__(parameters)

Constructor for rename columns operation.

RenameColumnsOp.do_op(dispatcher, df, name)

Rename columns as specified in column_mapping dictionary.

RenameColumnsOp.validate_input_data(parameters)

Additional validation required of operation parameters not performed by JSON schema validator.

Attributes

RenameColumnsOp.NAME

RenameColumnsOp.PARAMS

RenameColumnsOp.__init__(parameters)[source]

Constructor for rename columns operation.

Parameters:

parameters (dict) – Dictionary with the parameter values for required and optional parameters

RenameColumnsOp.do_op(dispatcher, df, name, sidecar=None)[source]

Rename columns as specified in column_mapping dictionary.

Parameters:
  • dispatcher (Dispatcher) – Manages the operation I/O.

  • df (DataFrame) – The DataFrame to be remodeled.

  • name (str) – Unique identifier for the dataframe – often the original file path.

  • sidecar (Sidecar or file-like) – Not needed for this operation.

Returns:

A new dataframe after processing.

Return type:

Dataframe

Raises:

KeyError

  • When ignore_missing is False and column_mapping has columns not in the data.

static RenameColumnsOp.validate_input_data(parameters)[source]

Additional validation required of operation parameters not performed by JSON schema validator.

RenameColumnsOp.NAME = 'rename_columns'
RenameColumnsOp.PARAMS = {'additionalProperties': False, 'properties': {'column_mapping': {'description': 'Mapping between original column names and their respective new names.', 'minProperties': 1, 'patternProperties': {'.*': {'type': 'string'}}, 'type': 'object'}, 'ignore_missing': {'description': "If true ignore column_mapping keys that don't correspond to columns, otherwise error.", 'type': 'boolean'}}, 'required': ['column_mapping', 'ignore_missing'], 'type': 'object'}