pandas.DataFrame.rename
pandas 3.1.1 · DataFrame · method
Change labels using a mapping or callable. A Series can also receive a new name.
Call syntax
DataFrame.rename(…) Full signature
DataFrame.rename(
mapper=None,
*,
index=None,
columns=None,
axis=None,
copy=…,
inplace=…,
level=None,
errors='ignore',
)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
mapper |
Optional Positional or keyword Default None |
dict-like or function Provide a dictionary or callable that maps input values or labels. |
index |
Optional Keyword only Default None |
dict-like or function Supply row labels or control how existing row labels are used. |
columns |
Optional Keyword only Default None |
dict-like or function Supply column labels or control how columns are handled. |
axis |
Optional Keyword only Default None |
{0 or 'index', 1 or 'columns'} Choose which axis the operation acts on. The accepted axis labels depend on the receiver. |
copy |
Optional Keyword only |
bool Control whether data is copied where the API supports that choice. |
inplace |
Optional Keyword only |
bool Choose whether to change the existing object. Where supported, an in-place call typically returns None. |
level |
Optional Keyword only Default None |
int or level name Choose an index level by name or integer position. |
errors |
Optional Keyword only Default 'ignore' |
{'ignore', 'raise'} Choose how to handle invalid input or failed operations. The available options depend on the API. |
Returns
DataFrame or None