- API reference
- DataFrame
- pandas.DataF...
pandas.DataFrame.add_prefix#
- DataFrame.add_prefix(prefix,axis=None)[source]#
Prefix labels with stringprefix.
For Series, the row labels are prefixed.For DataFrame, the column labels are prefixed.
- Parameters:
- prefixstr
The string to add before each label.
- axis{0 or ‘index’, 1 or ‘columns’, None}, default None
Axis to add prefix on
Added in version 2.0.0.
- Returns:
- Series or DataFrame
New Series or DataFrame with updated labels.
See also
Series.add_suffix
Suffix row labels with stringsuffix.
DataFrame.add_suffix
Suffix column labels with stringsuffix.
Examples
>>>s=pd.Series([1,2,3,4])>>>s0 11 22 33 4dtype: int64
>>>s.add_prefix('item_')item_0 1item_1 2item_2 3item_3 4dtype: int64
>>>df=pd.DataFrame({'A':[1,2,3,4],'B':[3,4,5,6]})>>>df A B0 1 31 2 42 3 53 4 6
>>>df.add_prefix('col_') col_A col_B0 1 31 2 42 3 53 4 6
On this page