The add_prefix()
function in pandas is used to prefix the rows of a Series
object.
A Series
object is a one-dimensional data structure used to hold integers, strings, and other python objects.
The add_prefix()
function takes the syntax shown below:
DataFrame.add_prefix(str)
The add_prefix()
function takes a single required parameter value, str
, representing the string to be prefixed or added before each label.
The add_prefix()
function returns a new dataframe with prefixed columns.
# A code to illustrate the add_prefix() function in Pandas# imporing the pandas libraryimport pandas as pd# creating a dataframedf = pd.Series([10, 20, 30, 40, 50])print(df)# adding prefixes to the columns of the dataframeprint(df.add_prefix("row_"))
df
.df
.row_
to the row labels of the df
. We print the result to the console.