cudf.DataFrame.rename#

DataFrame.rename(mapper=None, index=None, columns=None, axis=0, copy=True, inplace=False, level=None, errors='ignore')[source]#

Alter column and index labels.

Function / dict values must be unique (1-to-1). Labels not contained in a dict / Series will be left as-is. Extra labels listed don’t throw an error.

DataFrame.rename supports two calling conventions:
  • (index=index_mapper, columns=columns_mapper, ...)

  • (mapper, axis={0/'index' or 1/'column'}, ...)

We highly recommend using keyword arguments to clarify your intent.

Parameters:
mapperdict-like or function, default None

optional dict-like or functions transformations to apply to the index/column values depending on selected axis.

indexdict-like, default None

Optional dict-like transformations to apply to the index axis’ values. Does not support functions for axis 0 yet.

columnsdict-like or function, default None

optional dict-like or functions transformations to apply to the columns axis’ values.

axisint, default 0

Axis to rename with mapper. 0 or ‘index’ for index 1 or ‘columns’ for columns

copyboolean, default True

Also copy underlying data

inplaceboolean, default False

Return new DataFrame. If True, assign columns without copy

levelint or level name, default None

In case of a MultiIndex, only rename labels in the specified level.

errors{‘raise’, ‘ignore’, ‘warn’}, default ‘ignore’

Only ‘ignore’ supported Control raising of exceptions on invalid data for provided dtype.

  • raise : allow exceptions to be raised

  • ignore : suppress exceptions. On error return original object.

  • warn : prints last exceptions as warnings and return original object.

Returns:
DataFrame

Examples

>>> import cudf
>>> df = cudf.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
>>> df
   A  B
0  1  4
1  2  5
2  3  6

Rename columns using a mapping:

>>> df.rename(columns={"A": "a", "B": "c"})
   a  c
0  1  4
1  2  5
2  3  6

Rename index using a mapping:

>>> df.rename(index={0: 10, 1: 20, 2: 30})
    A  B
10  1  4
20  2  5
30  3  6

Pandas Compatibility Note

pandas.DataFrame.rename()

  • Not Supporting: level

Rename will not overwrite column names. If a list with duplicates is passed, column names will be postfixed with a number.