y.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.rename  #

DataFrame.  rename  (  _ mapper  =  None  _ , _ *  _ , _ index  =  None  _ , _
columns  =  None  _ , _ axis  =  None  _ , _ copy  =  None  _ , _ inplace  =
False  _ , _ level  =  None  _ , _ errors  =  'ignore'  _ )  [ [source]
](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L5636-L5776) #

    

Rename columns or 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.

See the [ user guide  ](../../user_guide/basics.html#basics-rename) for more.

Parameters  :

    

**mapper** dict-like or function

    

Dict-like or function transformations to apply to that axisâ values. Use
either ` mapper  ` and ` axis  ` to specify the axis to target with ` mapper
` , or ` index  ` and ` columns  ` .

**index** dict-like or function

    

Alternative to specifying axis ( ` mapper,  axis=0  ` is equivalent to `
index=mapper  ` ).

**columns** dict-like or function

    

Alternative to specifying axis ( ` mapper,  axis=1  ` is equivalent to `
columns=mapper  ` ).

**axis** {0 or âindexâ, 1 or âcolumnsâ}, default 0

    

Axis to target with ` mapper  ` . Can be either the axis name (âindexâ,
âcolumnsâ) or number (0, 1). The default is âindexâ.

**copy** bool, default True

    

Also copy underlying data.

Note

The  copy  keyword will change behavior in pandas 3.0. [ Copy-on-Write
](https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html) will be
enabled by default, which means that all methods with a  copy  keyword will
use a lazy copy mechanism to defer the copy and ignore the  copy  keyword. The
copy  keyword will be removed in a future version of pandas.

You can already get the future behavior and improvements through enabling copy
on write ` pd.options.mode.copy_on_write  =  True  `

**inplace** bool, default False

    

Whether to modify the DataFrame rather than creating a new one. If True then
value of copy is ignored.

**level** int or level name, default None

    

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

**errors** {âignoreâ, âraiseâ}, default âignoreâ

    

If âraiseâ, raise a  KeyError  when a dict-like  mapper  ,  index  , or
columns  contains labels that are not present in the Index being transformed.
If âignoreâ, existing keys will be renamed and extra keys will be ignored.

Returns  :

    

DataFrame or None

    

DataFrame with the renamed axis labels or None if ` inplace=True  ` .

Raises  :

    

KeyError

    

If any of the labels is not found in the selected axis and
âerrors=âraiseââ.

See also

[ ` DataFrame.rename_axis  `
](pandas.DataFrame.rename_axis.html#pandas.DataFrame.rename_axis
"pandas.DataFrame.rename_axis")

    

Set the name of the axis.

Examples

` DataFrame.rename  ` supports two calling conventions

  * ` (index=index_mapper,  columns=columns_mapper,  ...)  `

  * ` (mapper,  axis={'index',  'columns'},  ...)  `

We _highly_ recommend using keyword arguments to clarify your intent.

Rename columns using a mapping:

    
    
    >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
    >>> 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: "x", 1: "y", 2: "z"})
       A  B
    x  1  4
    y  2  5
    z  3  6
    

Cast index labels to a different type:

    
    
    >>> df.index
    RangeIndex(start=0, stop=3, step=1)
    >>> df.rename(i