@@ -984,117 +984,8 @@ def _rename(
984
984
level : Level | None = None ,
985
985
errors : str = "ignore" ,
986
986
) -> NDFrameT | None :
987
- """
988
- Alter axes input function or functions. Function / dict values must be
989
- unique (1-to-1). Labels not contained in a dict / Series will be left
990
- as-is. Extra labels listed don't throw an error. Alternatively, change
991
- ``Series.name`` with a scalar value (Series only).
992
-
993
- Parameters
994
- ----------
995
- %(axes)s : scalar, list-like, dict-like or function, optional
996
- Scalar or list-like will alter the ``Series.name`` attribute,
997
- and raise on DataFrame.
998
- dict-like or functions are transformations to apply to
999
- that axis' values
1000
- copy : bool, default True
1001
- Also copy underlying data.
1002
- inplace : bool, default False
1003
- Whether to return a new {klass}. If True then value of copy is
1004
- ignored.
1005
- level : int or level name, default None
1006
- In case of a MultiIndex, only rename labels in the specified
1007
- level.
1008
- errors : {'ignore', 'raise'}, default 'ignore'
1009
- If 'raise', raise a `KeyError` when a dict-like `mapper`, `index`,
1010
- or `columns` contains labels that are not present in the Index
1011
- being transformed.
1012
- If 'ignore', existing keys will be renamed and extra keys will be
1013
- ignored.
1014
-
1015
- Returns
1016
- -------
1017
- renamed : {klass} (new object)
1018
-
1019
- Raises
1020
- ------
1021
- KeyError
1022
- If any of the labels is not found in the selected axis and
1023
- "errors='raise'".
987
+ # called by Series.rename and DataFrame.rename
1024
988
1025
- See Also
1026
- --------
1027
- NDFrame.rename_axis
1028
-
1029
- Examples
1030
- --------
1031
- >>> s = pd.Series([1, 2, 3])
1032
- >>> s
1033
- 0 1
1034
- 1 2
1035
- 2 3
1036
- dtype: int64
1037
- >>> s.rename("my_name") # scalar, changes Series.name
1038
- 0 1
1039
- 1 2
1040
- 2 3
1041
- Name: my_name, dtype: int64
1042
- >>> s.rename(lambda x: x ** 2) # function, changes labels
1043
- 0 1
1044
- 1 2
1045
- 4 3
1046
- dtype: int64
1047
- >>> s.rename({1: 3, 2: 5}) # mapping, changes labels
1048
- 0 1
1049
- 3 2
1050
- 5 3
1051
- dtype: int64
1052
-
1053
- Since ``DataFrame`` doesn't have a ``.name`` attribute,
1054
- only mapping-type arguments are allowed.
1055
-
1056
- >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
1057
- >>> df.rename(2)
1058
- Traceback (most recent call last):
1059
- ...
1060
- TypeError: 'int' object is not callable
1061
-
1062
- ``DataFrame.rename`` supports two calling conventions
1063
-
1064
- * ``(index=index_mapper, columns=columns_mapper, ...)``
1065
- * ``(mapper, axis={'index', 'columns'}, ...)``
1066
-
1067
- We *highly* recommend using keyword arguments to clarify your
1068
- intent.
1069
-
1070
- >>> df.rename(index=str, columns={"A": "a", "B": "c"})
1071
- a c
1072
- 0 1 4
1073
- 1 2 5
1074
- 2 3 6
1075
-
1076
- >>> df.rename(index=str, columns={"A": "a", "C": "c"})
1077
- a B
1078
- 0 1 4
1079
- 1 2 5
1080
- 2 3 6
1081
-
1082
- Using axis-style parameters
1083
-
1084
- >>> df.rename(str.lower, axis='columns')
1085
- a b
1086
- 0 1 4
1087
- 1 2 5
1088
- 2 3 6
1089
-
1090
- >>> df.rename({1: 2, 2: 4}, axis='index')
1091
- A B
1092
- 0 1 4
1093
- 2 2 5
1094
- 4 3 6
1095
-
1096
- See the :ref:`user guide <basics.rename>` for more.
1097
- """
1098
989
if mapper is None and index is None and columns is None :
1099
990
raise TypeError ("must pass an index to rename" )
1100
991
0 commit comments