ReorderColumnsOp

class ReorderColumnsOp(parameters)[source]

Reorder columns in a columnar file.

Required parameters:
  • column_order (list): The names of the columns to be reordered.

  • ignore_missing (bool): If False and a column in column_order is not in df, skip the column.

  • keep_others (bool): If True, columns not in column_order are placed at end.

Methods

ReorderColumnsOp.__init__(parameters)

Constructor for reorder columns operation.

ReorderColumnsOp.do_op(dispatcher, df, name)

Reorder columns as specified in event dictionary.

ReorderColumnsOp.validate_input_data(parameters)

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

Attributes

ReorderColumnsOp.NAME

ReorderColumnsOp.PARAMS

ReorderColumnsOp.__init__(parameters)[source]

Constructor for reorder columns operation.

Parameters:

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

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

Reorder columns as specified in event 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:

ValueError

  • When ignore_missing is false and column_order has columns not in the data.

static ReorderColumnsOp.validate_input_data(parameters)[source]

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

ReorderColumnsOp.NAME = 'reorder_columns'
ReorderColumnsOp.PARAMS = {'additionalProperties': False, 'properties': {'column_order': {'description': 'A list of column names in the order you wish them to be.', 'items': {'type': 'string'}, 'minItems': 1, 'type': 'array', 'uniqueItems': True}, 'ignore_missing': {'description': "If true, ignore column_order columns that aren't in file, otherwise error.", 'type': 'boolean'}, 'keep_others': {'description': 'If true columns not in column_order are placed at end, otherwise ignored.', 'type': 'boolean'}}, 'required': ['column_order', 'ignore_missing', 'keep_others'], 'type': 'object'}