The add_suffix()
function in Pandas is used to suffix the columns of a DataFrame.
The add_suffix()
function takes the syntax shown below:
DataFrame.add_suffix(suffix)
The add_suffix()
function takes a single required parameter value suffix
, which represents the string to be prefixed or added after each label.
The add_suffix()
function returns a new DataFrame with prefixed/updated columns.
Let's look at the code below:
# A code to illustrate the add_suffix() function in Pandas # imporing the pandas library import pandas as pd # creating a dataframe df = pd.DataFrame({'Name': ["Theo", "John", "Mosh"], 'Height': [1.83, 1.80, 1.78]}) print(df) # adding prefixes to the columns of the dataframe print(df.add_suffix("_column"))
df
.df
."_column"
to the columns of df
. We print the result to the console.RELATED TAGS
CONTRIBUTOR
View all Courses