pandera.schemas.DataFrameSchema.rename_columns

DataFrameSchema.rename_columns(rename_dict)[source]

Rename columns using a dictionary of key-value pairs.

Parameters

rename_dict (Dict[str, str]) – dictionary of ‘old_name’: ‘new_name’ key-value pairs.

Return type

DataFrameSchema

Returns

DataFrameSchema (copy of original)

Raises

SchemaInitError if column not in the schema.

Example

To rename a column or set of columns, pass a dictionary of old column names and new column names, similar to the pandas DataFrame method.

>>> import pandera as pa
>>>
>>> example_schema = pa.DataFrameSchema({
...     "category" : pa.Column(str),
...     "probability": pa.Column(float)
... })
>>>
>>> print(
...     example_schema.rename_columns({
...         "category": "categories",
...         "probability": "probabilities"
...     })
... )
<Schema DataFrameSchema(
    columns={
        'categories': <Schema Column(name=categories, type=DataType(str))>
        'probabilities': <Schema Column(name=probabilities, type=DataType(float64))>
    },
    checks=[],
    coerce=False,
    dtype=None,
    index=None,
    strict=False
    name=None,
    ordered=False
)>

See also

update_column()