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(pa.String),
...     "probability": pa.Column(pa.Float)
... })
>>>
>>> print(
...     example_schema.rename_columns({
...         "category": "categories",
...         "probability": "probabilities"
...     })
... )
DataFrameSchema(
    columns={
        "categories": "<Schema Column: 'categories' type=str>",
        "probabilities": "<Schema Column: 'probabilities' type=float>"
    },
    checks=[],
    index=None,
    coerce=False,
    strict=False
)

See also

update_column()