RenamePlan#

class scikitplot.feature_selection.RenamePlan(pairs)[source]#

A complete, frozen old -> new name mapping.

Parameters:
pairstuple of (str, str)

One pair per input column, in column order.

Parameters:

pairs (tuple[tuple[str, str], ...])

See also

FeatureRenamer

Applies a plan inside a pipeline.

FeatureSchema.rename

Renames a fitted schema, keeping aliases.

Examples

>>> from scikitplot.feature_selection import RenamePlan
>>> RenamePlan.build(["a", "b", "c"], "col-{index}", start=1).names_out
['col-1', 'col-2', 'col-3']
>>> RenamePlan.build(["a", "b"], {"a": "alpha"}).names_out
['alpha', 'b']
>>> RenamePlan.build(["x", "y"], str.upper).mapping
{'x': 'X', 'y': 'Y'}
apply(X)[source]#

Rename the columns of X, which must equal names_in in order.

Parameters:
Xpandas.DataFrame

Frame to rename.

Returns:
pandas.DataFrame

A new frame with renamed columns (data not copied where pandas avoids it).

Raises:
ValueError

If the columns differ from the plan’s inputs.

Parameters:

X (DataFrame)

Return type:

DataFrame

classmethod build(names, rule, *, start=0, on_collision='raise', on_missing='raise')[source]#

Apply rule to names once and freeze the result.

Parameters:
namessequence of str

Input column names (unique).

rulemapping, sequence of str, callable, str or None

See the module documentation. None keeps every name.

startint, default=0

First {index} of a template.

on_collision{“raise”, “suffix”}, default=”raise”

Handling of duplicate new names.

on_missing{“raise”, “ignore”}, default=”raise”

Handling of mapping keys that are not in names.

Returns:
RenamePlan

The plan.

Raises:
ValueError

For a list of the wrong length, an unknown template field, an unknown mapping key, an empty new name or a refused collision.

TypeError

For a rule of an unsupported type or a callable returning a non-string.

Parameters:
Return type:

RenamePlan

property changed: dict[str, str]#

Only the columns whose name changes.

Type:

dict

classmethod from_dict(data)[source]#

Rebuild a plan from to_dict output.

Parameters:
datamapping

Stored form.

Returns:
RenamePlan

The plan.

Parameters:

data (Mapping[str, Any])

Return type:

RenamePlan

inverse()[source]#

Return the plan that undoes this one.

Returns:
RenamePlan

new -> old for every column.

Return type:

RenamePlan

property mapping: dict[str, str]#

Old name to new name, every column included.

Type:

dict

property names_in: list[str]#

Input names, in order.

Type:

List of str

property names_out: list[str]#

Output names, in order.

Type:

List of str

pairs: tuple[tuple[str, str], ...][source]#
to_dict()[source]#

Return {"pairs": [[old, new], ...]}.

Return type:

dict[str, Any]