larray.Axis.replace

Axis.replace(old, new=None) Axis[source]

Return a new axis with some labels replaced.

Parameters
oldany scalar (bool, int, str, …), tuple/list/array of scalars, or a mapping.

the label(s) to be replaced. Old can be a mapping {old1: new1, old2: new2, …}

newany scalar (bool, int, str, …) or tuple/list/array of scalars, optional

the new label(s). This is argument must not be used if old is a mapping.

Returns
Axis

a new Axis with the old labels replaced by new labels.

Examples

>>> sex = Axis('sex=M,F')
>>> sex
Axis(['M', 'F'], 'sex')
>>> sex.replace('M', 'Male')
Axis(['Male', 'F'], 'sex')
>>> sex.replace({'M': 'Male', 'F': 'Female'})
Axis(['Male', 'Female'], 'sex')
>>> sex.replace(['M', 'F'], ['Male', 'Female'])
Axis(['Male', 'Female'], 'sex')