@@ -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,9 @@ 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
2932
+ similar instead.
2933
+
2925
2934
Concatenate prefix string with panel items names.
2926
2935
2927
2936
Parameters
@@ -2931,13 +2940,21 @@ def add_prefix(self, prefix):
2931
2940
Returns
2932
2941
-------
2933
2942
with_prefix : type of caller
2943
+
2944
+ See Also:
2945
+ ---------
2946
+ rename : Alter axes labels.
2934
2947
"""
2948
+ warnings .warn ("'.add_prefix' is deprecated and will be removed in a "
2949
+ "future version. Use '.rename' instead" ,
2950
+ FutureWarning , stacklevel = 2 )
2935
2951
new_data = self ._data .add_prefix (prefix )
2936
2952
return self ._constructor (new_data ).__finalize__ (self )
2937
2953
2938
2954
def add_suffix (self , suffix ):
2939
2955
"""
2940
- Concatenate suffix string with panel items names.
2956
+ DEPRECATED: Use ``obj.rename(columns=lambda x: 'prefix_'+str(x))`` or
2957
+ similar instead. Concatenate suffix string with panel items names.
2941
2958
2942
2959
Parameters
2943
2960
----------
@@ -2946,7 +2963,13 @@ def add_suffix(self, suffix):
2946
2963
Returns
2947
2964
-------
2948
2965
with_suffix : type of caller
2966
+
2967
+ See Also:
2968
+ ---------
2969
+ rename : Alter axes labels.
2949
2970
"""
2971
+ warnings .warn ("'add_suffix' is deprecated and will be removed in a "
2972
+ "future version." , FutureWarning , stacklevel = 2 )
2950
2973
new_data = self ._data .add_suffix (suffix )
2951
2974
return self ._constructor (new_data ).__finalize__ (self )
2952
2975
0 commit comments