Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Pandas DataFrame add_prefix() Method

❮ DataFrame Reference


Example

Insert "person_" before each column label:

import pandas as pd

data = {
  "age": [50, 40, 30, 40, 20, 10, 30],
  "qualified": [True, False, False, False, False, True, True]
}
df = pd.DataFrame(data)

newdf = df.add_prefix("person_")
Try it Yourself »

Definition and Usage

The add_prefix() method inserts the specified value in front of the column label.

To add a value after the column label, use the  add_suffix() method.


Syntax

dataframe.add_prefix(prefix)

Parameters

Parameter Description
prefix Required. A string to add before the column labels

Return Value

A DataFrame with the result.

This method does not change the original DataFrame.


❮ DataFrame Reference