In this tutorial, we will look at how to add a suffix to the column names in a pandas dataframe with the help of some examples.
How to add a suffix to each column name of a pandas dataframe?

You can use the built-in pandas dataframe add_suffix()
function to add a suffix to the column names of a dataframe. Pass the suffix string as an argument.
The following is the syntax –
# add suffix to column names df = df.add_suffix(suffix)
It returns the dataframe (or series if applied on a pandas series) with the updated labels.
Alternatively, you can use a list comprehension to create a list of new column names with the suffix added.
Examples
Let’s now look at some examples of using the above methods.
First, we will create a dataframe that we will be using throughout this tutorial.
import pandas as pd # sales data data = { "Apple": [10, 12, 13, 9, 15], "Mango": [12, 11, 19, 18, 13] } # create pandas dataframe df = pd.DataFrame(data) # display the dataframe df
Output:
Introductory ⭐
- Harvard University Data Science: Learn R Basics for Data Science
- Standford University Data Science: Introduction to Machine Learning
- UC Davis Data Science: Learn SQL Basics for Data Science
- IBM Data Science: Professional Certificate in Data Science
- IBM Data Analysis: Professional Certificate in Data Analytics
- Google Data Analysis: Professional Certificate in Data Analytics
- IBM Data Science: Professional Certificate in Python Data Science
- IBM Data Engineering Fundamentals: Python Basics for Data Science
Intermediate ⭐⭐⭐
- Harvard University Learning Python for Data Science: Introduction to Data Science with Python
- Harvard University Computer Science Courses: Using Python for Research
- IBM Python Data Science: Visualizing Data with Python
- DeepLearning.AI Data Science and Machine Learning: Deep Learning Specialization
Advanced ⭐⭐⭐⭐⭐
- UC San Diego Data Science: Python for Data Science
- UC San Diego Data Science: Probability and Statistics in Data Science using Python
- Google Data Analysis: Professional Certificate in Advanced Data Analytics
- MIT Statistics and Data Science: Machine Learning with Python - from Linear Models to Deep Learning
- MIT Statistics and Data Science: MicroMasters® Program in Statistics and Data Science
🔎 Find Data Science Programs 👨💻 111,889 already enrolled
Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.

Here, we created a dataframe with information about the day-level sale volume of some fruits at a local grocery store. The dataframe has the following columns – “Apple” and “Mango” which represent the sale of the respective fruit in kilograms.
Example 1 – Add suffix to column names using add_suffix()
Let’s now add the suffix “_Kg” to the column names using the pandas dataframe add_suffix()
function.
# add suffix to column names df = df.add_suffix("_Kg") # display the dataframe df
Output:

The column names of the dataframe are now suffixed with “_Kg”.
Example 2 – Add suffix to column names using a list comprehension
Alternatively, you can use a list comprehension to create a new list of column names with the suffix added.
For example, let’s take the same use-case from the above example. We will reset the column names to their original values and then add the suffix to column names using a list comprehension.
# reset column names to original values df.columns = ["Apple", "Mange"] # add suffix to column names df.columns = [str(col)+"_Kg" for col in df.columns] # display the dataframe df
Output:

We get the same result as above.
You can further simplify this step by directly adding the suffix to df.columns
.
# reset column names to original values df.columns = ["Apple", "Mango"] # add suffix to column names df.columns = df.columns + "_Kg" # display the dataframe df
Output:

We get the same result as above. The suffix “_Kg” is added to each column name in the dataframe.
Summary
In this tutorial, we looked at how to add a suffix to each column name of a pandas dataframe. The following are the key takeaways.
- You can use the pandas dataframe built-in
add_suffix()
function to add a suffix to the column names. - Alternatively, you can use a list comprehension to modify the column names with the added suffix.
You might also be interested in –
- Pandas – Add Prefix to Column Names
- Pandas – Remove Spaces From Column Names
- Pandas – Change Column Names to Uppercase
- Pandas – Change Column Names to Lowercase
- Remove Prefix or Suffix from Pandas Column Names
- Get Column Names as List in Pandas DataFrame
- Pandas – Rename Column Names
Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.