MCPcopy
hub / github.com/pandas-dev/pandas / _transform_index

Method _transform_index

pandas/core/indexes/base.py:6654–6673  ·  view source on GitHub ↗

Apply function to all values found in index. This includes transforming multiindex entries separately. Only apply function to one level of the MultiIndex if level is specified.

(self, func, *, level=None)

Source from the content-addressed store, hash-verified

6652 # TODO: De-duplicate with map, xref GH#32349
6653 @final
6654 def _transform_index(self, func, *, level=None) -> Index:
6655 """
6656 Apply function to all values found in index.
6657
6658 This includes transforming multiindex entries separately.
6659 Only apply function to one level of the MultiIndex if level is specified.
6660 """
6661 if isinstance(self, ABCMultiIndex):
6662 values = [
6663 (
6664 self.get_level_values(i).map(func)
6665 if i == level or level is None
6666 else self.get_level_values(i)
6667 )
6668 for i in range(self.nlevels)
6669 ]
6670 return type(self).from_arrays(values)
6671 else:
6672 items = [func(x) for x in self]
6673 return Index(items, name=self.name, tupleize_cols=False)
6674
6675 def isin(self, values, level: str_t | int | None = None) -> npt.NDArray[np.bool_]:
6676 """

Callers 2

_renameMethod · 0.80

Calls 5

IndexClass · 0.85
get_level_valuesMethod · 0.80
funcFunction · 0.50
mapMethod · 0.45
from_arraysMethod · 0.45

Tested by

no test coverage detected