@@ -114,8 +114,9 @@ class NDFrame(PandasObject, SelectionMixin):
114
114
'__array_interface__' ]
115
115
_internal_names_set = set (_internal_names )
116
116
_accessors = frozenset ([])
117
- _deprecations = frozenset (['as_blocks' , 'blocks' ,
118
- 'consolidate' , 'convert_objects' , 'is_copy' ])
117
+ _deprecations = frozenset (['as_blocks' , 'add_prefix' , 'add_suffix' ,
118
+ 'blocks' , 'consolidate' , 'convert_objects' ,
119
+ 'is_copy' ])
119
120
_metadata = []
120
121
_is_copy = None
121
122
@@ -801,6 +802,11 @@ def swaplevel(self, i=-2, j=-1, axis=0):
801
802
1 2
802
803
4 3
803
804
dtype: int64
805
+ >>> s.rename('index_{}'.format) # function, changes labels
806
+ index_0 1
807
+ index_1 2
808
+ index_2 3
809
+ dtype: object
804
810
>>> s.rename({1: 3, 2: 5}) # mapping, changes labels
805
811
0 1
806
812
3 2
@@ -824,11 +830,11 @@ def swaplevel(self, i=-2, j=-1, axis=0):
824
830
We *highly* recommend using keyword arguments to clarify your
825
831
intent.
826
832
827
- >>> df.rename(index=str , columns={"A": "a", "B": "c"})
828
- a c
829
- 0 1 4
830
- 1 2 5
831
- 2 3 6
833
+ >>> df.rename(index="index_{}".format , columns={"A": "a", "B": "c"})
834
+ a c
835
+ index_0 1 4
836
+ index_1 2 5
837
+ index_2 3 6
832
838
833
839
>>> df.rename(index=str, columns={"A": "a", "C": "c"})
834
840
a B
@@ -2922,6 +2928,8 @@ def _update_inplace(self, result, verify_is_copy=True):
2922
2928
2923
2929
def add_prefix (self , prefix ):
2924
2930
"""
2931
+ DEPRECATED: Use ``obj.rename(columns=lambda x: 'prefix_'+str(x))`` or similar instead.
2932
+
2925
2933
Concatenate prefix string with panel items names.
2926
2934
2927
2935
Parameters
@@ -2931,12 +2939,19 @@ def add_prefix(self, prefix):
2931
2939
Returns
2932
2940
-------
2933
2941
with_prefix : type of caller
2942
+
2943
+ See Also:
2944
+ ---------
2945
+ rename : Alter axes labels.
2934
2946
"""
2947
+ warnings .warn ("'.add_prefix' is deprecated and will be removed in a "
2948
+ "future version. Use '.rename' instead" , FutureWarning , stacklevel = 2 )
2935
2949
new_data = self ._data .add_prefix (prefix )
2936
2950
return self ._constructor (new_data ).__finalize__ (self )
2937
2951
2938
2952
def add_suffix (self , suffix ):
2939
2953
"""
2954
+ DEPRECATED: Use ``obj.rename(columns=lambda x: 'prefix_'+str(x))`` or similar instead.
2940
2955
Concatenate suffix string with panel items names.
2941
2956
2942
2957
Parameters
@@ -2946,7 +2961,13 @@ def add_suffix(self, suffix):
2946
2961
Returns
2947
2962
-------
2948
2963
with_suffix : type of caller
2964
+
2965
+ See Also:
2966
+ ---------
2967
+ rename : Alter axes labels.
2949
2968
"""
2969
+ warnings .warn ("'add_suffix' is deprecated and will be removed in a "
2970
+ "future version." , FutureWarning , stacklevel = 2 )
2950
2971
new_data = self ._data .add_suffix (suffix )
2951
2972
return self ._constructor (new_data ).__finalize__ (self )
2952
2973
0 commit comments