Skip to content

Commit 7c5bae3

Browse files
astrastefaniaTomAugspurger
authored andcommitted
DOC: update docstring of pandas.Series.add_prefix docstring (#20313)
1 parent c6eec25 commit 7c5bae3

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

pandas/core/generic.py

+44-3
Original file line numberDiff line numberDiff line change
@@ -2934,15 +2934,56 @@ def _update_inplace(self, result, verify_is_copy=True):
29342934

29352935
def add_prefix(self, prefix):
29362936
"""
2937-
Concatenate prefix string with panel items names.
2937+
Prefix labels with string `prefix`.
2938+
2939+
For Series, the row labels are prefixed.
2940+
For DataFrame, the column labels are prefixed.
29382941
29392942
Parameters
29402943
----------
2941-
prefix : string
2944+
prefix : str
2945+
The string to add before each label.
29422946
29432947
Returns
29442948
-------
2945-
with_prefix : type of caller
2949+
Series or DataFrame
2950+
New Series or DataFrame with updated labels.
2951+
2952+
See Also
2953+
--------
2954+
Series.add_suffix: Suffix labels with string `suffix`.
2955+
2956+
Examples
2957+
--------
2958+
>>> s = pd.Series([1, 2, 3, 4])
2959+
>>> s
2960+
0 1
2961+
1 2
2962+
2 3
2963+
3 4
2964+
dtype: int64
2965+
2966+
>>> s.add_prefix('item_')
2967+
item_0 1
2968+
item_1 2
2969+
item_2 3
2970+
item_3 4
2971+
dtype: int64
2972+
2973+
>>> df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
2974+
>>> df
2975+
A B
2976+
0 1 3
2977+
1 2 4
2978+
2 3 5
2979+
3 4 6
2980+
2981+
>>> df.add_prefix('col_')
2982+
col_A col_B
2983+
0 1 3
2984+
1 2 4
2985+
2 3 5
2986+
3 4 6
29462987
"""
29472988
new_data = self._data.add_prefix(prefix)
29482989
return self._constructor(new_data).__finalize__(self)

0 commit comments

Comments
 (0)