Pandas DataFrame add_prefix() Method
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.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.