Skip to content

Commit 281ce99

Browse files
astrastefaniaTomAugspurger
authored andcommitted
DOC: update the pandas.Series.add_suffix docstring (#20315)
1 parent 7c5bae3 commit 281ce99

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

pandas/core/generic.py

+47-4
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,8 @@ def add_prefix(self, prefix):
29512951
29522952
See Also
29532953
--------
2954-
Series.add_suffix: Suffix labels with string `suffix`.
2954+
Series.add_suffix: Suffix row labels with string `suffix`.
2955+
DataFrame.add_suffix: Suffix column labels with string `suffix`.
29552956
29562957
Examples
29572958
--------
@@ -2990,15 +2991,57 @@ def add_prefix(self, prefix):
29902991

29912992
def add_suffix(self, suffix):
29922993
"""
2993-
Concatenate suffix string with panel items names.
2994+
Suffix labels with string `suffix`.
2995+
2996+
For Series, the row labels are suffixed.
2997+
For DataFrame, the column labels are suffixed.
29942998
29952999
Parameters
29963000
----------
2997-
suffix : string
3001+
suffix : str
3002+
The string to add after each label.
29983003
29993004
Returns
30003005
-------
3001-
with_suffix : type of caller
3006+
Series or DataFrame
3007+
New Series or DataFrame with updated labels.
3008+
3009+
See Also
3010+
--------
3011+
Series.add_prefix: Prefix row labels with string `prefix`.
3012+
DataFrame.add_prefix: Prefix column labels with string `prefix`.
3013+
3014+
Examples
3015+
--------
3016+
>>> s = pd.Series([1, 2, 3, 4])
3017+
>>> s
3018+
0 1
3019+
1 2
3020+
2 3
3021+
3 4
3022+
dtype: int64
3023+
3024+
>>> s.add_suffix('_item')
3025+
0_item 1
3026+
1_item 2
3027+
2_item 3
3028+
3_item 4
3029+
dtype: int64
3030+
3031+
>>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
3032+
>>> df
3033+
A B
3034+
0 1 3
3035+
1 2 4
3036+
2 3 5
3037+
3 4 6
3038+
3039+
>>> df.add_suffix('_col')
3040+
A_col B_col
3041+
0 1 3
3042+
1 2 4
3043+
2 3 5
3044+
3 4 6
30023045
"""
30033046
new_data = self._data.add_suffix(suffix)
30043047
return self._constructor(new_data).__finalize__(self)

0 commit comments

Comments
 (0)