Tutorials References Exercises Sign Up Menu
Create Website Get Certified Pro

Pandas DataFrame add_prefix() Method

❮ DataFrame Reference


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.




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