pandas.DataFrame.add_prefix() Function with example in python

Spread the love

pandas.DataFrame.add_prefix(): This function prefix labels with string prefix.

Synatx: DataFrame.add_prefix(prefix)

For Series, the row labels are prefixed. For DataFrame, the column labels are prefixed.

prefix : str
The string to add before each label.

Series or DataFrame
New Series or DataFrame with updated labels.

import pandas as pd df = pd.DataFrame({'a': [1, 2, 2], 'b': [30, 40, 50]}) print(df.add_prefix('test'))


   testa  testb
0      1     30
1      2     40
2      2     50



Leave a Reply

Your email address will not be published. Required fields are marked *