mindspore.dataset.Dataset.rename

View Source On Gitee
Dataset.rename(input_columns, output_columns)[source]

Rename the columns in input datasets.

Parameters
  • input_columns (Union[str, list[str]]) – List of names of the input columns.

  • output_columns (Union[str, list[str]]) – List of names of the output columns.

Returns

Dataset, a new dataset with the above operation applied.

Examples

>>> import mindspore.dataset as ds
>>> input_columns = ["input_col1", "input_col2", "input_col3"]
>>> output_columns = ["output_col1", "output_col2", "output_col3"]
>>>
>>> # Create a dataset with 3 columns
>>> dataset = ds.GeneratorDataset([(1, 2, 3), (3, 4, 5), (5, 6, 7)], column_names=input_columns)
>>>
>>> # Rename "input_col1" to "output_col1", "input_col2" to "output_col2", "input_col3" to "output_col3"
>>> dataset = dataset.rename(input_columns=input_columns, output_columns=output_columns)